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. What does the symbol table store for each name?

    • Its favourite colour and font
    • Nothing, it only counts names
    • Its kind, type, scope, and parameters
  2. Which error parses fine but fails semantic analysis?

    • Calling paint with one argument when it takes three
    • A missing closing bracket
    • A completely empty file
  3. Code that parses is guaranteed to be meaningful.

    Circle one:   True   False

  4. When is the symbol table written, and when is it read?

    • Written at uses, read at declarations
    • Written once per year, never read
    • Written at declarations, read at every use
  5. The compiler rejects paint(red) though it parses. What did it consult to catch this?

    • The file's creation date
    • The symbol table entry for paint with three parameters
    • The programmer's intentions
  6. Why is lowering to an intermediate form worth the extra pass?

    • One front end can serve many targets through it
    • It makes compilation slower on purpose
    • It deletes all type errors automatically
  7. A teammate says undeclared-variable errors should be caught by the parser. What is wrong with that?

    • Nothing, parsers know every name
    • Parsers run after semantic analysis
    • Names live across the whole program, beyond one local structure
  8. A new language targets three machines. Without a middle form that means three full translators, with one it means one front end plus three small ones. What principle is this?

    • Parsing three times for safety
    • Lowering once to serve many targets
    • Deleting the symbol table
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. Its kind, type, scope, and parameters · Those facts are what every later check consults.
  2. Calling paint with one argument when it takes three · Structure is fine, but the meaning breaks on arity.
  3. False · Parseable structure still needs its meaning checked.
  4. Written at declarations, read at every use · Declarations teach the table, and uses quiz it.
  5. The symbol table entry for paint with three parameters · The declaration's recorded arity exposes the short call.
  6. One front end can serve many targets through it · Each target learns one simple form instead of every language.
  7. Names live across the whole program, beyond one local structure · Structure is local, but meaning needs the table of all declarations.
  8. Lowering once to serve many targets · The shared middle form is what multiplies the saving.
Worksheet · LightMySky