Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 12
Q421:
Bottom-up parsing begins from:
A. Root of parse tree
B. Leaves of parse tree
C. Middle of parse tree
D. Any node in parse tree
Correct Answer:
B
Chapter: 12
Q422:
Top-down parsing may require:
A. No backtracking
B. Backtracking
C. Only leftmost derivations
D. Only rightmost derivations
Correct Answer:
B
Chapter: 12
Q423:
In the parse tree for x – (2 * y), what is the order of evaluation?
A. Left to right
B. Right to left
C. Multiplication before subtraction
D. Subtraction before multiplication
Correct Answer:
C
Chapter: 12
Q424:
Which sentential form corresponds to the rule "expr → term * factor"?
A. expr - term * factor
B. expr + term * factor
C. expr * term * factor
D. expr * factor
Correct Answer:
A
Chapter: 12
Q425:
The term "sentential form" refers to:
A. A sequence of terminals and non-terminals
B. A complete parse tree
C. Only terminals
D. Only non-terminals
Correct Answer:
A
Chapter: 12
Q426:
Fill in the blank: The rule b A g → b a g is an example of __________ grammar.
A. Context-free
B. Context-sensitive
C. Regular
D. Unambiguous
Correct Answer:
B
Chapter: 12
Q427:
In bottom-up parsing, the parser's internal state encodes:
A. Parsing errors
B. Legal tokens and states
C. Possible parse trees
D. Grammar rules
Correct Answer:
B
Chapter: 12
Q428:
What is the goal symbol in the grammar that parses x - 2 * y?
A. Expr
B. Term
C. Factor
D. Goal
Correct Answer:
D
Chapter: 12
Q429:
Which parsing technique is generally more powerful and handles more grammar types?
A. Top-down
B. Bottom-up
C. Leftmost
D. Rightmost
Correct Answer:
B
Chapter: 12
Q430:
In ambiguous grammars, multiple __________ exist for the same sentential form.
A. Leftmost derivations
B. Rightmost derivations
C. Parse trees
D. Operators
Correct Answer:
C
Chapter: 12
Q431:
What does the non-terminal "WithElse" in the rewritten grammar help resolve?
A. Operator precedence
B. Assignment ambiguity
C. If-then-else ambiguity
D. Function calls
Correct Answer:
C
Chapter: 12
Q432:
The leftmost derivation applies production rules to the __________ non-terminal first.
A. Rightmost
B. Leftmost
C. Any
D. None
Correct Answer:
B
Chapter: 12
Q433:
In the example grammar, what is the first step to parse x - 2 * y?
A. Expr → Expr – Term
B. Expr → Term
C. Expr → Factor
D. Expr → Term * Factor
Correct Answer:
A
Chapter: 12
Q434:
Which grammar rule type uses the form A → a with no context restrictions?
A. Context-sensitive
B. Context-free
C. Regular
D. Unambiguous
Correct Answer:
B
Chapter: 12
Q435:
Fill in the blank: In bottom-up parsing, parsing grows from the __________ to the __________.
A. Leaves, root
B. Root, leaves
C. Left, right
D. Right, left
Correct Answer:
A
Chapter: 12
Q436:
What is the main disadvantage of ambiguous grammars?
A. Difficulty parsing multiple expressions
B. Multiple parse trees cause ambiguity
C. No parse trees generated
D. No terminals found
Correct Answer:
B
Chapter: 12
Q437:
Which parsing technique uses backtracking when it picks wrong production rules?
A. Top-down
B. Bottom-up
C. Leftmost
D. Rightmost
Correct Answer:
A
Chapter: 12
Q438:
In the classic if-then-else ambiguity, which statement causes the ambiguity?
A. Multiple else statements
B. Multiple then statements
C. Nesting of if without else
D. Nesting of else without if
Correct Answer:
C
Chapter: 12
Q439:
What is the effect of creating a non-terminal for each level of precedence?
A. It removes ambiguity
B. It simplifies the grammar
C. It encodes expected operator precedence
D. It removes terminals
Correct Answer:
C
Chapter: 12
Q440:
What does the term "backtrack-free grammar" imply?
A. Grammar without recursion
B. Grammar without ambiguity
C. Grammar without need for backtracking
D. Grammar without terminals
Correct Answer:
C