GATE Computer ScienceHardGATE CS
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 and, among rules matching the same length, the earliest rule. White space is skipped. For the input if iffy if1 if 12ab 7 iff what are the numbers of IF, ID and NUM tokens?
- A. (2, 3, 2)
- B. (3, 3, 2)
- C. (2, 4, 2)
- D. (1, 5, 2)
Correct answer: C. (2, 4, 2)
if → IF (tie with rule 2, earlier rule wins); iffy, if1 → ID; if → IF; 12ab → NUM(12) then ID(ab); 7 → NUM; iff → ID. So IF = 2, ID = 4 (iffy, if1, ab, iff), NUM = 2 (12, 7).
More Compiler Design questions
- 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 /([^]|+[^/])+/…
- A flow graph has nodes 1 to 10, entry node 1, and edges 1→2, 2→3, 3→4, 4→5, 5→3, 4→6, 6→7, 7→2, 7→8, 8→9, 9→8, 9→10, 6→10, 3→9. A back…
- For the flow graph with entry 1 and edges 1→2, 2→3, 3→4, 4→5, 5→3, 4→6, 6→7, 7→2, 7→8, 8→9, 9→8, 9→10, 6→10, 3→9, which is the dominance…