GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The grammar A → B a | A a | c; B → B b | A b | d is transformed by the standard algorithm that removes (indirect and immediate) left recursion, processing the non-terminals in the order A, B and substituting earlier non-terminals into later ones. How many productions does the resulting grammar have? (Count each alternative, including A′ → ε, as one production.)
- A. 12
- B. 6
- C. 9
- D. 11
Correct answer: C. 9
Resulting grammar: A → B a A' | c A'; B → c A' b B' | d B'; A' → a A' | ε; B' → b B' | a A' b B' | ε. That is 9 productions.
More Compiler Design questions
- SDD: D → T L { L.inh = T.type }; T → int { T.type = integer }; L → L1 , id { L1.inh = L.inh; addType(id.entry, L.inh) }; L → id {…
- Which of the following are true? I. Every LL(1) grammar is LR(1). II. Every LL(1) grammar is LALR(1). III. Every LALR(1) grammar is LR(1)…
- Available-expressions analysis (expressions compared textually, so a b and b a differ; assigning an operand kills an expression) is run on…
- Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively…
- void p(int x, int y) { x = x + 1; y = y + x; } is called as p(a, a) with a = 2. What is a after the call when the parameters are passed by…
- How many distinct LR(0) items does the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id have (do not augment it…