GATE Computer ScienceVery hardGATE CS (PYQ pattern)
An LR parser for E → T E′; E′ → + T E′ | ε; T → F T′; T′ → * F T′ | ε; F → ( E ) | id parses "id + id * id". How many reductions does it make (not counting accept), and how many of them are by ε-productions?
- A. 11 reductions, 2 by ε-productions
- B. 8 reductions, 3 by ε-productions
- C. 13 reductions, 5 by ε-productions
- D. 11 reductions, 3 by ε-productions
Correct answer: D. 11 reductions, 3 by ε-productions
Reductions: F → id, T′ → ε (before +), T → F T′; F → id; F → id, T′ → ε (at $), T′ → * F T′, T → F T′, E′ → ε, E′ → + T E′, E → T E′. That is 11, of which T′ → ε twice and E′ → ε once are ε-reductions. (No T′ → ε occurs between the second id and *, because * is shifted.)
More Compiler Design questions
- For each choice of terminals x, y ∈ {a, b, c} consider G(x, y): S → A x B; A → a A | ε; B → b B | y. Of the nine grammars, how many are…
- The grammar S → a S | S a | b is ambiguous. How many distinct parse trees does the string "a a a b a a" have?
- For S → b A d | c A e | b B e; A → x; B → x (augmented), how many ACTION cells of the SLR(1) table are multiply defined, and how many…
- Procedures are nested as follows: main contains P (nesting depth 2); P contains Q (depth 3) and S (depth 3); Q contains R (depth 4)…
- Which of the following is/are true? I. An LL(1) grammar can contain ε-productions. II. An LL(1) grammar is never ambiguous. III. If FIRST…
- For G: S → A S | b; A → S A | a, which statements are true? I. FOLLOW(A) ⊂ FOLLOW(S) (proper subset). II. The LL(1) table has exactly two…