-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (37 loc) · 1.08 KB
/
main.cpp
File metadata and controls
49 lines (37 loc) · 1.08 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
//
// Created by maruf on 4/9/22.
//
#include <iostream>
#include "antlr4-runtime.h"
#include "parser/grootLexer.h"
#include "parser/grootParser.h"
#include "parser/grootBaseVisitor.h"
#include "visitor.h"
using namespace antlr4;
int main(int argc, const char *argv[])
{
std::ifstream stream;
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " <source file>" << std::endl;
}
stream.open(argv[1]);
if (!stream.is_open())
{
std::cerr << "Can not open input file " << argv[1] << std::endl;
}
ANTLRInputStream input(stream);
grootLexer lexer(&input);
CommonTokenStream tokens(&lexer);
grootParser parser(&tokens);
tree::ParseTree *tree = parser.prog();
std::shared_ptr<scope> top_scope = std::make_shared<scope>();
std::shared_ptr<grootVisitor> v = std::make_shared<visitor>(top_scope);
auto return_val = v->visit(tree);
auto result = reinterpret_cast<int_value *> (return_val.as<std::shared_ptr<value>>().get());
if (result)
{
std::cout << result->val_<< std::endl;
}
return 0;
}