GATE Computer ScienceVery hardGATE CSE
A lexer uses longest match, with ties broken in favour of the rule listed first. Rules in order: IF = "if"; ELSE = "else"; ID = [a-z][a-z0-9]*; NUM = [0-9]+; LE = "<="; NE = "<>"; LT = "<"; EQ = "="; blanks are skipped. For the input iffy if x1<=7<>y9 else2 else<3 how many tokens are produced and how many of them are ID tokens?
- A. 11 tokens, 3 IDs
- B. 10 tokens, 4 IDs
- C. 12 tokens, 5 IDs
- D. 11 tokens, 4 IDs
Correct answer: D. 11 tokens, 4 IDs
Tokens: ID(iffy) IF(if) ID(x1) LE(<=) NUM(7) NE(<>) ID(y9) ID(else2) ELSE(else) LT(<) NUM(3). "iffy" and "else2" are longer ID matches than the keywords, while "if" and "else" tie and go to the earlier keyword rules.
More Compiler Design questions
- Three-address code: 1: x = 0; 2: if a > b goto 8; 3: x = x + 1; 4: if x > 5 goto 7; 5: y = y 2; 6: goto 2; 7: y = y + 1; 8: if y < 100…
- Grammar: S → L = R | R; L → R | id; R → L, augmented with S' → S. How many distinct LR(1) items (production, dot position, lookahead) does…
- Grammar: S → a S b | S S | ε. How many distinct strings of length exactly 10 belong to the language it generates?
- Backpatching with no fall-through optimisation, numbering from 100, translates while (a < b && c < d || e < f) { if (x < y) p = 1; else q…
- For the augmented grammar S′ → S; S → a S a | b S b | c, how many states does the canonical LR(1) automaton have, and how many does the…
- For the grammar G: S → A b | B c; A → a A | ε; B → a B | ε, the LL(1) predictive table is built. Which statement is correct?