-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (43 loc) · 934 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
#include "lexer.hpp"
#include "parser.hpp"
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
bool test_lexer = false;
bool with_file = false;
int main(int argc, char **argv) {
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-lex") == 0) {
test_lexer = true;
} else {
with_file = true;
}
}
std::istream *is;
if (!with_file) {
std::cerr << "no file input, input from stdin!" << std::endl;
is = &std::cin;
} else {
is = new std::ifstream(argv[argc - 1]);
}
SymbolTable sym_tab;
Lexer lexer(*is);
// test lexer
if (test_lexer) {
while (true) {
Token token = lexer.nextToken();
token.print(std::cout);
if (token.type == TERMINATE) {
std::cout << std::endl;
break;
}
}
exit(0);
}
Parser pars(lexer, sym_tab);
auto *prog = pars.parse();
std::cout << std::endl;
delete is;
return 0;
}