-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
35 lines (28 loc) · 888 Bytes
/
main.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
32
33
34
35
import Parser from "./cmd/parser.ts";
import Environment from "./runtime/environment.ts";
import { setupGlobalEnv } from "./runtime/environment.ts";
import { evaluate} from "./runtime/interpreter.ts";
import { MAKE_NUMBER, MAKE_BOOL, MAKE_NULL } from "./runtime/values.ts";
// repl();
run('./test.txt')
async function run(filename: string) {
const parser = new Parser();
const env = setupGlobalEnv();
const input = await Deno.readTextFile(filename);
const program = parser.produceAst(input);
const result = evaluate(program, env);
console.log(result);
}
function repl() {
const parser = new Parser();
const env = setupGlobalEnv();
while (true) {
const input = prompt(">> ");
if (!input || input === "exit") {
break;
}
const program = parser.produceAst(input);
const result = evaluate(program, env);
console.log(result);
}
}