%token [looseness] token1 [... tokenn]
(where the square brackets mean "optional"). The looseness must be an integer in the range [1..1200]. If specified, it will be used to set the precedence of the declared tokens. If it is not specified, the precedence is implicitly set to a higher one than the last implicit precedence value used in a previous similar declaration. Jacc uses looseness values in the range [1..1200] following Prolog's binding looseness convention. The higher this looseness number, the lesser the precedence.
%left [looseness] token1 [... tokenn]
(where the square brackets mean "optional"). The looseness must be an integer in the range [1..1200]. If specified, it will be used to set the precedence of the declared tokens. If it is not specified, the precedence is implicitly set to a higher one than the last implicit precedence value used in a previous similar declaration. Jacc uses looseness values in the range [1..1200] following Prolog's binding looseness convention. The higher this looseness number, the lesser the precedence.
%right [looseness] token1 [... tokenn]
(where the square brackets mean "optional"). The looseness must be an integer in the range [1..1200]. If specified, it will be used to set the precedence of the declared tokens. If it is not specified, the precedence is implicitly set to a higher one than the last implicit precedence value used in a previous similar declaration. Jacc uses looseness values in the range [1..1200] following Prolog's binding looseness convention. The higher this looseness number, the lesser the precedence.
%nonassoc [looseness] token1 [... tokenn]
(where the square brackets mean "optional"). The looseness must be an integer in the range [1..1200]. If specified, it will be used to set the precedence of the declared tokens. If it is not specified, the precedence is implicitly set to a higher one than the last implicit precedence value used in a previous similar declaration. Jacc uses looseness values in the range [1..1200] following Prolog's binding looseness convention. The higher this looseness number, the lesser the precedence.
%root foo
will generate the following methods in the parser:public final void parseFoo (String) throws IOException; public final void parseFoo (java.io.Reader) throws IOException;which can be used for the obvious purpose. One can always use the normal parse(), parse(boolean), or parse(int) methods for full parsing. The start symbol (i.e., declared with the %start command) is always implicitly declared as a partial parse unit. Hence, the two partial parse methods are always generated for it. Note that using these partial parsing methods disables error recovery. This is because of a technicality; namely, error recovery may put the parsing automaton in a state that does not belong to a sublanguage's parser. Therefore, an error encountered while performing a partial parse is always fatal (i.e., a FatalParseErrorException is thrown). This makes sense as these parses are meant to be done on relatively short strings.
For an example of use of partial parsing, we use the calculator grammar, where two partial parsing units are declared (i.e., expression and definition). The tokenizer and the driver for the full calculator remain unchanged. But now, we also can define a partial Calculator application. Here is its resulting output. Note that it uses the same tokenizer.
%nodeclass [ public ] foo
[ extends bar ]
[ implements interface1 [ , ... , interfacen ] ]
[ locates buz ]
{ [ <Java class member declarations> ] }
(where the square brackets mean "optional"). The parameters foo and bar must be the names of nonterminal symbols, and buz the name of an attribute of this node class (defined here or inherited) that must be of a type implementing the Locatable interface.
This declaration defines a Java class whose name is $foo$ and body is as specified. If an extends clause is missing, the class $foo$ will be a direct subclass of class ParseNode; otherwise, it will be a direct subclass of the node class $bar$, which must itself be also declared with a %nodeclass command (missing such declarations are eventually reported as errors). If an implements clause is present, the class $foo$ will be declared to implement all the specified interfaces (i.e., the body of the %nodeclass should contain the appropriate definitions implementing them). Unless the public option is specified, this class is written as part of the parser's file. If it is a public class, it is written as a separate file named $foo$.java (as mandated by Java). One may change the $...$ class name bracketing used by default, with one, or both, of the commands %nodeprefix and %nodesuffix. If a locates clause is present, the location of this node class will be automatically transmitted to the Locatable attribute it indicates.
%xmlinfo symbol [ annotation ]
where the first argument is a (possibly single- or double-quoted) string, and such that the square brackets are a required part of the command enclosing an XML serialization annotation, which is allowed to run over several lines as needed. The annotation follows a notation of the form:
nsprefix
:
prefix
localname
:
name
attributes
:
{
attr1
=
value1
, ... ,
attrn
=
valuen
}
children
:
(
i1
, ... ,
in
)
All entries are optional except for the localname entry. This notation is described in more details here.
%xmlroot [ nsprefix ] localname
(where the square brackets mean "optional"). Both argument are (possibly single- or double-quoted) strings.
%xmlns nsprefix uri
The first argument is a (possibly single- or double-quoted) string. The second must be a (single- or double-) quoted string.
In addition, dynamic operator commands may be used if defined by the %dynamic command. For example, declaring:
%dynamic op
enables the %op command to be used to define dynamic operators of this category (for more details, read the section on declaring dynamic operators in the specification).