GATE Computer ScienceHardGATE CS (PYQ pattern)

A C lexer applies the longest-match (maximal munch) rule. The number of tokens in the statement x = a---b*c++; is:

  1. A. 10
  2. B. 9
  3. C. 12
  4. D. 11

Correct answer: A. 10

Maximal munch reads --- as the token -- followed by -. The tokens are x, =, a, --, -, b, *, c, ++ and ; which makes 10 tokens. Reading three separate minus signs would give 12.

More Compiler Design questions

Exams that ask this topic