Skip to content
Official PYQ · 2026

GATE CS 2026 Set 1 Q43 — Syntax-directed Translation

Explain with AI

GATE CSE 2026 | Set 1-43

  1. GATE CSE 2026 | Set 1-199
  2. GATE CSE 2026 | Set 1-199
  3. GATE CSE 2026 | Set 1-199
  4. GATE CSE 2026 | Set 1-199

Consider the following two syntax-directed definitions SDD1\text{SDD1} and SDD2\text{SDD2} for type declarations.
SDD1Grammar(G1)Semantic RulesD→TVD.type=T.typeV.type=T.typeT→intT.type=intT→floatT.type=floatV→V1 idV1.type=V.typeput(id.entry, V.type)V→idput(id.entry, V.type)\begin{array}{|l|l|} \hline {\textbf{SDD1}} \\ \hline { \begin{array}{c} \textbf{Grammar} \\ (G_1) \end{array}} & {\textbf{Semantic Rules}} \\ \hline \hline D \rightarrow TV & \begin{array}{l} D.type = T.type \\ V.type = T.type \end{array} \\ \hline T \rightarrow \text{int} & T.type = \text{int} \\ \hline T \rightarrow \text{float} & T.type = \text{float} \\ \hline V \rightarrow V_1\ \text{id} & \begin{array}{l} V_1.type = V.type \\ \text{put(id.entry, V.type)} \end{array} \\ \hline V \rightarrow \text{id} & \text{put(id.entry, V.type)} \\ \hline \end{array}

SDD2Grammar(G2)Semantic RulesD→D1 idD.type=D1.typeput(id.entry, D_1.type)D→T idD.type=T.typeput(id.entry, T.type)T→intT.type=intT→floatT.type=float\begin{array}{|l|l|} \hline {\textbf{SDD2}} \\ \hline { \begin{array}{c} \textbf{Grammar} \\ (G_2) \end{array}} & {\textbf{Semantic Rules}} \\ \hline \hline D \rightarrow D_1\ \text{id} & \begin{array}{l} D.type = D_1.type \\ \text{put(id.entry, D\_1.type)} \end{array} \\ \hline D \rightarrow T\ \text{id} & \begin{array}{l} D.type = T.type \\ \text{put(id.entry, T.type)} \end{array} \\ \hline T \rightarrow \text{int} & T.type = \text{int} \\ \hline T \rightarrow \text{float} & T.type = \text{float} \\ \hline \end{array}
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?

Select all correct options
View worked solution

Answer: A;B;D

Let us analyze each option step-by-step:

1. Language Equivalence (Option A):

  • Grammar G1G_1: The productions are D→TVD \rightarrow T V, T→int∣floatT \rightarrow \text{int} \mid \text{float}, and V→V id∣idV \rightarrow V \ \text{id} \mid \text{id}. This generates a type followed by one or more identifiers: P={int idn,float idn∣n≥1}P = \{\text{int}\ \text{id}^n, \text{float}\ \text{id}^n \mid n \ge 1\}.
  • Grammar G2G_2: The productions are D→D id∣T idD \rightarrow D \ \text{id} \mid T \ \text{id} and T→int∣floatT \rightarrow \text{int} \mid \text{float}. This also generates a type followed by one or more identifiers: Q={int idn,float idn∣n≥1}Q = \{\text{int}\ \text{id}^n, \text{float}\ \text{id}^n \mid n \ge 1\}.

Since P=QP = Q, Option A is true.

2. Attributes of SDD2 (Option B):

  • The attributes defined in SDD2\text{SDD2} are T.typeT.type and D.typeD.type.
  • T.typeT.type is defined directly from terminals (synthesized).
  • D.typeD.type is defined using the attributes of its children (T.typeT.type or D1.typeD_1.type), which are also synthesized.
  • Since every attribute in SDD2\text{SDD2} is synthesized, it is S-attributed and contains only synthesized attributes. Thus, Option B is true.

3. Attributes of SDD1 (Option C):

  • In SDD1\text{SDD1}, V.typeV.type is an inherited attribute because its value in D→TVD \rightarrow T V is defined as V.type=T.typeV.type = T.type (inherited from sibling TT).
  • However, T.typeT.type and D.typeD.type are synthesized attributes. Since SDD1\text{SDD1} contains both synthesized and inherited attributes, the claim that it contains only inherited attributes is false. Thus, Option C is false.

4. Symbol Table Entries (Option D):

  • For any declaration string like int id1 id2 … idn\text{int}\ \text{id}_1\ \text{id}_2\ \dots\ \text{id}_n:
    • In SDD1\text{SDD1}, the type int\text{int} is inherited down the parse tree through V.typeV.type, and put(idi.entry,int)\text{put}(\text{id}_i.\text{entry}, \text{int}) is called for every identifier.
    • In SDD2\text{SDD2}, the type int\text{int} is synthesized up the parse tree through D.typeD.type, and put(idi.entry,int)\text{put}(\text{id}_i.\text{entry}, \text{int}) is called for every identifier.
  • In both cases, the exact same identifier-to-type mappings are added to the symbol table. Thus, Option D is true.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Syntax-directed Translation questions