THE GENERAL PROBLEM. Let A X1 ... Xn be a production used in a parse tree. We consider the case where for a grammar symbol Xi in the rigth side of the production possesses an inherited attriute Xi.in which cannot be given value before the subtree rooted at A is completely visited.
AN EXAMPLE AND ITS SOLUTION.
Production | Semantic Rule | |
1 | E E1 M E2 | { backpatch( E1.falselist, M.quad) |
E.truelist := merge( E1.truelist, E2.truelist) | ||
E.falselist := E2.falselist } | ||
2 | E E1 M E2 | { backpatch( E1.truelist, M.quad) |
E.truelist := E2.truelist | ||
E.falselist := merge( E1.falselist, E2.falselist) } | ||
3 | E E1 | { E.truelist := E1.falselist |
E.falselist := E1.truelist } | ||
4 | E (E1) | { E.truelist := E1.truelist |
E.falselist := E1.falselist } | ||
5 | E | { E.truelist := makelist(nextaddr) |
nextaddr := nextaddr + 1 | ||
E.falselist := makelist(nextaddr) | ||
nextaddr := nextaddr + 1 | ||
emit('if' .place .place 'goto __') | ||
emit('goto __') } | ||
6 | E | { E.truelist := makelist(nextaddr) } |
7 | E | { E.falselist := makelist(nextaddr) } |
8 | M | { M.quad := nextaddr } |
a < bWe only need to apply the above Production 5 leading to
100 | if a < b goto __ |
101 | goto __ |
Moreover this expression, say E1, is associated with the lists
a < b or c < dDuring a bottom-up parsing we will apply twice Production 5 and one Production 1. Before performing the actions of Production 1 the generated code is
100 | if a < b goto __ |
101 | goto __ |
102 | if c < d goto __ |
103 | goto __ |
and the subexpressions E1 = a < b and E2 = c < d are associated with the lists
100 | if a < b goto __ |
101 | goto 102 |
102 | if c < d goto __ |
103 | goto __ |
Moreover the expression E = a < b or c < d is associated with
a < b or (c < d and e < f)During a bottom-up parsing we will apply
Before performing the actions of Production 1 the generated code is
100 | if a < b goto __ |
101 | goto __ |
102 | if c < d goto 104 |
103 | goto __ |
104 | if c < d goto __ |
105 | goto __ |
and the subexpressions E1 = a < b and E4 = c < d and e < f are associated with the lists
100 | if a < b goto __ |
101 | goto 102 |
102 | if c < d goto 104 |
103 | goto __ |
104 | if c < d goto __ |
105 | goto __ |
Moreover the expression E = a < b or (c < d and e < f) is associated with