Glossary

What is a tree-walk interpreter?

A tree-walk interpreter parses source code into an abstract syntax tree (AST) and then runs the program by visiting that tree: to evaluate 1 + 2, it evaluates the left child, the right child, and adds them. jlox is one.

Taught in Crafting Interpreters 7: Evaluating Expressions, Crafting Interpreters 8: Statements and State

How it works

The parser builds a tree of nodes: a Binary node with an operator and two children, a Call node with a callee and arguments, and so on. The interpreter has one function per node type (often written with the Visitor pattern) that evaluates the node, recursing into its children. Variables live in environments, maps from names to values chained by scope.

Trade-offs

It is the simplest way to make a language run, which is why Crafting Interpreters starts with one and why many scripting languages began as one. The cost is speed: every operation chases pointers between scattered tree nodes and goes through a dynamic dispatch. A bytecode VM flattens the program into a compact array of instructions and runs it in a loop, which is much faster. See jlox vs clox.

Questions

Are tree-walk interpreters used in real languages?

Yes, mostly early in a language's life or where simplicity matters more than speed. Many mature languages moved to bytecode VMs or JIT compilers later.