TopBottom-up ParsingMassaging Grammars

Massaging Grammars

  1. We have seen that for a given language some grammars may be harder to parse with than others (In fact, some may be impossible to parse with "deterministically"). Accordingly, one sometimes must apply techniques for rewriting a grammar into a more appropriate form.

  2. We have already used on of these techniques known as left-factoring. Remember the problem I noted with using the standard rules for an if statement in a top down parser.

    < stmt > if < expr > then < stmt > end
     |  if < expr > then < stmt > else < stmt > end

    The problem can be remedied by "factoring" out the common prefix of these two productions giving the rules:

    < stmt > if < expr > then < stmt > < iftail >
    < iftail > else < stmt > end
     |  end

    Note, however, that the phrase structure one gets by parsing may no longer be quite what you had in mind.

  3. Another common problem one may encounter in a grammar is a self-recursive rule.

  4. Grammar alterations designed to avoid undesirable forms of recursion can seriously impact phrase structure.

Computer Science 434
Department of Computer Science
Williams College

TopBottom-up ParsingMassaging Grammars