-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathata.cpp
55 lines (45 loc) · 1.33 KB
/
ata.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
52
53
54
55
#include "headers/lexer.hpp"
#include "headers/parser.hpp"
// test
int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Please provide a file";
exit(1);
}
std::cout << std::endl
<< "Reading from: " << argv[1] << std::endl;
std::ifstream mainFile(argv[1]);
std::stringstream buf;
char t;
while (mainFile.get(t))
buf << t;
std::string orgCode = buf.str();
std::cout << "The code is:" << std::endl
<< std::endl
<< orgCode << std::endl;
// create the lexer
Lexer lexer(orgCode);
std::vector<Token *> tokens = lexer.tokonize(); // create Tokens
std::cout << std::endl
<< "[*] Tokenize success!" << std::endl;
// print Tokens
// std::cout << std::endl
// << std::endl;
// int counter = 0;
// for (Token *t : tokens)
// {
// counter++;
// std::cout << counter << ". " << typeToString(t->TYPE) << ", " << t->VALUE << std::endl;
// }
// create the parser
Parser parser(tokens);
AST_NODE *root = parser.parse();
std::cout
<< "[*] Parsing success!, found: " << root->SUB_STATEMENTS.size() << " statements" << std::endl;
// end of code
std::cout << std::endl
<< "Compiling Success!!!" << std::endl;
return 0;
}