-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
57 lines (41 loc) · 1.08 KB
/
index.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
49
50
51
52
53
54
55
56
57
import Parser from "./parser.ts";
import { evaluate } from "./runtime/interpreter.ts";
import Environment from "./runtime/env.ts";
// Create a parser
const parser: Parser = new Parser();
// Initialize a new environment
const env: Environment = new Environment(null);
// Main.simpl file
const read = () => {
const file = Deno.readTextFileSync("./main.simpl");
// Produce AST From source-code
const program = parser.parse(file);
// Print the AST
// console.log(program);
// Evaluate the program
const result = evaluate(program, env);
// Print the result
// console.log(result);
};
// Repl
const repl = () => {
for (;;) {
// Get the user input
const input = prompt(">> ");
// Check for no user input or exit keyword.
if (!input || input === "exit") break;
// Parse the input
const program = parser.parse(input);
// Print the AST
// console.log(program);
// Get the result
const result = evaluate(program, env);
// Print the result
// console.log(result);
}
};
// Read
read();
// Repl
repl();
// deno run --allow-read index.ts