Semantic Analysis

  • parsing gives shape; analysis validates meaning
  • names, binding kinds, scope, and call legality before runtime

Scope policy

  • explicit scope stack: current → parent → root
  • duplicate declarations forbidden in same scope
  • inner declaration shadows outer

Function strategy

  • two-phase often needed: 1) register function declarations 2) validate function bodies
  • enables recursion and arity checks at call sites

Assignment rules

  • const binding may not be reassigned
  • var may be updated in nearest enclosing scope
  • unresolved targets are undefined name errors

Control-flow validation

  • track inFunctionDepth
  • return valid only when inside function

Diagnostic quality

  • deterministic issue order
  • messages include location + concrete symbol/call count
  • examples:
    • undefined name: x
    • redeclare in same scope: x
    • cannot assign to const: pi
    • return outside function
    • arity mismatch: add expects 2, got 1

Why good analysis

  • catches failures early
  • aligns compiler and VM error model
  • keeps runtime traces meaningful

Quick checks

  • same-name in one scope -> declare error
  • same-name in child scope -> shadow allowed
  • recursion accepted after declaration pass
  • call arity mismatch flagged before compile emit
  • valid call path may still error at runtime if types mismatch
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.