Conversion of ambiguous left recursive grammar to LL(1) I have been strugling with this LL(1) transformation for far longer than expected and am getting quite desperate. We are given a grammar $ G = \left\{V_N, V_T, S, \Phi \right\}$, with the non-terminal set $V_N = \left\{S\right\}$, terminal set $V_T = \left\{\underline{o}, \underline{l}, \underline{r}, \underline{i}\right\}$, start symbol $ S $ and the production rules in $\Phi$:

$$ \begin{equation}\begin{split} S \rightarrow &amp; \ S \underline{o} S \\ S \rightarrow &amp; \ S \underline{l} S \underline{r} \\ S \rightarrow &amp; \ \underline{i}\end{split}\end{equation}$$

I have tried the standard tricks like left factoring, left recursion removing, which lead to an infinite transformation loop. Trying to fix first and follow set clashes also did not help. Here are some results after applying the transformations:

$$ \begin{equation}\begin{split} S \rightarrow &amp; \ \underline{i} A &amp; \ \ \ \ \ \ \ \ \ \ \ S \rightarrow &amp; \ S A \\ A \rightarrow &amp; \ \underline{o} S A &amp; \ \ \ \ \ \ \ \ \ \ \ S \rightarrow &amp; \ \underline{i} \\ A \rightarrow &amp; \ \underline{l} S \underline{r} A &amp; \ \ \ \ \ \ \ \ \ \ \ A \rightarrow &amp; \ \underline{o} S \\ A \rightarrow &amp; \ \epsilon &amp; \ \ \ \ \ \ \ \ \ \ \ A \rightarrow &amp; \ \underline{l} S \underline{r} \end{split}\end{equation} $$

However I go about the problem, I cannot seem to get even close to eliminating the double entries in my LL(1) table.
I don't want to do your homework, but the two insights that appear to solve it for me are:


What the first rules

$S \rightarrow SoS$

$S \rightarrow SlSr$


say is that whatever else $S$ can be rewritten to (which, in this case, is just $i$) can be followed by any number of occurrences of $oS$ and $lSr$ arbitrarily often.


If we introduce a nonterminal for that (the part that follows the $i$), left-factorized rules for it follow immediately.