# What is a tree-walk interpreter?

> A tree-walk interpreter runs a program by evaluating its syntax tree directly. How it works, why it is easy to build, and why it is slow.

**Tree-walk interpreter**: A tree-walk interpreter executes a program by recursively evaluating the nodes of its abstract syntax tree, with no compilation to another form.

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](https://cracked.guide/glossary/jlox) is one.

## 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](https://cracked.guide/glossary/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](https://cracked.guide/learn/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.

---

Source: https://cracked.guide/glossary/tree-walk-interpreter
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
