Master the fundamental concepts of semantic analysis through this focused micro-challenge.
Block scope, function scope, and file scope determine which declaration a name refers to. Clang tracks Scope objects; Java bytecode carries scope in debug tables. Shadowing (inner x hides outer x) is legal in C but dead outer bindings are often flagged as warnings.
When an inner block declares x while outer x exists, inner uses bind to inner x. The outer x is shadowed inside the block. If inner x is never used, compilers like GCC emit -Wunused-variable.
cLoading…
{, pop on }Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement scope analysis that detects variable shadowing and unused declarations. This exercise requires tracking nested scopes and reporting when inner names hide outer names or when variables are never used.
Implement scope analysis with shadowing detection and dead code identification.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github