-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
49 lines (38 loc) · 1.13 KB
/
Copy pathmain.ts
File metadata and controls
49 lines (38 loc) · 1.13 KB
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
49
import Parser from "./frontend/parser.ts";
import {evaluate} from "./runtime/interpreter.ts";
import Environment, {createGlobalEnv} from "./runtime/environment.ts";
async function runFile() {
const parser = new Parser();
const env = createGlobalEnv();
console.log('Repl v0.1')
const input = await Deno.readTextFile('test.txt')
// check for no user input
if (!input || input.includes('exit')) {
Deno.exit(1)
}
// tokenize every character
const program = parser.produceAst(input);
// console.log(program);
// interpret every token that is getting created
const result = evaluate(program, env);
console.log(result)
}
function repl() {
const parser = new Parser();
const env = createGlobalEnv();
console.log('Repl v0.1')
while (true) {
const input = prompt('> ')
// check for no user input
if (!input || input.includes('exit')) {
Deno.exit(1)
}
// tokenize every character
const program = parser.produceAst(input);
console.log(program);
// interpret every token that is getting created
const result = evaluate(program, env);
console.log(result)
}
}
runFile()