Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 15
Q521:
The function `Expr::isPresent()` starts parsing with a call to ________.
A. new Factor(s)
B. new Expr(s)
C. new Term(s)
D. nextToken()
Correct Answer: C
Chapter: 15
Q522:
When does `Factor::isPresent()` throw a syntax error regarding parentheses?
A. If ID is missing
B. If token is NUM
C. If RPAREN is missing
D. If LPAREN is missing
Correct Answer: C
Chapter: 15
Q523:
The purpose of the TreeNode constructor used in arithmetic operations is to ________.
A. Store syntax rules
B. Link the left and right expressions
C. Generate machine code
D. Ignore extra tokens
Correct Answer: B
Chapter: 15
Q524:
If `s->nextToken()` is MUL, what happens in `Tprime::isPresent()`?
A. Parse ends immediately
B. Tree is reset
C. The function parses the next Factor and continues
D. Returns false
Correct Answer: C
Chapter: 16
Q525:
What is the final output of parsing the expression 2+4*6 in the AST form?
A. (2+4)*6
B. 2+(4*6)
C. (2*4)+6
D. None of the above
Correct Answer: B
Chapter: 16
Q526:
What does the LL(1) parser use to decide which production to apply?
A. Input symbols
B. Output stream
C. Parsing table
D. Error handler
Correct Answer: C
Chapter: 16
Q527:
The token value for numeric values like '2', '4', and '6' is represented by which number?
A. 257
B. 267
C. 269
D. 255
Correct Answer: A
Chapter: 16
Q528:
The expression grammar's production for E is
A. + T E'
B. T + E'
C. E → T E'
D. F → T E'
Correct Answer: C
Chapter: 16
Q529:
Which function is responsible for handling addition and subtraction in the AST?
A. Term::isPresent()
B. Eprime::isPresent()
C. Tprime::isPresent()
D. Factor::isPresent()
Correct Answer: B
Chapter: 16
Q530:
In the parsing trace, what causes Tprime::isPresent() to return false?
A. Encountering *
B. Encountering +
C. Encountering id
D. None of these
Correct Answer: B
Chapter: 16
Q531:
What data structure is used in non-recursive predictive parsing?
A. Array
B. Tree
C. Queue
D. Stack
Correct Answer: D
Chapter: 16
Q532:
The predictive parser uses an explicit _______ to keep track of pending non-terminals.
A. stack
B. table
C. tree
D. queue
Correct Answer: A
Chapter: 16
Q533:
The parsing table M is indexed using which combination?
A. Terminal and expression
B. Production and stack
C. Non-terminal and terminal
D. Symbol and pointer
Correct Answer: C
Chapter: 16
Q534:
What is the start symbol in the expression grammar discussed?
A. F
B. T
C. E
D. E'
Correct Answer: C
Chapter: 16
Q535:
How does the parser know it has successfully completed parsing?
A. When input buffer is full
B. When stack is empty
C. When input symbol and top of stack are both $
D. When all productions are used
Correct Answer: C
Chapter: 16
Q536:
Which of the following is a terminal in the predictive parsing table?
A. T'
B. E'
C. +
D. F
Correct Answer: C
Chapter: 16
Q537:
Which grammar rule corresponds to multiplication operation?
A. T' → * F T'
B. F → ( E )
C. T → F T'
D. E' → + T E'
Correct Answer: A
Chapter: 16
Q538:
The parser consults the parsing table when the top of the stack is a _______.
A. terminal
B. non-terminal
C. operator
D. value
Correct Answer: B
Chapter: 16
Q539:
A parsing table entry M[X, a] = error implies ________.
A. production found
B. stack is cleared
C. no error
D. recovery is needed
Correct Answer: D
Chapter: 16
Q540:
The operator * is handled in which function during parsing?
A. Eprime::isPresent()
B. Tprime::isPresent()
C. Term::isPresent()
D. Factor::isPresent()
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now