-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (27 loc) · 929 Bytes
/
Copy pathmain.cpp
File metadata and controls
33 lines (27 loc) · 929 Bytes
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
#include "antlr.cpp"
int main(int argc, const char *argv[])
{
ifstream file;
file.open(argv[1]);
if (file.bad() || file.fail())
{
throw runtime_error("Invalid file!");
}
// Generate parse tree
ANTLRInputStream input(file);
SinkedSeaLexer lexer(&input);
CommonTokenStream tokens(&lexer);
SinkedSeaParser parser(&tokens);
tree::ParseTree *tree = parser.file();
// Generate the AST that we'll use to actually run the program
SinkedSea::Visitor visitor;
SinkedSea::ThreadTree mainTree;
mainTree.child = visitor.visit(tree).as<shared_ptr<SinkedSea::CommandTree>>();
file.close();
// Start the program in another thread
mainTree.eval({});
// Wait until all threads have terminated until exiting
std::unique_lock<std::mutex> lk(SinkedSea::globalM);
SinkedSea::globalCV.wait(lk, [] { return SinkedSea::globalCount == 0; });
return 0;
}