Compiler Design

Question 1
Consider the following augmented grammar with \{ \#, @, <, >, a, b, c \} as the set of terminals.

\begin{array}{l} S' \rightarrow S \\ S \rightarrow S \# cS \\ S \rightarrow SS \\ S \rightarrow S @ \\ S \rightarrow < S > \\ S \rightarrow a \\ S \rightarrow b \\ S \rightarrow c \end{array}

Let I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\}). The number of items in the set \text{GOTO(GOTO}(I_0 \lt ), \lt ) is ___________
A
6
B
7
C
8
D
9
GATE CSE 2021 SET-2      Parsing
Question 2
For a statement S in a program, in the context of liveness analysis, the following sets are defined:

USE(S) : the set of variables used in S
IN(S) : the set of variables that are live at the entry of S
OUT(S) : the set of variables that are live at the exit of S

Consider a basic block that consists of two statements, S1 followed by S2. Which one of the following statements is correct?
A
OUT(S1) = IN (S2)
B
OUT (S1) = IN (S1) \cup USE (S1)
C
OUT (S1) =IN (S2) \cup OUT (S2)
D
OUT (S1) = USE (S1)\cup IN (S2)
GATE CSE 2021 SET-2      Runtime Environment
Question 3
In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?
A
Three address code
B
Abstract Syntax Tree (AST)
C
Control Flow Graph (CFG)
D
Symbol table
GATE CSE 2021 SET-2      Intermediate Code Generation
Question 4
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?
A
Lexical analyzer
B
Syntax analyzer
C
Semantic analyzer
D
Machine dependent optimizer
GATE CSE 2021 SET-2      Syntax-directed Translation
Question 5
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 _____________
A
11
B
6
C
5
D
10
GATE CSE 2021 SET-1      Parsing
Question 6
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

\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?
A
The actions can be used to correctly type-check any syntactically correct program
B
The actions can be used to type-check syntactically correct integer variable declarations and integer expressions
C
The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.
D
The actions will lead to an infinite loop
GATE CSE 2021 SET-1      Syntax-directed Translation
Question 7
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(n^3) time to parse a string of length n.

Which one of the following options is correct?
A
S1 is true and S2 is false
B
S1 is false and S2 is true
C
S1 is true and S2 is true
D
S1 is false and S2 is false
GATE CSE 2021 SET-1      Parsing
Question 8
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?
A
S1 is true and S2 is false
B
S1 is false and S2 is true
C
S1 is true and S2 is true
D
S1 is false and S2 is false
GATE CSE 2021 SET-1      Runtime Environment
Question 9
A grammar is defined as
A \rightarrow B C
B \rightarrow x \mid B x
C \rightarrow B \mid D
D \rightarrow y \mid Ey
E \rightarrow z
The non terminal alphabet of the grammar is
A
\{A, B, C, D, E\}
B
\{B, C, D, E\}
C
\{A, B, C, D, E,x,y,z\}
D
\{x,y,z\}
ISRO CSE 2020      Parsing
Question 10
A given grammar is called ambiguous if
A
two or more productions have the same non-terminal on the left hand side
B
a derivation tree has more than one associated sentence
C
there is a sentence with more than one derivation tree corresponding to it
D
brackets are not present in the grammar
ISRO CSE 2020      Parsing


There are 10 questions to complete.

Leave a Comment

Like this FREE website? Please share it among all your friends and join the campaign of FREE Education to ALL.