Next: Java Scanner Interface, Previous: Java Location Values, Up: Java Parsers [Contents][Index]
The name of the generated parser class defaults to YYParser
. The
YY
prefix may be changed using the %name-prefix
directive
or the -p/--name-prefix option. Alternatively, use
‘%define parser_class_name {name}’ to give a custom name to
the class. The interface of this class is detailed below.
By default, the parser class has package visibility. A declaration
‘%define public’ will change to public visibility. Remember that,
according to the Java language specification, the name of the .java
file should match the name of the class in this case. Similarly, you can
use abstract
, final
and strictfp
with the
%define
declaration to add other modifiers to the parser class.
A single ‘%define annotations {annotations}’ directive can
be used to add any number of annotations to the parser class.
The Java package name of the parser class can be specified using the
‘%define package’ directive. The superclass and the implemented
interfaces of the parser class can be specified with the %define
extends
and ‘%define implements’ directives.
The parser class defines an inner class, Location
, that is used
for location tracking (see Java Location Values), and a inner
interface, Lexer
(see Java Scanner Interface). Other than
these inner class/interface, and the members described in the interface
below, all the other members and fields are preceded with a yy
or
YY
prefix to avoid clashes with user code.
The parser class can be extended using the %parse-param
directive. Each occurrence of the directive will add a protected
final
field to the parser class, and an argument to its constructor,
which initialize them automatically.
Build a new parser object with embedded %code lexer
. There are
no parameters, unless %param
s and/or %parse-param
s and/or
%lex-param
s are used.
Use %code init
for code added to the start of the constructor
body. This is especially useful to initialize superclasses. Use
‘%define init_throws’ to specify any uncaught exceptions.
Build a new parser object using the specified scanner. There are no
additional parameters unless %param
s and/or %parse-param
s are
used.
If the scanner is defined by %code lexer
, this constructor is
declared protected
and is called automatically with a scanner
created with the correct %param
s and/or %lex-param
s.
Use %code init
for code added to the start of the constructor
body. This is especially useful to initialize superclasses. Use
‘%define init_throws’ to specify any uncaught exceptions.
Run the syntactic analysis, and return true
on success,
false
otherwise.
Get or set the option to produce verbose error messages. These are only available with ‘%define parse.error verbose’, which also turns on verbose error messages.
Print an error message using the yyerror
method of the scanner
instance in use. The Location
and Position
parameters are
available only if location tracking is active.
During the syntactic analysis, return true
if recovering
from a syntax error.
See Error Recovery.
Get or set the stream used for tracing the parsing. It defaults to
System.err
.
Get or set the tracing level. Currently its value is either 0, no trace, or nonzero, full tracing.
Identify the Bison version and skeleton used to generate this parser.
Next: Java Scanner Interface, Previous: Java Location Values, Up: Java Parsers [Contents][Index]