-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
38 lines (30 loc) · 1002 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
36
37
38
import Parser from "./frontend/parser.ts";
import { createGlobalEnv } from "./runtime/environment.ts";
import { evaluate } from "./runtime/interpreter.ts";
run("./test.txt");
async function run(filename: string) {
const parser = new Parser();
const env = createGlobalEnv();
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 = createGlobalEnv();
// INITIALIZE Language
console.log("\nCustom Language v0.1");
// Continue Until User Stops Or Types `exit`
while (true) {
const input = prompt("> ");
// Check for no user input or exit keyword.
if (!input || input.includes("exit")) {
Deno.exit(1);
}
// Produce AST From sourc-code
const program = parser.produceAST(input);
const result = evaluate(program, env);
console.log(result);
}
}