Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Multiple Choice Questions
Q151: What does the method `idChar(char c)` check for?
- A: Only alphabets
- B: Only digits
- C: Valid identifier characters
- D: Special symbols
View Answer
C
Q152: In the C++ Lexer class, which character indicates the start of a string token?
- A: '='
- B: '{'
- C: '"'
- D: '/'
View Answer
C
Q153: Which of the following methods is used to create a number token in Lexer?
- A: readNumber()
- B: readToken()
- C: readFloat()
- D: readDigit()
View Answer
A
Q154: What is returned when `idChar(c)` returns false in `readId()`?
- A: A symbol
- B: An integer
- C: A new token
- D: An error
View Answer
C
Q155: What character can be used as part of an identifier?
- A: *
- B: _
- C: $
- D: @
View Answer
B
Q156: What function checks if a character is part of a number in the Lexer?
- A: isDigit()
- B: isAlpha()
- C: isNumber()
- D: isChar()
View Answer
C
Q157: The function `isAlpha(c)` is used to check if character c is a(n) ________.
- A: digit
- B: symbol
- C: alphabet
- D: string
View Answer
B
Q158: The lexer partitions the input string by reading ________.
- A: right-to-left
- B: top-down
- C: bottom-up
- D: left-to-right
View Answer
D
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
View Answer
D
Q160: If a token starts with "i", what could it possibly be?
- A: keyword "if"
- B: identifier "i"
- C: both
- D: A or B
View Answer
C