Syntax-directed Translation: GATE CS Previous Year Questions

Syntax-directed Translation · Compiler Design

17 questions · asked in 11 of 27 years (2000–2026)

MCQ 13 · MSQ 2 · NAT 21-mark 10 · 2-mark 7

2000Questions per year2026

Questions 1–5 of 17

Q1GATE 2026 (Session 1)2 marksMSQ
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, D1.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?

One or more options are correct.

Q2GATE 2026 (Session 2)1 markMCQ−0.33 if wrong
Consider the following three ANSI-C programs, P1, P2,\text{P1, P2,} and P3\text{P3}.

P1P2P3#include < stdio.h >#include < stdio.h >#include < stdio.h >int a=5;int main(){int a=7;return(0);int main(){int a=5;int a=7;return(0);int main(){int a=5;float a=7;return(0);}}}\begin{array}{|l|l|l|} \hline \quad\quad\quad \textbf{P1} & \quad\quad\quad \textbf{P2} & \quad\quad\quad \textbf{P3} \\ \hline \text{\#include < stdio.h >} & \text{\#include < stdio.h >} & \text{\#include < stdio.h >} \\ \begin{array}{l} \text{int a=5;} \\ \text{int main()\{} \\ \quad \text{int a=7;} \\ \quad \text{return(0);} \end{array} & \begin{array}{l} \text{int main()\{} \\ \quad \text{int a=5;} \\ \quad \text{int a=7;} \\ \quad \text{return(0);} \end{array} & \begin{array}{l} \text{int main()\{} \\ \quad \text{int a=5;} \\ \quad \text{float a=7;} \\ \quad \text{return(0);} \end{array} \\ {\text{\}}} & {\text{\}}} & {\text{\}}} \\ \hline \end{array}

Which one of the following statements is true?

Q3GATE 2025 (Session 2)1 markMCQ−0.33 if wrong
Given the following syntax-directed translation rules:

Rule 1: R→AB{B.i=R.i−1;A.i=B.i;R.i=A.i+1;}\text{Rule 1: } R \rightarrow AB \{ B.i = R.i - 1; A.i = B.i; R.i = A.i + 1; \}
Rule 2: P→CD{P.i=C.i+D.i;D.i=C.i+2;}\text{Rule 2: } P \rightarrow CD \{ P.i = C.i + D.i; D.i = C.i + 2; \}
Rule 3: Q→EF{Q.i=E.i+F.i;}\text{Rule 3: } Q \rightarrow EF \{ Q.i = E.i + F.i; \}

Which ONE is the CORRECT option among the following?

Q4GATE 2024 (Session 1)2 marksMCQ−0.67 if wrong
Consider the following syntax-directed definition (SDD).

S→DHTU{S.val=D.val+H.val+T.val+U.val;}D→"M"D1{D.val=5+D1.val;}D→ϵ{D.val=−5;}H→"L"H1{H.val=5∗10+H1.val;}H→ϵ{H.val=−10;}T→"C"T1{T.val=5∗100+T1.val;}T→ϵ{T.val=−5;}U→"K"{U.val=5;}\begin{array}{|l|l|} \hline S \rightarrow DHTU & \{ S.val = D.val + H.val + T.val + U.val; \} \\ \hline D \rightarrow "M"D_1 & \{ D.val =5+D_1 . val; \} \\ \hline D \rightarrow \epsilon & \{ D.val =-5 ;\} \\ \hline H \rightarrow "L" H_1 & \{ H.val =5 * 10+H_1 . val; \} \\ \hline H \rightarrow \epsilon & \{ H.val =-10 ;\} \\ \hline T \rightarrow "C" T_1 & \{T . v a l=5 * 100+T_1 . val; \} \\ \hline T \rightarrow \epsilon & \{T . v a l=-5 ;\} \\ \hline U \rightarrow "K" & \{ U.val =5 ;\} \\ \hline \end{array}

Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.val)?

Q5GATE 2024 (Session 2)1 markMSQ
Which of the following statements is/are FALSE?

One or more options are correct.

Keep practising

Topics in Compiler Design

All CS topics ›