For top-down parsing, we can assume that an action is executed at the time that a symbol in the same position would be expanded. Thus, in the second production in Fig. 2., the 1st action (assignment to R1:i) is done after T has been fully expanded to terminals, and the second action is done after R1 has been fully expanded. Also, as discussed in the previous lecture, for an L-attributed translation an inherited attribute of a symbol must be computed by an action appearing before the symbol and a synthesized attribute of the non-terminal on the left must be computed after all the attributes it depends on, have been computed.
The new scheme produces annotated parse tree of the figure shown in slide 49 for the expression 9 - 5 + 2. The arrows show the evaluation order of all the L-attributes of various grammar symbols as per the new symbol.
|