mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
Various Java skeleton improvements.
* NEWS: Document them.
General Java skeleton improvements.
* configure.ac (gt_JAVACOMP): Request target of 1.4, which allows
using gcj < 4.3 in the testsuite, according to comments in
gnulib/m4/javacomp.m4.
* data/java.m4 (stype, parser_class_name, lex_throws, throws,
location_type, position_type): Remove extraneous brackets from
b4_percent_define_default.
(b4_lex_param, b4_parse_param): Remove extraneous brackets from
m4_define and m4_define_default.
* data/lalr1.java (b4_pre_prologue): Change to b4_user_post_prologue,
which marks the end of user code with appropriate syncline, like all
the other skeletons.
(b4_user_post_prologue): Add. Don't silently drop.
(yylex): Remove.
(parse): Inline yylex.
* doc/bison.texinfo (bisonVersion, bisonSkeleton): Document.
(%{...%}): Fix typo of %code imports.
* tests/java.at (AT_JAVA_COMPILE): Add "java" keyword.
Support annotations on parser class with %define annotations.
* data/lalr1.java (annotations): Add to parser class modifier.
* doc/bison.texinfo (Java Parser Interface): Document
%define annotations.
(Java Declarations Summary): Document %define annotations.
* tests/java.at (Java parser class modifiers): Test annotations.
Do not generate code for %error-verbose unless requested.
* data/lalr1.java (errorVerbose): Rename to yyErrorVerbose.
Make private. Make conditional on %error-verbose.
(getErrorVerbose, setErrorVerbose): New.
(yytnamerr_): Make conditional on %error-verbose.
(yysyntax_error): Make some code conditional on %error-verbose.
* doc/bison.texinfo (Java Bison Interface): Remove the parts
about %error-verbose having no effect.
(getErrorVerbose, setErrorVerbose): Document.
Move constants for token names to Lexer interface.
* data/lalr1.java (Lexer): Move EOF, b4_token_enums(b4_tokens) here.
* data/java.m4 (b4_token_enum): Indent for move to Lexer interface.
(parse): Qualify EOF to Lexer.EOF.
* doc/bison.texinfo (Java Parser Interface): Move documentation of
EOF and token names to Java Lexer Interface.
* tests/java.at (_AT_DATA_JAVA_CALC_Y): Remove Calc qualifier.
Make yyerror public.
* data/lalr1.java (Lexer.yyerror): Use longer parameter name.
(yyerror): Change to public. Add Javadoc comments. Use longer
parameter names. Make the body rather than the declarator
conditional on %locations.
* doc/bison.texinfo (yyerror): Document. Don't mark as protected.
Allow user to add code to the constructor with %code init.
* data/java.m4 (b4_init_throws): New, for %define init_throws.
* data/lalr1.java (YYParser.YYParser): Add b4_init_throws.
Add %code init to the front of the constructor body.
* doc/bison.texinfo (YYParser.YYParser): Document %code init
and %define init_throws.
(Java Declarations Summary): Document %code init and
%define init_throws.
* tests/java.at (Java %parse-param and %lex-param): Adjust grep.
(Java constructor init and init_throws): Add tests.
This commit is contained in:
66
ChangeLog
66
ChangeLog
@@ -1,3 +1,69 @@
|
||||
2008-11-10 Di-an Jan <dianj@freeshell.org>
|
||||
|
||||
* NEWS: Document them.
|
||||
|
||||
General Java skeleton improvements.
|
||||
* configure.ac (gt_JAVACOMP): Request target of 1.4, which allows
|
||||
using gcj < 4.3 in the testsuite, according to comments in
|
||||
gnulib/m4/javacomp.m4.
|
||||
* data/java.m4 (stype, parser_class_name, lex_throws, throws,
|
||||
location_type, position_type): Remove extraneous brackets from
|
||||
b4_percent_define_default.
|
||||
(b4_lex_param, b4_parse_param): Remove extraneous brackets from
|
||||
m4_define and m4_define_default.
|
||||
* data/lalr1.java (b4_pre_prologue): Change to b4_user_post_prologue,
|
||||
which marks the end of user code with appropriate syncline, like all
|
||||
the other skeletons.
|
||||
(b4_user_post_prologue): Add. Don't silently drop.
|
||||
(yylex): Remove.
|
||||
(parse): Inline yylex.
|
||||
* doc/bison.texinfo (bisonVersion, bisonSkeleton): Document.
|
||||
(%{...%}): Fix typo of %code imports.
|
||||
* tests/java.at (AT_JAVA_COMPILE): Add "java" keyword.
|
||||
|
||||
Support annotations on parser class with %define annotations.
|
||||
* data/lalr1.java (annotations): Add to parser class modifier.
|
||||
* doc/bison.texinfo (Java Parser Interface): Document
|
||||
%define annotations.
|
||||
(Java Declarations Summary): Document %define annotations.
|
||||
* tests/java.at (Java parser class modifiers): Test annotations.
|
||||
|
||||
Do not generate code for %error-verbose unless requested.
|
||||
* data/lalr1.java (errorVerbose): Rename to yyErrorVerbose.
|
||||
Make private. Make conditional on %error-verbose.
|
||||
(getErrorVerbose, setErrorVerbose): New.
|
||||
(yytnamerr_): Make conditional on %error-verbose.
|
||||
(yysyntax_error): Make some code conditional on %error-verbose.
|
||||
* doc/bison.texinfo (Java Bison Interface): Remove the parts
|
||||
about %error-verbose having no effect.
|
||||
(getErrorVerbose, setErrorVerbose): Document.
|
||||
|
||||
Move constants for token names to Lexer interface.
|
||||
* data/lalr1.java (Lexer): Move EOF, b4_token_enums(b4_tokens) here.
|
||||
* data/java.m4 (b4_token_enum): Indent for move to Lexer interface.
|
||||
(parse): Qualify EOF to Lexer.EOF.
|
||||
* doc/bison.texinfo (Java Parser Interface): Move documentation of
|
||||
EOF and token names to Java Lexer Interface.
|
||||
* tests/java.at (_AT_DATA_JAVA_CALC_Y): Remove Calc qualifier.
|
||||
|
||||
Make yyerror public.
|
||||
* data/lalr1.java (Lexer.yyerror): Use longer parameter name.
|
||||
(yyerror): Change to public. Add Javadoc comments. Use longer
|
||||
parameter names. Make the body rather than the declarator
|
||||
conditional on %locations.
|
||||
* doc/bison.texinfo (yyerror): Document. Don't mark as protected.
|
||||
|
||||
Allow user to add code to the constructor with %code init.
|
||||
* data/java.m4 (b4_init_throws): New, for %define init_throws.
|
||||
* data/lalr1.java (YYParser.YYParser): Add b4_init_throws.
|
||||
Add %code init to the front of the constructor body.
|
||||
* doc/bison.texinfo (YYParser.YYParser): Document %code init
|
||||
and %define init_throws.
|
||||
(Java Declarations Summary): Document %code init and
|
||||
%define init_throws.
|
||||
* tests/java.at (Java %parse-param and %lex-param): Adjust grep.
|
||||
(Java constructor init and init_throws): Add tests.
|
||||
|
||||
2008-11-10 Akim Demaille <demaille@gostai.com>
|
||||
|
||||
Update TODO.
|
||||
|
||||
6
NEWS
6
NEWS
@@ -3,7 +3,11 @@ Bison News
|
||||
|
||||
Changes in version ?.? (????-??-??):
|
||||
|
||||
*
|
||||
* Java skeleton improvements:
|
||||
|
||||
The constants for token names were moved to the Lexer interface.
|
||||
Also, it is possible to add code to the parser's constructors using
|
||||
"%code init" and "%define init_throws".
|
||||
|
||||
Changes in version 2.4 (2008-11-02):
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ AC_SUBST([GCC])
|
||||
AC_SUBST([O0CFLAGS], [`echo $CFLAGS | sed 's/-O[[0-9]] *//'`])
|
||||
AC_SUBST([O0CXXFLAGS], [`echo $CXXFLAGS | sed 's/-O[[0-9]] *//'`])
|
||||
|
||||
gt_JAVACOMP([1.3])
|
||||
gt_JAVACOMP([1.3], [1.4])
|
||||
gt_JAVAEXEC
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
|
||||
25
data/java.m4
25
data/java.m4
@@ -125,8 +125,8 @@ m4_define([b4_null], [null])
|
||||
# ---------------------------------------
|
||||
# Output the definition of this token as an enum.
|
||||
m4_define([b4_token_enum],
|
||||
[ /** Token number, to be returned by the scanner. */
|
||||
public static final int $1 = $2;
|
||||
[ /** Token number, to be returned by the scanner. */
|
||||
static final int $1 = $2;
|
||||
])
|
||||
|
||||
|
||||
@@ -154,24 +154,27 @@ m4_define([b4_case], [ case $1:
|
||||
## ---------------- ##
|
||||
|
||||
m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
|
||||
b4_percent_define_default([[stype]], [[Object]])])
|
||||
b4_percent_define_default([[stype]], [[Object]])
|
||||
|
||||
# %name-prefix
|
||||
m4_define_default([b4_prefix], [[YY]])
|
||||
|
||||
b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
|
||||
b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
|
||||
m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
|
||||
|
||||
b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
|
||||
b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
|
||||
m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
|
||||
|
||||
b4_percent_define_default([[throws]], [])])
|
||||
b4_percent_define_default([[throws]], [])
|
||||
m4_define([b4_throws], [b4_percent_define_get([[throws]])])
|
||||
|
||||
b4_percent_define_default([[location_type]], [Location])])
|
||||
b4_percent_define_default([[init_throws]], [])
|
||||
m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])])
|
||||
|
||||
b4_percent_define_default([[location_type]], [Location])
|
||||
m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
|
||||
|
||||
b4_percent_define_default([[position_type]], [Position])])
|
||||
b4_percent_define_default([[position_type]], [Position])
|
||||
m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
|
||||
|
||||
|
||||
@@ -218,9 +221,9 @@ m4_define([b4_rhs_location],
|
||||
# it to be single quoted. Same for b4_parse_param.
|
||||
|
||||
# TODO: should be in bison.m4
|
||||
m4_define_default([b4_lex_param], [[]]))
|
||||
m4_define([b4_lex_param], b4_lex_param))
|
||||
m4_define([b4_parse_param], b4_parse_param))
|
||||
m4_define_default([b4_lex_param], [[]])
|
||||
m4_define([b4_lex_param], b4_lex_param)
|
||||
m4_define([b4_parse_param], b4_parse_param)
|
||||
|
||||
# b4_lex_param_decl
|
||||
# -------------------
|
||||
|
||||
125
data/lalr1.java
125
data/lalr1.java
@@ -29,14 +29,16 @@ b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
||||
|
||||
b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
|
||||
])[/* First part of user declarations. */
|
||||
]b4_pre_prologue
|
||||
]b4_user_pre_prologue
|
||||
b4_user_post_prologue
|
||||
b4_percent_code_get([[imports]])
|
||||
[/**
|
||||
* A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
|
||||
*
|
||||
* @@author LALR (1) parser skeleton written by Paolo Bonzini.
|
||||
*/
|
||||
]b4_public_if([public ])dnl
|
||||
]b4_percent_define_get3([annotations], [], [ ])dnl
|
||||
b4_public_if([public ])dnl
|
||||
b4_abstract_if([abstract ])dnl
|
||||
b4_final_if([final ])dnl
|
||||
b4_strictfp_if([strictfp ])dnl
|
||||
@@ -45,9 +47,22 @@ b4_percent_define_get3([extends], [ extends ])dnl
|
||||
b4_percent_define_get3([implements], [ implements ])[
|
||||
{
|
||||
]b4_identification[
|
||||
|
||||
]b4_error_verbose_if([[
|
||||
/** True if verbose error messages are enabled. */
|
||||
public boolean errorVerbose = ]b4_flag_value([error_verbose]);
|
||||
private boolean yyErrorVerbose = true;
|
||||
|
||||
/**
|
||||
* Return whether verbose error messages are enabled.
|
||||
*/
|
||||
public final boolean getErrorVerbose() { return yyErrorVerbose; }
|
||||
|
||||
/**
|
||||
* Set the verbosity of error messages.
|
||||
* @@param verbose True to request verbose error messages.
|
||||
*/
|
||||
public final void setErrorVerbose(boolean verbose)
|
||||
{ yyErrorVerbose = verbose; }
|
||||
]])
|
||||
|
||||
b4_locations_if([[
|
||||
/**
|
||||
@@ -93,11 +108,6 @@ b4_locations_if([[
|
||||
|
||||
]])
|
||||
|
||||
[ /** Token returned by the scanner to signal the end of its input. */
|
||||
public static final int EOF = 0;]
|
||||
|
||||
b4_token_enums(b4_tokens)
|
||||
|
||||
b4_locations_if([[
|
||||
private ]b4_location_type[ yylloc (YYStack rhs, int n)
|
||||
{
|
||||
@@ -112,6 +122,11 @@ b4_token_enums(b4_tokens)
|
||||
* parser <tt>]b4_parser_class_name[</tt>.
|
||||
*/
|
||||
public interface Lexer {
|
||||
/** Token returned by the scanner to signal the end of its input. */
|
||||
public static final int EOF = 0;
|
||||
|
||||
]b4_token_enums(b4_tokens)[
|
||||
|
||||
]b4_locations_if([[/**
|
||||
* Method to retrieve the beginning position of the last scanned token.
|
||||
* @@return the position at which the last scanned token starts. */
|
||||
@@ -140,8 +155,8 @@ b4_token_enums(b4_tokens)
|
||||
*
|
||||
* ]b4_locations_if([[@@param loc The location of the element to which the
|
||||
* error message is related]])[
|
||||
* @@param s The string for the error message. */
|
||||
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String s);]
|
||||
* @@param msg The string for the error message. */
|
||||
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
|
||||
}
|
||||
|
||||
b4_lexer_if([[private class YYLexer implements Lexer {
|
||||
@@ -157,7 +172,9 @@ b4_lexer_if([[
|
||||
/**
|
||||
* Instantiates the Bison-generated parser.
|
||||
*/
|
||||
public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) {
|
||||
public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) ]b4_maybe_throws([b4_init_throws])[
|
||||
{
|
||||
]b4_percent_code_get([[init]])[
|
||||
this.yylexer = new YYLexer(]b4_lex_param_call[);
|
||||
]b4_parse_param_cons[
|
||||
}
|
||||
@@ -167,7 +184,9 @@ b4_lexer_if([[
|
||||
* Instantiates the Bison-generated parser.
|
||||
* @@param yylexer The scanner that will supply tokens to the parser.
|
||||
*/
|
||||
b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) {
|
||||
b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
|
||||
{
|
||||
]b4_percent_code_get([[init]])[
|
||||
this.yylexer = yylexer;
|
||||
]b4_parse_param_cons[
|
||||
}
|
||||
@@ -201,20 +220,35 @@ b4_lexer_if([[
|
||||
*/
|
||||
public final void setDebugLevel(int level) { yydebug = level; }
|
||||
|
||||
private final int yylex () ]b4_maybe_throws([b4_lex_throws]) [{
|
||||
return yylexer.yylex ();
|
||||
/**
|
||||
* Print an error message via the lexer.
|
||||
*]b4_locations_if([[ Use a <code>null</code> location.]])[
|
||||
* @@param msg The error message.
|
||||
*/
|
||||
public final void yyerror (String msg)
|
||||
{
|
||||
yylexer.yyerror (]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
|
||||
}
|
||||
protected final void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String s) {
|
||||
yylexer.yyerror (]b4_locations_if([loc, ])[s);
|
||||
]b4_locations_if([[
|
||||
/**
|
||||
* Print an error message via the lexer.
|
||||
* @@param loc The location associated with the message.
|
||||
* @@param msg The error message.
|
||||
*/
|
||||
public final void yyerror (]b4_location_type[ loc, String msg)
|
||||
{
|
||||
yylexer.yyerror (loc, msg);
|
||||
}
|
||||
|
||||
]b4_locations_if([
|
||||
protected final void yyerror (String s) {
|
||||
yylexer.yyerror ((]b4_location_type[)null, s);
|
||||
}
|
||||
protected final void yyerror (]b4_position_type[ loc, String s) {
|
||||
yylexer.yyerror (new ]b4_location_type[ (loc), s);
|
||||
}])
|
||||
/**
|
||||
* Print an error message via the lexer.
|
||||
* @@param pos The position associated with the message.
|
||||
* @@param msg The error message.
|
||||
*/
|
||||
public final void yyerror (]b4_position_type[ pos, String msg)
|
||||
{
|
||||
yylexer.yyerror (new ]b4_location_type[ (pos), msg);
|
||||
}]])
|
||||
|
||||
[protected final void yycdebug (String s) {
|
||||
if (yydebug > 0)
|
||||
@@ -372,6 +406,7 @@ b4_lexer_if([[
|
||||
return YYNEWSTATE;
|
||||
}
|
||||
|
||||
]b4_error_verbose_if([[
|
||||
/* Return YYSTR after stripping away unnecessary quotes and
|
||||
backslashes, so that it's suitable for yyerror. The heuristic is
|
||||
that double-quoting is unnecessary unless the string contains an
|
||||
@@ -406,6 +441,7 @@ b4_lexer_if([[
|
||||
|
||||
return yystr;
|
||||
}
|
||||
]])[
|
||||
|
||||
/*--------------------------------.
|
||||
| Print this symbol on YYOUTPUT. |
|
||||
@@ -498,19 +534,19 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
/* Read a lookahead token. */
|
||||
if (yychar == yyempty_)
|
||||
{
|
||||
yycdebug ("Reading a token: ");
|
||||
yychar = yylex ();]
|
||||
yycdebug ("Reading a token: ");
|
||||
yychar = yylexer.yylex ();]
|
||||
b4_locations_if([[
|
||||
yylloc = new ]b4_location_type[(yylexer.getStartPos (),
|
||||
yylexer.getEndPos ());]])
|
||||
yylloc = new ]b4_location_type[(yylexer.getStartPos (),
|
||||
yylexer.getEndPos ());]])
|
||||
yylval = yylexer.getLVal ();[
|
||||
}
|
||||
|
||||
/* Convert token to internal form. */
|
||||
if (yychar <= EOF)
|
||||
if (yychar <= Lexer.EOF)
|
||||
{
|
||||
yychar = yytoken = EOF;
|
||||
yycdebug ("Now at end of input.\n");
|
||||
yychar = yytoken = Lexer.EOF;
|
||||
yycdebug ("Now at end of input.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -591,16 +627,16 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
]b4_locations_if([yyerrloc = yylloc;])[
|
||||
if (yyerrstatus_ == 3)
|
||||
{
|
||||
/* If just tried and failed to reuse lookahead token after an
|
||||
error, discard it. */
|
||||
/* If just tried and failed to reuse lookahead token after an
|
||||
error, discard it. */
|
||||
|
||||
if (yychar <= EOF)
|
||||
{
|
||||
/* Return failure if at end of input. */
|
||||
if (yychar == EOF)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (yychar <= Lexer.EOF)
|
||||
{
|
||||
/* Return failure if at end of input. */
|
||||
if (yychar == Lexer.EOF)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
yychar = yyempty_;
|
||||
}
|
||||
|
||||
@@ -682,8 +718,8 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
|
||||
// Generate an error message.
|
||||
private String yysyntax_error (int yystate, int tok)
|
||||
{
|
||||
if (errorVerbose)
|
||||
{]b4_error_verbose_if([[
|
||||
if (yyErrorVerbose)
|
||||
{
|
||||
int yyn = yypact_[yystate];
|
||||
if (yypact_ninf_ < yyn && yyn <= yylast_)
|
||||
@@ -716,14 +752,13 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
res.append (yytnamerr_ (yytname_[x]));
|
||||
}
|
||||
}
|
||||
return res.toString ();
|
||||
return res.toString ();
|
||||
}
|
||||
}
|
||||
|
||||
]])[
|
||||
return "syntax error";
|
||||
}
|
||||
|
||||
|
||||
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
|
||||
STATE-NUM. */
|
||||
private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
|
||||
|
||||
@@ -8845,12 +8845,12 @@ No header file can be generated for Java parsers. Do not use the
|
||||
@code{%defines} directive or the @option{-d}/@option{--defines} options.
|
||||
|
||||
@c FIXME: Possible code change.
|
||||
Currently, support for debugging and verbose errors are always compiled
|
||||
Currently, support for debugging is always compiled
|
||||
in. Thus the @code{%debug} and @code{%token-table} directives and the
|
||||
@option{-t}/@option{--debug} and @option{-k}/@option{--token-table}
|
||||
options have no effect. This may change in the future to eliminate
|
||||
unused code in the generated parser, so use @code{%debug} and
|
||||
@code{%verbose-error} explicitly if needed. Also, in the future the
|
||||
unused code in the generated parser, so use @code{%debug} explicitly
|
||||
if needed. Also, in the future the
|
||||
@code{%token-table} directive might enable a public interface to
|
||||
access the token names and codes.
|
||||
|
||||
@@ -8960,6 +8960,8 @@ according to the Java language specification, the name of the @file{.java}
|
||||
file should match the name of the class in this case. Similarly, you can
|
||||
use @code{abstract}, @code{final} and @code{strictfp} with the
|
||||
@code{%define} declaration to add other modifiers to the parser class.
|
||||
A single @code{%define annotations "@var{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
|
||||
@code{%define package} directive. The superclass and the implemented
|
||||
@@ -8973,21 +8975,19 @@ these inner class/interface, and the members described in the interface
|
||||
below, all the other members and fields are preceded with a @code{yy} or
|
||||
@code{YY} prefix to avoid clashes with user code.
|
||||
|
||||
@c FIXME: The following constants and variables are still undocumented:
|
||||
@c @code{bisonVersion}, @code{bisonSkeleton} and @code{errorVerbose}.
|
||||
|
||||
The parser class can be extended using the @code{%parse-param}
|
||||
directive. Each occurrence of the directive will add a @code{protected
|
||||
final} field to the parser class, and an argument to its constructor,
|
||||
which initialize them automatically.
|
||||
|
||||
Token names defined by @code{%token} and the predefined @code{EOF} token
|
||||
name are added as constant fields to the parser class.
|
||||
|
||||
@deftypeop {Constructor} {YYParser} {} YYParser (@var{lex_param}, @dots{}, @var{parse_param}, @dots{})
|
||||
Build a new parser object with embedded @code{%code lexer}. There are
|
||||
no parameters, unless @code{%parse-param}s and/or @code{%lex-param}s are
|
||||
used.
|
||||
|
||||
Use @code{%code init} for code added to the start of the constructor
|
||||
body. This is especially useful to initialize superclasses. Use
|
||||
@code{%define init_throws} to specify any uncatch exceptions.
|
||||
@end deftypeop
|
||||
|
||||
@deftypeop {Constructor} {YYParser} {} YYParser (Lexer @var{lexer}, @var{parse_param}, @dots{})
|
||||
@@ -8997,6 +8997,10 @@ additional parameters unless @code{%parse-param}s are used.
|
||||
If the scanner is defined by @code{%code lexer}, this constructor is
|
||||
declared @code{protected} and is called automatically with a scanner
|
||||
created with the correct @code{%lex-param}s.
|
||||
|
||||
Use @code{%code init} for code added to the start of the constructor
|
||||
body. This is especially useful to initialize superclasses. Use
|
||||
@code{%define init_throws} to specify any uncatch exceptions.
|
||||
@end deftypeop
|
||||
|
||||
@deftypemethod {YYParser} {boolean} parse ()
|
||||
@@ -9004,6 +9008,21 @@ Run the syntactic analysis, and return @code{true} on success,
|
||||
@code{false} otherwise.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {YYParser} {boolean} getErrorVerbose ()
|
||||
@deftypemethodx {YYParser} {void} setErrorVerbose (boolean @var{verbose})
|
||||
Get or set the option to produce verbose error messages. These are only
|
||||
available with the @code{%error-verbose} directive, which also turn on
|
||||
verbose error messages.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {YYParser} {void} yyerror (String @var{msg})
|
||||
@deftypemethodx {YYParser} {void} yyerror (Position @var{pos}, String @var{msg})
|
||||
@deftypemethodx {YYParser} {void} yyerror (Location @var{loc}, String @var{msg})
|
||||
Print an error message using the @code{yyerror} method of the scanner
|
||||
instance in use. The @code{Location} and @code{Position} parameters are
|
||||
available only if location tracking is active.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {YYParser} {boolean} recovering ()
|
||||
During the syntactic analysis, return @code{true} if recovering
|
||||
from a syntax error.
|
||||
@@ -9022,6 +9041,11 @@ Get or set the tracing level. Currently its value is either 0, no trace,
|
||||
or nonzero, full tracing.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypecv {Constant} {YYParser} {String} {bisonVersion}
|
||||
@deftypecvx {Constant} {YYParser} {String} {bisonSkeleton}
|
||||
Identify the Bison version and skeleton used to generate this parser.
|
||||
@end deftypecv
|
||||
|
||||
|
||||
@node Java Scanner Interface
|
||||
@subsection Java Scanner Interface
|
||||
@@ -9032,7 +9056,9 @@ or nonzero, full tracing.
|
||||
There are two possible ways to interface a Bison-generated Java parser
|
||||
with a scanner: the scanner may be defined by @code{%code lexer}, or
|
||||
defined elsewhere. In either case, the scanner has to implement the
|
||||
@code{Lexer} inner interface of the parser class.
|
||||
@code{Lexer} inner interface of the parser class. This interface also
|
||||
contain constants for all user-defined token names and the predefined
|
||||
@code{EOF} token.
|
||||
|
||||
In the first case, the body of the scanner class is placed in
|
||||
@code{%code lexer} blocks. If you want to pass parameters from the
|
||||
@@ -9156,11 +9182,12 @@ operation.
|
||||
@xref{Error Recovery}.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn {Function} {protected void} yyerror (String msg)
|
||||
@deftypefnx {Function} {protected void} yyerror (Position pos, String msg)
|
||||
@deftypefnx {Function} {protected void} yyerror (Location loc, String msg)
|
||||
@deftypefn {Function} {void} yyerror (String @var{msg})
|
||||
@deftypefnx {Function} {void} yyerror (Position @var{loc}, String @var{msg})
|
||||
@deftypefnx {Function} {void} yyerror (Location @var{loc}, String @var{msg})
|
||||
Print an error message using the @code{yyerror} method of the scanner
|
||||
instance in use.
|
||||
instance in use. The @code{Location} and @code{Position} parameters are
|
||||
available only if location tracking is active.
|
||||
@end deftypefn
|
||||
|
||||
|
||||
@@ -9276,6 +9303,11 @@ Code inserted just after the @code{package} declaration.
|
||||
@xref{Java Differences}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%code init} @{ @var{code} @dots{} @}
|
||||
Code inserted at the beginning of the parser constructor body.
|
||||
@xref{Java Parser Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%code lexer} @{ @var{code} @dots{} @}
|
||||
Code added to the body of a inner lexer class within the parser class.
|
||||
@xref{Java Scanner Interface}.
|
||||
@@ -9288,7 +9320,7 @@ Code (after the second @code{%%}) appended to the end of the file,
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %@{ @var{code} @dots{} %@}
|
||||
Not supported. Use @code{%code import} instead.
|
||||
Not supported. Use @code{%code imports} instead.
|
||||
@xref{Java Differences}.
|
||||
@end deffn
|
||||
|
||||
@@ -9297,6 +9329,11 @@ Whether the parser class is declared @code{abstract}. Default is false.
|
||||
@xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define annotations} "@var{annotations}"
|
||||
The Java annotations for the parser class. Default is none.
|
||||
@xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define extends} "@var{superclass}"
|
||||
The superclass of the parser class. Default is none.
|
||||
@xref{Java Bison Interface}.
|
||||
@@ -9313,6 +9350,12 @@ Default is none.
|
||||
@xref{Java Bison Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define init_throws} "@var{exceptions}"
|
||||
The exceptions thrown by @code{%code init} from the parser class
|
||||
constructor. Default is none.
|
||||
@xref{Java Parser Interface}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} {%define lex_throws} "@var{exceptions}"
|
||||
The exceptions thrown by the @code{yylex} method of the lexer, a
|
||||
comma-separated list. Default is @code{java.io.IOException}.
|
||||
|
||||
@@ -148,7 +148,7 @@ AT_LOCATION_IF([[
|
||||
int ttype = st.nextToken ();
|
||||
]AT_LOCATION_IF([[yystartpos = yyendpos;]])[
|
||||
if (ttype == st.TT_EOF)
|
||||
return Calc.EOF;
|
||||
return EOF;
|
||||
|
||||
else if (ttype == st.TT_EOL)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ AT_LOCATION_IF([[
|
||||
else if (ttype == st.TT_WORD)
|
||||
{
|
||||
yylval = new Integer (st.sval);
|
||||
return Calc.NUM;
|
||||
return NUM;
|
||||
}
|
||||
|
||||
else
|
||||
@@ -225,7 +225,8 @@ m4_define([AT_DATA_JAVA_CALC_Y],
|
||||
# Compile SOURCES into Java class files. Skip the test if java or javac is
|
||||
# not installed.
|
||||
m4_define([AT_JAVA_COMPILE],
|
||||
[AT_CHECK([test -n "$CONF_JAVA" || exit 77
|
||||
[AT_KEYWORDS(java)
|
||||
AT_CHECK([test -n "$CONF_JAVA" || exit 77
|
||||
test -n "$CONF_JAVAC" || exit 77])
|
||||
AT_CHECK([$SHELL ../../../javacomp.sh $1],
|
||||
0, [ignore], [ignore])])
|
||||
@@ -549,6 +550,12 @@ AT_CHECK_JAVA_MINIMAL([[
|
||||
%define strictfp]])
|
||||
AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
|
||||
|
||||
# FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
|
||||
AT_CHECK_JAVA_MINIMAL([[
|
||||
%define annotations "/*@Deprecated @SupressWarnings(\"unchecked\") @SupressWarnings({\"unchecked\", \"deprecation\"}) @SupressWarnings(value={\"unchecked\", \"deprecation\"})*/"
|
||||
%define public]])
|
||||
AT_CHECK_JAVA_GREP([[/\*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
@@ -579,54 +586,54 @@ AT_CLEANUP
|
||||
AT_SETUP([Java %parse-param and %lex-param])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) {]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) {]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([[
|
||||
%parse-param {int parse_param1}
|
||||
%parse-param {long parse_param2}]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser () {]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) {]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
|
||||
[], [[return EOF;]])
|
||||
[], [[return EOF;]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) {]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) {]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||
%parse-param {int parse_param1}
|
||||
%parse-param {long parse_param2}]],
|
||||
[], [[return EOF;]])
|
||||
[], [[return EOF;]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) {]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) {]])
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
|
||||
AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||
%lex-param {char lex_param1}
|
||||
%lex-param {short lex_param2}]],
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) {]])
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||
@@ -634,14 +641,14 @@ AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||
%parse-param {long parse_param2}
|
||||
%lex-param {char lex_param1}
|
||||
%lex-param {short lex_param2}]],
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
|
||||
[], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) {]])
|
||||
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
|
||||
AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -735,6 +742,28 @@ AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
# ------------------------------------- #
|
||||
# Java constructor init and init_throws #
|
||||
# ------------------------------------- #
|
||||
|
||||
AT_SETUP([Java constructor init and init_throws])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL([[
|
||||
%define extends "Thread"
|
||||
%code init { super("Test Thread"); if (true) throw new InterruptedException(); }
|
||||
%define init_throws "InterruptedException"
|
||||
%lex-param {int lex_param}]])
|
||||
AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
|
||||
|
||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||
%define extends "Thread"
|
||||
%code init { super("Test Thread"); if (true) throw new InterruptedException(); }
|
||||
%define init_throws "InterruptedException"]], [], [[return EOF;]])
|
||||
AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
# --------------------------------------------- #
|
||||
# Java stype, position_class and location_class #
|
||||
# --------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user