This repository contains an Odin implementation of the code in Jack Crenshaw Let's Build a Compiler. If you find the original text hard to read, there is a nice MDBook version available here.
The original code is in Pascal and, as I was following along, I implemented it in Odin. The translation is as close to the original code as possible, not because this is the best style for Odin, but because it helps follow along. Odin is a imperative language which borrows a lot from Pascal and C, you should have no problem following along without learning the language first.
Where I had to deviate from the original code:
- I built a minimal Pascal library (in
pascal/pascal_lib.odin) for functions provided by the pascal compiler such asRead. - Because Odin test runner is multi-threaded, I had to remove the global state and move it into a
Compilerobject which is passed to each parsing procedure. - Also to be able to test, I needed to redirect the compiler input and output from
stdin/stdoutto astringand astrings.Builder(string buffer) respectively. This is wrapped into anIOobject in the Pascal pseudo-library and each PascalIOfunction uses it to determine how to direct the input and output streams.
If you want to compile the code, you will need to install the Odin compiler. There are releases for Windows, MacOs, and Linux.
I use The Just package manager to gather all my commands into one script (Justfile). The commands are self-explanatory if you don't want to use it, just look in Justfile.
You can install just with you favorite package manager (brew on macOs, scoop on Windows, your distro package manager on Linux).
There are Odin language server extensions for VSCode, vim, and Zed if you are interested.
The original text and code is copyrighted (c) 1988 Jack Crenshaw.
I couldn't find a license for the original work so I am releasing the Odin code under the Creative Common license. The Odin code is copyrighted (c) 2026 Robert Monnet.
The code can be found under the repository root.
compiler/compiler.odincontains the compiler.compiler/compiler_test.odincontains the compiler tests.interpreter/interpreter.odincontains the interpreter from chapter 4.interpreter/interpreter_test.odincontains the interpreter tests.pascal/pascal_lib.odincontains Odin emulation for the procedures from the original Pascal library.
Each chapter correspond to a git tag and can be retrieved by typing git checkout <chapter>.
01-Introduction02-Expression-Parsing03-More-Expressions04-Interpreters
If you plan to play with the code, the best way to keep your changes isolated to a chapter is to create your own branch: git checkout -b <review-chapter> <chapter>.