My TypeScript implementation of an interpreter for the Lox programming language, based on the fantastic book Crafting Interpreters. I have tried to stick closely to the original code, i.e., to implement the Java code in TypeScript, including classes, visitor pattern, and so on.
To get started, clone the repository:
git clone https://github.com/bpetermann/ts-lox.git
cd ts-loxThen, install dependencies and build the project:
npm run build:fresh // Installs dependencies and builds the projectFinally, start the REPL (Read-Eval-Print Loop):
npm run start // Starts the REPLor pass a .lox file as an argument
npm run start <filename>.lox>> fun fib(n) {
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
>> fib(30);The following command executes all Jest test suites. At the moment, there are not so many tests; the ones included are mostly code snippets from the book. I will expand this.
npm run testThe following command executes the benchmark test contained in the book, the recursive Fibonacci function from above with the input of 40.
npm run benchmark