I have the following grammar which handles mathematical and logical expression:
A ==> B A'
A' ==> | B A'
A' ==> epsilon
B ==> C B'
B' ==> ^ C B'
B' ==> epsilon
C ==> D C'
C' ==> & D C'
C' ==> epsilon
D ==> E D'
D' ==> << E D' | >> E D'
D' ==> epsilon
E ==> F E'
E' ==> + F E' | - F E'
E' ==> epsilon
F ==> G F'
F' ==> * G F' | / G F' | % G F'
F' ==> epsilon
G ==> +H | -H | ++H | --H | ~H | !H | &H
G ==> H
H ==> (A) | A T
T ==> -- | ++ | epsilon
H ==> number
The problem occurs when the following derivation happens:
A ==> B ==> C ==> D ==> E ==> F ==> G ==> H ==> A
And JavaCC won't compile the grammar file because of indirect left recursion .
So what steps should be done to eliminate this indirect left recursion from the previous grammar ?