Skip to content

Crafting Interpreters: Build Two Languages from Scratch

Descriptions

  • Source: Robert Nystrom
  • Prerequisites: Proficiency in at least one programming language
  • Programming Language: Java (Part 1), C (Part 2)
  • Difficulty: 🌟�🌟🌟
  • Class Hour: 60+

Crafting Interpreters is a free online tutorial by Robert Nystrom that teaches you to implement two programming languages (Lox) from scratch. Part 1 builds a tree-walking interpreter in Java; Part 2 builds a bytecode compiler and VM in C.

The book's greatest strength is its extreme practicality. Every chapter has complete code, and you can follow along to build a working interpreter and compiler step by step.

Resources

Content Structure

Part 1: Tree-Walking Interpreter (Java)

  • Scanning (lexical analysis)
  • Parsing
  • Expression evaluation
  • Statements and control flow
  • Functions and closures
  • Classes and inheritance

Part 2: Bytecode Compiler (C)

  • Bytecode design
  • Compiler implementation
  • Virtual machine
  • Garbage collection
  • Optimization techniques

Self-Study Tips

Write code along with the tutorial, don't just read. The book's value is in hands-on implementation. After each chapter, you'll have a more capable interpreter/compiler.

Read Part 1 before Part 2. Part 1 uses Java and is easier to understand. Part 2 uses C and involves memory management and performance optimization.

Reference, don't copy. Implement first, then check the author's code when stuck.

Notes

Crafting Interpreters is the best hands-on tutorial for getting started with compilers. It doesn't replace a formal compiler course (like Stanford CS143), but it gives you the most intuitive understanding — building a programming language isn't that hard.

Many consider it one of the best programming books they've ever read.