Example .
. Every tine a reduction to L is made value of T type is just below it
. Use the fact that T.val (type information) is at a known place in the stack
. When production L ® id is applied, id.entry is at the top of the stack and T.type is just below it, therefore,
addtype(id.entry, L.in) addtype(val[top], val[top-1])
. Similarly when production L ® L 1 , id is applied id.entry is at the top of the stack and T.type is three places below it, therefore,
addtype(id.entry, L.in) addtype(val[top],val[top-3])
Suppose that the parser stack is implemented as a pair of arrays, state and val. If state[i] is grammar symbol X, then val[i] holds a synthesized attribute X.s. T.val (type information) is at a known place in the val stack, relative to the top. Let top and ntop be the indices of the top entry in the stack just before and just after a reduction takes place, respectively. When production L -> id is applied, id.entry is at the top of the val stack and T.type is just below it, therefore,
addtype(id.entry, L.in) addtype(val[top], val[top - 1]).
Similarly, when production L -> L1, id is applied id.entry is at the top of the stack and T.type is three places below it where T is. Hence,
addtype(id.entry, L.in) addtype(val[top], val[top - 3])
|