-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvar_ut.cpp
More file actions
67 lines (58 loc) · 1.38 KB
/
var_ut.cpp
File metadata and controls
67 lines (58 loc) · 1.38 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iterator>
#include <typeinfo>
#include <vector>
#include <list>
#include "expr.hpp"
#include "context.hpp"
#include "eval.hpp"
#include "check.hpp"
#include "lexer.hpp"
#include "parser.hpp"
#include "stmt.hpp"
#include "scope.hpp"
using stack = std::list<scope>;
using value_map = std::unordered_map<decl*, expr*>;
int main()
{
context context;
keyword_table kw;
symbol_table sym;
stack stk;
value_map vm;
// push the global scope
stk.emplace_front();
bool quit = false;
std::string input;
while( !quit )
{
std::string line;
getline(std::cin, line);
if( line == "quit" )
quit = true;
else
input += line + '\n';
// input = "var int x = 5; print 5;";
// input = "5 + 7;";
// 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 );
// ref_expr* h = new ref_expr( d->entity, v->m_init, context );
// std::cout << eval( *h ) << '\n';
// expr* n = new int_expr( 8, context );
// h->set_value( n );
// std::cout << eval( *h ) << '\n';
// }
// break;
}
lexer l ( input.begin(), input.end(), kw, sym );
parser p( l, context, stk, vm );
p.program();
return 0;
}