Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 10
Q361:
Which keyword will return the token WHILE in Flex?
A. for
B. loop
C. while
D. until
Correct Answer:
C
Chapter: 10
Q362:
The C++ keyword 'const_cast' is mapped to which Flex token?
A. CAST
B. CONST
C. CONST_CAST
D. STATIC_CAST
Correct Answer:
C
Chapter: 10
Q363:
The token returned for the expression "++i" includes which operator?
A. ++
B. --
C. +=
D. +
Correct Answer:
A
Chapter: 10
Q364:
Identifiers in Flex must start with ______.
A. A digit
B. An operator
C. An alphabet or underscore
D. An asterisk
Correct Answer:
C
Chapter: 10
Q365:
Which of the following is not a valid C++ keyword defined in Flex rules?
A. operator
B. register
C. package
D. typedef
Correct Answer:
C
Chapter: 10
Q366:
Flex is primarily used in which phase of a compiler?
A. Code generation
B. Semantic analysis
C. Lexical analysis
D. Optimization
Correct Answer:
C
Chapter: 11
Q367:
What type of error occurs when code follows syntax rules but the meaning is incorrect?
A. Semantic error
B. Syntax error
C. Runtime error
D. Linker error
Correct Answer:
A
Chapter: 11
Q368:
What is missing at the end of 'sum = sum+i' in the given C++ code?
A. Semicolon
B. Parenthesis
C. Braces
D. Colon
Correct Answer:
A
Chapter: 11
Q369:
What role does the parser play in a compiler?
A. It checks syntax validity
B. It executes the code
C. It allocates memory
D. It manages input/output
Correct Answer:
A
Chapter: 11
Q370:
Which formal grammar is typically used to represent syntax of programming languages?
A. Regular Grammar
B. Context-Free Grammar
C. Unrestricted Grammar
D. Regular Expression
Correct Answer:
B
Chapter: 11
Q371:
Why are regular expressions not suitable for syntax representation of programming languages?
A. They are too complex
B. They lack memory of repeated states
C. They are slow
D. They do not support tokens
Correct Answer:
B
Chapter: 11
Q372:
In CFG notation G = (S, N, T, P), what does 'P' represent?
A. Start symbol
B. Non-terminals
C. Productions
D. Terminals
Correct Answer:
C
Chapter: 11
Q373:
What does the start symbol 'S' in a Context-Free Grammar represent?
A. A terminal symbol
B. The beginning of a derivation
C. A production rule
D. A non-terminal symbol
Correct Answer:
B
Chapter: 11
Q374:
Which of the following is NOT a component of a Context-Free Grammar?
A. Terminals
B. Non-terminals
C. Attributes
D. Start symbol
Correct Answer:
C
Chapter: 11
Q375:
In parsing, what is the difference between leftmost and rightmost derivation?
A. Leftmost replaces rightmost non-terminal
B. Rightmost replaces leftmost non-terminal
C. Leftmost replaces leftmost non-terminal, Rightmost replaces rightmost non-terminal
D. No difference
Correct Answer:
C
Chapter: 11
Q376:
What is the correct boolean expression syntax for a for loop?
A. for(i=0; i<j; i++)
B. for(k=0; i j;)
C. for(i=0; j<k;)
D. for(i=0 i<j i++)
Correct Answer:
A
Chapter: 11
Q377:
In semantic analysis, the sentence "He wrote the computer" is
A. Correct
B. Incorrect due to syntax
C. Incorrect due to semantics
D. Correct but incomplete
Correct Answer:
C
Chapter: 11
Q378:
Which language's syntax influenced C, C++, and Java?
A. JavaScript
B. Algol-60
C. Python
D. COBOL
Correct Answer:
B
Chapter: 11
Q379:
Which form was developed by John Backus and adapted by Peter Naur for Algol-60?
A. Regular Expression
B. Backus-Naur Form (BNF)
C. Chomsky Normal Form
D. Extended BNF
Correct Answer:
B
Chapter: 11
Q380:
Which of the following is an example of a terminal symbol in CFG?
A. <id>
B. <expr>
C. +
D. <op>
Correct Answer:
C