This repository was archived by the owner on Dec 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (43 loc) · 1.37 KB
/
main.cpp
File metadata and controls
51 lines (43 loc) · 1.37 KB
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 "lexer.hpp"
#include "baseGramma.hpp"
#include "LR1.hpp"
#include "utils.hpp"
#include "tree.hpp"
#include <vector>
#include <list>
#include <string>
#include <fstream>
#include <iostream>
int main() {
const std::vector<std::string> Terminals = {
"#", "$", "int", "float", "double", "void", "if", "else",
"while", "return", "+", "-", "*", "/", "=", "<", ">",
"<=", ">=", "==", "!=", "+=", "-=", "*=", "/=",
"(", ")", "{", "}", ";", ",", "<ID>", "<INT>"
};
std::string to_lex = read_file("code.txt");
//std::cout << to_lex << std::endl;
//std::cout << "int main() { int a = 1; if ( a == 1 ) { a += 1; } return 0;}" << std::endl;
Lexer lex(Terminals);
std::vector<Token> lex_res = lex.parse(to_lex);
std::list<Token> token_stream(lex_res.begin(), lex_res.end());
/* debug
for (const auto& elem : token_stream) {
std::cout << elem.id << "," << elem.line_number << ","
<< elem.name << ", " << elem.value << std::endl;
}
*/
LR1Gramma g;
g.readGramma("gramma.txt");
g.calcuAllTerminalFirstSet();
g.calcuAllUnterminalFirstSet();
g.calcuLR0Derivations();
g.calcuLR1Derivations();
g.calcuActionTable();
g.calcuGotoTable();
tree T(
token_stream, g.derivation_set,
g.action_table, g.goto_table
);
T.print_tree();
}