-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
48 lines (37 loc) · 1.16 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
43
44
45
46
47
48
import Parser from "./src/frontend/parser.ts";
import { setup_global_environment } from "./src/runtime/environment/environment.ts";
import { evaluate } from "./src/runtime/interpreter.ts";
const VERSION = "0.3"
const args = Deno.args
if (args.length > 1) {
throw Error(`Kmoet gen of 1 argument hebbe`)
}
if (args.length == 0) {
repl()
} else {
if (args[0] == "-v" || args[0] == "--version") {
console.log("KPT version", VERSION)
} else {
run(args[0])
}
}
async function run(filename: string){
const parser = new Parser()
const environment = setup_global_environment()
const input = await Deno.readTextFile(filename)
const program = parser.produce_ast(input)
evaluate(program, environment)
}
function repl() {
const parser = new Parser()
const environment = setup_global_environment()
console.log(`KPT v${VERSION}`)
while (true){
const input = prompt(">>")
if (!input || input.includes("deruit")) {
Deno.exit(0)
}
const program = parser.produce_ast(input)
evaluate(program, environment)
}
}