To determine whether each syntax-directed definition (SDD) rule is S-attributed or L-attributed, we apply the standard definitions:
S-attributed SDD: Uses only synthesized attributes (i.e., attributes of the non-terminal on the LHS are computed solely from attributes of the children on the RHS).
L-attributed SDD: Allows both synthesized and inherited attributes. For any production A→X1X2…Xn, an inherited attribute of Xj may depend only on:
Inherited attributes of the head A, and/or
Attributes of symbols X1,X2,…,Xj−1 appearing to the left of Xj.
*(Every S-attributed SDD is also an L-attributed SDD).*
---
### Analysis of Each Rule:
Rule 1: R→AB{B.i=R.i−1;A.i=B.i;R.i=A.i+1;}
In A.i=B.i, the attribute of the symbol A depends on B, which lies to its right. This violates the L-attributed property.
Since it contains inherited attributes (B.i and A.i), it is also not S-attributed.
Therefore, Rule 1 is neither S-attributed nor L-attributed.
Rule 2: P→CD{P.i=C.i+D.i;D.i=C.i+2;}
P.i=C.i+D.i computes a synthesized attribute for the head P from children C and D.
D.i=C.i+2 computes an inherited attribute for D using C, which is strictly to the left of D. This satisfies the L-attributed condition.
Because it includes the inherited attribute D.i, it is not S-attributed.
Therefore, Rule 2 is not S-attributed and is L-attributed.
Rule 3: Q→EF{Q.i=E.i+F.i;}
Q.i is computed solely from the attributes of its children E and F.
This uses only synthesized attributes, so it is S-attributed.
Every S-attributed grammar is also L-attributed.
Therefore, Rule 3 is S-attributed and L-attributed.
Matching these classifications with the choices gives Option (C) as the correct answer.