GATE Computer ScienceVery hardGATE CSE · NIELIT
Grammar: E → E + T | T; T → T * F | F; F → id. An SLR(1) parser parses id + id * id + id * id (followed by $). Counting each shift and each reduce as one move (excluding the final accept), how many shift moves and reduce moves are made?
- A. 9 shifts and 12 reduces
- B. 9 shifts and 13 reduces
- C. 8 shifts and 14 reduces
- D. 9 shifts and 15 reduces
Correct answer: B. 9 shifts and 13 reduces
Every id and operator is shifted (5 + 4 = 9); reduces: 5 for F→id, 3 for T→F (one per term), 2 for T→T*F, 1 for E→T and 2 for E→E+T = 13.
More Compiler Design questions
- Grammar: S → A B C; A → a | ε; B → a | b | ε; C → a | c | ε. How many cells of the LL(1) table contain more than one production?
- A lexer uses longest match, with ties broken in favour of the rule listed first. Rules in order: IF = "if"; ELSE = "else"; ID =…
- 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…