Semantic Analysis and the Intermediate Representation · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

It parses, but is it right?

Computing · Computer Systems · ages 21-22
Name ______________________   Date ____________
  1. Which information belongs in a symbol table for semantic checking?

    • Editor colours, line-wrapping preferences and current cursor positions
    • Processor clock speeds, cache capacities and remaining battery charge
    • Declaration kinds, types, scopes and function parameters
  2. Here + requires two numbers and does not convert strings. n is a number and s is a string. Which expression has valid syntax but fails type checking?

    • n + s
    • n + )
    • (n + n
  3. Valid grammatical structure guarantees that code passes this lesson's static semantic checks.

    Circle one:   True   False

  4. In the lesson's symbol-table model, when are entries added and consulted?

    • Uses create declarations; declarations later search the recorded name uses
    • Parsing completes every name check; later stages never consult declarations
    • Declarations add entries; name uses consult them under scope rules
  5. paint takes three numbers, and red is a declared number. paint(red) has valid syntax. What information exposes its argument-count mismatch?

    • The token entries saying paint and red are both names
    • The declaration saying paint takes three parameters
    • The target's instruction list specifying its visible registers
  6. How can a shared IR support several languages and targets?

    • Front ends produce it, and compatible target back ends consume it
    • Each source language requires an incompatible IR for every target machine
    • It replaces declaration checking by deleting all names from the source text
  7. A name has valid token spelling and appears in a valid expression. What further information decides whether it is declared here?

    • Only whether its letters match the language's identifier-token pattern
    • Only whether its expression node occupies a valid grammatical position
    • Which declaration is visible under the current scope rules, if any
  8. Three existing back ends consume one IR. A new language can express all its operations in that IR. Which new component lets it reuse those back ends?

    • Three new parsers, each emitting a different target's machine instructions
    • One new front end translating the language into the shared IR
    • One replacement symbol table removing all target-specific instructions
LightMySky · lightmysky.comW1-mt_f2z_WQxfiw-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

It parses, but is it right? W1-mt_f2z_WQxfiw-s1

  1. Declaration kinds, types, scopes and function parameters · Declaration facts support checks of name visibility, operand types and calls.
  2. n + s · n + s has a valid addition structure but incompatible operand types. The other expressions have malformed parentheses.
  3. False · Valid structure does not establish visible declarations, compatible types or the required argument count.
  4. Declarations add entries; name uses consult them under scope rules · Declarations provide binding facts. Uses consult bindings visible under scope rules.
  5. The declaration saying paint takes three parameters · The call supplies one argument, while the declaration requires three.
  6. Front ends produce it, and compatible target back ends consume it · The shared representation connects language-specific translation with target-specific translation.
  7. Which declaration is visible under the current scope rules, if any · Valid spelling and syntax do not establish a binding. Name resolution needs visible declaration information.
  8. One new front end translating the language into the shared IR · The target translation already exists. A new front end supplies its expected IR.
Worksheet · LightMySky