An open API service indexing awesome lists of open source software.

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

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
```