Last Updated :
02 Nov, 2018
After Eliminating the left recursion from the given grammar:
A → A*X / X
X → X+B / B
B → id
Which of the following represent grammar to represent the equivalent left recursion free grammar?
(I): A → XA\'
A\' → *XA\'
X → BX\'
X\' → +BX\'
B → id
(II): A → XA\'
A\' → ϵ / *XA\'
X → BX\'
X\' → ϵ / +BX\'
B → id
(III): A → XA\' /ϵ
A\' → ϵ / *XA\'
X → BX\' /ϵ
X\' → ϵ / +BX\'
B → id
(IV): A → XA\' /ϵ
A\' → *XA\'
X → BX\' /ϵ
X\' → +BX\'
B → id
(A) (I)
(B) (II)
(C) (III)
(D) (IV)
Answer: (B)
Explanation: Removal of left recursion:
A → A x X / X will be results in
→ X , X x X, X x X, X x X x X, ...X(x X)*
A → XA\'
A\'→ ϵ / x X A\'
X → X + B / B will be results in
→ B , B + B, B + B + B, ...B(+ B)*
X → BX\'
X\'→ ϵ / +BX*
B → id
So, option (B) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...