Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 27
Q841:
Fill in the blank: The notation [A → α•a β, b] means the dot is before ________.
A. Terminal 'a'
B. Non-terminal 'A'
C. End of input
D. Start symbol
Correct Answer: A
Chapter: 27
Q842:
What is the condition for Action[i,a] ← "reduce A → α"?
A. If [A → α•, a] ∈ Ii and A ≠ S'
B. If [A → α•a β, b] ∈ Ii
C. If [S' → S•, $] ∈ Ii
D. If [A → α•a β, b] ∈ Ii and A = S'
Correct Answer: A
Chapter: 27
Q843:
Which of these actions is set for Action[3, ×]?
A. Shift 6
B. Reduce 5
C. Accept
D. Error
Correct Answer: A
Chapter: 27
Q844:
Fill in the blank: The goto table maps pairs of (state, ________) to states.
A. Non-terminals
B. Terminals
C. Actions
D. Productions
Correct Answer: A
Chapter: 27
Q845:
Which production is reduced by Action[7, $]?
A. E → T – E
B. T → F
C. F → id
D. E → T
Correct Answer: A
Chapter: 27
Q846:
Fill in the blank: The end marker in the input string is represented by the symbol ________.
A. $
B. #
C. %
D. &
Correct Answer: A
Chapter: 27
Q847:
What does Ij represent in the LR parser?
A. The state reached by goto function
B. The input token
C. The grammar rule
D. The lookahead symbol
Correct Answer: A
Chapter: 27
Q848:
In the example, what is the parsing action for Action[6, id]?
A. Shift 4
B. Reduce 6
C. Accept
D. Shift 6
Correct Answer: A
Chapter: 27
Q849:
Fill in the blank: The expression to be parsed in the example is ________.
A. x – y × z
B. x + y × z
C. x – y + z
D. x × y – z
Correct Answer: A
Chapter: 28
Q850:
In the LR(1) parser, what is the initial item pushed onto the stack before parsing starts?
A. dummy
B. token
D. scanner
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
Q855:
In the dangling else grammar, which action is usually taken when encountering "else"?
A. Shift
B. Reduce
C. Accept
D. Error
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
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
Correct Answer: A
Chapter: 28
Q860:
In LR(1) parsing, how many elements are popped when reducing by A → β?
A. 2 × length of β
B. length of β
C. 1
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now