Compiler Design questions — page 2 of 5

Q40

GATE CS 2024 CS-2ParsingMCQ2 marks−2/3 if wrong
Consider the following context-free grammar where the start symbol is SS and the set of terminals is {a,b,c,d}\{a,b,c,d\}.

S→AaAb∣BbBaS \to AaAb \mid BbBa
A→cS∣ϵA \to cS \mid \epsilon
B→dS∣ϵB \to dS \mid \epsilon

The following is a partially-filled LL(1) parsing table.
aabbccdd$\$
SSS→AaAbS \to AaAbS→BbBaS \to BbBa(1)(2)
AAA→ϵA \to \epsilon(3)A→cSA \to cS
BB(4)B→ϵB \to \epsilonB→dSB \to dS
Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?

Note: In the options, "blank" denotes that the corresponding cell is empty.
Show answer without attempting

Answer: A

Q43

GATE CS 2024 CS-2Intermediate CodeMCQ2 marks−2/3 if wrong
Consider the following expression: x[i]=(p+r)∗−s[i]+u/wx[i] = (p + r) * -s[i] + u/w. The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).

Which one of the following options fills in the missing entries CORRECTLY?
Question figure
Show answer without attempting

Answer: A

Q65

GATE CS 2024 CS-2ParsingNAT2 marks
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a,b,c,d,#,@}\{a,b,c,d,\#,@\}

S′→SS' \to S
S→SS∣Aa∣bAc∣Bc∣bBaS \to SS \mid Aa \mid bAc \mid Bc \mid bBa
A→d#A \to d\#
B→@B \to @

Let I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S' \to \bullet S\}). The number of items in the set GOTO(I0,S)\text{GOTO}(I_0, S) is ___________
Show answer without attempting

Answer: 9

Q11

GATE CS 2023 CSLexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following statements regarding the front-end and back-end of a compiler.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.

Identify the CORRECT option.
Show answer without attempting

Answer: B

Q19

GATE CS 2023 CSLexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:
<br>letter→[A-Za-z]<br>digit→[0-9]<br>id→letter (letter ∣ digit)∗<br>\begin{align*}<br>\text{letter} & \to \text{[A-Za-z]} \\<br>\text{digit} & \to \text{[0-9]} \\<br>\text{id} & \to \text{letter (letter } | \text{ digit)}^*<br>\end{align*}

Which one of the following Non-deterministic Finite-state Automata with ϵ\epsilon-transitions accepts the set of valid identifiers? (A double-circle denotes a final state)
Show answer without attempting

Answer: C

Q37

GATE CS 2023 CSOptimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the control flow graph shown.

Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?
Question figure
Show answer without attempting

Answer: 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

Q13

GATE CS 2022 CSParsingMCQ1 mark−1/3 if wrong
Which one of the following statements is TRUE?
Show answer without attempting

Answer: D

Q29

GATE CS 2022 CSParsingNAT1 mark
Consider the augmented grammar with {+,∗,(,),id}\{+, *, (, ), \text{id}\} as the set of terminals.

S′→SS' \to S
S→S+R∣RS \to S + R \mid R
R→R∗P∣PR \to R * P \mid P
P→(S)∣idP \to (S) \mid \text{id}

If I0I_0 is the set of two LR(0)LR(0) items {[S′→S∙],[S→S∙+R]}\bigl\{[S' \to S\bullet], [S \to S\bullet + R]\bigr\}, then goto(closure(I0),+)\text{goto}(\text{closure}(I_0), +) contains exactly __________ items.
Show answer without attempting

Answer: 5

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

Q4

GATE CS 2021 CS-1Runtime EnvironmentsMCQ1 mark−1/3 if wrong
Consider the following statements.
S1S_1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2S_2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
Show answer without attempting

Answer: C

Q5

GATE CS 2021 CS-1ParsingMCQ1 mark−1/3 if wrong
Consider the following statements.
S1S_1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2S_2: For any context-free grammar, there is a parser that takes at most O(n3)O(n^3) time to parse a string of length nn.
Which one of the following options is correct?
Show answer without attempting

Answer: C

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

Q31

GATE CS 2021 CS-1ParsingMCQ2 marks−2/3 if wrong
Consider the following context-free grammar where the set of terminals is {a,b,c,d,f}\{a, b, c, d, f\}.
S→daT∣RfS \to daT \mid Rf
T→aS∣baT∣ϵT \to aS \mid baT \mid \epsilon
R→caTR∣ϵR \to caTR \mid \epsilon
The following is a partially-filled LL(1) parsing table.
aabbccddff$\$
S(1)S→daTS \to daT(2)
TT→aST \to aST→baTT \to baT(3)T→ϵT \to \epsilon(4)
RR→caTRR \to caTRR→ϵR \to \epsilon
Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?
Show answer without attempting

Answer: A

Q50

GATE CS 2021 CS-1Intermediate CodeNAT2 marks
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 ______.
Show answer without attempting

Answer: 6

Q3

GATE CS 2021 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Consider the following ANSI C program:
int main() {
    Integer x;
    return 0;
}
Which one of the following phases in a seven-phase C compiler will throw an error?
Show answer without attempting

Answer: C

Q13

GATE CS 2021 CS-2Intermediate CodeMSQ1 mark
In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?
More than one option can be correct.
Show answer without attempting

Answer: D

Q30

GATE CS 2021 CS-2Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider the following ANSI C code segment:
z = x + 3 + y->f1 + y->f2;
for (i = 0; i < 200; i = i + 2){
    if (z > i) {
        p = p + x + 3;
        q = q + y->f1;
    } else {
        p = p + y->f2;
        q = q + x + 3;
    }
}
Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and dereference operations (of the form y->f1 or y->f2) in the optimized code, respectively, are:
Show answer without attempting

Answer: D

Q38

GATE CS 2021 CS-2Optimization and Data FlowMCQ2 marks−2/3 if wrong
For a statement SS in a program, in the context of liveness analysis, the following sets are defined:

<br>USE(S):the set of variables used in S<br>IN(S):the set of variables that are live at the entry of S<br>OUT(S):the set of variables that are live at the exit of S<br>\begin{array}{rll}<br>\text{USE}(S) & : & \text{the set of variables used in } S \\<br>\text{IN}(S) & : & \text{the set of variables that are live at the entry of } S \\<br>\text{OUT}(S) & : & \text{the set of variables that are live at the exit of } S<br>\end{array}

Consider a basic block that consists of two statements, S1S_1 followed by S2S_2.
Which one of the following statements is correct?
Show answer without attempting

Answer: A

Q51

GATE CS 2021 CS-2ParsingNAT2 marks
Consider the following augmented grammar with {#,@,<,>,a,b,c}\{\#, @, <, >, a, b, c\} as the set of terminals.

<br>S′→S<br>S→S#cS<br>S→SS<br>S→S@<br>S→<S><br>S→a<br>S→b<br>S→c<br>\begin{aligned}<br>S' & \to S \\<br>S & \to S \# c S \\<br>S & \to S S \\<br>S & \to S @ \\<br>S & \to < S > \\<br>S & \to a \\<br>S & \to b \\<br>S & \to c<br>\end{aligned}

Let I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S' \to \bullet S\}). The number of items in the set GOTO(GOTO(I0,<),<)\text{GOTO}(\text{GOTO}(I_0, <), <) is ____________.
Show answer without attempting

Answer: 8

0/200 correct0 marks

Related topics in GATE CS