Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 28
Q861:
The "$" token in LR(1) parsing indicates:
A. End of input
B. Start of input
C. Any terminal
D. Any non-terminal
Correct Answer:
A
Chapter: 28
Q862:
Fill in the blank: The LR(1) parser stack initially contains _______ and 0.
A. dummy
B. token
C. EOF
D. start symbol
Correct Answer:
A
Chapter: 28
Q863:
What is the usual parser action when the state contains both [X → α•aβ, b] and [Y → γ•, a]?
A. Shift
B. Reduce
C. Accept
D. Error
Correct Answer:
A
Chapter: 28
Q864:
The action "accept" in the LR(1) parser means:
A. Parsing is complete successfully
B. Continue parsing
C. Reduce by start symbol
D. Report an error
Correct Answer:
A
Chapter: 29
Q865:
A shift/reduce conflict occurs when the parser has to decide between _______ and _______ on the same input.
A. shifting and reducing
B. accepting and rejecting
C. scanning and shifting
D. reducing and accepting
Correct Answer:
A
Chapter: 29
Q866:
Which conflict occurs when a DFA state has two different productions both ending at the same input?
A. Shift/Reduce conflict
B. Reduce/Reduce conflict
C. Syntax error
D. Lexical ambiguity
Correct Answer:
B
Chapter: 29
Q867:
Reduce/Reduce conflicts usually occur because of what?
A. Ambiguous grammar
B. Missing tokens
C. Wrong token
D. Infinite recursion
Correct Answer:
A
Chapter: 29
Q868:
The core of an LR(1) item set consists of:
A. Items without lookahead terminals
B. Items with all lookaheads
C. Only terminals
D. Only non-terminals
Correct Answer:
A
Chapter: 29
Q869:
What is the main advantage of LALR(1) parsing over LR(1) parsing?
A. Smaller parsing table
B. More accurate parsing
C. Supports more grammars
D. Easier to implement
Correct Answer:
A
Chapter: 29
Q870:
The LALR(1) parser has roughly ______ the number of states compared to LR(1).
A. 10 times fewer
B. 2 times more
C. Same number
D. 100 times fewer
Correct Answer:
A
Chapter: 29
Q871:
LALR(1) parsing tables are constructed by merging states that have the same _______.
A. core
B. lookahead
C. terminal
D. action
Correct Answer:
A
Chapter: 29
Q872:
Which of the following best describes LALR(1) languages?
A. Efficiency hack on LR languages
B. Completely new parsing approach
C. More ambiguous languages
D. Only used for natural languages
Correct Answer:
A
Chapter: 29
Q873:
The algorithm to generate LALR(1) DFA involves repeatedly merging states with the same _______.
A. core
B. lookahead
C. terminals
D. stack
Correct Answer:
A
Chapter: 29
Q874:
In shift/reduce conflict with E → E × E and E → E + E, the usual resolution is to _______.
A. shift for ×, reduce for +
B. reduce for ×, shift for +
C. shift for both
D. reduce for both
Correct Answer:
A
Chapter: 29
Q875:
Fill in the blank: The size of an LR(1) parsing table is usually ______ compared to simpler parsers.
A. very large
B. very small
C. always fixed
D. constant
Correct Answer:
A
Chapter: 29
Q876:
The lookahead terminal in an LR(1) item helps to decide:
A. When to reduce
B. When to shift
C. When to accept
D. When to scan
Correct Answer:
A
Chapter: 29
Q877:
In the given DFA states { [X → α•, a], [Y → β•, c] } and { [X → α•, b], [Y → β•, d] }, merging results in:
A. { [X → α•, a/b], [Y → β•, c/d] }
B. { [X → α•, a], [Y → β•, d] }
C. { [X → α•, c], [Y → β•, b] }
D. { [X → α•, b/c], [Y → β•, a/d] }
Correct Answer:
A
Chapter: 29
Q878:
Which of the following is NOT true about LALR(1) parsers?
A. They have smaller tables than LR(1)
B. They merge states with the same core
C. They handle all ambiguous grammars
D. They are used in many programming languages
Correct Answer:
C
Chapter: 29
Q879:
Fill in the blank: The conflict where the parser cannot decide between two possible reductions is called ______.
A. reduce/reduce conflict
B. shift/reduce conflict
C. shift/shift conflict
D. accept/reduce conflict
Correct Answer:
A
Chapter: 29
Q880:
In LALR(1) parsing, merging states reduces the number of states and hence ______.
A. reduces table size
B. increases parsing time
C. causes errors
D. removes all conflicts
Correct Answer:
A