Question

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

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

DD is the start symbol, and int\text{int}, float\text{float} and id\text{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\text{put} updates the symbol table with the type information for an identifier.

Let PP and QQ be the languages specified by grammars G1 and G2, respectively.

Which of the following statements is/are true?

Choose every correct option
Official answer and solution
Official answer
A, B and D
From
Official GATE 2026 answer key

Solution

Check the languages generated by G1 and G2, classify the attributes in SDD1 and SDD2 as synthesized or inherited, and compare their symbol table updates.

  1. Option (A) is true: Both G1 and G2 generate the regular language (int∣float) id+(\text{int} \mid \text{float})\,\text{id}^+ (a type keyword followed by one or more identifiers).
  2. Option (B) is true: In SDD2, every attribute (T.typeT.\text{type} and D.typeD.\text{type}) is computed for the LHS non-terminal from attributes of its children on the RHS. Hence SDD2 contains only synthesized attributes and is S-attributed.
  3. Option (C) is false: Although SDD1 is L-attributed, it does not contain only inherited attributes: T.typeT.\text{type} and D.typeD.\text{type} are synthesized attributes (while V.typeV.\text{type} is an inherited attribute).
  4. Option (D) is true: For any valid declaration string t id1 id2…idkt\,\text{id}_1\,\text{id}_2\dots \text{id}_k, both SDD1 and SDD2 invoke put(idi.entry,t)\text{put}(\text{id}_i.\text{entry}, t) for every identifier idi\text{id}_i, adding the exact same entries to the symbol table.
Final answer

Options (A), (B), (D)

Common trap

Selecting (C) without noticing that T.typeT.\text{type} and D.typeD.\text{type} in SDD1 are synthesized attributes.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 1 (CS1)
Question
53 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.