don't need the tests any more
parent
6652c0f970
commit
accf1fd1dd
@ -1,51 +0,0 @@
|
||||
import { evaluate } from './interpreter'
|
||||
import type { Env } from './env'
|
||||
import { tokenize } from './lexer'
|
||||
import { Parser } from './parser'
|
||||
import { prettyPrint } from './ast';
|
||||
|
||||
function e(str: string) {
|
||||
console.log(str);
|
||||
const tokens = tokenize(str);
|
||||
console.log(tokens);
|
||||
const p = new Parser(tokens, str);
|
||||
const ast = p.parse();
|
||||
console.log(ast);
|
||||
console.log(prettyPrint(ast));
|
||||
const env: Env = new Map();
|
||||
console.log(evaluate(ast, env, str));
|
||||
}
|
||||
|
||||
e('add1 = (x \\ x + 1); add1 3');
|
||||
e('sum = x y \\ x + y; sum 5 3');
|
||||
e('[1, 2, 3]');
|
||||
e('c = 5; { a = 3, b = c }');
|
||||
e('rec = { a = 3, b = 5 }; rec.a');
|
||||
e('rec = { a = 3, b = 5 }; rec{ a = 10 }');
|
||||
e('add1 = (x \\ x + 1); 3 > add1');
|
||||
e('[1, 2] & [3, 4]');
|
||||
e('"abc" & "def"');
|
||||
e('head = list \\ list | [x, _] \\ Some x | [] \\ None; head');
|
||||
e('n = 5; n | 5 \\ "five" | _ \\ "other"');
|
||||
e('list = [1, 2, 3]; list | [x, y, z] \\ x + y + z');
|
||||
e('point = {x = 5, y = 10}; point | {x = px, y = py} \\ px + py');
|
||||
e('some5 = Some 5; some5');
|
||||
|
||||
e(`factorial = n \\ n
|
||||
| 0 \\ 1
|
||||
| n \\ n * factorial (n - 1);
|
||||
|
||||
factorial 5`)
|
||||
|
||||
e(`
|
||||
factorial = n \\ n
|
||||
| 0 \\ 1
|
||||
| n \\ n * factorial (n - 1);
|
||||
|
||||
fib = n \\ n
|
||||
| 0 \\ 0
|
||||
| 1 \\ 1
|
||||
| n \\ fib (n - 1) + fib (n - 2);
|
||||
|
||||
[ fib 10, factorial 5 ];
|
||||
`);
|
||||
Loading…
Reference in New Issue