Interpreters · Weeks 1 to 28
Crafting Interpreters: a chapter-by-chapter study guide
About half a year building two complete interpreters for Lox, a small but real language with closures and classes. First jlox, a tree-walking interpreter in Java (chapters 1 to 13), then clox, a bytecode virtual machine in C with its own hash table and garbage collector (chapters 14 to 30). A chapter a week, next to two NeetCode problems. You type every line yourself. It is the most fun phase of the path and the one that changes how you see every language you use.
Every chapter
| Chapter | Part | Week | Time | Test suite |
|---|---|---|---|---|
| 1. Introduction | Welcome | 1 | 2 h | reading |
| 2. A Map of the Territory | Welcome | 1 | 2 h | reading |
| 3. The Lox Language | Welcome | 1 | 2 h | reading |
| 4. Scanning | jlox | 2 | 6 h | chap04_scanning |
| 5. Representing Code | jlox | 3 | 4 h | reading |
| 6. Parsing Expressions | jlox | 4 | 6 h | chap06_parsing |
| 7. Evaluating Expressions | jlox | 5 | 5 h | chap07_evaluating |
| 8. Statements and State | jlox | 6 | 6 h | chap08_statements |
| 9. Control Flow | jlox | 7 | 4 h | chap09_control |
| 10. Functions | jlox | 8 | 7 h | chap10_functions |
| 11. Resolving and Binding | jlox | 9 | 7 h | chap11_resolving |
| 12. Classes | jlox | 10 | 7 h | chap12_classes |
| 13. Inheritance | jlox | 11 | 5 h | chap13_inheritance |
| 14. Chunks of Bytecode | clox | 12 | 5 h | reading |
| 15. A Virtual Machine | clox | 13 | 5 h | reading |
| 16. Scanning on Demand | clox | 14 | 4 h | reading |
| 17. Compiling Expressions | clox | 15 | 7 h | chap17_compiling |
| 18. Types of Values | clox | 16 | 4 h | chap18_types |
| 19. Strings | clox | 17 | 5 h | chap19_strings |
| 20. Hash Tables | clox | 18 | 7 h | chap20_hash |
| 21. Global Variables | clox | 19 | 5 h | chap21_global |
| 22. Local Variables | clox | 20 | 6 h | chap22_local |
| 23. Jumping Back and Forth | clox | 21 | 5 h | chap23_jumping |
| 24. Calls and Functions | clox | 22 | 8 h | chap24_calls |
| 25. Closures | clox | 23 | 8 h | chap25_closures |
| 26. Garbage Collection | clox | 24 | 8 h | chap26_garbage |
| 27. Classes and Instances | clox | 25 | 6 h | chap27_classes |
| 28. Methods and Initializers | clox | 26 | 7 h | chap28_methods |
| 29. Superclasses | clox | 27 | 4 h | chap29_superclasses |
| 30. Optimization | clox | 28 | 6 h | chap30_optimization |
Each chapter links to its reading guide: what it builds, how to approach it, which challenges are worth doing, common traps and the official test suite that checks it. On cracked.guide a passing suite on GitHub Actions marks the chapter verified.
What you will be able to do
- Explain exactly what happens between typing code and it running: scanning, parsing, resolving, compiling, executing.
- Write a recursive descent parser and a Pratt parser for any expression language.
- Build a hash table, a bytecode VM, closures with upvalues and a mark-sweep garbage collector in C.
- Debug memory bugs in C with sanitizers instead of guessing.
Before you start
- Comfort with one programming language, including classes and recursion.
- Enough Java to read and write classes, interfaces and generics (see Week 0).
- Enough C for pointers, structs and malloc/free before chapter 14, where clox starts (see Week 0).
- A JDK, a C compiler, git and a public GitHub repo for verification.
Tips
- Type the code, do not paste it. The typing is where the learning happens.
- Run the official test suite for each chapter; cracked.guide verifies your repo the same way.
- Do challenges on a branch so semantic changes do not break the tests.
- Compile clox with -Wall -Wextra -fsanitize=address,undefined from the first C chapter.
Guides
- How to build an interpreterHow to build your own programming language interpreter: scanner, parser, evaluator, then a bytecode VM with a garbage collector, and the book that shows how.
- Crafting Interpreters study planHow long Crafting Interpreters takes (about 160 hours) and a 28-week, chapter-by-chapter plan for jlox and clox with hours per chapter and tests.
- jlox vs cloxjlox and clox, the two Lox interpreters in Crafting Interpreters, compared: design, speed, memory, difficulty, and whether you can skip one.
- Lox test suiteHow to run the official Crafting Interpreters test suite against your own jlox or clox: Dart setup, test.dart, chapter suites, and running it in CI.
Questions
How long does Crafting Interpreters take?
About 163 hours typing the code and doing some challenges, by the reading guides' budgets. The path gives it 28 weeks, a chapter a week next to two NeetCode problems.
Is Crafting Interpreters free?
Yes. The whole book is free to read at craftinginterpreters.com, and the source and test suite are on GitHub. Print and eBook editions support the author.
What languages does Crafting Interpreters use?
Java for jlox, the tree-walk interpreter in chapters 4 to 13, and C for clox, the bytecode VM in chapters 14 to 30.