-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (38 loc) · 889 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "interpreter.hpp"
#include "compiler.hpp"
enum MODE {
INTERPRET,
COMPILE
};
int main(int argc, char **argv) {
std::string input;
MODE mode;
if (argc == 3) {
if (argv[1][0] == 'i') {
mode = INTERPRET;
} else {
mode = COMPILE;
}
std::string f_name(argv[2]);
std::ifstream t(f_name);
std::stringstream buffer;
buffer << t.rdbuf();
input = buffer.str();
} else {
std::cerr << "usage: " << argv[0] << " i|c file.bf\n";
std::exit(1);
}
if (mode == INTERPRET) {
BF::Interpreter inter;
inter.interpret(input);
} else {
std::ofstream out ("a.c");
BF::Compiler comp (100000);
comp.compile(input, out);
}
return 0;
}