Skip to content
grammarware edited this page Jan 19, 2013 · 5 revisions

Massage modulo factorisation over choices. The transformation is either attempted for all production rules of a nonterminal or for a specific one appointed by its label.

Syntax

factor:
        expression expression in::scope?

Semantics

Factor transformations tend to be quite frequently used in grammar convergence. They also have a tendency to be very long, since it is impossible to implement factor symmetrically to distribute (i.e., fully automated), the language engineer needs to supply two complete expressions. The transformer then can easily assert that they are related by distribution: basically, it internally performs distribute on both of them and expects them to become identical. Hence, it is possible to do “incomplete” factoring by pushing choices inwards but not to the innermost position.

Two most commonly seen patterns of factor use are the following. First, it is applied when we have a choice of two long expressions that are almost identical except for some mismatching part. That part can be either extracted or massaged later with more transformations. Second, it is needed when we have a wide choice with the same leading (or trailing) symbol, and the goal is to let the common part stay and encapsulate the rest inside a different nonterminal (by following extract).

Example

For instance,

a:
        a
        b
        c d e
        c f g
        h
        i

After using this transformation (note the order of expressions):

factor(
 ((c d e) | (c f g)),
 (c ((d e) | (f g))));

Will look like this:

a:
        a
        b
        c ((d e) | (f g))
        h
        i

Relevant files

See also

  • Factor is a part of XBGF

Contributors

Clone this wiki locally