Session 13 Exercise Handout

Augmented Algorithm

  1. Push the end of stream symbol, $, onto the parse stack.
  2. Push the start symbol onto the parse stack.
  3. Repeat
    • A is a terminal.
      If A == t, then
      1. Pop A from the parse stack and consume t. If the terminal has a value, store it in the matched-terminal variable.
      2. Else we have a token mismatch, so fail.
    • A is a non-terminal.
      If table entry [A, t] contains a rule A := Y1 Y2 ... Yn, then
      1. Pop A from the parse stack. Push Yn Yn-1 ... Y1 onto the parse stack, in that order.
      2. Else there is no transition for this pair, so fail.
    • A is a semantic action.
      Pop A from the parse stack and apply it to the semantic stack.
    until the parse stack is empty.
  4. Return the value on top of the semantic stack.

Parse Table for Augmented Grammar

. identifier + * ( ) $
E TE' . . TE' . .
E' . +T make-+ E' . . ε ε
T FT' . . FT' . .
T' . ε *F make-* T' . ε ε
F identifier make-id . . ( E ) . .