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:
- A. 10
- B. 9
- C. 12
- 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
- Which of the following grammars are LL(1)? (I) S → a S b | ε. (II) S → a S a | a. (III) S → A B, A → a | ε, B → a | b. (IV) S → a S | b S…
- Consider this pseudo-code (arrays are 1-based): i = 1; a = [5, 6, 7]; procedure P(x, y) { x = x + 1; y = y 2; } P(i, a[i]); print(i, a[1]…
- A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++…
- 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…