GATE Computer ScienceHardGATE CS

A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++, --, ->, +=, -=, >>=, >>, >=, >, =, ==, +, -, <<=, <<, <=, <. No whitespace separates the characters of the input i+++++j->k-->>=m>>=n---o==p How many tokens does the scanner return?

  1. A. 18
  2. B. 15
  3. C. 19
  4. D. 17

Correct answer: D. 17

Reading greedily: i, ++, ++, +, j, ->, k, --, >>=, m, >>=, n, --, -, o, ==, p. That is 17 tokens. Maximal munch never splits ++ or >>= to make the program parse, so +++++ becomes ++ ++ + and n---o becomes n -- - o.

More Compiler Design questions

Exams that ask this topic