-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.ts
More file actions
44 lines (40 loc) · 1011 Bytes
/
browser.ts
File metadata and controls
44 lines (40 loc) · 1011 Bytes
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
import { evaluate } from "./lib/eval";
import { tokenize } from "./lib/tokenise";
import { parse } from "./lib/parser";
console.log("Click the run button to run your eclisp program. :)");
const defaultInput = `(defn fibDp (n) (
(if (= n 0) (
0
) (if (= n 1) (
1
) (
(let a 0)
(let b 1)
(let i 2)
(while (<= i n) (
(let temp b)
(set b (+ a b))
(set a temp)
(set i (+ i 1))
))
(b)
)))
))
(for (let i 0) (<= i 100) (set i (+ i 1)) (
(print (fibDp i))
))
`;
const textBox = document.querySelector("textarea");
textBox.value = defaultInput;
function run() {
console.log("---RUNNING ECLISP PROGRAM---");
const tokens = tokenize(textBox.value);
const ast = parse(tokens);
evaluate(ast);
console.log("---DONE RUNNING ECLISP PROGRAM---");
}
const form = document.querySelector("form");
form.addEventListener("submit", e => {
e.preventDefault();
run();
});