GATE | GATE-CS-2017 (Set 2) | Question 40

Consider the following expression grammar G.

E -> E - T | T
T -> T + F | F
F -> (E) | id

Which of the following grammars are not left recursive, but equivalent to G.

A)
E -> E - T | T
T -> T + F | F
F -> (E) | id

B)
E -> TE'
E' -> -TE' | ε
T -> T + F | F
F -> (E) | id

C)
E -> TX
X -> -TX | ε
T -> FY
Y -> +FY | ε
F -> (E) | id

D)
E -> TX | (TX)
X -> -TX | +TX | ε
T -> id

(A) A
(B) B
(C) C
(D) D


Answer: (C)

Explanation: We know for left recursion : A -> Aα/β
After removing left recursion it can be written as



A->βA’
A’->αA’/ε

Thus for : E->E- T/T
α= -T , β= T . thus new production after removing left recursion
is E->TE’ and E’->- TE’/ ε

T->FT’ and T’->+FT’/ ε

F->(E)/id .

Quiz of this Question



My Personal Notes arrow_drop_up