Compiler Design questions

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/100 correct0 marks

Related topics in GATE CS