Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
B
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
View Answer
C
Q303: Lexical analyzer works at which phase of compilation?
- A: Parsing
- B: Syntax checking
- C: Lexical analysis
- D: Semantic analysis
View Answer
C
Q304: == is longer than "=" so lexical analyzer will return
- A: =
- B: ==
- C: Token for "="
- D: Error
View Answer
B
Q305: The scanner always returns
- A: Shortest match
- B: Longest match
- C: Random match
- D: First match
View Answer
B
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
View Answer
A
Q307: The Flex tool is a modern version of
- A: Parser generator
- B: Lex tool
- C: GCC tool
- D: JavaCC
View Answer
B
Q308: The lexical analyzer breaks the input stream into
- A: Statements
- B: Tokens
- C: Lines
- D: Characters
View Answer
B
Q309: The process of constructing a lexical analyzer can be
- A: Manually only
- B: Automated
- C: Not possible
- D: Reversed
View Answer
B
Q310: void matched in Flex returns which token?
- A: TOK_ID
- B: TOK_VOID
- C: TOK_ELSE
- D: TOK_INT
View Answer
B