Skip to main content

GATE CSE 2026Compiler Design › Syntax-Directed Translation & Intermediate CodeVerified

GATE CSE 2026 PYQ: ​​​​​​Consider the following two syntax-directed definitions SDD1 \text{SDD1} SDD1 and SDD2 \text{SDD2} SDD2…

​​​​​​Consider the following two syntax-directed definitions SDD1\text{SDD1} and SDD2\text{SDD2} for type declarations.

 
SDD1
Grammar (G1)Semantic Rules
D→T VD \rightarrow T\ VD.type=T.typeD.type = T.type
V.type=T.typeV.type = T.type
T→intT \rightarrow \text{int}T.type=intT.type = \text{int}
T→floatT \rightarrow \text{float}T.type=floatT.type = \text{float}
V→V1 idV \rightarrow V_1\ \text{id}V1.type=V.typeV_1.type = V.type
put(id.entry, V.type)\text{put(id.entry, V.type)}
V→idV \rightarrow \text{id}put(id.entry, V.type)\text{put(id.entry, V.type)}
 
SDD2
Grammar (G2)Semantic Rules
D→D1 idD \rightarrow D_1\ \text{id}D.type=D1.typeD.type = D_1.type
put(id.entry, D_1.type)\text{put(id.entry, D\_1.type)}
D→T idD \rightarrow T\ \text{id}D.type=T.typeD.type = T.type
put(id.entry, T.type)\text{put(id.entry, T.type)}
T→intT \rightarrow \text{int}T.type=intT.type = \text{int}
T→floatT \rightarrow \text{float}T.type=floatT.type = \text{float}


DD is the start symbol, and int, float and id are the three terminals. The non-terminal V1V_{1} is the same as VV and the non-terminal D1D_{1} is the same as DD. Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function put updates the symbol table with the type information for an identifier.

Let P\text{P} and Q\text{Q} be the languages specified by grammars G1\text{G1} and G2\text{G2}, respectively.
Which of the following statements is/are true?

  1. A
    The languages P\text{P} and Q\text{Q} are the same
    Correct answer
  2. B
    SDD2\text{SDD2} is S\text{S}-attributed and contains only synthesized attributes
    Correct answer
  3. C
    SDD1\text{SDD1} is L\text{L}-attributed and contains only inherited attributes
  4. D
    The specifications of SDD1\text{SDD1} and SDD2\text{SDD2} are such that the same entries get added to the symbol table
    Correct answer

Answer

(A, B, D) The languages P \text{P} P and Q \text{Q} Q are the same; SDD2 \text{SDD2} SDD2 is S \text{S} S -attributed and contains only synthesized attributes; The specifications of SDD1 \text{SDD1} SDD1 and SDD2 \text{SDD2} SDD2 are such that the same entries get added to the symbol table

Approach

Compare the languages generated by G1 and G2, then classify the attributes in each syntax-directed definition. Finally, verify whether the put operations insert the same identifier-type pairs into the symbol table.

G1 and G2 are equivalent for type declarations, producing type id+ strings. SDD2 is purely synthesized, hence S-attributed. SDD1 is L-attributed but has both inherited and synthesized attributes, so its claim of only inherited attributes is false. Both SDDs insert identical identifier-type information into the symbol table. Hence A, B, and D are true; C is false.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.