interpreting record update, and > (func application pipe thing). cleaning up main.ts test code
parent
59b718619c
commit
c44a6858ff
@ -1,39 +1,21 @@
|
|||||||
import { evaluate } from './interpreter'
|
import { evaluate } from './interpreter'
|
||||||
// import type { AST } from './ast'
|
|
||||||
import type { Env } from './env'
|
import type { Env } from './env'
|
||||||
import { tokenize } from './lexer'
|
import { tokenize } from './lexer'
|
||||||
import { Parser } from './parser'
|
import { Parser } from './parser'
|
||||||
import { prettyPrint } from './ast';
|
import { prettyPrint } from './ast';
|
||||||
|
|
||||||
// const env: Env = new Map();
|
function e(str: string) {
|
||||||
|
const tokens = tokenize(str);
|
||||||
|
const p = new Parser(tokens);
|
||||||
|
const ast = p.parse();
|
||||||
|
const env: Env = new Map();
|
||||||
|
console.log(str, tokens, prettyPrint(ast), evaluate(ast, env));
|
||||||
|
}
|
||||||
|
|
||||||
// const res = evaluate(ast, env);
|
e('add1 = (x \\ x + 1); add1 3');
|
||||||
|
e('sum = x y \\ x + y; sum 5 3');
|
||||||
// console.log(res);
|
e('[1, 2, 3]');
|
||||||
|
e('c = 5; { a = 3, b = c }');
|
||||||
const str = `
|
e('rec = { a = 3, b = 5 }; rec.a');
|
||||||
# This is a comment
|
e('rec = { a = 3, b = 5 }; rec{ a = 10 }');
|
||||||
double = x \\ x * 2
|
e('add1 = (x \\ x + 1); 3 > add1');
|
||||||
read_line! : Unit \\ String
|
|
||||||
`;
|
|
||||||
console.log(tokenize(str));
|
|
||||||
|
|
||||||
// const tokens = tokenize("x");
|
|
||||||
// const p = new Parser(tokens);
|
|
||||||
// console.log(p.parse());
|
|
||||||
|
|
||||||
// const tokens2 = tokenize("let x = (y) => 5 + y in x(3)");
|
|
||||||
// const tokens2 = tokenize("let x = 5 in x * 4");
|
|
||||||
// const tokens2 = tokenize("(x, y) => x + y");
|
|
||||||
// const tokens2 = tokenize('point { x = 3 }');
|
|
||||||
// const tokens2 = tokenize('add1 = (x \\ x + 1); add1 3');
|
|
||||||
// const tokens2 = tokenize('sum = x y \\ x + y; sum 5 3');
|
|
||||||
// const tokens2 = tokenize('[1, 2, 3]');
|
|
||||||
// const tokens2 = tokenize('c = 5; { a = 3, b = c }');
|
|
||||||
const tokens2 = tokenize('rec = { a = 3, b = 5 }; rec.a');
|
|
||||||
const p2 = new Parser(tokens2);
|
|
||||||
const ast3 = p2.parse();
|
|
||||||
console.log(ast3);
|
|
||||||
console.log(prettyPrint(ast3));
|
|
||||||
const env3: Env = new Map();
|
|
||||||
console.log(evaluate(ast3, env3));
|
|
||||||
|
|||||||
Loading…
Reference in New Issue