Grammatica uses its own grammar format, normally stored in
files with a .grammar
extension. The files are
divided into three parts -- header, tokens, and productions. The
header part is used for declarations about the grammar, such as
the grammar type. The token and production parts are used for
token and production declarations, which is explained in later
chapters. See the figure below for an example of the file
structure.
%header% GRAMMARTYPE = "LL" ... %tokens% ... %productions% ...
Figure 1. The overall structure of a grammar file.
Grammar files also support comments anywhere in the file. The comment syntax is similar to the comments in C# and Java (as well as many other popular languages). Two example comments can be seen in the example below.
/* A comment spanning multiple lines */ // A comment reaching to end of line
Figure 2. The two types of comments available in grammar files.
The header part in a grammar file contains definitions of
grammar parameters. These are name-value pairs, with the name
normally being all upper-case. In order for Grammatica to process
a grammar file, at least the GRAMMARTYPE
parameter
must be defined. See below for a list of the standard parameter
names and values.
@author
tags in the Java
output.
@version
tags in the Java output.