Consider the following productions with semantic actions: S → A + B { S.val =…

Consider the following productions with semantic actions:

S → A + B { S.val = A.val + B.val }
A → a { A.val = a }
B → b { B.val = b }

Select the wrong option.

Answer: D. The given SDT has inherited attributes.In the given SDT, every semantic rule computes the attribute of the left-hand-side nonterminal: A.val is computed in A → a. B.val is computed in B → b. S.val…

  1. A.

    The given SDT has synthesized attributes.

  2. B.

    The given SDT is L-attributed.

  3. C.

    The given SDT can be evaluated by a bottom-up parser.

  4. D.

    The given SDT has inherited attributes.

Attempted by 66 students.

Show answer & explanation

Correct answer: D

In the given SDT, every semantic rule computes the attribute of the left-hand-side nonterminal:

A.val is computed in A → a.
B.val is computed in B → b.
S.val is computed from A.val and B.val in S → A + B.

No rule assigns an attribute to a child symbol using information from its parent or left sibling, so there are no inherited attributes. Therefore, the SDT is S-attributed. Since every S-attributed definition is also L-attributed and synthesized attributes can be evaluated during bottom-up reductions, options A, B, and C are true.

The wrong option is D: the given SDT has inherited attributes.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…