gitmyhub

craftinginterpreters

HTML ★ 11k updated 1y ago

Repository for the book "Crafting Interpreters"

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.

JavaCDartMakefilesetup: moderatecomplexity 3/5

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.

Where it fits