Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Multiple Choice Questions
Q851: In LR(1) parsing, what action is performed when Action[s, token] = "shift i"?
- A: Push token and state i
- B: Pop token and push i
- C: Accept the input
- D: Report error
View Answer
A
Q852: When does the LR(1) parser terminate successfully?
- A: When token == "$" and action=accept
- B: When stack is empty
- C: When scanner returns EOF
- D: When error is detected
View Answer
A
Q853: What is a shift-reduce conflict in LR parsing?
- A: A choice between shifting or reducing on same input
- B: A choice between accepting or rejecting
- C: When the parser stack overflows
- D: When scanner returns invalid token
View Answer
A
Q854: Which grammar example demonstrates the classic shift-reduce conflict?
- A: The dangling else grammar
- B: Arithmetic expression grammar
- C: Variable declaration grammar
- D: Loop statement grammar
View Answer
A
Q855: In the dangling else grammar, which action is usually taken when encountering "else"?
- A: Shift
- B: Reduce
- C: Accept
- D: Error
View Answer
A
Q856: What does the dot (•) symbol in LR items represent?
- A: Current parsing position
- B: End of input
- C: Accepted production
- D: Next token to parse
View Answer
A
Q857: What does the Goto[s, A] represent in LR(1) parsing?
- A: Next state after reducing A
- B: Next token to scan
- C: Current input token
- D: Error state
View Answer
A
Q858: What is the role of the scanner in the LR(1) parser?
- A: To provide the next input token
- B: To decide the parser action
- C: To maintain parser stack
- D: To resolve conflicts
View Answer
A
Q859: What does the parser do if it encounters an unexpected token in LR(1) parsing?
- A: Report error and try to recover
- B: Accept the input
- C: Shift token
- D: Reduce production
View Answer
A
Q860: In LR(1) parsing, how many elements are popped when reducing by A → β?
- A: 2 × length of β
- B: length of β
- C: 1
- D: 0
View Answer
A