-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
57 lines (52 loc) · 1.8 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
49
50
51
52
53
54
55
56
57
import Parser from './analysis/parser';
import * as readline from 'readline';
import { evaluate } from './synthesis/interpreter'
import Environment from './synthesis/environment';
import { MKBOOL, MKNUMBER, MKNULL, NumberVal } from './synthesis/values';
import * as fs from 'fs';
import { Call, Declaration, Member } from './analysis/ast';
readFromFile();
function readFromFile() {
const filename = './examples/example2.astro';
let content = fs.readFileSync(filename, 'utf8');
const parser = new Parser();
const env = new Environment();
const ast = parser.createAST(content);
console.log(content);
console.log(ast);
console.log((ast.body[0] as Declaration).value);
// console.log((ast.body[0] as Call).caller);
// console.log((ast.body[0] as Member).object);
// console.log((ast.body[0] as Member).property);
// console.log((ast.body[0] as Call).args);
// const result = evaluate(ast, env);
// console.log(result);
}
function repl() {
const parser = new Parser();
const env = new Environment();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
console.log("repl v0.1");
cmd(rl, parser, env);
// cmd line
function cmd(rl: readline.Interface, parser: Parser, env: Environment) {
rl.question('> ', (answer) => {
switch(answer) {
case 'exit':
rl.close();
process.exit();
case 'quit':
rl.close();
process.exit();
default:
const ast = parser.createAST(answer);
const result = evaluate(ast, env);
console.log(result);
}
cmd(rl, parser, env);
});
}
}