Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 5
Q161:
Which symbol may require lookahead to distinguish between assignment and comparison?
A. !
B. =
C. &
D. +
Correct Answer:
B
Chapter: 5
Q162:
Which of the following is a string token?
A. error
B. 123
C. ==
D. ++
Correct Answer:
A
Chapter: 5
Q163:
The scanner reads the source code and generates _______.
A. objects
B. errors
C. tokens
D. instructions
Correct Answer:
C
Chapter: 5
Q164:
Scanner is also known as ________.
A. optimizer
B. lexer
C. parser
D. compiler
Correct Answer:
B
Chapter: 5
Q165:
Which token type does `maxsize` belong to?
A. Keyword
B. Identifier
C. Operator
D. Symbol
Correct Answer:
B
Chapter: 5
Q166:
The scanner ignores ______ between tokens.
A. operators
B. characters
C. blanks
D. errors
Correct Answer:
C
Chapter: 5
Q167:
In lexical analysis, the program is treated as a stream of ______.
A. tokens
B. variables
C. characters
D. identifiers
Correct Answer:
C
Chapter: 5
Q168:
A lexical analyzer classifies substrings according to their ______.
A. value
B. role
C. position
D. size
Correct Answer:
B
Chapter: 5
Q169:
“==” is an example of which kind of token?
A. Identifier
B. Boolean operator
C. String
D. Float
Correct Answer:
B
Chapter: 5
Q170:
What is the role of `readId()` in Lexer?
A. Read a float
B. Read a keyword
C. Read an identifier
D. Read an operator
Correct Answer:
C
Chapter: 5
Q171:
The code `if( idChar(next) ) return readId();` checks for a _______.
A. number
B. string
C. valid identifier character
D. operator
Correct Answer:
C
Chapter: 5
Q172:
Which of the following is NOT part of a token?
A. Word
B. Role
C. Type
D. Length
Correct Answer:
D
Chapter: 5
Q173:
The look-ahead character in Lexer helps in ______.
A. reading strings
B. checking syntax
C. deciding token boundaries
D. matching grammar rules
Correct Answer:
C
Chapter: 5
Q174:
What happens if the character is not part of a valid identifier in `readId()`?
A. It is stored in buffer
B. It is skipped
C. It ends the identifier
D. A token is returned
Correct Answer:
D
Chapter: 6
Q175:
What is the most popular method for specifying tokens in lexical analysis?
A. Context-Free Grammars
B. Regular Languages
C. Turing Machines
D. Fuzzy Logic
Correct Answer:
B
Chapter: 6
Q176:
Regular languages are preferred for token specification because they are _______.
A. complex and theoretical
B. easy and intuitive
C. based on difficult logic
D. used in database queries
Correct Answer:
B
Chapter: 6
Q177:
The alphabet in formal language theory is _______.
A. A complete sentence
B. A syntax rule
C. A set of characters
D. A set of rules
Correct Answer:
C
Chapter: 6
Q178:
Which of the following is an example of a language over ASCII?
A. English Sentence
B. C++ Program
C. Binary Code
D. HTML Tag
Correct Answer:
B
Chapter: 6
Q179:
A regular expression describes _______.
A. A programming loop
B. A conditional expression
C. A regular language
D. Grammar rules
Correct Answer:
C
Chapter: 6
Q180:
Which notation is used to denote the language defined by a regular expression A?
A. L(A)
B. R(A)
C. Reg(A)
D. Expr(A)
Correct Answer:
A