Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Multiple Choice Questions

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()
View Answer
C

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
View Answer
C

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
View Answer
B

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
View Answer
C

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
View Answer
B

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
View Answer
C

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
View Answer
A

Q528: The expression grammar's production for E is
  • A: + T E'
  • B: T + E'
  • C: E → T E'
  • D: F → T E'
View Answer
C

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()
View Answer
B

Q530: In the parsing trace, what causes Tprime::isPresent() to return false?
  • A: Encountering *
  • B: Encountering +
  • C: Encountering id
  • D: None of these
View Answer
B

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now