GATE 2026 CS (CS1) – Question 53
Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations:
**SDD1**:
- $D \to T \, V \quad \{ D.type = T.type; \; V.type = T.type; \}$
- $T \to int \quad \{ T.type = int; \}$
- $T \to float \quad \{ T.type = float; \}$
- $V \to V_1 \, id \quad \{ V_1.type = V.type; \; put(id.entry, V.type); \}$
- $V \to id \quad \{ put(id.entry, V.type); \}$
**SDD2**:
- $D \to D_1 \, id \quad \{ D.type = D_1.type; \; put(id.entry, D_1.type); \}$
- $D \to T \, id \quad \{ D.type = T.type; \; put(id.entry, T.type); \}$
- $T \to int \quad \{ T.type = int; \}$
- $T \to float \quad \{ T.type = float; \}$
Let P and Q be the languages specified by grammars G1 and G2, respectively. Which of the following statements is/are true?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) The languages P and Q are the same; (B) SDD2 is S-attributed and contains only synthesized attributes; (D) The specifications of SDD1 and SDD2 are such that the same entries get added to the symbol table
Explanation
**Grammars.** G1 (from SDD1): $D\to TV$, $V\to V\,id\mid id$. G2 (from SDD2): $D\to D\,id\mid T\,id$. Both generate $T\,id^+$ (a type followed by one or more identifiers).
- **(A) True.** $L(G_1)=L(G_2)=\{\text{int, float}\}\,id^+$, so the languages are the same.
- **(B) True.** In SDD2 every attribute ($D.type$, $T.type$) is **synthesized**: $D.type$ is computed from the child $D_1.type$ or $T.type$, and $T.type$ from a terminal. The $put(\dots)$ calls are side effects that only read children's attributes. So SDD2 is S-attributed.
- **(C) False.** SDD1 is L-attributed, but it does not contain *only* inherited attributes: $T.type$ is synthesized and $V.type$ is inherited.
- **(D) True.** In both definitions each identifier is entered into the symbol table with the declared type, so the same entries are added.
Answer: A, B, D.