Consider the following SDT Above SDT is
Consider the following SDT

Above SDT is
Answer: B. neither L-attributed nor S-attributed — In the two rules for S S → 2 A C { C.x = A.x } S → 3 A B M C { M.x = A.x + B.x } the action assigns attributes of RHS children (C.x, M.x) after their subtrees…
- A.
L attribute grammar only
- B.
neither L-attributed nor S-attributed
- C.
S attribute grammar only
- D.
both L and S attribute grammar
Attempted by 57 students.
Show answer & explanation
Correct answer: B
In the two rules for S
S → 2 A C { C.x = A.x }S → 3 A B M C { M.x = A.x + B.x }
the action assigns attributes of RHS children (C.x,M.x) after their subtrees are complete. In an attribute grammar, actions should compute the head’s attributes (synthesized) or set inherited attributes before visiting a child. Writing to a child’s attribute at the end of the production violates both S- and L-attributed conventions.If you try to treat
C.xandM.xas inherited, then their own productions also set them:C → 4 { C.x = 4 },M → ε { M.x = 0 }
which makes the same attribute both inherited and synthesized—not allowed.
Therefore this SDT, as stated, is not S-attributed and not L-attributed;