Scope Resolution

CS 432 — Which declaration does each name refer to? · Shadowing · Scope errors
Generated with the assistance of Claude Code (Opus 5.5)
— ← / → to step · click a name to jump to it
declaration resolved use current lookup error

Source

Each arrow runs from a use of a name to the declaration it refers to. Any correct Decaf compiler must draw the same arrows.

No traces loaded — run tracer/regen_traces.sh

Current Step

The scopes searched, innermost first, until a declaration is found or the search fails

What to notice
Every use, in source order

Reference Implementation — Symbol Tables

One table for the program, one per function (its parameters), one per block (its locals). Phase 1 builds them, and they persist on the AST, linked to their parents.

Tables, with parent links
Construction stack
This is one design, not the required one. Other designs can produce exactly the same arrows: a scope stack kept during a single checking pass, parent pointers on AST nodes, or an environment passed down the recursion. What every design must reproduce is the behavior in the panels above. Example 4 (forward references) shows where a naive one-pass design gives a different answer.

Trace

The events this page replays, dumped from the reference compiler's own tables and lookups by tracer/scope-trace. Click an event to jump to it.