Closing Exercise: Small Program, Big Doubts
Here is the trace for x * y + z:
| Parse Stack | Input | Semantic Stack |
|---|---|---|
$ |
x * y + z $ |
|
$E |
x * y + z $ |
|
$E'T |
x * y + z $ |
|
$E'T'F |
x * y + z $ |
|
$E'T' m-id id |
x * y + z $ |
|
$E'T' m-id |
* y + z $ |
|
$E'T' |
* y + z $ |
[x] |
$E'T'm-* F * |
* y + z $ |
[x] |
$E'T'm-* F |
y + z $ |
[x] |
$E'T'm-* m-id id |
y + z $ |
[x] |
$E'T'm-* m-id |
+ z $ |
[x] |
$E'T'm-* |
+ z $ |
[y] [x] |
$E'T' |
+ z $ |
[[x] * [y]] |
$E' |
+ z $ |
[[x] * [y]] |
$E' m-+ T + |
+ z $ |
[[x] * [y]] |
$E' m-+ T |
z $ |
[[x] * [y]] |
$E' m-+ T'F |
z $ |
[[x] * [y]] |
$E' m-+ T' m-id id |
z $ |
[[x] * [y]] |
$E' m-+ T' m-id |
$ |
[[x] * [y]] |
$E' m-+ T' |
$ |
[z] [[x] * [y]] |
$E' m-+ |
$ |
[z] [[x] * [y]] |
$E' |
$ |
[ [[x] * [y]] + [z] ] |
$ |
$ |
[ [[x] * [y]] + [z] ] |
[ [[x] * [y]] + [z] ] |
I have highlighted in
aquamarine
the two rows at the critical point in the derivation. The
parser sees the make-* semantic action and creates the
[[x] + [y]] node before it expands the
E' that pushes the make-+ semantic action
on to the stack.
Hurray! It works. I feel a lot better now. More next time.