Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 15
Q501:
Which operator(s) does `Eprime::isPresent()` specifically handle?
A. MULTIPLICATION and DIVISION
B. LPAREN and RPAREN
C. PLUS and MINUS
D. ID and NUM
Correct Answer: C
Chapter: 15
Q502:
In `Tprime::isPresent()`, the method returns false when the next token is not __________.
A. ID or NUM
B. PLUS or MINUS
C. MUL or DIV
D. LPAREN or RPAREN
Correct Answer: C
Chapter: 15
Q503:
The function `Factor::isPresent()` checks for which two types of tokens initially?
A. ID and NUM
B. MUL and DIV
C. PLUS and MINUS
D. LPAREN and RPAREN
Correct Answer: A
Chapter: 15
Q504:
What will happen if the expected closing parenthesis is not found in Factor?
A. The function returns true
B. The program skips the token
C. A syntax error is thrown
D. It creates a new node
Correct Answer: C
Chapter: 15
Q505:
What does the `tree` variable typically store in these classes?
A. An integer value
B. A boolean flag
C. An AST node
D. A token list
Correct Answer: C
Chapter: 15
Q506:
The object `op1` in `Expr::isPresent()` is an instance of which class?
A. Expr
B. Factor
C. Tprime
D. Term
Correct Answer: D
Chapter: 15
Q507:
In the context of this code, the abbreviation AST stands for __________.
A. Abstract Syntax Tree
B. Application Syntax Token
C. Advanced Syntax Tree
D. All Syntax Tokens
Correct Answer: A
Chapter: 15
Q508:
Which of the following constructs recursive parsing using itself in the grammar implementation?
A. TreeNode
B. Factor
C. Tprime
D. Eprime
Correct Answer: D
Chapter: 15
Q509:
The `syntaxError(s)` function is called when ________.
A. A valid token is found
B. Parsing completes successfully
C. A required component is missing in the expression
D. AST creation is complete
Correct Answer: C
Chapter: 15
Q510:
The method `advance()` is used to __________.
A. Go back one token
B. Read a new file
C. Move to the next token
D. Save a variable
Correct Answer: C
Chapter: 15
Q511:
The expression `tree = op3->AST();` in `Tprime::isPresent()` shows ________.
A. Tree merging
B. Loop breaking
C. Syntax checking
D. Parsing ID
Correct Answer: C
Chapter: 15
Q512:
Which function checks for the presence of multiplication or division operators?
A. Expr::isPresent()
B. Tprime::isPresent()
C. Eprime::isPresent()
D. Factor::isPresent()
Correct Answer: B
Chapter: 15
Q513:
TreeNode objects are created during parsing to build __________.
A. A GUI
B. Tree Structure
C. Compiler interface
D. Parse Table
Correct Answer: B
Chapter: 15
Q514:
In recursive descent parsing, the parser directly uses __________.
A. AST traversal
B. Stack memory
C. Control flow and function calls
D. Finite automata
Correct Answer: C
Chapter: 15
Q515:
The `s->advance()` call inside parentheses parsing occurs ________ the closing RPAREN check.
A. before
B. after
C. only if needed
D. never
Correct Answer: B
Chapter: 15
Q516:
Each `isPresent()` function generally returns true only if ________.
A. At least one sub-part is missing
B. The parse tree is complete
C. The syntax is invalid
D. The program ends
Correct Answer: B
Chapter: 15
Q517:
The role of `new Term(s)` in `Expr::isPresent()` is to ________.
A. Handle subtraction
B. Create a Term parser object
C. Delete a class
D. Trigger an error
Correct Answer: B
Chapter: 15
Q518:
Tree construction in these classes is done by ________.
A. Appending tokens
B. Linking operators with operands
C. Sorting tokens in order
D. Matching all token types
Correct Answer: B
Chapter: 15
Q519:
The `Factor::isPresent()` method parses expressions inside __________.
A. square brackets
B. parentheses
C. double quotes
D. angle brackets
Correct Answer: B
Chapter: 15
Q520:
If the next token is neither ID, NUM, nor LPAREN, `Factor::isPresent()` will ________.
A. return true
B. call AST()
C. throw syntaxError(s)
D. return false
Correct Answer: D

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now