Browse Source

remove namespace errors

canon
Hazel Levine 3 years ago
parent
commit
d528a72d21
  1. BIN
      bin/bfi
  2. BIN
      build/lex.o
  3. BIN
      build/main.o
  4. BIN
      build/read.o
  5. 4
      src/error.hpp
  6. 8
      src/lex.cpp
  7. 6
      src/lex.hpp
  8. 28
      src/main.cpp
  9. 16
      src/read.cpp
  10. 47
      src/read.hpp

BIN
bin/bfi

BIN
build/lex.o

BIN
build/main.o

BIN
build/read.o

4
src/error.hpp

@ -2,8 +2,6 @@
#include <exception>
using namespace std;
enum class ErrType {
Success,
BracketMismatch,
@ -11,7 +9,7 @@ enum class ErrType {
Something
};
class ParseExcept: public exception {
class ParseExcept: public std::exception {
public:
ErrType err;

8
src/lex.cpp

@ -7,14 +7,12 @@
#include "error.hpp"
#include "lex.hpp"
using namespace std;
void Lexer::printCode() {
cout << bf << endl;
std::cout << bf << std::endl;
}
vector<OpCode> Lexer::lexCode() {
vector<OpCode> v;
std::vector<OpCode> Lexer::lexCode() {
std::vector<OpCode> v;
for (auto c : bf) {
switch(c) {

6
src/lex.hpp

@ -8,9 +8,7 @@
#include "brainfuck.hpp"
#include "error.hpp"
using namespace std;
typedef string BFProgram;
typedef std::string BFProgram;
class Lexer {
public:
@ -23,7 +21,7 @@ public:
}
void printCode();
vector<OpCode> lexCode();
std::vector<OpCode> lexCode();
private:
BFProgram bf;
};

28
src/main.cpp

@ -1,27 +1,29 @@
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "brainfuck.hpp"
#include "error.hpp"
#include "lex.hpp"
#include "read.hpp"
using namespace std;
std::string getFile(std::string filename) {
std::ifstream file{filename.c_str()};
std::stringstream ss;
ss << file.rdbuf();
return ss.str();
}
int main(int argc, char* argv[]) {
std::vector<string> argList;
for (int i = 0; i < argc; i++) {
argList.push_back(argv[i]);
std::vector<std::string> args{argv + 1, argv + argc};
if (args.size() == 0) {
return 1;
}
if (argc == 2) { // must have only 1 arg: file
Reader r(argList[1]);
Lexer lex(r.getFile());
Lexer lex{getFile(args[0])};
vector<OpCode> v = lex.lexCode();
std::vector<OpCode> v = lex.lexCode(); // this works, yay
return 0;
} else {
return 1;
}
return 0;
}

16
src/read.cpp

@ -1,16 +0,0 @@
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "read.hpp"
using namespace std;
void Reader::printFile() {
cout << contents << endl;
}
string Reader::getFile() {
return contents;
}

47
src/read.hpp

@ -1,47 +0,0 @@
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <streambuf>
#include <string>
#include "error.hpp"
using namespace std;
class Reader {
public:
Reader(void) {
throw ParseExcept(ErrType::NoInput);
}
Reader(string filename) {
if (filename == "-") { // stdin
for (string line; std::getline(cin, line);) {
if (line != "done.") {
contents.append(line);
} else {
break;
}
}
} else {
ifstream code(filename);
if (!code) {
throw ParseExcept(ErrType::NoInput);
} else {
std::string str((std::istreambuf_iterator<char>(code)),
std::istreambuf_iterator<char>());
contents = str;
}
code.close();
}
}
void printFile();
string getFile();
private:
string contents = "";
};
Loading…
Cancel
Save