Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 5
Q141:
What is the output of a scanner in lexical analysis?
A. Parse tree
B. Tokens
C. Source code
D. Errors
Correct Answer: B
Chapter: 5
Q142:
A token is a _______ category in a sentence of a language.
A. semantic
B. syntactic
C. lexical
D. grammatical
Correct Answer: B
Chapter: 5
Q143:
In the sentence “He wrote the program”, “wrote” is classified as a ______.
A. subject
B. verb
C. object
D. conjunction
Correct Answer: B
Chapter: 5
Q144:
In programming, “if”, “else”, and “while” are categorized as ________.
A. keywords
B. identifiers
C. symbols
D. operators
Correct Answer: A
Chapter: 5
Q145:
What would be the token for the word 'b' in the sentence `if(b == 0)`?
A. Keyword
B. Identifier
C. Operator
D. Integer
Correct Answer: B
Chapter: 5
Q146:
Which of the following is a valid float token?
A. 1000
B. 0.0034
C. error
D. ==
Correct Answer: B
Chapter: 5
Q147:
Which of the following is NOT a token type?
A. Keywords
B. Identifiers
C. Statements
D. Integers
Correct Answer: C
Chapter: 5
Q148:
Which class is responsible for generating tokens in the provided C++ code?
A. Token
B. Scanner
C. Parser
D. Lexer
Correct Answer: D
Chapter: 5
Q149:
The Lexer class uses _______ to look ahead for the next character.
A. next
B. prev
C. curr
D. lookahead
Correct Answer: A
Chapter: 5
Q150:
In the Lexer class, what function is used to recognize identifiers?
A. readToken()
B. readId()
C. readIdentifier()
D. readChar()
Correct Answer: B
Chapter: 5
Q151:
What does the method `idChar(char c)` check for?
A. Only alphabets
B. Only digits
C. Valid identifier characters
D. Special symbols
Correct Answer: C
Chapter: 5
Q152:
In the C++ Lexer class, which character indicates the start of a string token?
A. '='
B. '{'
C. '"'
D. '/'
Correct Answer: C
Chapter: 5
Q153:
Which of the following methods is used to create a number token in Lexer?
A. readNumber()
B. readToken()
C. readFloat()
D. readDigit()
Correct Answer: A
Chapter: 5
Q154:
What is returned when `idChar(c)` returns false in `readId()`?
A. A symbol
B. An integer
C. A new token
D. An error
Correct Answer: C
Chapter: 5
Q155:
What character can be used as part of an identifier?
A. *
B. _
C. $
D. @
Correct Answer: B
Chapter: 5
Q156:
What function checks if a character is part of a number in the Lexer?
A. isDigit()
B. isAlpha()
C. isNumber()
D. isChar()
Correct Answer: C
Chapter: 5
Q157:
The function `isAlpha(c)` is used to check if character c is a(n) ________.
A. digit
B. symbol
C. alphabet
D. string
Correct Answer: B
Chapter: 5
Q158:
The lexer partitions the input string by reading ________.
A. right-to-left
B. top-down
C. bottom-up
D. left-to-right
Correct Answer: D
Chapter: 5
Q159:
Which of the following causes difficulty in writing a hand-written lexer?
A. Token prediction
B. Token ambiguity
C. Multi-character tokens
D. All of the above
Correct Answer: D
Chapter: 5
Q160:
If a token starts with "i", what could it possibly be?
A. keyword "if"
B. identifier "i"
C. both
D. A or B
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now