Similar questions 1 more →
Semantic Analysis & Type Checking

Answer & solution
Official answer: B
Worked explanation
An inherited attribute of a child in an L-attributed definition may depend on inherited attributes of the parent and attributes of siblings to its left. In A→PQ, P has no left sibling, and its inherited value depends only on A.i. Q can use P.i because P is left of Q. Synthesized A.s is evaluated after both children return. A valid evaluation order is A.i, P.i, process P to get P.s, Q.i, process Q to get Q.s, then A.s. In A→XY, X.i needs Y.s even though Y is on X’s right, violating the restriction. Y.i’s use of X.s would be allowed by itself; it does not rescue the first dependency.
Derivation and answer
Rule1 computes each inherited attribute from the parent’s inherited attribute and, for Q, a left sibling’s attribute; the parent synthesized attribute can then combine child results. This is L-attributed. Rule2 computes X.i using right sibling Y.s, violating the left-to-right dependency restriction. Only Rule1, B.