Grammatica Reference Manual

Productions

The production definitions in the grammar files are written in EBNF. This is a common notation for grammars, and is described elsewhere. Please be aware of that the grammar files use its own "dialect" of EBNF, explained below.

Each production definition consists of a production name and a set of production alternatives. Each alternative in turn contains references to tokens or other productions. Self-referencing is also accepted. A simple example of a production definition is shown in the figure below.

Prod = "Value"
     | TOKEN_NAME
     | OtherProd ;

Figure 1. A simple example production. This production contains three alternatives illustrating all the valid ways of referring to a token or a production.

In the example above "=" is used for separating the production name from the definition, instead of the standard EBNF ":=". Also the definition must end with a ";" character. The production name follows the same restrictions as the token name, i.e. it may only contain characters from the set [a-zA-Z0-9_].

The grammar files also allow some constructs that are not part of standard BNF or EBNF. In particular this include parenthesizing with the "{", "}", "[", and "]" characters. See the figure below for an example of this.

Prod = ("1")?
     | ("2")*
     | ("3")+
     | {"4"}
     | ["5"] ;

Figure 2. An example of the accepted forms of grouping and repetitions allowed. The "*" and "+" are also allowed after production or token names. The "{}" parenthesis is a shortform for "()*", and the "[]" parenthesis is a shortform for "()?".