-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.ts
40 lines (32 loc) · 844 Bytes
/
repl.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
import Interpreter from "./src/interpreter";
import Readline from "node:readline";
class Repl {
private readline: Readline.Interface;
constructor() {
this.readline = Readline.createInterface({
input: process.stdin,
output: process.stdout
});
};
private recall(): void {
this.readline.question(">>> ", (answer) => {
let input = answer;
if (input === "exit") {
this.readline.close();
return
};
Interpreter.parser.setSource(input, false);
const nodes = Interpreter.parser.execute();
Interpreter.parser.reset();
Interpreter.walker.setSource = nodes;
Interpreter.walker.execute();
this.recall();
});
};
public execute(): void {
console.log("Golosina v1.0.0")
this.recall();
};
};
const repl = new Repl();
repl.execute();