Session 13 Exercise Handout
Augmented Grammar and Parse Table
Augmented Algorithm
-
Push the end of stream symbol, $, onto the parse stack.
-
Push the start symbol onto the parse stack.
-
Repeat
-
A is a terminal.
If A == t, then
-
Pop A from the parse stack and
consume t. If the terminal has a
value, store it in the matched-terminal
variable.
- 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
-
Pop A from the parse stack.
Push Yn Yn-1 ... Y1
onto the parse stack, in that order.
-
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.
-
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 ) |
. |
. |