Translation Schemes questions

Q53

GATE CS 2026 CS-1Syntax Directed TranslationMSQ2 marks
Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

DD is the start symbol, and intint, floatfloat and idid 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 putput 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?
Question figure
More than one option can be correct.
Show answer without attempting

Answer: A, B, D

Q22

GATE CS 2025 CS-2Syntax Directed TranslationMCQ1 mark−1/3 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;}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;}P \rightarrow CD \{P.i = C.i + D.i; D.i = C.i + 2;\}
Rule 3: Q→EF{Q.i=E.i+F.i;}Q \rightarrow EF \{Q.i = E.i + F.i;\}

Which ONE is the CORRECT option among the following?
Show answer without attempting

Answer: C

Q37

GATE CS 2024 CS-1Syntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the following syntax-directed definition (SDD).
S→DHTU{S.val=D.val+H.val+T.val+U.val;}S \to DHTU \{ S.val = D.val + H.val + T.val + U.val; \}
D→"M"D1{D.val=5+D1.val;}D \to \text{"M"}D_1 \{ D.val = 5 + D_1.val; \}
D→ϵ{D.val=−5;}D \to \epsilon \{ D.val = -5; \}
H→"L"H1{H.val=5∗10+H1.val;}H \to \text{"L"}H_1 \{ H.val = 5 * 10 + H_1.val; \}
H→ϵ{H.val=−10;}H \to \epsilon \{ H.val = -10; \}
T→"C"T1{T.val=5∗100+T1.val;}T \to \text{"C"}T_1 \{ T.val = 5 * 100 + T_1.val; \}
T→ϵ{T.val=−5;}T \to \epsilon \{ T.val = -5; \}
U→"K"{U.val=5;}U \to \text{"K"} \{ U.val = 5; \}
Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.valS.val)?
Show answer without attempting

Answer: A

Q29

GATE CS 2024 CS-2Syntax Directed TranslationMSQ1 mark
Which of the following statements is/are FALSE?
More than one option can be correct.
Show answer without attempting

Answer: B, D

Q60

GATE CS 2023 CSSyntax Directed TranslationNAT2 marks
Consider the syntax directed translation given by the following grammar and semantic rules. Here N,I,FN, I, F and BB are non-terminals. NN is the starting non-terminal, and #, 0 and 1 are lexical tokens corresponding to input letters "#", "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 0 and 1, 0.val=00.val = 0 and 1.val=11.val = 1.

<br>N→I#FN.val=I.val+F.val<br>I→I1BI.val=(2×I1.val)+B.val<br>I→BI.val=B.val<br>F→BF1F.val=12(B.val+F1.val)<br>F→BF.val=12B.val<br>B→0B.val=0.val<br>B→1B.val=1.val<br>\begin{align*}<br>N & \to I \# F && N.val = I.val + F.val \\<br>I & \to I_1 B && I.val = (2 \times I_1.val) + B.val \\<br>I & \to B && I.val = B.val \\<br>F & \to B F_1 && F.val = \frac{1}{2}(B.val + F_1.val) \\<br>F & \to B && F.val = \frac{1}{2} B.val \\<br>B & \to 0 && B.val = 0.val \\<br>B & \to 1 && B.val = 1.val<br>\end{align*}

The value computed by the translation scheme for the input string
10#01110\#011
is ____________. (Rounded off to three decimal places)
Show answer without attempting

Answer: 2.374 to 2.376

Q65

GATE CS 2022 CSSyntax Directed TranslationNAT2 marks
Consider the following grammar along with translation rules.

S→S1#T{Sval=S1val∗Tval}S \to S_1 \# T \quad \{S_{\text{val}} = S_{1\text{val}} * T_{\text{val}}\}
S→T{Sval=Tval}S \to T \quad \{S_{\text{val}} = T_{\text{val}}\}
T→T1%R{Tval=T1val÷Rval}T \to T_1 \% R \quad \{T_{\text{val}} = T_{1\text{val}} \div R_{\text{val}}\}
T→R{Tval=Rval}T \to R \quad \{T_{\text{val}} = R_{\text{val}}\}
R→id{Rval=idval}R \to \text{id} \quad \{R_{\text{val}} = \text{id}_{\text{val}}\}

Here # and % are operators and id\text{id} is a token that represents an integer and idval\text{id}_{\text{val}} represents the corresponding integer value. The set of non-terminals is {S,T,R,P}\{S, T, R, P\} and a subscripted non-terminal indicates an instance of the non-terminal.

Using this translation scheme, the computed value of SvalS_{\text{val}} for root of the parse tree for the expression 20#10%5#8%2%220\#10\%5\#8\%2\%2 is _____________.
Show answer without attempting

Answer: 80

Q26

GATE CS 2021 CS-1Syntax Directed TranslationMCQ2 marks−2/3 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}
With respect to the above grammar, which one of the following choices is correct?
Show answer without attempting

Answer: B

Q33

GATE CS 2020 CSSyntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the productions A→PQA \rightarrow PQ and A→XYA \rightarrow XY. Each of the five non-terminals A, P, Q, X, and Y has two attributes: ss is a synthesized attribute, and ii is an inherited attribute. Consider the following rules.

Rule 1: P.i=A.i+2P.i = A.i + 2, Q.i=P.i+A.iQ.i = P.i + A.i, and A.s=P.s+Q.sA.s = P.s + Q.s

Rule 2: X.i=A.i+Y.sX.i = A.i + Y.s and Y.i=X.s+A.iY.i = X.s + A.i

Which one of the following is TRUE?
Show answer without attempting

Answer: B

Q36

GATE CS 2019 CSSyntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1,X2,X3,X4,X5,X_1, X_2, X_3, X_4, X_5, and X6X_6 be the placeholders for the non-terminals D,T,LD, T, L or L1L_1 in the following table:
Production ruleSemantic action
D→T  LD \to T \; LX1.type=X2.typeX_1.\text{type} = X_2.\text{type}
T→intT \to \text{int}T.type=intT.\text{type} = \text{int}
T→floatT \to \text{float}T.type=floatT.\text{type} = \text{float}
L→L1,idL \to L_1, \text{id}X3.type=X4.typeX_3.\text{type} = X_4.\text{type}; addType(id.entry,X5.type)\text{addType}(\text{id.entry}, X_5.\text{type})
L→idL \to \text{id}addType(id.entry,X6.type)\text{addType}(\text{id.entry}, X_6.\text{type})
Which one of the following are the appropriate choices for X1,X2,X3X_1, X_2, X_3 and X4X_4?
Show answer without attempting

Answer: A

Q46

GATE CS 2016 CS-1Syntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b}.
S→aA{print 1}S \to aA \{ \text{print } 1 \}
S→a{print 2}S \to a \{ \text{print } 2 \}
A→Sb{print 3}A \to Sb \{ \text{print } 3 \}
Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:
Show answer without attempting

Answer: C

0/100 correct0 marks