| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
10.2.8 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 section Special Features for Use in Java Actions.Note that of these three symbols, only
YYACCEPTandYYABORTwill cause a return from theyyparsemethod(1). -
Java lacks unions, so
%unionhas no effect. Instead, semantic values have a common base type:Objector as specified by ‘%define api.value.type’. Angle brackets 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 section Java Semantic Values, and Special Features for Use in Java Actions. -
The prologue declarations have a different meaning than in C/C++ code.
%code importsblocks are placed at the beginning of the Java source code. They may include copyright notices. For a
packagedeclarations, it is suggested to use ‘%define package’ instead.- unqualified
%code blocks are placed inside the parser class.
%code lexerblocks, 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 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] | [ ? ] |
This document was generated on December 1, 2013 using texi2html 5.0.
