-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
27 lines (23 loc) · 858 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
import Parser from './src/frontend/parser.ts';
import Environment from './src/runtime/environtment.ts';
import { evaluate } from './src/runtime/interpreter.ts';
import { NumberVal } from './src/runtime/values.ts';
async function repl() {
const parser = new Parser();
const env = new Environment();
env.declareVar("x", { value: 312, type: "number" } as unknown as NumberVal);
while (true) {
const input = prompt("> nói gì đi ní:");
if (!input || input.includes("exit")) {
process.exit();
}
const program = parser.produceAST(input);
// console.log(JSON.stringify(program));
// for (let [key, value] of Object.entries(program)) {
// console.log(key, value);
// }
const result = evaluate(program, env);
console.log(result);
}
}
repl();