A Monkey Interpreter made in Typescript and Bun.
Install dependencies
bun installTo run:
bun run index.tsTo test:
bun testMonkey is the programming language described in the book Writing an Interpreter in Go. You might call it an educational programming language, so production-ready interpreters aren’t typically expected—and this one is no exception. However, thanks to Bun, it does come with a few nice features:
- It can run directly without transpiling to JavaScript.
- It can create a standalone REPL executable.
This repository contains a TypeScript implementation of the process laid out in the book. Initially, it was using object-oriented programming. Once I got a working version, I decided to experiment further, and rewrote it. First in a more functional style, and then a full‑blown reactive flavour with Signux. Again, nothing production‑ready, just experiments that were fun to hack on.
- Lexer → plain JS generator (
for…of lexer()to get tokens). - Parser → a bunch of pure Pratt helpers that chew the generator.
- Evaluator → always was a pure function, so I left it mostly untouched.
- Same core but every piece talks through Signux events/stores.
- You still pull tokens, but you can also react to them — perfect for live‑coding UIs.
- The parser exposes both a reactive state and a Promise wrapper (
await parseProgram()).
Because:
- I wanted an excuse to practise FP/FRP in a tiny codebase.
- Generators keep memory low and make REPL streaming super easy.
- Signux lets me time‑travel debug the interpreter. Although this has not been implemented, the Lexer would allow it easily. Nerdy, but neat.