/
parser.cpp
51 lines (46 loc) · 1.27 KB
/
parser.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
50
51
#include "symbol.h"
#include "cfg.h"
#include "regex.h"
#include "grammar.h"
#include "lexer.h"
#include <sstream>
void regex_test() {
while(true) {
cout << "Input a regex: ";
string str;
cin >> str;
Regex_eval rgx(str, true);
while (true) {
cin >> str;
if (str == "n")
break;
if (str == "q")
return;
cout << (rgx.accept(str)?"Accept":"Reject") << endl;
}
}
}
string file_to_string(const char *filename) {
ifstream file(filename);
stringstream ss;
ss << file.rdbuf();
file.close();
return ss.str();
}
int main(int argc, char *argv[]) {
//regex_test();
/*
CFG<Parse_data> *cfg = read_grammar(ss.str());
if (cfg)
cout << endl << cfg->str() << endl << endl;
*/
SymbolTable *symtab = new SymbolTable();
Lexer<int> *lexer = read_lexer(file_to_string(argv[1]), symtab);
CFG<int> *cfg = read_grammar(file_to_string(argv[2]), symtab);
//cout << cfg->dfa->str() << endl << endl;
cfg->parse(lexer->lex(file_to_string(argv[3]), true, true), true);
// for (int i = 0; i < lexer->rules.size()-2; ++i) {
// cout << lexer->rules[i].regex.dfa->str() << endl;
// }
return 0;
}