repl.it
TypeScript

A toy programming langauge

fork
loading
Files
  • index.ts
  • definitions.ts
  • interpreter.ts
  • lexer.ts
  • parser.ts
  • tsconfig.json
index.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
import { lexer } from "./lexer";
import { parser } from "./parser";
import { inspect } from "util";
import { interpreter } from "./interpreter";

function evaluate(smol: string) {
    const tokens = lexer(smol);
    const ast = parser(tokens);
    interpreter(ast, {});
}

evaluate(`
    let x = 1;
    let y = 7;

    let do_math = |x, y| {
        let add = |a, b| { a + b };

        print("x + y:");
        print(add(x, y));

        if y > 3 {
            print("y is greater than 3");
        }
    };

    do_math(x, y);
`);
Fetching token
?