GATE Computer ScienceHardGATE CS (PYQ pattern)
Build the LL(1) table for E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id (^ is right-associative exponent). How many cells are non-blank, and how many of those hold an ε-production?
- A. 15 and 4
- B. 15 and 6
- C. 13 and 6
- D. 17 and 8
Correct answer: B. 15 and 6
FOLLOW(E) = FOLLOW(R) = {$, )}; FOLLOW(T) = FIRST(R) − ε ∪ FOLLOW(R) = {+, −, $, )} and FOLLOW(P) = FOLLOW(T) (P → ^ T ends with T). Non-blank: E 2, R 4 (+, −, $, )), T 2, P 5 (^ and the 4 of FOLLOW(P)), F 2 = 15. ε-entries: R → ε in 2 cells, P → ε in 4 cells = 6.
More Compiler Design questions
- An LR parser for E → id | E [ E ] | ( E ) parses "id [ ( id [ id ] ) ]". What is the largest number of grammar symbols on its stack at any…
- S → ( S ) S | ε is both LL(1) and SLR(1). Both parsers process "( ( ) ( ) )". What is the largest number of grammar symbols on the LL(1)…
- Augment S → ( L ) | x; L → S | L , S with S′ → S and build the canonical collection of LR(0) item sets. How many states does it have, and…
- The grammar S → A B; A → a | ε; B → A b | c is not LL(1). Each change below is applied to it on its own. Which of them make the grammar…
- L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states…
- A compiler generates jumping code by backpatching (each relation gives 'if r goto ' then 'goto ', numbering from 100) for: if (!(a < b) &&…