the-super-tiny-compiler
:snowman: Possibly the smallest compiler ever
A single, heavily commented JavaScript file that teaches you how compilers work by implementing one from scratch, covering tokenizing, parsing, and code generation in a way that is intentionally tiny and easy to read.
The Super Tiny Compiler is a teaching resource written in JavaScript that walks you through how a compiler works. A compiler is a program that translates code written in one language into another — the tools you use every day (like the ones that turn modern JavaScript into code older browsers can run) are compilers. This project makes the concept approachable by implementing all the essential stages of a compiler in a single, heavily commented JavaScript file that is intentionally small and easy to read. The README acknowledges that compilers have a reputation for being intimidating, and the goal here is to show that the core ideas are actually straightforward once explained clearly. It is a learning tool, not a production-use library. Tests can be run with node test.js. Licensed under Creative Commons BY 4.0.
Where it fits
- Read through the commented source file to understand the tokenizing, parsing, and code generation stages of a real compiler.
- Use it as a teaching aid when explaining compiler fundamentals to students or junior developers at a study group or workshop.
- Fork it as a hands-on starting point for building a custom mini-language or domain-specific language as a learning project.