Compiler Design MCQ Question Bank Last Update 29-Dec-20202 Page 1 of 18
Compiler Design MCQ Question Bank Last Update 29-Dec-20202 Page 1 of 18
Compiler Design MCQ Question Bank Last Update 29-Dec-20202 Page 1 of 18
Q) A compiler that runs on one machine and produces code for a different
machine is called
(A) Removing left recursion alone (B) Factoring the grammar alone
(C) Removing left recursion and factoring the grammar (D) None of these
Answer: (D)
Explanation: Removing left recursion and factoring the grammar do not suffice to
convert an arbitrary CFG to LL(1) grammar.
Answer: (A)
Explanation: Recursive Descent parsing is LL(1) parsing which is top down parsing.
Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal
between them, the given grammar is LL(1).
A. LL(1)
a) Canonical LR
b) SLR
c) LALR
Answer: (B) Canonical LR
Q. Assume that SLR parser for a grammar G has N1 states and the LALR parser
for G has N2 states. The relationship between N1 and N2 is: [GATE 2003]
A. N1 is necessarily less than N2.
B. N1 is necessarily equal to N2.
C. N1 is necessarily greater than N2.
D. None of these.
Answer: (B) N1 is necessarily equal to N2.
Explanation: The question is asked with respect to the symbol ‘ < ‘ which is not
present in the given canonical set of items. Hence it is neither a shift-reduce conflict
nor a reduce-reduce conflict on symbol ‘<‘.
Hence D is the correct option.
Q. The lexical analysis for a modern computer language such as Java needs the
power of which one of the following machine models in a necessary and
sufficient sense? (GATE CS 2011)
6. Match all items in Group 1 with correct options from those given in Group 2.
(GATE-CS-2009)
Group 1 Group 2
P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
S. Register allocation 4. Code optimization
Answer: (C)
Explanation: Lexical analysis is the process of converting a sequence of characters
into a sequence of tokens. A token can be a keyword.
Q. The lexical analysis for a modern computer language such as Java needs the
power of which one of the following machine models in a necessary and
sufficient sense?
Answer: (A)
Q. A canonical set of items is given below
S --> L. > R
Q --> R.
On input symbol < the set has
(A) a shift-reduce conflict and a reduce-reduce conflict.
(B) a shift-reduce conflict but not a reduce-reduce conflict.
(C) a reduce-reduce conflict but not a shift-reduce conflict.
(D) neither a shift-reduce nor a reduce-reduce conflict.
Answer: (D)
Explanation: The question is asked with respect to the symbol ‘ < ‘ which is not
present in the given canonical set of items. Hence it is neither a shift-reduce conflict
nor a reduce-reduce conflict on symbol ‘<‘.
Answer: (A)
Explanation: Recursive Descent parsing is LL(1) parsing which is top down parsing.
Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal
between them, the given grammar is LL(1).
Answer: (D)
Q. Match all items in Group 1 with correct options from those given in Group 2.
Compiler Design MCQ question bank last update 29-Dec-20202 Page 7 of 18
Group 1 Group 2
P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
S. Register allocation 4. Code optimization
Q.
Which of the following is the most powerful parsing method?
A. LL(1)
Canonical LR
SLR
LALR
Answer: (B) Canonical LR
Q. Assume that SLR parser for a grammar G has N1 states and the LALR parser for G
has N2 states. The relationship between N1 and N2 is: [GATE 2003]
A. N1 is necessarily less than N2.
A. N1 is necessarily equal to N2.
B. N1 is necessarily greater than N2.
C. None of these.
Answer: (B) N1 is necessarily equal to N2.
Answer A
Q) A compiler that runs on one machine and produces code for a different
machine is called
(A) Removing left recursion alone (B) Factoring the grammar alone
(C) Removing left recursion and factoring the grammar (D) None of these
Answer: (D)
Explanation: Removing left recursion and factoring the grammar do not suffice to
convert an arbitrary CFG to LL(1) grammar.
Answer: (A)
Explanation: Recursive Descent parsing is LL(1) parsing which is top down parsing.
Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal
between them, the given grammar is LL(1).
Q. Assume that SLR parser for a grammar G has N1 states and the LALR parser for G
has N2 states. The relationship between N1 and N2 is: [GATE 2003]
A. N1 is necessarily less than N2.
B. N1 is necessarily equal to N2.
C. N1 is necessarily greater than N2.
D. None of these.
Answer: (B) N1 is necessarily equal to N2.
Compiler Design MCQ question bank last update 29-Dec-20202 Page 11 of 18
Explanation: The question is asked with respect to the symbol ‘ < ‘ which is not
present in the given canonical set of items. Hence it is neither a shift-reduce conflict
nor a reduce-reduce conflict on symbol ‘<‘.
Hence D is the correct option.
Q. The lexical analysis for a modern computer language such as Java needs the
power of which one of the following machine models in a necessary and sufficient
sense? (GATE CS 2011)
6. Match all items in Group 1 with correct options from those given in Group 2.
(GATE-CS-2009)
Group 1 Group 2
P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
S. Register allocation 4. Code optimization
Answer: (C)
Explanation: Lexical analysis is the process of converting a sequence of characters
into a sequence of tokens. A token can be a keyword.
2.The lexical analysis for a modern computer language such as Java needs the
power of which one of the following machine models in a necessary and sufficient
sense?
Answer: (A)
A canonical set of items is given below
S --> L. > R
Q --> R.
On input symbol < the set has
(A) a shift-reduce conflict and a reduce-reduce conflict.
(B) a shift-reduce conflict but not a reduce-reduce conflict.
(C) a reduce-reduce conflict but not a shift-reduce conflict.
(D) neither a shift-reduce nor a reduce-reduce conflict.
Answer: (D)
Explanation: The question is asked with respect to the symbol ‘ < ‘ which is not
present in the given canonical set of items. Hence it is neither a shift-reduce conflict
nor a reduce-reduce conflict on symbol ‘<‘.
Hence D is the correct option.
4.Which one of the following is a top-down parser?
(A) Recursive descent parser.
(B) Operator precedence parser.
(C) An LR(k) parser.
(D) An LALR(k) parser
Answer: (A)
Compiler Design MCQ question bank last update 29-Dec-20202 Page 14 of 18
Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal
between them, the given grammar is LL(1).
Answer: (D)
Q. Match all items in Group 1 with correct options from those given in Group 2.
Group 1 Group 2
Compiler Design MCQ question bank last update 29-Dec-20202 Page 15 of 18
Q. Assume that SLR parser for a grammar G has N1 states and the LALR parser for G has
N2 states. The relationship between N1 and N2 is: [GATE 2003]
A. N1 is necessarily less than N2.
B. N1 is necessarily equal to N2.
C. N1 is necessarily greater than N2.
D. None of these.
Answer: (B) N1 is necessarily equal to N2.
This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses
on “Top-Down Parsing – 1”.
1. Which of the following derivations does a top-down parser use while
parsing an input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
Answer: a
Explanation: In top down parser takes input from Left to right constructing
leftmost derivation of the sentence.
Answer: c
Explanation: Relocation is the process of replacing symbolic references or
names of libraries with actual usable addresses in memory before running a
program. Linker performs it during compilation.
Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost)
derivation the grammar is ambiguous. Sometimes in unambiguous
grammar the rightmost derivation and leftmost derivations may differ.
Compiler Design MCQ question bank last update 29-Dec-20202 Page 17 of 18
Answer: b
Explanation:Precedence is that a higher precedence operator will never
produce an expression with operator with lower precedence.
In the given grammar MINUS has higher precedence than ASTERIX.
Compiler Design MCQ question bank last update 29-Dec-20202 Page 18 of 18