Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 9
Q321:
Flex generates code in
A. C/C++ only
B. Java only
C. Assembly
D. Python
Correct Answer: A
Chapter: 9
Q322:
The longest matching token is selected by
A. Flex
B. Jlex
C. Parser
D. Lexical Analyzer
Correct Answer: D
Chapter: 10
Q323:
What is the role of a scanner in a compiler?
A. To parse syntax
B. To identify tokens
C. To execute programs
D. To optimize code
Correct Answer: B
Chapter: 10
Q324:
Which command is used to run the scanner on main.cpp file?
A. ./scanner main.cpp
B. lex main.cpp
C. lex <main.cpp
D. g++ main.cpp
Correct Answer: C
Chapter: 10
Q325:
What does '259,void' represent in the scanner output?
A. Token type and token
B. Line number and variable
C. Data type and size
D. Line number and token
Correct Answer: A
Chapter: 10
Q326:
Which token is returned by the Flex rule for "{"?
A. '}'
B. '['
C. '{'
D. '('
Correct Answer: C
Chapter: 10
Q327:
Which Flex rule skips whitespace characters like tab and space?
A. [\t]+
B. [\s]+
C. [\t\f\v\r ]+
D. [ \n\t]+
Correct Answer: C
Chapter: 10
Q328:
Which function is used to skip multi-line comments in Flex?
A. skip_multiline()
B. skip_comment()
C. skip_block()
D. remove_comment()
Correct Answer: B
Chapter: 10
Q329:
Which symbol represents the start of a multi-line comment in C++?
A. //
B. /*
C. #
D. <!
Correct Answer: B
Chapter: 10
Q330:
The Flex rule for the character '!' returns which token?
A. NOT
B. AND
C. OR
D. EQUAL
Correct Answer: A
Chapter: 10
Q331:
Which keyword returns the token 'AUTO' in Flex?
A. automatic
B. auto
C. autotype
D. automate
Correct Answer: B
Chapter: 10
Q332:
What does the Flex rule '[a-zA-Z_][a-zA-Z_0-9]*' identify?
A. Constants
B. Strings
C. Identifiers
D. Numbers
Correct Answer: C
Chapter: 10
Q333:
What kind of token is returned for numeric literals like 123 or 045?
A. INTEGER
B. FLOAT
C. STRING
D. CHAR
Correct Answer: A
Chapter: 10
Q334:
How is a floating-point literal like 3.14E+10 recognized in Flex?
A. Using floatsuffix
B. Using exppart
C. Using intsuffix
D. Using chartext
Correct Answer: B
Chapter: 10
Q335:
In Flex, what does the rule for '++' return?
A. PLUS
B. PLUSPLUS
C. INCREMENT
D. ADDITION
Correct Answer: B
Chapter: 10
Q336:
Which of the following is a valid string literal token rule in Flex?
A. ["string"]
B. \"string\"
C. ‘string’
D. ''string''
Correct Answer: B
Chapter: 10
Q337:
The token 'class' in C++ is returned by which rule in Flex?
A. class
B. [Cc]lass
C. <class>
D. CLASS_NAME
Correct Answer: A
Chapter: 10
Q338:
In Flex, the rule for 'return' maps to which token?
A. RET
B. RETURN
C. EXIT
D. END
Correct Answer: B
Chapter: 10
Q339:
The purpose of the check_identifier function is to ______.
A. Check if a string is a reserved keyword
B. Check identifier length
C. Validate syntax
D. Check variable types
Correct Answer: A
Chapter: 10
Q340:
Which keyword in C++ represents a logical OR?
A. ||
B. or
C. and
D. either
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now