Inheriting attribute on parser stacks
. bottom up parser reduces rhs of A XY by removing XY from stack and putting A on the stack
. synthesized attributes of Xs can be inherited by Y by using the copy rule Y.i=X.s
Example :take string real p,q,r
D T |
{L.in = T.type}
|
L
|
|
T int |
{T.type = integer}
|
T real |
{T.type = real}
|
L |
{L 1 .in =L.in} L 1 ,id |
|
{addtype(id.entry,L in )}
|
L id |
{addtype(id.entry,L in )}
|
|
|
A bottom-up parser reduces the right side of production A -> XY by removing X and Y from the top of the parser stack and putting A on the stack. Since the synthesized attribute of X, X.s is already on the parser stack before any reduction takes place in the subtree below Y , this value can be inherited by Y by using the copy rule Y.i = X.s. Similarly, in the above given example T.type is the synthesized attribute and L.in is the inherited attribute.
|