GATE Computer ScienceVery hardGATE CS
A table-driven predictive parser for E → T E'; E' → + T E' | ε; T → F T'; T' → * F T' | ε; F → ( E ) | id parses ( id + id ) * id + id. One move is either replacing a non-terminal on the stack by a production body (an ε body also counts) or matching and popping a terminal; the final acceptance on $ is not counted. How many moves does the parser make?
- A. 31
- B. 29
- C. 28
- D. 33
Correct answer: B. 29
The number of moves equals the number of productions applied (including ε-productions) plus the number of terminal matches. The input has 9 terminals, giving 9 matches, and 20 production applications, a total of 29. (For id + id * id the same count is 16.)
More Compiler Design questions
- An array A[2..6][−1..4][0..5] of 4-byte elements has base address 1000. The address of A[4][2][3] is computed in row-major order and…
- A scanner discards comments, which begin with / and end at the FIRST / (comments do not nest). Identifiers are letters, and and / are…
- A C lexer uses maximal munch. How many tokens does it produce for the line int x = a++ + --b >= 3 ? 1 : 0; (whitespace is ignored)?
- For the grammar S → A B c; A → a A | ε; B → b B | ε, how many terminals are in FIRST(S)?
- For the standard expression grammar E → T E′; E′ → + T E′ | ε; T → F T′; T′ → F T′ | ε; F → ( E ) | id, how many symbols (including ) are…
- How many states does the canonical LR(0) collection of the augmented grammar S′ → S; S → A A; A → a A | b contain?