Questions: Tree-Walking Interpreters

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In a tree-walking interpreter, a function is called with a local variable `x = 5`. Later in the function body, `x` is referenced. Where does the interpreter find the value of `x`, and what happens when the function returns?

AIt looks up `x` in a global symbol table that persists across all function calls
BIt finds `x` in a new environment created for this function call; when the function returns, that environment is discarded and the enclosing scope is restored
CIt compiles the function to bytecode and stores `x` in a stack frame before executing
DIt searches the AST node for the function definition and reads the parameter value from the parse tree
Question 2 Multiple Choice

Why is a tree-walking interpreter slower than a compiler that generates native machine code, even when both correctly execute the same program?

ATree-walking interpreters are written in slower programming languages than compilers
BTree-walking requires reading the source file on every execution, while compilers cache the output
CEvery operation requires navigating pointer-based tree nodes, dispatching on node types, and environment chain lookups — overhead that a compiler eliminates by generating direct machine instructions
DTree-walking interpreters cannot perform arithmetic operations directly; they must call external library functions for every computation
Question 3 True / False

A tree-walking interpreter compiles the AST into bytecode and then executes the bytecode, which is why it requires no separate compilation step.

TTrue
FFalse
Question 4 True / False

A tree-walking interpreter and a compiled language implementation can have identical observable behavior for a given program, even though their internal execution strategies differ entirely.

TTrue
FFalse
Question 5 Short Answer

How does a tree-walking interpreter implement lexical scoping for nested function calls, and why is a chain of environments the natural solution?

Think about your answer, then reveal below.