-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (41 loc) · 926 Bytes
/
main.cpp
File metadata and controls
48 lines (41 loc) · 926 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <iterator>
#include <typeinfo>
#include <vector>
#include "expr.hpp"
#include "astcontext.hpp"
#include "eval.hpp"
#include "check.hpp"
#include "lexer.hpp"
#include "parser.hpp"
#include "stmt.hpp"
int main()
{
ASTContext context;
std::vector<Token*> Tokens;
keyword_table kw;
symbol_table sym;
bool quit = false;
while( !quit )
{
std::string input;
std::string line;
getline(std::cin, line);
input += line + '\n';
Lexer l ( input.begin(), input.end(), kw, sym );
Parser p( l, context );
stmt* s = p.Statement();
if( dynamic_cast<expr_stmt*>(s) )
{
expr_stmt* exst = dynamic_cast<expr_stmt*>( s );
std::cout << eval(exst->expression) << '\n';
}
else if( dynamic_cast<decl_stmt*>(s) )
{
decl_stmt* d = dynamic_cast<decl_stmt*>( s );
var_decl* v = dynamic_cast<var_decl*>( d->entity );
std::cout << eval(v->init) << '\n';
}
}
return 0;
}