Simulating the evaluation of inherited attributes
. The scheme works only if grammar allows position of attribute to be predicted.
. Consider the grammar
S aAC |
Ci = A s
|
S bABC |
Ci = A s
|
C c |
Cs = g(Ci )
|
. C inherits A s
. there may or may not be a B between A and C on the stack when reduction by rule C c takes place
. When reduction by C c is performed the value of C i is either in [top- 1] or [top-2]
Reaching into the parser stack for an attribute value works only if grammar allows position of attribute to be predicted.
As an instance where we cannot predict the position, consider the grammar given above.
C inherits A.s by a copy rule. Note that there may or may not be a B between A and C on the stack when reduction by rule C -> c takes place. When reduction by C -> c is performed the value of C.i is either in [top-1] or [top-2], but it is not clear which case applies.
|