Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 16
Q561:
The parser reads the token 'id' as input. Which rule is applied?
A. F → id
B. T → id
C. F → (E)
D. E → T
Correct Answer:
B
Chapter: 17
Q562:
What does the FIRST(X) set represent in grammar analysis?
A. All terminal symbols in the grammar
B. All non-terminal symbols that can derive epsilon
C. The set of terminals that begin strings derivable from X
D. The set of terminals following X in derivations
Correct Answer:
C
Chapter: 17
Q563:
Which of the following is TRUE about LL(1) parsing?
A. It constructs the parse tree from leaves to root
B. It requires backtracking
C. It expands the rightmost non-terminal
D. It always expands the leftmost non-terminal
Correct Answer:
D
Chapter: 17
Q564:
In LL(1) table construction, when is a production A → a valid?
A. When FIRST(a) contains the current token
B. When FOLLOW(A) contains a terminal symbol
C. When A is a terminal symbol
D. When a is not nullable
Correct Answer:
A
Chapter: 17
Q565:
If ε ∈ FIRST(A), what does it imply?
A. A is a terminal
B. A is not used in derivation
C. A can derive an empty string
D. A can only derive a terminal
Correct Answer:
C
Chapter: 17
Q566:
What does FOLLOW(A) represent?
A. All terminals that can follow A in any derivation
B. All terminals that A can start with
C. All non-terminals that follow A
D. The set of terminals at the beginning of A
Correct Answer:
A
Chapter: 17
Q567:
What is the purpose of FIRST and FOLLOW sets in LL(1) parsing?
A. To check syntax errors
B. To determine operator precedence
C. To construct predictive parsing tables
D. To compute symbol frequency
Correct Answer:
C
Chapter: 17
Q568:
In LL(1) parsing, what happens if M[X,a] = error?
A. The parser crashes
B. The parser uses backtracking
C. The parser calls an error recovery routine
D. The parser restarts from beginning
Correct Answer:
C
Chapter: 17
Q569:
A grammar is suitable for LL(1) parsing if:
A. It contains left recursion
B. It is left-factored and non-left-recursive
C. It contains right recursion only
D. It allows ambiguity
Correct Answer:
B
Chapter: 17
Q570:
What is the initial content of the parsing stack in LL(1) parsing?
A. Just $
B. Start symbol followed by $
C. Start symbol only
D. Input string followed by $
Correct Answer:
B
Chapter: 17
Q571:
Top-down parsing begins parsing from:
A. Rightmost terminal
B. Leftmost terminal
C. Start symbol
D. Follow set of grammar
Correct Answer:
C
Chapter: 17
Q572:
In the production S → *bAg, what symbol is expected after matching b in bbg?
A. A
B. g
C. S
D. F
Correct Answer:
B
Chapter: 17
Q573:
If b ∈ FIRST(a), then which of the following is TRUE?
A. A → a can be used when the next input is b
B. A must be replaced by epsilon
C. A cannot be expanded
D. B should be replaced by a
Correct Answer:
A
Chapter: 17
Q574:
If ε ∈ FIRST(A) and b ∈ FOLLOW(A), then:
A. A can be expanded using A → ε
B. A must be skipped
C. A cannot be used
D. A must derive terminal
Correct Answer:
A
Chapter: 17
Q575:
The FIRST set of a non-terminal includes:
A. Only terminals directly used in its productions
B. Only non-terminals that can derive it
C. Terminals that appear first in any derivation from that symbol
D. All tokens in the grammar
Correct Answer:
C
Chapter: 17
Q576:
FOLLOW(A) contains:
A. All terminals that appear before A in derivations
B. Terminals that can immediately follow A in derivations
C. Non-terminals following A in productions
D. All nullable symbols in the grammar
Correct Answer:
B
Chapter: 17
Q577:
The parse tree for a valid string is built by a _______ parser from the start symbol to the leaves.
A. top-down
B. bottom-up
C. left-right
D. right-left
Correct Answer:
A
Chapter: 17
Q578:
If a non-terminal has multiple productions starting with the same terminal, the grammar is:
A. Left-factored
B. LL(1)
C. Ambiguous
D. Non-recursive
Correct Answer:
C
Chapter: 17
Q579:
The parsing stack helps in:
A. Identifying lexical tokens
B. Simulating recursion by tracking derivations
C. Evaluating expressions only
D. Storing user-defined variables
Correct Answer:
B
Chapter: 17
Q580:
Predictive parsing is called table-driven because:
A. It uses a stack to store functions
B. It constructs the table dynamically
C. It looks up a parsing table to decide the production to apply
D. It stores entire grammar in table form
Correct Answer:
C