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.

30chapters
28weeks
~163hours
23tested chapters

Every chapter

ChapterPartWeekTimeTest suite
1. IntroductionWelcome12 hreading
2. A Map of the TerritoryWelcome12 hreading
3. The Lox LanguageWelcome12 hreading
4. Scanningjlox26 hchap04_scanning
5. Representing Codejlox34 hreading
6. Parsing Expressionsjlox46 hchap06_parsing
7. Evaluating Expressionsjlox55 hchap07_evaluating
8. Statements and Statejlox66 hchap08_statements
9. Control Flowjlox74 hchap09_control
10. Functionsjlox87 hchap10_functions
11. Resolving and Bindingjlox97 hchap11_resolving
12. Classesjlox107 hchap12_classes
13. Inheritancejlox115 hchap13_inheritance
14. Chunks of Bytecodeclox125 hreading
15. A Virtual Machineclox135 hreading
16. Scanning on Demandclox144 hreading
17. Compiling Expressionsclox157 hchap17_compiling
18. Types of Valuesclox164 hchap18_types
19. Stringsclox175 hchap19_strings
20. Hash Tablesclox187 hchap20_hash
21. Global Variablesclox195 hchap21_global
22. Local Variablesclox206 hchap22_local
23. Jumping Back and Forthclox215 hchap23_jumping
24. Calls and Functionsclox228 hchap24_calls
25. Closuresclox238 hchap25_closures
26. Garbage Collectionclox248 hchap26_garbage
27. Classes and Instancesclox256 hchap27_classes
28. Methods and Initializersclox267 hchap28_methods
29. Superclassesclox274 hchap29_superclasses
30. Optimizationclox286 hchap30_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

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.