Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 11
Q381:
Which of the following is a non-terminal in the expression grammar?
A. +
B. -
C. <expr>
D. *
Correct Answer:
C
Chapter: 11
Q382:
Fill in the blank: A parser must distinguish between valid and ______ sequences of tokens.
A. Invalid
B. Syntactical
C. Grammatical
D. Complete
Correct Answer:
A
Chapter: 11
Q383:
What is the function return type in 'int* foo(int i, int j)'?
A. Integer pointer
B. Integer
C. Character
D. String
Correct Answer:
A
Chapter: 11
Q384:
Which statement about parsing is true?
A. It discovers a derivation for a sentence
B. It executes program code
C. It allocates variables
D. It performs memory management
Correct Answer:
A
Chapter: 11
Q385:
Which of the following is NOT a terminal symbol?
A. '+'
B. 'id'
C. 'expr'
D. '*'
Correct Answer:
C
Chapter: 11
Q386:
Which is the correct production rule for op in the given grammar?
A. op -> + | - | * | /
B. op -> num | id
C. op -> expr
D. op -> baa
Correct Answer:
A
Chapter: 11
Q387:
In the for loop 'for(k=0; i < j; j++)', what semantic error is present?
A. Incrementing the wrong variable
B. Incorrect syntax
C. Wrong data type
D. Missing semicolon
Correct Answer:
A
Chapter: 11
Q388:
Which grammar rule corresponds to 'expr -> num'?
A. Rule 1
B. Rule 2
C. Rule 3
D. Rule 4
Correct Answer:
B
Chapter: 11
Q389:
What is the significance of a parse tree?
A. Shows evaluation order
B. Allocates memory
C. Executes code
D. Checks data types
Correct Answer:
A
Chapter: 11
Q390:
Which of the following is NOT a property of regular languages?
A. Expressive enough for programming syntax
B. Recognized by finite automata
C. Do not have memory of visited states
D. Closed under union
Correct Answer:
A
Chapter: 11
Q391:
Fill in the blank: In CFG, the 'N' set refers to ______.
A. Non-terminals
B. Terminals
C. Productions
D. Start symbols
Correct Answer:
A
Chapter: 11
Q392:
In the sentence "SheepNoise -> SheepNoise baa | baa", what does 'baa' represent?
A. Terminal symbol
B. Non-terminal symbol
C. Production rule
D. Start symbol
Correct Answer:
A
Chapter: 11
Q393:
What error type is caused by missing declaration of variable 'sum'?
A. Semantic error
B. Syntax error
C. Runtime error
D. Linker error
Correct Answer:
A
Chapter: 11
Q394:
What will happen if the return value type does not match the function's declared return type?
A. Compilation error
B. Runtime error
C. No effect
D. Logical error
Correct Answer:
A
Chapter: 11
Q395:
Fill in the blank: A grammar G generates a language denoted by ______.
A. L(G)
B. G(L)
C. Lang(G)
D. Gram(L)
Correct Answer:
A
Chapter: 11
Q396:
Which derivation type replaces the leftmost non-terminal first?
A. Leftmost derivation
B. Rightmost derivation
C. Top-down derivation
D. Bottom-up derivation
Correct Answer:
A
Chapter: 11
Q397:
Which programming language grammar first used rules similar to those described here?
A. Algol-60
B. Java
C. Python
D. C++
Correct Answer:
A
Chapter: 11
Q398:
What is the purpose of productions (P) in CFG?
A. Rewrite rules
B. Terminals
C. Non-terminals
D. Start symbol
Correct Answer:
A
Chapter: 11
Q399:
Fill in the blank: Parsing can be described as discovering a ______ for a sentence.
A. Derivation
B. Program
C. Output
D. Code
Correct Answer:
A
Chapter: 11
Q400:
Which of these is NOT part of the four tuple in CFG?
A. Start symbol
B. Terminals
C. Parser
D. Productions
Correct Answer:
C