Next: Java Parser Context 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 ‘%define api.prefix’.
Alternatively, use ‘%define api.parser.class {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 api.parser.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 api.parser.abstract
, api.parser.final
and api.parser.strictfp
with the %define
declaration to add
other modifiers to the parser class. A single ‘%define
api.parser.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
api.parser.extends
and ‘%define api.parser.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 initializes 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.
Lexer
lexer, parse_param, …) ¶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 detailed’ (or ‘verbose’), which also turns on verbose error messages.
String
msg) ¶Position
pos, String
msg) ¶Location
loc, String
msg) ¶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.
java.io.PrintStream
o) ¶Get or set the stream used for tracing the parsing. It defaults to
System.err
.
int
l) ¶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.
If you enabled token internationalization (see Token Internationalization), you must provide the parser with the following function:
string
s) ¶Return the translation of s in the user’s language. As an example:
%code { static ResourceBundle myResources = ResourceBundle.getBundle("domain-name"); static final String i18n(String s) { return myResources.getString(s); } }
Next: Java Parser Context Interface, Previous: Java Location Values, Up: Java Parsers [Contents][Index]