| [ < ] | [ > ] | [ << ] | [ 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,YYABORTsymbols (see section Bison Symbols) cannot obviously be macros. Instead, they should be preceded byreturnwhen 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
YYACCEPTandYYABORTwill cause a return from theyyparsemethod(3). -
Java lacks unions, so
%unionhas no effect. Instead, semantic values have a common base type:Objector as specified by%define stype. Angle backets on%token,type,$nand$$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,$nand@nare 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
packagedeclarations, it is suggested to use%define packageinstead.- 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
%codeblocks 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] | [ ? ] |
