-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.cpp
45 lines (37 loc) · 963 Bytes
/
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
37
38
39
40
41
42
43
44
45
// repl.h definitions
#include "repl.h"
void printParserErrors(Parser& p);
// REPL constructor
// EFFECTS: creates a REPL object
REPL::REPL(){
lexer = Lexer();
};
// Start the REPL
// EFFECTS: starts the REPL
void REPL::start(){
Environment env = Environment();
while(true){
std::cout << PROMPT;
std::string input;
std::getline(std::cin, input);
if(input == "")
return;
lexer = Lexer(input);
parser = Parser(&lexer);
Program* program = parser.parseProgram();
if(parser.errors.size() != 0){
printParserErrors(parser);
continue;
}
Object* evaluated = Eval(program, &env);
if(evaluated){
std::cout<<evaluated->inspect()<<"\n";
}
}
}
void printParserErrors(Parser& p){
std::cout<<"ERRORS:\n\tParser Errors:\n";
for(std::string error:p.errors){
std::cout<<"\t"<<error<<"\n";
}
}