Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 27
Q821:
In the LR parsing example, what is the purpose of the stack?
A. Store grammar rules
B. Store input symbols
C. Store parser states and grammar symbols
D. Store input string
Correct Answer:
A
Chapter: 27
Q822:
What is the input string encoded by the scanner in the example?
A. id – id × id $
B. id + id × id $
C. id – id + id $
D. id × id – id $
Correct Answer:
A
Chapter: 27
Q823:
In the parsing stack, what does "s4" signify?
A. Shift and go to state 4
B. Reduce by rule 4
C. Accept state
D. Shift and go to state 3
Correct Answer:
A
Chapter: 27
Q824:
Which of these is a valid reduce action in the example?
A. Action[7, $] ← reduce 2
B. Action[1, id] ← reduce 3
C. Action[0, id] ← reduce 6
D. Action[3, id] ← reduce 5
Correct Answer:
A
Chapter: 27
Q825:
Fill in the blank: The LR parsing table uses ________ sets to build states and actions.
A. FOLLOW
B. FIRST
C. LALR
D. CLOSURE
Correct Answer:
B
Chapter: 27
Q826:
Fill in the blank: The "accept" action is set when the item ________ is present in the state.
A. [S' → S•, $]
B. [E → T•, $]
C. [T → F•, $]
D. [F → id•, $]
Correct Answer:
A
Chapter: 27
Q827:
Fill in the blank: In the grammar example, the symbol "×" belongs to the FIRST set of ________.
A. id
B. ×
C. –
D. F
Correct Answer:
A
Chapter: 27
Q828:
What is the reduce action for Action[8, –] in the example?
A. Reduce 4
B. Reduce 5
C. Shift 6
D. Accept
Correct Answer:
A
Chapter: 27
Q829:
When does the LR parser shift the input symbol?
A. When the item has a dot before a terminal symbol
B. When the item has a dot at the end
C. When the item has a dot before a non-terminal symbol
D. When the item is the accept item
Correct Answer:
A
Chapter: 27
Q830:
Fill in the blank: The action "r5" means ________.
A. Reduce by production 5
B. Shift 5
C. Accept
D. Reject
Correct Answer:
A
Chapter: 27
Q831:
Which production is reduced at state 3 on input $ according to the LR table?
A. T → F
B. F → id
C. E → T – E
D. E → T
Correct Answer:
A
Chapter: 27
Q832:
Which is the correct goto entry for goto(0, E) in the example?
A. 1
B. 2
C. 3
D. 4
Correct Answer:
A
Chapter: 27
Q833:
In the LR parsing example, the state I4 contains which items?
A. [F → id•, $], [F → id•, –], [F → id•, ×]
B. [E → T•, $], [E → T• – E, $]
C. [T → F• ×T, $], [T → F•, $]
D. [S' → •E, $]
Correct Answer:
A
Chapter: 27
Q834:
What is the role of the scanner in LR parsing?
A. Tokenize the input string
B. Build the parsing table
C. Generate grammar rules
D. Apply reduce actions
Correct Answer:
A
Chapter: 27
Q835:
Which of the following best describes the 'shift' operation in LR parsing?
A. Move the dot one symbol to the right
B. Move to the next input token and push it to the stack
C. Pop from stack
D. Accept input
Correct Answer:
B
Chapter: 27
Q836:
Fill in the blank: In LR parsing, the stack keeps track of states and ________.
A. grammar symbols
B. input tokens
C. errors
D. productions
Correct Answer:
A
Chapter: 27
Q837:
In the example, which action corresponds to Action[5, id]?
A. Shift 4
B. Reduce 6
C. Accept
D. Shift 5
Correct Answer:
A
Chapter: 27
Q838:
Fill in the blank: The set I0 in the example contains items derived by ________.
A. Closure
B. goto
C. Reduce
D. Shift
Correct Answer:
A
Chapter: 27
Q839:
What is the purpose of "closure" in LR parser state construction?
A. Add all possible items reachable from a non-terminal
B. Add only items with terminal symbols
C. Ignore lookahead symbols
D. Only add initial item
Correct Answer:
A
Chapter: 27
Q840:
In the LR table, what does "acc" mean?
A. Accept
B. Error
C. Shift
D. Reduce
Correct Answer:
A