4.
|
Sometimes,
when we left factor, there are several prefixes that occur in two or more
production bodies for the same variable. If so, the standard factoring
algorithm from Section 4.3.4 (p. 214) begins by choosing the longest of
these prefixes, which therefore occurs in the fewest of the production
bodies. After factoring out that prefix, we will find another opportunity
to left-factor, using a shorter, but nonempty, prefix. We continue
factoring, until no nonempty common prefixes remain. Here is a grammar:
S → 0SS1S | 0SS0S | 01 | 1
that illustrates this situation. There
are two common prefixes, 0 and 0SS. Transform this grammar to an
equivalent grammar that has no two production bodies for the same
variable with a nonempty common prefix. When you have to introduce new
variables, introduce S', S'', S''', and so on, in that order. Then,
identify from the list below the production that appears in your final
grammar.
|
|