-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.cpp
36 lines (29 loc) · 1.08 KB
/
repl.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
// #include"parser.cpp"
#include<iostream>
#include"vm.cpp"
using namespace std;
#define MAX_INPUT_LENGTH 200
void repl() {
// auto constants = vector<unique_ptr<Object>>();
// auto globals = vector<unique_ptr<Object>>(globalsSize);
// auto symbolTable = SymbolTable();
// auto compiler = Compiler();
while (1) {
cout << "> ";
char input[MAX_INPUT_LENGTH];
cin.getline(input, MAX_INPUT_LENGTH, '\n');
Lexer l = Lexer(input);
Parser p = Parser(l);
auto program = Program();
int error = p.parseProgram(&program);
if (error) cout << "test failed due to error in parser..." << endl;
auto compiler = Compiler();
int err = compiler.compileProgram(&program);
if (err) cout << "test failed due to error in compiler..." << endl;
// auto bytecode = compiler.getByteCode();
auto vm = VM(compiler.getByteCode());
if (vm.run()) cout << "test failed due to error in vm..." << endl;
cout << vm.getLastPopped().get()->serialize() << endl;
// cin.clear();
}
};