-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.cpp
More file actions
27 lines (24 loc) · 708 Bytes
/
repl.cpp
File metadata and controls
27 lines (24 loc) · 708 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
#include <iostream>
#include <stdexcept>
#include "interpreter.h"
#include "environment.h"
#include "ast.h"
using namespace std;
int main() {
Environment env("global");
Interpreter intr(&env);
cout << "Alyssa P. Hacker's LISP REPL" << endl;
cout << ">> ";
string line;
while (std::getline(cin, line)) {
if (line.empty()) { cout << ">> "; continue; }
try {
SExpr result = intr.eval(line);
cout << "\033[0;32m" << toString(result) << "\033[0m" << endl;
} catch (const std::exception &e) {
cout << "\033[1;31m" << e.what() << "\033[0m" << endl;
}
cout << ">> ";
}
cout << endl << "LOGOUT" << endl;
}