I'm attempting to eliminate left recursion from a CFG by eliminating indirect recursion then direct recursion as this algorithm shows.
I'll be using this grammar:
A = A a | A B C | B C | D D
When i = 1, and j = 1 we are looking at replacing all productions of the form A -> A r with:
A -> δ1 γ | δ2 γ | .. | δk γ
So when I look at A -> A a which matches, i should replace it with
A -> A a a | A B C a a | B C a | D D a
which im sure is wrong
Can anyone point me in the right direction for how to replace productions when your replacing it with the production itself?
NOTE : Also, I'm only stuck on the first rule so have omitted the others for simplicity
Any help would be greatly appreciated
[UPDATE]Found as close to the original greek symbols as I could. Also, am I perhaps approaching this in the wrong direction. When i=1 and j=1, Aj -> A a | A B C | B C | D D, BUT should I be using Aj -> B C | D D If so then I would get:
A -> B C A | B C B C | D D A | D D B C | B C | D D
As that would then eliminate the recursion in that production. This a better direction?
This is the recipe:
should be transformed to:
That is:
For your grammar:
you would obtain: