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 6–10 of 17

Q6GATE 20232 marksNAT
Consider the syntax directed translation given by the following grammar and semantic rules. Here N,I,F  and  BN, I, F \; and \; B are non-terminals. NN is the starting non-terminal, and #,0  and  1\#,0 \; and \; 1 are lexical tokens corresponding to input letters "#","0"  and  "1""\#","0" \; and \; "1", respectively. X.valX.val denotes the synthesized attribute (a numeric value) associated with a non-terminal XX. I1I_1 and F1F_1 denote occurrences of II and FF on the right hand side of a production, respectively. For the tokens 00 and 11, 0.val=00.val=0 and 1.val=11.val=1.

The value computed by the translation scheme for the input string
N→I#FN.val=I.val+F.valI→I1BI.val=(2I1.val)+B.valI→BI.val=B.valF→BF1F.val=12(B.val+F1.val)F→BF.val=12B.valB→0B.val=0.valB→1B.val=1.val\begin{aligned} N & \rightarrow I \# F & N.val=I.val+F.val \\ I &\rightarrow I_1B & I.val = (2 I1.val) + B.val\\ I &\rightarrow B&I.val = B.val\\ F &\rightarrow BF_1& F.val = \frac{1}{2}(B.val + F1.val)\\ F &\rightarrow B& F.val = \frac{1}{2} B.val\\ B&\rightarrow 0& B.val = 0.val\\ B &\rightarrow 1&B.val = 1.val \end{aligned}
10#01110\# 011

is ____ (Rounded off to three decimal places)

Q7GATE 2021 (Session 1)2 marksMCQ−0.67 if wrong
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code

P→D∗E∗D→int ID{record that ID.lexeme is of type int}D→bool ID{record that ID.lexeme is of type bool}E→E1+E2{check that E1.type=E2.type=int;set E.type :=int}E→!E1{check that E1.type=bool; set E.type:=bool}E→ID{set E.type :=int}\begin{array}{lll} P & \rightarrow & D^* E^* \\ D & \rightarrow & \textsf{int ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ int\}} \\ D & \rightarrow & \textsf{bool ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ bool\}} \\ E& \rightarrow & E_1 +E_2 \{ \text{check that } E_1. \text{type}=E_2. \text{type} = \textsf{int}; \text{set } E.\text{type }:= \textsf{int} \} \\ E & \rightarrow & !E_1 \{ \text{check that } E_1. \text{type} = \textsf{bool}; \text{ set } E.\text{type} := \textsf{bool} \} \\ E & \rightarrow & \textsf{ID} \{ \text{set } E. \text{type } := \textsf{int} \} \end{array}

With respect to the above grammar, which one of the following choices is correct?

Q8GATE 2021 (Session 1)2 marksNAT
Consider the following C code segment:

a = b + c;
e = a + 1;
d = b + c;
f = d + 1;
g = e + f;

In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is _____________

Q9GATE 20192 marksMCQ−0.67 if wrong
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1,X2,X3,X4,X5  and  X6X_1,X_2,X_3,X_4,X_5 \; and \; X_6 be the placeholders for the non-terminals D, T, L or L1L_1 in the following table:
Production ruleSemantic action
D → T LX1.type = X2.type
T → intT.type = int
T → floatT.type = float
L → L1 , idX3.type = X4.type
addType(id.entry, X5.type)
L → idaddType(id.entry, X6.type)

Which one of the following are the appropriate choices for X1,X2,X3  and  X4X_1,X_2,X_3 \; and \; X_4?

Q10GATE 20181 markMCQ−0.33 if wrong
Which one of the following statements is FALSE?

Keep practising

Topics in Compiler Design

All CS topics ›