Built from scratch · Java · Crafting Interpreters · Summer 2026
LoxLang
A complete tree-walking interpreter for Lox, a small dynamically-typed language, built following Crafting Interpreters by Robert Nystrom. Scanner, recursive-descent parser, and evaluator, all handwritten. Supports variables, functions, closures, classes with inheritance, and a custom string-interpolation extension I added myself. Ported to JavaScript below so you can write and run real Lox code in this page.
Write Lox code on the left, hit Run, see the output on the right. This is the same scanner → parser → interpreter pipeline as the Java version, just ported to run in your browser instead of the JVM. Pick an example to see closures, classes and inheritance, or the custom f-string extension in action.
Two implementations exist in the real project. The tree-walking interpreter above is fully working and is what's running in this page.
f"..." string interpolation is detected and expanded into a chain of concatenations.expression() down to primary(). Precedence is baked into the call structure, lower-precedence rules call higher-precedence ones.Environment pointing at its enclosing scope. Closures work because a function stores a reference to the environment active when it was defined, not when it's called.lox-c/; the compiler and VM aren't finished yet.Files (Java interpreter)
Selected pieces of the actual Java source.
What I learned
I'd seen it described in textbooks but never understood why you'd want it. The interpreter uses it to add interpret, print, and resolve operations to the AST without modifying the AST node classes. Once I built it, I got it.
The Java version stores the closing Environment directly in the function object. It's conceptually clean but keeps every captured variable alive as long as the closure exists. The planned C VM uses "upvalues" instead, a smarter scheme where captured variables live on the stack until the closure outlives its scope, then get moved to the heap.
That's the part of the C VM I haven't built yet, load factors, open addressing, tombstone deletion, and why string interning makes equality checks O(1) rather than O(n). Reason enough to finish lox-c.