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?
- A. 18
- B. 15
- C. 19
- 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
- A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead…
- A scanner generator is given the rules, in this order: (1) if → IF; (2) [a-z][a-z0-9] → ID; (3) [0-9]+ → NUM. It uses the longest match…
- The Thompson construction (Aho–Sethi–Ullman style: a symbol gets 2 states; union and star each add a new start and a new final state…
- In the Thompson NFA for (a|b), each symbol machine has 2 states and 1 non-ε edge; union and star add a new start and final state with 4…
- A floating-point literal is defined over the symbols d (digit), '.', e and s (sign) as d⁺ ( . d⁺ )? ( e s? d⁺ )?. How many states does the…
- A C comment is / followed by any text that does not contain / followed by / . Over the alphabet { /, , x } the language is /([^]|+[^/])+/…