-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (61 loc) · 1.2 KB
/
main.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
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
68
69
70
71
72
73
74
75
76
#include <Tokenizer.h>
#include <Parser.h>
#include <Interpreter.h>
#include <iostream>
#include <exception>
#include <Exceptions.h>
#include <memory>
#include <queue>
#ifdef WITH_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
using namespace std;
using namespace JarJar;
auto output = queue<string>();
string getInput();
void print();
int main(int argc, char *argv[])
{
Interpreter *i = new Interpreter(&output);
while (true) {
try
{
string input = getInput();
if(input == "quit") break;
Tokenizer t = Tokenizer(input);
Parser p = Parser(t.getTokens());
i->interpert(p.eval());
print();
}
catch (const runtime_error &e)
{
cout << "Caught runtime error " << type(e) << endl;
cout << e.what() << endl;
}
}
delete i;
}
void print()
{
while(!output.empty())
{
cout << output.front() << endl;
output.pop();
}
}
string getInput()
{
#ifdef WITH_READLINE
char * line = readline(">");
add_history(line);
string input = line;
free(line);
return input;
#else
cout << ">";
string input;
getline(cin, input);
return input;
#endif
}