-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (35 loc) · 1.08 KB
/
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 "ast.h"
#include "semantic/semantic.h"
#include "codegen/codegen.h"
#include "./utils/io.hpp"
#include "./parser/parser.tab.h"
#include <FlexLexer.h>
#include <iostream>
#include <filesystem>
yyFlexLexer* lexer;
PackageAST* Root;
int main(int argc, char** argv) {
yydebug = 0; // set 1 to debug bison
std::istringstream iStringStream;
if (argc > 1) {
iStringStream = StreamLinesFromFile(argv[1]);
if (!iStringStream.rdbuf()->in_avail()) {
std::cout << "file is empty or not found" << std::endl;
return 1;
}
} else {
std::cout << "no go files listed" << std::endl;
return 1;
}
lexer = new yyFlexLexer(iStringStream, std::cout);
yyparse();
auto semantic = new Semantic(Root);
bool isSematicOk = semantic->analyze();
CreateDotFile(Root);
if (isSematicOk) {
// Only package class
std::unordered_map<std::string, ClassEntity*> classes = { { "$" + Root->packageName, semantic->packageClass} };
Generator(classes).generate();
}
return 0;
}