Machine-translated by Google. Questions are authored in English.
Top

Discussion

In a hand written scanner, a retract or unget operation is needed when

  • A.the input buffer must be refilled from the source file
  • B.a character was read that belongs to the next lexeme rather than this
  • C.the symbol table already contains the identifier being scanned
  • D.the parser rejects the token that the scanner has only just produced

Answer: B

Correct answer: a character was read that belongs to the next lexeme rather than this

The scanner often knows a lexeme has ended only by reading the character after it - the digits of a number end at the first non-digit. That character belongs to the next lexeme, so it must be pushed back for the next call to read. This is why one character of lookahead, and a way of retracting it, is part of every scanner.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.