[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
10.2.7 Differences between C/C++ and Java Grammars
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.
-
Java lacks a preprocessor, so the
YYERROR
,YYACCEPT
,YYABORT
symbols (see section Bison Symbols) cannot obviously be macros. Instead, they should be preceded byreturn
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 see section Special Features for Use in Java Actions.Note that of these three symbols, only
YYACCEPT
andYYABORT
will cause a return from theyyparse
method(3). -
Java lacks unions, so
%union
has no effect. Instead, semantic values have a common base type:Object
or as specified by%define stype
. Angle backets 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 see section Java Semantic Values and see section Special Features for Use in Java Actions. -
The prolog declarations have a different meaning than in C/C++ code.
-
%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.- unqualified
%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 see section 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.
-
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |