next up previous contents
Next: Eliminating Ambiguity Up: Modifying Grammars Previous: Modifying Grammars   Contents

Left Factoring

In general, if $A$ is a single non-terminal, and $\alpha$, $\beta$ and $\gamma$ are strings of terminals or non- terminals, then a production rule of the form: $A\; \rightarrow\; \alpha \beta\; \mid\; \alpha
\gamma$ can be left-factored into two rules of the form:

\begin{displaymath}\begin{array}{rcl}
A & \rightarrow & \alpha\; B \\
B & \rightarrow & \beta\; \mid\; \gamma \\
\end{array}\end{displaymath}

where $B$ is some new non-terminal.



James Power 2002-11-29