-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
42 lines (34 loc) · 1.07 KB
/
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
39
40
41
42
// import { tokenize } from "./frontend/lexer.ts";
import Parser from "./frontend/parser.ts";
import Environment, { setupGlobalEnv } from "./runtime/environment.ts";
import { evaluate } from "./runtime/interpreter.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);
console.log("program: ",program)
// const result = evaluate(program, env);
// console.log(result)
}
function repl () {
const parser = new Parser();
const env = setupGlobalEnv();
console.log("\nRepl v0.1");
while (true) {
const input = prompt ("> ");
//check for no user input or exit keyword.
if(!input || input.includes("exit")){
Deno.exit(1);
}
const program = parser.produceAST(input);
// for (const token of tokenize(input)) {
// console.log("token: ", token)
// }
// console.log("ast : ", program)
const result = evaluate(program, env);
console.log("\n",result);
}
}