-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.cpp
More file actions
54 lines (50 loc) · 1.35 KB
/
Copy pathrepl.cpp
File metadata and controls
54 lines (50 loc) · 1.35 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
#include "repl.h"
#include "evaluator.h"
#include <memory>
#include <string>
#include <iostream>
using namespace std;
namespace repl {
const char* MONKEY_FACE = R"(
',
.-`-,\__
."` `,
.'_. ._ `;.
__ / ` ` `.\ .--.
/--,| 0) 0) )`_.-,)
| ;.-----.__ _-'); /
'--./ `.`/ `"`
: '` |.
| \ / //
\ '---' /'
`------' \
_/ `--...
__
)";
const string PROMPT = ">>> ";
void start(){
string input;
auto environment = std::make_unique<object::Environment>(nullptr);
while(true){
cout << PROMPT;
getline(cin, input);
lexer::Lexer l(input);
auto p = parser::Parser(l);
auto program = p.parse_program();
if(!p.errors.empty()){
std::cout << MONKEY_FACE << std::endl;
std::cerr << "parser errors:" << std::endl;
for(auto s: p.errors){
cout << "\t" << s << std::endl;
}
continue;
}
// std::cout << program->string() << std::endl;
auto evaluated =
eval::eval(std::move(program), environment);
if(evaluated != nullptr){
std::cout << evaluated->inspect() << std::endl;
}
}
}
} // namespace repl