Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 9
Q301:
In lexical analysis, the error is returned when
A. All tokens matched
B. No match is found
C. Longest token is found
D. Token matches more than once
Correct Answer:
B
Chapter: 9
Q302:
What is the primary function of a lexical analyzer in a compiler?
A. Translate to machine code
B. Parse expressions
C. Tokenize input
D. Optimize program
Correct Answer:
C
Chapter: 9
Q303:
Lexical analyzer works at which phase of compilation?
A. Parsing
B. Syntax checking
C. Lexical analysis
D. Semantic analysis
Correct Answer:
C
Chapter: 9
Q304:
== is longer than "=" so lexical analyzer will return
A. =
B. ==
C. Token for "="
D. Error
Correct Answer:
B
Chapter: 9
Q305:
The scanner always returns
A. Shortest match
B. Longest match
C. Random match
D. First match
Correct Answer:
B
Chapter: 9
Q306:
Which of the following is a valid identifier according to the pattern {L}({L}|{D})*?
A. _abc
B. 9abc
C. abc!
D. 1_abc
Correct Answer:
A
Chapter: 9
Q307:
The Flex tool is a modern version of
A. Parser generator
B. Lex tool
C. GCC tool
D. JavaCC
Correct Answer:
B
Chapter: 9
Q308:
The lexical analyzer breaks the input stream into
A. Statements
B. Tokens
C. Lines
D. Characters
Correct Answer:
B
Chapter: 9
Q309:
The process of constructing a lexical analyzer can be
A. Manually only
B. Automated
C. Not possible
D. Reversed
Correct Answer:
B
Chapter: 9
Q310:
void matched in Flex returns which token?
A. TOK_ID
B. TOK_VOID
C. TOK_ELSE
D. TOK_INT
Correct Answer:
B
Chapter: 9
Q311:
A minimized DFA accepts the ______ language as the original DFA.
A. Smaller
B. Different
C. Same
D. Larger
Correct Answer:
C
Chapter: 9
Q312:
Each group of equivalent states in DFA minimization is represented by
A. One transition
B. One input
C. One merged state
D. One path
Correct Answer:
C
Chapter: 9
Q313:
States in group G1 must transition to
A. Any state
B. Other groups
C. The same group G2
D. Random states
Correct Answer:
C
Chapter: 9
Q314:
The symbol “%%” in Flex input file separates
A. Functions
B. Classes
C. Sections
D. Tokens
Correct Answer:
C
Chapter: 9
Q315:
In Flex, user code is written in which section?
A. First
B. Second
C. Third
D. None
Correct Answer:
C
Chapter: 9
Q316:
The header file included in lex.l is
A. <token.h>
B. tokdefs.h
C. defs.h
D. <tokenmap.h>
Correct Answer:
B
Chapter: 9
Q317:
The lexical analyzer returns _______ matching token.
A. First
B. Longest
C. Shortest
D. Random
Correct Answer:
B
Chapter: 9
Q318:
In lexical analyzer, “while” is returned as
A. TOK_IF
B. TOK_LOOP
C. TOK_WHILE
D. TOK_REPEAT
Correct Answer:
C
Chapter: 9
Q319:
The FlexLexer class is used to
A. Generate parser
B. Simulate DFA
C. Invoke scanner
D. Write tokens
Correct Answer:
C
Chapter: 9
Q320:
DFA Minimization results in a DFA with
A. More states
B. Same states
C. Fewer states
D. No states
Correct Answer:
C