Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 19
Q621:
A grammar must be __________ before being used in predictive parsing.
A. normalized
B. compiled
C. lexed
D. left-factored
Correct Answer:
D
Chapter: 19
Q622:
What is the purpose of left factoring a grammar?
A. To increase ambiguity
B. To eliminate left recursion
C. To simplify semantic analysis
D. To make grammar suitable for predictive parsing
Correct Answer:
D
Chapter: 19
Q623:
Which of the following grammars is NOT suitable for predictive parsing?
A. Left-factored grammar
B. Unambiguous grammar
C. Grammar with common prefixes
D. Grammar with distinct terminals
Correct Answer:
C
Chapter: 19
Q624:
The left-factoring transformation introduces a new non-terminal denoted by:
A. Y
B. Z
C. K
D. X
Correct Answer:
B
Chapter: 19
Q625:
If the original grammar is A → αβ1 | αβ2 | αβ3, the left-factored form of A is:
A. A → α | β1β2β3
B. A → β1β2β3 | α
C. A → αZ
D. B → αA
Correct Answer:
C
Chapter: 19
Q626:
Which is a correct set of productions for left-factored form of A → αβ1 | αβ2 | αβ3?
A. A → αZ, Z → β1 | β2 | β3
B. A → α | β1 | β2 | β3
C. A → β1Z, Z → α | β2 | β3
D. A → αZ, Z → α | β1 | β3
Correct Answer:
A
Chapter: 19
Q627:
Given the grammar: Factor → id | id[ExprList] | id(ExprList), which form is left-factored?
A. Factor → id | [ExprList] | (ExprList)
B. Factor → id Args; Args → [ExprList] | (ExprList) | ε
C. Factor → id + Args; Args → [ExprList]
D. Factor → ExprList | id | ε
Correct Answer:
B
Chapter: 19
Q628:
Which of the following makes a grammar non-LL(1)?
A. Use of ε in FIRST set
B. Overlapping FIRST sets for same non-terminal
C. Use of terminal in FOLLOW set
D. Use of distinct terminals
Correct Answer:
B
Chapter: 19
Q629:
Which of the following is TRUE about LL(1) grammar?
A. It can have common prefixes
B. It must be left-recursive
C. It must be left-factored
D. It can have multiple productions for the same terminal
Correct Answer:
C
Chapter: 19
Q630:
If two productions for a non-terminal start with the same terminal, what should be done?
A. Remove one
B. Use recursion
C. Left-factor the grammar
D. Ignore error
Correct Answer:
C
Chapter: 20
Q631:
What does LR stand for in LR Parsing?
A. Left Recursion
B. Left-to-right Rightmost derivation
C. Left Rewrite
D. Logic Rewrite
Correct Answer:
B
Chapter: 20
Q632:
Bottom-up parsing is also called ______.
A. Top-down parsing
B. LL parsing
C. LR parsing
D. Recursive descent parsing
Correct Answer:
C
Chapter: 20
Q633:
Which type of grammars can LR parsers handle that top-down parsers cannot?
A. Right-recursive grammars
B. Left-recursive grammars
C. Context-free grammars
D. Context-sensitive grammars
Correct Answer:
B
Chapter: 20
Q634:
In bottom-up parsing, derivation is built in ______.
A. Leftmost order
B. Forward direction
C. Reverse order
D. Top-down fashion
Correct Answer:
C
Chapter: 20
Q635:
The process of reducing a string to the start symbol in bottom-up parsing is called ______.
A. Expansion
B. Reduction
C. Shifting
D. Derivation
Correct Answer:
B
Chapter: 20
Q636:
Bottom-up parsing traces ______ derivation in reverse.
A. Rightmost
B. Leftmost
C. Centermost
D. None of these
Correct Answer:
A
Chapter: 20
Q637:
What does the 'Shift' action do in shift-reduce parsing?
A. Adds non-terminal
B. Deletes a terminal
C. Moves ► to the right
D. Adds production rule
Correct Answer:
C
Chapter: 20
Q638:
What happens during a 'Reduce' action in bottom-up parsing?
A. Parser rewrites the input
B. Parser shifts input
C. Parser applies inverse production
D. Parser reads next token
Correct Answer:
C
Chapter: 20
Q639:
Which of the following is TRUE about LR parsing?
A. It constructs a leftmost derivation
B. It reads tokens right to left
C. It constructs a rightmost derivation
D. It uses recursive calls
Correct Answer:
C
Chapter: 20
Q640:
The symbol ► in bottom-up parsing indicates ______.
A. End of input
B. Start of derivation
C. Current parsing position
D. Error indicator
Correct Answer:
C