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

Folding replaces every expression that matches with the right hand side of the given nonterminal's definition with the nonterminal itself. As with unfold, fold works on the scope of the grammar, and its impact can be limited to one labelled production rule or to all the productions belonging to one nonterminal. Regardless of the specified scope, folding is not applied to the definition of the argument nonterminal.

Since this transformation strives to preserve the language, it needs a horizontal definition to work. When only one of several existing definitions is used for folding, it would actually increase the semantics of the language after transformation: the corresponding XBGF command is called upgrade.

Syntax

fold:
        nonterminal in::scope?

Example

Very much like unfolding, folding can take place locally. For instance,

[l1] foo:
        wez*
[l2] qux:
        wez*
bar:
        wez*

After using this transformation:

fold(bar in foo);

Will look like this:

[l1] foo:
        bar
[l2] qux:
        wez*
bar:
        wez*

Relevant files

See also

  • Fold is a part of XBGF

Contributors

Clone this wiki locally