-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
31 lines (25 loc) · 879 Bytes
/
index.ts
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
import Parser from "./parser.ts";
import { evaluate } from "./interpreter.ts";
import Environment from "./environment.ts";
import { BooleanValue, NullValue } from "./values.ts";
repl();
async function repl() {
const parser = new Parser();
const env = new Environment();
env.declareVar("true", { value: true, type: "boolean" } as BooleanValue, true);
env.declareVar("false", { value: false, type: "boolean" } as BooleanValue, true);
env.declareVar("null", { value: "null", type: "null" } as NullValue, true);
while (true) {
const input = prompt("> ");
if (!input || input.includes("exit")) {
return;
}
try {
const ast = parser.buildAST(input);
const result = evaluate(ast, env);
console.log(result);
} catch (e) {
console.error(e);
}
}
}