Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 9
Q281:
In lexical analyzers, what happens when two patterns match with same prefix?
A. Shorter match is selected
B. Longest match is selected
C. Alphabetical token is selected
D. Error is returned
Correct Answer: B
Chapter: 9
Q282:
Flex is a tool that generates
A. Assembler
B. Code optimizer
C. Lexical analyzer
D. Parser
Correct Answer: C
Chapter: 9
Q283:
Which language does Flex generate the lexical analyzer in?
A. Python
B. C or C++
C. Java
D. Rust
Correct Answer: B
Chapter: 9
Q284:
Jlex is implemented in _______.
A. C++
B. Python
C. Java
D. Assembly
Correct Answer: C
Chapter: 9
Q285:
The file extension for Flex specification files is
A. .cpp
B. .lex
C. .l
D. .yy
Correct Answer: C
Chapter: 9
Q286:
The three sections in a Flex input file are separated by
A. ;;
B. ::
C. %%
D. #
Correct Answer: C
Chapter: 9
Q287:
In Flex, what section contains token definitions and actions?
A. First
B. Second
C. Third
D. Header
Correct Answer: B
Chapter: 9
Q288:
Which keyword is returned by Flex as TOK_IF?
A. int
B. if
C. else
D. while
Correct Answer: B
Chapter: 9
Q289:
The regular expression [0-9] matches
A. Letters
B. Digits
C. Spaces
D. Alphabets
Correct Answer: B
Chapter: 9
Q290:
The pattern [a-zA-Z_] represents
A. Uppercase only
B. Lowercase only
C. Letters and underscore
D. Digits
Correct Answer: C
Chapter: 9
Q291:
The expression {L}({L}|{D})* is used to match what?
A. Integer numbers
B. Identifiers
C. Keywords
D. Operators
Correct Answer: B
Chapter: 9
Q292:
What does the token TOK_NE represent?
A. <=>
B. =
C. ==
D. !=
Correct Answer: D
Chapter: 9
Q293:
Which file contains the token definitions used by Flex?
A. tokens.cpp
B. tokdefs.h
C. lexer.h
D. tokmap.h
Correct Answer: B
Chapter: 9
Q294:
Which token is represented by the keyword "void" in Flex?
A. TOK_INT
B. TOK_IF
C. TOK_VOID
D. TOK_ELSE
Correct Answer: C
Chapter: 9
Q295:
What is the value of TOK_IF defined in tokdefs.h?
A. 2
B. 3
C. 5
D. 8
Correct Answer: B
Chapter: 9
Q296:
Which token value is assigned to TOK_ID in tokdefs.h?
A. 111
B. 101
C. 10
D. 11
Correct Answer: A
Chapter: 9
Q297:
Which of the following is a command to invoke Flex?
A. run flex
B. flex lex.l
C. flex -compile lex.l
D. build lex.l
Correct Answer: B
Chapter: 9
Q298:
Which command compiles the output file from Flex?
A. gcc -c lex.cpp
B. g++ –c lex.cpp
C. clang lex.cpp
D. cc lex.cpp
Correct Answer: B
Chapter: 9
Q299:
The final command to create executable file in Windows is
A. g++ –o lex.exe lex.o main.o
B. link lex.o main.o
C. g++ compile exe
D. compile –win –o lex.exe
Correct Answer: A
Chapter: 9
Q300:
The main function uses which method to get token codes from scanner?
A. getToken()
B. YYText()
C. yylex()
D. getLex()
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now