GATE Computer ScienceVery hardGATE CS
Grammar: E → E + T | T; T → T * F | F; F → ( E ) | id. An SLR(1) parser parses id + id * ( id + id ) * id. Counting every shift, every reduce and the final accept as one action, how many parser actions are executed?
- A. 31
- B. 28
- C. 27
- D. 25
Correct answer: B. 28
There are 11 tokens, so 11 shifts. Reductions: 6 F-reductions (5 ids and one parenthesised E), 6 T-reductions (4 of the form T → F, 2 of the form T → T * F) and 4 E-reductions (2 of E → T and 2 of E → E + T), a total of 16. 11 + 16 + 1 accept = 28.
More Compiler Design questions
- 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…
- 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…