explaingit

munificent/craftinginterpreters

10,755HTMLAudience · developerComplexity · 3/5Setup · moderate

TLDR

A free online book and full source code for building two complete working programming language interpreters from scratch, one in Java, one in C, covering every step from reading characters to running closures and classes.

Mindmap

mindmap
  root((Crafting Interpreters))
    Two implementations
      jlox in Java
      clox in C
    Language built
      Lox scripting language
      Lexing and parsing
      Closures and classes
    Repo contents
      Book source
      Full interpreter code
      Test suite
    Audience
      Developers
      CS learners
    Build tools
      Dart
      Java
      C compiler
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Work through the book chapter by chapter to build a fully working scripting language interpreter in Java or C, with tests to verify your work at each stage.

USE CASE 2

Use the included test suite to check your own Lox interpreter written in a different language against the reference implementation.

USE CASE 3

Study the C source code for a real bytecode virtual machine to understand how scripting languages compile and execute programs under the hood.

Tech stack

JavaCDartMakefile

Getting it running

Difficulty · moderate Time to first run · 1day+

Building the full book site requires Dart, a C compiler, and Java, running just the interpreter code needs only a C compiler or Java.

In plain English

Crafting Interpreters is a free online book that walks readers through building two complete programming language interpreters from scratch. The language being built is called Lox, and the book covers it twice: first in Java, producing an interpreter called jlox, and then in C, producing a faster, bytecode-based interpreter called clox. Both full implementations are included in this repository. The book is aimed at people who want to understand how programming languages actually work under the hood. No prior experience with compilers or interpreters is assumed. The author takes readers step by step through lexing, parsing, evaluating expressions, handling variables, functions, closures, and classes, explaining each concept in plain terms before showing the code that implements it. This repository contains not just the finished interpreter code but also the Markdown source for every chapter of the book, along with a custom build system that weaves prose and code together into the final website at craftinginterpreters.com. The build is driven by Dart scripts and a Makefile. Running it locally requires Dart, a C compiler, and Java. There is also a full test suite for both interpreters. The tests can be run against any chapter's version of the code, not only the final build. This lets readers verify that the interpreter is working correctly even midway through the book. The test runner also accepts custom interpreter executables, so anyone who writes their own Lox implementation in another language can use the same tests to check it. If you find a typo or error in the book, you can file a GitHub issue or send a pull request. A community wiki page lists Lox implementations written in other languages by readers who worked through the material.

Copy-paste prompts

Prompt 1
I am following Crafting Interpreters and just finished the jlox scanner chapter. Show me how to run the test suite against my current implementation to check which tests pass.
Prompt 2
In the clox bytecode VM from Crafting Interpreters, how does the chunk structure store both opcodes and their source line numbers? Explain and show the relevant C struct.
Prompt 3
I want to implement the Lox language in Python by following Crafting Interpreters. How do I use the book's test suite with my own Python interpreter executable?
Prompt 4
Explain how closures are implemented in the jlox Java interpreter from Crafting Interpreters. What is an Environment object and how does it chain to capture variables from outer scopes?
Prompt 5
How do I build the Crafting Interpreters book website locally from source? What tools do I need and what command do I run?
Open on GitHub → Explain another repo

← munificent on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.