Consider the SDT. S→PQ { S.a = P.a + Q.a} P→ QR {Q.a = R.a} R→ id {R.a = id}…

Consider the SDT.

S→PQ { S.a = P.a + Q.a}

P→ QR {Q.a = R.a}

R→ id {R.a = id}

Which of the given option is correct:

Answer: D. None of theseKey observations: examine each production and how attribute "a" is used. For S → P Q with semantic rule S.a = P.a + Q.a: the attribute a of S is synthesized…

  1. A.

    Given SDT is L-attributed

  2. B.

    Attribute “a” is inherited only

  3. C.

    Attribute “a” is synthesized only

  4. D.

    None of these

Attempted by 90 students.

Show answer & explanation

Correct answer: D

Key observations: examine each production and how attribute "a" is used.

  • For S → P Q with semantic rule S.a = P.a + Q.a: the attribute a of S is synthesized because it is computed from attributes of the children P and Q.

  • For P → Q R with semantic rule Q.a = R.a: the attribute a of Q is being set using R (a right sibling), so this is an inherited attribute for Q that depends on a right sibling.

  • Because a appears as both a synthesized attribute (in S) and an inherited attribute (in Q), it is neither only synthesized nor only inherited.

  • An L-attributed definition requires that inherited attributes of a symbol may depend only on the parent’s inherited attributes and attributes of symbols to its left, not on symbols to its right. Here Q.a depends on the right sibling R, so the SDT is not L-attributed.

Conclusion: None of the listed statements is correct because the attribute "a" is both synthesized and inherited, and the inherited use violates the L-attributed restriction.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…