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

A new definition is introduced by extraction. The argument provided for this transformation is a production that identifies both the fresh nonterminal to be introduced and the expression that is used both as a pattern for folding and as a right hand side of the added definition. An optional scope can limit the application of the folding part of the extraction transformation to a specific production or a specific nonterminal.

If the nonterminal defined by the argument production is already mentioned (i.e., defined or referenced) in the current grammar, the transformation refuses to work and reports an error. This usually signals an error in the language engineer's logic because the existing traces of a possibly similar nonterminal conflict with the definition that is being introduced.

Syntax

extract:
        production in::scope?

Semantics

As seen from the experience gained from Java Language Specification case study, it is highly unusual for extract to have limited scope. However, sometimes a limited impact is desired in order to avoid excessive subsequent unfoldings when the convergence requests for having several nonterminals with similar definitions.

Example

Extraction also works vertically. Given the input:

TypeDeclaration:
        ClassDeclaration
        InterfaceDeclaration
        ";"

After performing this transformation step:

extract(
 ClassOrInterfaceDeclaration:
        ClassDeclaration
        InterfaceDeclaration
);

The result will be:

TypeDeclaration:
        ClassOrInterfaceDeclaration
        ";"
ClassOrInterfaceDeclaration:
        ClassDeclaration
        InterfaceDeclaration

Relevant files

See also

  • Extract is a part of XBGF

Contributors

Clone this wiki locally