Chapter 4:Syntax Analysis

Left factoring

. In top-down parsing when it is not clear which production to choose for expansion of a symbol

defer the decision till we have seen enough input.

In general if A αβ1 | αβ2

defer decision by expanding A to a A'

we can then expand A' to β1 or β2

. Therefore A αβ1 | αβ2

transforms to

A α A'

A' β1 | β2

Left factoring is a grammar transformation that is useful for producing a grammar suitable for predictive parsing. The basic idea is that when it is not clear which of two or more alternative productions to use to expand a non-terminal A, we defer the decision till we have seen enough input to make the right choice.

In general if A α ß 1 | α ß 2 , we defer decision by expanding A to a A'.

and then we can expand A ' to ß1 or ß1

Therefore A α ß1 | α ß2 transforms to

A α A'

A ' ß1 | ß2