more CG syntax. parsing the easy stuff
This commit is contained in:
parent
71237d0307
commit
1ed325e98b
3 changed files with 204 additions and 82 deletions
39
src/main.ts
39
src/main.ts
|
|
@ -1,31 +1,10 @@
|
|||
import { evaluate } from './interpreter'
|
||||
import type { AST } from './ast'
|
||||
import type { Env } from './env'
|
||||
// import { evaluate } from './interpreter'
|
||||
// import type { AST } from './ast'
|
||||
// import type { Env } from './env'
|
||||
import { tokenize } from './lexer'
|
||||
import { Parser } from './parser'
|
||||
|
||||
const ast: AST = {
|
||||
kind: 'binaryop',
|
||||
operator: '+',
|
||||
left: {
|
||||
kind: 'literal',
|
||||
value: { kind: 'int', value: 1 }
|
||||
},
|
||||
right: {
|
||||
kind: 'binaryop',
|
||||
operator: '*',
|
||||
left: {
|
||||
kind: 'literal',
|
||||
value: { kind: 'int', value: 2 }
|
||||
},
|
||||
right: {
|
||||
kind: 'literal',
|
||||
value: { kind: 'int', value: 3 }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const env: Env = new Map();
|
||||
// const env: Env = new Map();
|
||||
|
||||
// const res = evaluate(ast, env);
|
||||
|
||||
|
|
@ -42,13 +21,13 @@ console.log(tokenize(str));
|
|||
// 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 = (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('[1, 2, 3]');
|
||||
const p2 = new Parser(tokens2);
|
||||
const ast3 = p2.parse();
|
||||
const env3: Env = new Map();
|
||||
console.log(ast3);
|
||||
console.log(evaluate(ast3, env3));
|
||||
*/
|
||||
// const env3: Env = new Map();
|
||||
// console.log(ast3);
|
||||
// console.log(evaluate(ast3, env3));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue