In a Syntax-Directed Definition (SDD), an attribute grammar is L-attributed if each inherited attribute of a grammar symbol Xj on the right-hand side of a production A→X1X2…Xn depends only on:
The inherited attributes of the parent non-terminal A.
The attributes (synthesized or inherited) of symbols X1,X2,…,Xj−1 appearing to the left of Xj.
Inherited attributes of Xj itself, such that no cycles are formed.
Let us evaluate each rule:
Rule 1 for A→PQ:
P.i=A.i+2: Inherited attribute of P depends only on the parent's inherited attribute A.i. (Valid)
Q.i=P.i+A.i: Inherited attribute of Q depends on P.i (a symbol to the left of Q) and A.i (parent). (Valid)
A.s=P.s+Q.s: Synthesized attribute of parent depends on attributes of its children. (Valid)
Therefore, Rule 1 is L-attributed.
Rule 2 for A→XY:
X.i=A.i+Y.s: Inherited attribute of X depends on Y.s, where Y appears to the right of X. This violates the L-attributed definition.
Therefore, Rule 2 is not L-attributed.
Hence, only Rule 1 is L-attributed, making (B) the correct option.