Interpreters

jlox vs clox

jlox is a tree-walk interpreter in Java: it parses Lox into a syntax tree and evaluates the tree, leaning on the JVM for memory. clox is a bytecode virtual machine in C: it compiles Lox in one pass to bytecode and runs it in a loop, with its own hash table and garbage collector. Same language, same tests, very different insides.

Updated

Side by side

jloxclox
LanguageJavaC
Chapters4 to 1314 to 30
Front endScanner, recursive descent parser, ASTScanner on demand, single-pass Pratt parser, no AST
ExecutionWalks the AST (Visitor pattern)Stack-based bytecode VM
VariablesEnvironments: chained hash mapsStack slots, globals table, upvalues
MemoryThe JVM's garbage collectorIts own mark-sweep collector
Hash tablejava.util.HashMapWritten from scratch, with string interning
SpeedSlowMany times faster
Hours in our guidesabout 57about 100

Why the book builds both

jlox makes the ideas visible: you can see the tree, and every concept (scope, closures, classes) maps to a few clear classes. clox makes them fast, and in doing so shows you what high-level languages hide: how values are represented, how a call frame works, how closures capture variables, how memory is reclaimed. Most people find clox harder and more rewarding.

Can I skip one?

You can skip jlox if you already understand ASTs, environments and resolvers, but clox explains its design by contrast with jlox, so you lose some of the why. You can stop after jlox if you only want the front end, but you miss the half of the book that teaches performance and memory. On the cracked.guide path both are required: jlox in weeks 1 to 11, clox in weeks 12 to 28, and both pass the official test suite.

Writing them in other languages

Many people write "jlox" in Python, Go, TypeScript or Rust, and "clox" in Rust or Zig. That works and the test suite still applies: point it at your executable. Be aware that a garbage-collected host language hides the memory chapters of clox, and Rust's ownership rules make some of clox's pointer tricks awkward.

Questions

Is clox harder than jlox?

Yes, for most people. C gives you nothing for free, and closures and garbage collection are the hardest chapters in the book.

Which is faster, jlox or clox?

clox, by a wide margin, because it runs compact bytecode in a tight loop instead of walking a tree of Java objects.