Consider the following two syntax-directed definitions SDD1 and SDD2 for type…

2026

Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

image.png

𝐷 is the start symbol, and 𝑖𝑛𝑑, π‘“π‘™π‘œπ‘Žπ‘‘ and 𝑖𝑑 are the three terminals. The non-terminal 𝑉1 is the same as 𝑉 and the non-terminal 𝐷1 is the same as 𝐷. Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function 𝑝𝑒𝑑 updates the symbol table with the type information for an identifier. Let P and Q be the languages specified by grammars G1 and G2, respectively.
Which of the following statements is/are true?

  1. A.

    The languages P and Q are the same

  2. B.

    SDD2 is S-attributed and contains only synthesized attributes

  3. C.

    SDD1 is L-attributed and contains only inherited attributes

  4. D.

    The specifications of SDD1 and SDD2 are such that the same entries get added to the symbol table

Attempted by 3 students.

Show answer & explanation

Correct answer: A, B, D

Both grammars generate declarations of the form type followed by one or more identifiers.

Statement A is true. In G1, D β†’ T V and V β†’ V₁ id | id generate one or more identifiers after a type. In G2, D β†’ D₁ id | T id generates the same strings by left recursion. Hence P = Q.

Statement B is true. In SDD2, every type attribute is synthesized: T.type is set from the terminal int/float, and D.type is computed from T.type or D₁.type. No inherited attribute is used, so SDD2 is S-attributed.

Statement C is false. SDD1 is L-attributed because the inherited attribute V.type is passed to V₁.type in a left-to-right manner. However, it does not contain only inherited attributes; T.type and D.type are synthesized attributes.

Statement D is true. In both SDDs, each identifier receives the type computed from the declaration, so the same put(id.entry, type) entries are added to the symbol table.

Therefore, the correct options are A, B, and D.

Explore the full course: Gate Guidance By Sanchit Sir