Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 12
Q441:
Fill in the blank: The parsing method that grows the parse tree from the leaves is called __________ parsing.
A. Top-down
B. Bottom-up
C. Leftmost
D. Rightmost
Correct Answer:
B
Chapter: 12
Q442:
What is represented by <id,x> in the parse tree?
A. Terminal symbol
B. Non-terminal
C. Operator
D. Keyword
Correct Answer:
A
Chapter: 12
Q443:
Which of the following best describes context-free grammar?
A. Non-terminals can be replaced in any context
B. Non-terminals replaced depending on neighbors
C. Terminals replaced by non-terminals
D. Terminals replaced in any context
Correct Answer:
A
Chapter: 13
Q444:
A top-down parser starts parsing from the ________ of the parse tree.
A. root
B. node
C. leaf
D. terminal
Correct Answer:
A
Chapter: 13
Q445:
If a terminal symbol added to the fringe does not match the input string, the parser must ________.
A. continue
B. backtrack
C. restart
D. skip
Correct Answer:
B
Chapter: 13
Q446:
In a top-down parser, the key to correct parsing is picking the right ________.
A. production
B. terminal
C. lexer
D. token
Correct Answer:
A
Chapter: 13
Q447:
During parsing, if the parser makes the wrong choice at a production, it will ________.
A. backtrack
B. restart
C. abort
D. fail
Correct Answer:
A
Chapter: 13
Q448:
Top-down parsers cannot handle grammars with ________ recursion.
A. left
B. right
C. indirect
D. mutual
Correct Answer:
A
Chapter: 13
Q449:
A grammar is left recursive if a non-terminal A can derive a string starting with ________.
A. A itself
B. only terminals
C. only non-terminals
D. ε (empty string)
Correct Answer:
A
Chapter: 13
Q450:
To remove left recursion, the grammar A → A a | b is rewritten as ________.
A. A → b A' and A' → a A' | ε
B. A → A a B | b
C. B → b A | A a
D. A → b A | a B
Correct Answer:
A
Chapter: 13
Q451:
The symbol A' introduced in removing left recursion is a ________.
A. new non-terminal
B. terminal
C. production rule
D. parser function
Correct Answer:
A
Chapter: 13
Q452:
Predictive parsing avoids backtracking by using ________.
A. look-ahead
B. FIRST sets
C. FOLLOW sets
D. All of the above
Correct Answer:
D
Chapter: 13
Q453:
The FIRST set of a grammar symbol is the set of tokens that appear as the ________ symbol in some string derived from that symbol.
A. first
B. last
C. middle
D. optional
Correct Answer:
A
Chapter: 13
Q454:
The root node in a top-down parse tree is labeled with the ________.
A. start symbol
B. non-terminal
C. terminal
D. production rule
Correct Answer:
A
Chapter: 13
Q455:
If a parser selects a wrong production and fails to match input, it must ________.
A. backtrack
B. skip
C. restart
D. finish
Correct Answer:
A
Chapter: 13
Q456:
Left recursion in a grammar can cause ________ in a top-down parser.
A. non-termination
B. efficiency
C. ambiguity
D. optimization
Correct Answer:
A
Chapter: 13
Q457:
Left recursion can be converted to ________ recursion to ensure parser termination.
A. right
B. left
C. indirect
D. mutual
Correct Answer:
A
Chapter: 13
Q458:
After removing left recursion, the grammar retains the original ________.
A. left associativity
B. right associativity
C. ambiguity
D. precedence
Correct Answer:
A
Chapter: 13
Q459:
In the expression "x – 2 * y," after matching "x – 2," the parser must expand which symbol next?
A. term
B. factor
C. expr
D. goal
Correct Answer:
A
Chapter: 13
Q460:
When parsing "x – 2 * y," the operator "*" is handled by expanding ________.
A. factor
B. term
C. expr
D. goal
Correct Answer:
A