IAE Academy

GATE 2026 CS1 Q.53: solution and answer

GATE 2026 · CS1Q.53 · 2 marks · MSQ

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

SDD1, grammar G1 and semantic rules:
- : ;
- :
- :
- : ;
- :

SDD2, grammar G2 and semantic rules:
- : ;
- : ;
- :
- :

is the start symbol, and int, float and id are the three terminals. The non-terminal is the same as and the non-terminal is the same as . 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 and Q be the languages specified by grammars G1 and G2, respectively.

Which of the following statements is/are true?

GATE 2026 CS1 question 53: Two side-by-side tables titled SDD1 and SDD2, each with columns Grammar (G1 or G2) and Semantic Rules, listing the…Tap to open full size
Figure from the GATE 2026 CS1 paper. It is part of the question.
Figure description

Two side-by-side tables titled SDD1 and SDD2, each with columns Grammar (G1 or G2) and Semantic Rules, listing the productions and semantic rules given in the stem.

  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

Answer and solution

ANSWER

The true statements are (A), (B) and (D).

Official answer: A, B, DSource: Official answer key, GATE 2026 CS1 (IIT Guwahati)

  1. Language of G1: from and , derives (one or more ids), so .

  2. Language of G2: from , derives , so . Hence and (A) is true.

  3. SDD2: every rule defines the head's attribute from attributes of body symbols ( from or ; from a constant). The calls only read or , and is a lexical value supplied by the scanner. So every attribute is synthesized, SDD2 is S-attributed, and (B) is true.

  4. SDD1: and define an attribute of a body symbol from the parent's or a left sibling's attribute, so is inherited and the definition is L-attributed. But and are defined from the head's own production body or a constant, so they are synthesized. SDD1 therefore does not contain only inherited attributes, and (C) is false.

  5. Symbol table entries: in SDD1 each id receives , which is copied from down the chain of nodes. In SDD2 each id receives (first id) or (later ids), which is the same declared type passed up the chain. In both, every id of a declaration is entered with the declared type, so the same entries are added and (D) is true.

  6. Answer: A, B and D.

KEY IDEA

Synthesized attributes depend on the children (or constants); inherited attributes depend on the parent or left siblings. S-attributed means synthesized only. Compare grammars by the languages they derive, and compare SDDs by what they put in the symbol table.

WATCH OUT FOR

Calling SDD1 'only inherited' because is inherited, forgetting that and are synthesized. Another slip is thinking G2's left recursion changes the language, when both grammars generate the same strings.

From the GATE 2026 CS1 paper. Every question of this paper · Download the full paper · All 7 Syntax-directed translation questions, with notes

More Syntax-directed translation questions