Compiler Design

Compiler Design Questions Answers GATE 2021

Compiler Design GATE Question Answers with Explanation.

Q1 – Consider the following statements.
S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct? (GATE 2021 Set 1)
  1. S1 is true and S2 is false.
  2. S1 is false and S2 is true.
  3. S1 is true and S2 is true.
  4. S1 is false and S2 is false.

Ans – (3)

Explanation – 

Q2 – Consider the following statements.
S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most O(n3) time to parse a string of length n.
Which one of the following options is correct? (GATE 2021 Set 1)
  1. S1 is true and S2 is false.
  2. S1 is false and S2 is true.
  3. S1 is true and S2 is true.
  4. S1 is false and S2 is false.

Ans – (3)

Explanation

Q3 – 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. 

Q26 Compiler design GATE 2021

With respect to the above grammar, which one of the following choices is correct? (GATE 2021 Set 1)

 

  1. The actions can be used to correctly type-check any syntactically correct program.
  2. The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
  3. The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.
  4. The actions will lead to an infinite loop.

Ans – (2)

Explanation

Q4 – Consider the following context-free grammar where the set of terminals is {a, b, c, d, f}.
Compiler Design GATE 2021 Set 1 1
The following is a partially-filled LL(1) parsing table.
Compiler Design GATE 2021 Set 1
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)? (GATE 2021 Set 1)

 

Compiler Design GATE 2021 Set 1 3

 

  1. A
  2. B
  3. C
  4. D

Ans – (2)

Explanation

Q5 – 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 _____________ . (GATE 2021 Set 1)

Ans – (6)

Explanation