Consider the following SDT Above SDT is

Consider the following SDT

Above SDT is

Answer: B. neither L-attributed nor S-attributedIn 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…

  1. A.

    L attribute grammar only

  2. B.

    neither L-attributed nor S-attributed

  3. C.

    S attribute grammar only

  4. 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.x and M.x as 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;

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…