Glossary

What is Lox?

Lox is the programming language you build in Robert Nystrom's book Crafting Interpreters. It is small enough to implement in a book and real enough to be interesting: dynamic types, first-class functions, closures, classes and single inheritance.

Taught in Crafting Interpreters 3: The Lox Language

What Lox has

  • Numbers (double precision), strings, booleans and nil
  • Variables with block scope, if, while and for
  • Functions as values, and closures that capture variables
  • Classes with methods, this, initializers and single inheritance with super
  • A print statement and a clock() native function

It leaves out arrays, maps and a standard library on purpose, so the book can spend its pages on how a language works, not on library code.

Two implementations

The book implements Lox twice. jlox is a tree-walk interpreter in Java. clox is a bytecode virtual machine in C with its own hash table and garbage collector. Both pass the same test suite, which is how you know yours works: see running the Lox test suite.

Questions

Is Lox used in production?

No. It is a teaching language. Its value is that you can understand and build every part of it.

Where is the Lox language described?

Chapter 3 of Crafting Interpreters, "The Lox Language", free at craftinginterpreters.com.