Example
. Consider rule B B1 B2 with inherited attribute ps and synthesized attribute ht
. The parse tree for this string and a snapshot of the stack at each node appears as
For example, consider the following rule that was discussed in the context of a type-setting system
B -> B1B2 |
B1.ps = B.ps
|
|
B2.ps = B.ps
|
|
B.ht = max(B1.ht;B2.ht)
|
|
|
This slide gives the snapshot of the stack as each node appears. Note that in this case, the stack size may increase by as much as 5. This is because we have to push B1:ps and B2:ps on to the stack, even though there are simply copies of B:ps.
|