Next: Java Declarations Summary, Previous: Java Push Parser Interface, Up: Java Parsers [Contents][Index]
The different structure of the Java language forces several differences between C/C++ grammars, and grammars designed for Java parsers. This section summarizes these differences.
YYERROR
, YYACCEPT
,
YYABORT
symbols (see Table of Symbols) cannot obviously be
macros. Instead, they should be preceded by return
when they
appear in an action. The actual definition of these symbols is
opaque to the Bison grammar, and it might change in the future. The
only meaningful operation that you can do, is to return them.
See Java Action Features.
Note that of these three symbols, only YYACCEPT
and
YYABORT
will cause a return from the yyparse
method1.
%union
has no effect. Instead, semantic
values have a common base type: Object
or as specified by
‘%define api.value.type’. Angle brackets on %token
, type
,
$n
and $$
specify subtypes rather than fields of
an union. The type of $$
, even with angle brackets, is the base
type since Java casts are not allow on the left-hand side of assignments.
Also, $n
and @n
are not allowed on the
left-hand side of assignments. See Java Semantic Values, and
Java Action Features.
%code imports
blocks are placed at the beginning of the Java source code. They may
include copyright notices. For a package
declarations, it is
suggested to use ‘%define package’ instead.
%code
blocks are placed inside the parser class.
%code lexer
blocks, if specified, should include the implementation of the scanner. If there is no such block, the scanner can be any class that implements the appropriate interface (see Java Scanner Interface).
Other %code
blocks are not supported in Java parsers.
In particular, %{ … %}
blocks should not be used
and may give an error in future versions of Bison.
The epilogue has the same meaning as in C/C++ code and it can be used to define other classes used by the parser outside the parser class.
Java parsers include the actions in a separate
method than yyparse
in order to have an intuitive syntax that
corresponds to these C macros.
Next: Java Declarations Summary, Previous: Java Push Parser Interface, Up: Java Parsers [Contents][Index]