Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 24
Q761:
What does the set I0 = closure({[S → •E, $]}) contain initially?
A. Only [S → •E, $]
B. Items for S and E productions
C. Only terminal items
D. Only lookahead symbols
Correct Answer:
B
Chapter: 25
Q762:
The initial set of LR(1) items I0 contains which of the following items?
A. [S → •E, $]
B. [E → •E+(E), $/+]
C. [E → •int, $/+]
D. All of the above
Correct Answer:
D
Chapter: 25
Q763:
In the LR(1) item [E → •int, $/+], why does the closure procedure add no new items?
A. The dot is at the end
B. The dot is followed by terminal int
C. The dot is followed by non-terminal
D. Epsilon production
Correct Answer:
B
Chapter: 25
Q764:
If [A → β•Cδ, a] ∈ s, what does closure add for the production C → γ?
A. Items with dot at the end
B. Items with dot before γ and lookahead from FIRST(δa)
C. Items without dot
D. None
Correct Answer:
B
Chapter: 25
Q765:
The lookahead symbols added in closure for a production C → γ include all terminals in which set?
A. FIRST(δ)
B. FIRST(a)
C. FIRST(δa)
D. FOLLOW(C)
Correct Answer:
C
Chapter: 25
Q766:
The function goto(s, y) returns what?
A. The set of items with dot before y
B. Closure of all items with dot after y
C. Closure of all items with dot moved past y
D. Items with dot at the end
Correct Answer:
C
Chapter: 25
Q767:
What does the goto procedure do in LR(1) parser construction?
A. It computes parser states after recognizing symbol y
B. It deletes items with dot before y
C. It adds new productions
D. It simplifies grammar
Correct Answer:
A
Chapter: 25
Q768:
In the goto procedure, for each item [X → α•yβ, b] ∈ s, what is added to m?
A. [X → α y•β, b]
B. [X → α•yβ, b]
C. [X → α yβ•, b]
D. [X → α β•y, b]
Correct Answer:
A
Chapter: 25
Q769:
LR(1) items are used as states in what kind of automaton?
A. Finite Automaton
B. Non-deterministic Finite Automaton
C. Deterministic Finite Automaton
D. Both A and C
Correct Answer:
D
Chapter: 25
Q770:
The LR(1) parser’s finite automaton starts as which type before subset construction?
A. NFA
B. DFA
C. Moore Machine
D. Mealy Machine
Correct Answer:
A
Chapter: 25
Q771:
In the NFA of LR(0) items, a transition on symbol X from state A→ α•Xη leads to which state?
A. A→ αX•η
B. A→ α•Xη
C. A→ αXη•
D. A→ •αXη
Correct Answer:
A
Chapter: 25
Q772:
In the LR(1) parsing stack, a transition on a terminal symbol corresponds to which action?
A. Shift
B. Reduce
C. Accept
D. Reject
Correct Answer:
A
Chapter: 25
Q773:
If X is a non-terminal, what does the transition on X correspond to in the parser?
A. Pushing X onto the stack
B. Reading X from input
C. Reducing X
D. Shifting X
Correct Answer:
A
Chapter: 25
Q774:
The dot (•) in an LR(1) item indicates what?
A. The current parsing position
B. The start of production
C. The end of production
D. Lookahead symbol
Correct Answer:
A
Chapter: 25
Q775:
The set s changes during closure, so the procedure must be repeated to find ________.
A. All reachable items
B. Only terminals
C. Only non-terminals
D. Lookahead symbols
Correct Answer:
A
Chapter: 25
Q776:
FIRST(δa) in closure includes which of the following?
A. All terminals that can appear at start of δ and a
B. If ε ∈ FIRST(δ), it also includes a
C. Only ε
D. Only a
Correct Answer:
B
Chapter: 25
Q777:
The transition on terminal symbol X in LR(0) NFA corresponds to which parser operation?
A. Shift
B. Reduce
C. Push
D. Pop
Correct Answer:
A
Chapter: 25
Q778:
The production S → E in the augmented grammar is used to create which initial item?
A. [S → •E, $]
B. [E → •int, $]
C. [S → E•, $]
D. [E → •E+(E), $]
Correct Answer:
A
Chapter: 25
Q779:
Fill in the blank: In goto(s, y), the symbol y can be a ________.
A. Terminal or non-terminal
B. Only terminal
C. Only non-terminal
D. Only production
Correct Answer:
A
Chapter: 25
Q780:
Fill in the blank: The NFA of LR(0) items has transitions labeled by ________.
A. Grammar symbols
B. Dot positions
C. Lookahead symbols
D. Productions
Correct Answer:
A