GATE Computer ScienceHardGATE CS (PYQ pattern)
A scanner has two token rules, R1 = a b* and R2 = b c. It always takes the longest prefix matching some rule and never backtracks over a token it has chosen. For which inputs does it report an error even though the input can be split into a sequence of tokens? I. abbc II. bcab III. abc
- A. I only
- B. I, II and III
- C. II and III only
- D. I and III only
Correct answer: D. I and III only
I: the scanner takes abb (R1) and is left with c, which no rule matches; yet ab | bc is a valid split. II: bc then ab: success. III: it takes ab and is stuck at c, though a | bc works. Maximal munch is greedy, so a valid tokenisation can exist where it fails.
More Compiler Design questions
- Register allocation by graph colouring is done on the loop 1: L1: v1 = v4 + 1; 2: v2 = v5 + 1; 3: v3 = v1 + 1; 4: v4 = v2 + 1; 5: v5 = v3…
- An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of…
- For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION…
- S → C C; C → c C | d is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column…
- For S → A b | B c; A → a A | ε; B → a B | ε (augmented), in how many LR(0) states is there a conflict, how many ACTION cells of the LR(0)…
- How many distinct LR(0) items does the grammar S → i E t S Z | a; Z → e S | ε; E → b have (do not augment it; an ε-production gives…