-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.cpp
More file actions
54 lines (39 loc) · 827 Bytes
/
repl.cpp
File metadata and controls
54 lines (39 loc) · 827 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
49
50
51
52
53
54
#include <iostream>
#include <string>
#include "./header/lexer.hpp"
#include "./header/parser.hpp"
#include "./header/evaluator.hpp"
// Read Evaluate Print Loop
void REPL()
{
const std::string PROMPT = ">> ";
Lexer lexer;
Parser parser;
Evaluator evaluator;
Environment *env = new Environment();
std::string line;
while (true)
{
std::cout << PROMPT;
std::getline(std::cin, line);
if (line.empty())
continue;
lexer.New(line);
parser.New(lexer);
Program *program = parser.ParseProgram();
if (parser.Errors().size())
for (std::string error : parser.Errors())
std::cout << error << std::endl;
else {
Object *obj = evaluator.Eval(program, env);
if (obj != __NULL)
std::cout << obj->inspect() << std::endl;
}
parser.resetErrors();
}
}
int main()
{
REPL();
return 0;
}