Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 10
Q341:
What happens when an unexpected character is found in input?
A. An error is printed silently
B. Line number is ignored
C. Error is printed with line number
D. Scanner terminates abruptly
Correct Answer: C
Chapter: 10
Q342:
What type of lexical analyzer is being developed using Flex in this example?
A. Python lexical analyzer
B. C++ lexical analyzer
C. Java lexical analyzer
D. C lexer
Correct Answer: B
Chapter: 10
Q343:
Which character in Flex input increases line number on newline?
A. ' '
B. '\t'
C. '\n'
D. '\r'
Correct Answer: C
Chapter: 10
Q344:
Which of these symbols is NOT defined in the given Flex rules?
A. '@'
B. ';'
C. '('
D. '['
Correct Answer: A
Chapter: 10
Q345:
The token 'try' in C++ is returned as ______.
A. TRY
B. CATCH
C. EXCEPTION
D. CHECK
Correct Answer: A
Chapter: 10
Q346:
The function skip_until_eol() skips characters until it finds what?
A. EOF
B. Newline
C. Tab
D. Space
Correct Answer: B
Chapter: 10
Q347:
The token returned by '++' is equivalent to what kind of operator?
A. Arithmetic
B. Relational
C. Increment
D. Logical
Correct Answer: C
Chapter: 10
Q348:
Which header is included in the Flex scanner code for character processing?
A. <stdio.h>
B. <string.h>
C. <ctype.h>
D. <stdlib.h>
Correct Answer: C
Chapter: 10
Q349:
The function yywrap() in Flex is used to ______.
A. Wrap code into functions
B. End input processing
C. Handle errors
D. Scan again after wrapping
Correct Answer: B
Chapter: 10
Q350:
In Flex, what is the purpose of the '%' section?
A. Define rules
B. Import libraries
C. Define macros
D. Separate sections
Correct Answer: D
Chapter: 10
Q351:
What does 'void' return as a token according to the sample scanner output?
A. 259
B. 258
C. 260
D. 261
Correct Answer: A
Chapter: 10
Q352:
In the scanner output, what token is associated with the identifier 'main'?
A. 258
B. 259
C. 260
D. 261
Correct Answer: A
Chapter: 10
Q353:
The character ',' in Flex rules returns which token?
A. COMMA
B. SEMICOLON
C. ','
D. SEPARATOR
Correct Answer: C
Chapter: 10
Q354:
Which keyword among the following is not defined in the sample Flex rules?
A. auto
B. new
C. bool
D. string
Correct Answer: D
Chapter: 10
Q355:
The operator '!=' corresponds to which token in Flex rules?
A. NOTEQ
B. EQ
C. NE
D. EQUAL
Correct Answer: A
Chapter: 10
Q356:
Which rule will match a hexadecimal number in C++?
A. 0x[0-9]+
B. 0[xX][0-9a-fA-F]+{intsuffix}?
C. #[0-9A-F]+
D. [HEX]+
Correct Answer: B
Chapter: 10
Q357:
How many parts are in the typical Flex input file?
A. One
B. Two
C. Three
D. Four
Correct Answer: C
Chapter: 10
Q358:
C++ comment starting with '//' is skipped by which function?
A. skip_comment()
B. skip_to_newline()
C. skip_until_eol()
D. clear_line()
Correct Answer: C
Chapter: 10
Q359:
The Flex pattern for recognizing string literals involves ______.
A. \d+
B. \"{stringtext}\"
C. [a-zA-Z]+
D. '{chartext}'
Correct Answer: B
Chapter: 10
Q360:
Which token is associated with the 'if' keyword in C++ in the Flex rules?
A. COND
B. IF
C. BRANCH
D. CONTROL
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now