RECUSRIVITE2
RECUSRIVITE2
13 14
Eliminating immediate left recursion among Let’s look at examples showing that this algorithm can fail if
the grammar has ǫ-productions or cycles.
X → XSS ′ a | Xb | b | aS ′ a
In the simplest case, when there is only one variable, call it X,
yields
the presence of a cycle implies that the grammar includes the
X → bX ′ | aS ′ aX ′
production
X ′ → SS ′ aX ′ | bX ′ | ǫ
X →X.
So the final result is Moreover, the whole left recursion elimination algorithm
S → XSS ′ | aS ′ reduces to elimination of immediate left recursion among
′ ′ ′
S → XS | SbS | ǫ X-productions.
′ ′ ′
X → bX | aS aX
And we have previously observed that our construction for
X ′ → SS ′ aX ′ | bX ′ | ǫ
immediate left recursion elimination is no good in the presence
of X → X.
X→X |a
15 16