https://github.com/bpetermann/ts-lox
Typescript interpreter for lox
https://github.com/bpetermann/ts-lox
interpreter nodejs parser scanner typescript
Last synced: 6 months ago
JSON representation
Typescript interpreter for lox
- Host: GitHub
- URL: https://github.com/bpetermann/ts-lox
- Owner: bpetermann
- Created: 2024-03-17T20:41:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T19:51:05.000Z (about 2 years ago)
- Last Synced: 2025-01-23T09:45:23.245Z (over 1 year ago)
- Topics: interpreter, nodejs, parser, scanner, typescript
- Language: TypeScript
- Homepage:
- Size: 209 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TypeScript Lox
My TypeScript implementation of an interpreter for the Lox programming language, based on the fantastic book [Crafting Interpreters](https://craftinginterpreters.com/). 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.
## โ๏ธ Installation
To get started, clone the repository:
```bash
git clone https://github.com/bpetermann/ts-lox.git
cd ts-lox
```
Then, install dependencies and build the project:
```js
npm run build:fresh // Installs dependencies and builds the project
```
## ๐ Start
Finally, start the REPL (Read-Eval-Print Loop):
```js
npm run start // Starts the REPL
```
or pass a .lox file as an argument
```js
npm run start .lox
```
## ๐ Usage Examples
```js
>> fun fib(n) {
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
>> fib(30);
```
## ๐งช Tests
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.
```js
npm run test
```
## Performance
The following command executes the benchmark test contained in the book, the recursive Fibonacci function from above with the input of 40.
```js
npm run benchmark
```