GATE Computer ScienceVery hardNIELIT Scientist B
Indirect left recursion is removed from S → A a | b; A → A c | S d | ε by ordering the non-terminals S, A, substituting S into A's rules, and then removing immediate left recursion (the new non-terminal is A′). How many productions does the resulting grammar have?
- A. 6
- B. 8
- C. 9
- D. 7
Correct answer: D. 7
S → A a | b stays (2). Substituting gives A → A c | A a d | b d | ε; removing the recursion yields A → b d A′ | A′ (2) and A′ → c A′ | a d A′ | ε (3): 2 + 2 + 3 = 7.
More Compiler Design questions
- In S → A B C | C a; A → a A | ε; B → b B | A c | ε; C → d | B e, how many symbols (including ) does FOLLOW(B) contain?
- How many of these four grammars are LL(1)? (1) S → a S b | ε; (2) S → A B; A → a | ε; B → a | b; (3) S → a A | b; A → S c | ε; (4) S → S a…
- Statements: 1: a = 1; 2: b = 2; 3: c = a + b; 4: d = c 2; 5: if d > 10 goto 8; 6: e = a + d; 7: goto 9; 8: e = b + 1; 9: print e. Which…
- A C lexer applies the maximal-munch rule (always take the longest possible token). How many tokens does it produce for the input…
- How many basic blocks does this three-address code contain? 1: i = 0; 2: s = 0; 3: if i >= n goto 9; 4: t = a[i]; 5: if t < 0 goto 7; 6: s…
- Using Sethi–Ullman numbering (a leaf that is a left operand needs 1 register, a leaf that is a right operand can be used from memory and…