In a bottom-up evaluation of a syntax directed definition, inherited…
2003
In a bottom-up evaluation of a syntax directed definition, inherited attributes can
- A.
always be evaluated
- B.
be evaluated only if the definition is L-attributed
- C.
be evaluated only if the definition has synthesized attributes
- D.
never be evaluated
Attempted by 80 students.
Show answer & explanation
Correct answer: B
Correct answer: be evaluated only if the definition is L-attributed
Why:
Definition distinction: Synthesized attributes are computed from a node's children and naturally fit bottom-up evaluation. Inherited attributes are supplied by a node's parent or left siblings and may require information not yet available at the time of reduction.
L-attributed condition: An SDD is L-attributed if each inherited attribute of a symbol on the right-hand side of a production depends only on
attributes of the parent (the left-hand side) and
attributes of symbols to the left of that symbol in the production
Implication for bottom-up parsing: If the SDD is L-attributed, inherited attributes for a symbol can be computed during a left-to-right traversal of the right-hand side or at appropriate reductions by using values stored on the parser stack, so bottom-up parsers (for example, LR) can evaluate them.
If the SDD is not L-attributed, inherited attributes may depend on information that is not yet available during reductions, so bottom-up evaluation cannot in general compute them without additional transformations or mechanisms.
Takeaway: inherited attributes are evaluable in bottom-up parsing only under L-attributed restrictions (or after transforming the SDD).
A video solution is available for this question — log in and enroll to watch it.