Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 11
Q401:
What is the correct syntax for a C++ function header?
A. int foo(int i, int j)
B. int* foo(int i, int j))
C. void foo(int i, int j
D. int* foo(int i, int j)
Correct Answer: A
Chapter: 11
Q402:
In the expression 'x - 2 * y', which operator has higher precedence?
A. -
B. *
C. +
D. /
Correct Answer: B
Chapter: 11
Q403:
What kind of error is caused by 'for(k=0; i < j; j++)' when 'k' is not declared?
A. Syntax error
B. Semantic error
C. Logical error
D. Runtime error
Correct Answer: A
Chapter: 11
Q404:
Fill in the blank: The set 'T' in CFG consists of ______.
A. Terminals
B. Non-terminals
C. Productions
D. Start symbols
Correct Answer: A
Chapter: 11
Q405:
Which symbol represents the start symbol in CFG?
A. S
B. N
C. P
D. T
Correct Answer: B
Chapter: 11
Q406:
What is the result of the production 'expr -> expr op expr'?
A. A terminal
B. A non-terminal
C. A number
D. An operator
Correct Answer: B
Chapter: 11
Q407:
What is the meaning of semantic analysis in compiler design?
A. Checking meaning of statements
B. Checking syntax
C. Generating code
D. Allocating memory
Correct Answer: A
Chapter: 11
Q408:
Which of the following can be considered a semantic error?
A. Using undeclared variable
B. Missing semicolon
C. Misspelled keyword
D. Extra parenthesis
Correct Answer: A
Chapter: 11
Q409:
In CFG, what does 'L(G)' denote?
A. The language generated by grammar G
B. The length of G
C. The lexical tokens of G
D. The last rule in G
Correct Answer: A
Chapter: 11
Q410:
Which of these statements about finite automata is correct?
A. They can remember infinite states
B. They cannot remember number of times visiting a state
C. They are used for semantic analysis
D. They are slower than parsers
Correct Answer: B
Chapter: 12
Q411:
What do interior nodes in a parse tree represent?
A. Terminals
B. Non-terminals
C. Operators
D. Operands
Correct Answer: B
Chapter: 12
Q412:
Which derivation starts from the leftmost non-terminal in the parse tree?
A. Rightmost derivation
B. Leftmost derivation
C. Top-down parsing
D. Bottom-up parsing
Correct Answer: B
Chapter: 12
Q413:
In the expression x - 2 * y, which operator has higher precedence?
A. Subtraction
B. Multiplication
C. Addition
D. Division
Correct Answer: B
Chapter: 12
Q414:
To encode operator precedence in grammar, what is created for each precedence level?
A. Operator
B. Terminal
C. Non-terminal
D. Keyword
Correct Answer: C
Chapter: 12
Q415:
Which parsing technique starts at the root and works toward the leaves?
A. Bottom-up parsing
B. Leftmost derivation
C. Top-down parsing
D. Rightmost derivation
Correct Answer: C
Chapter: 12
Q416:
What problem does ambiguous grammar cause?
A. Multiple parse trees for same input
B. No parse trees
C. Parsing failure
D. No ambiguity
Correct Answer: A
Chapter: 12
Q417:
Which of the following is a property of context-free grammars?
A. Non-terminals appear anywhere
B. Terminals appear on left side
C. Non-terminals appear alone on left side
D. Terminals appear on right side
Correct Answer: C
Chapter: 12
Q418:
What is the correct interpretation of the rule A → a in context-free grammars?
A. A can be replaced by a anywhere
B. A can be replaced only in specific contexts
C. A must not be replaced
D. A is terminal
Correct Answer: A
Chapter: 12
Q419:
Which grammar type requires context before and after a non-terminal for replacement?
A. Context-free
B. Context-sensitive
C. Unambiguous
D. Regular
Correct Answer: B
Chapter: 12
Q420:
In the ambiguous if-then-else grammar, the "else" is conventionally matched with which "if"?
A. The outermost if
B. The most recent unmatched if
C. The first if
D. The last if
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now