mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
java: honor %define parse.trace
* data/skeletons/lalr1.java: Don't generate debug code if parse.trace is not enabled.
This commit is contained in:
5
NEWS
5
NEWS
@@ -6,6 +6,11 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
In Java, %define api.prefix was ignored. It now behaves as expected.
|
In Java, %define api.prefix was ignored. It now behaves as expected.
|
||||||
|
|
||||||
|
** New features
|
||||||
|
|
||||||
|
The Java backend no longer emits code and data for parser tracing if the
|
||||||
|
%define variable parse.trace is not defined.
|
||||||
|
|
||||||
* Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
|
* Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
|
||||||
|
|
||||||
** Bug fixes
|
** Bug fixes
|
||||||
|
|||||||
@@ -19,10 +19,6 @@ m4_include(b4_skeletonsdir/[java.m4])
|
|||||||
|
|
||||||
b4_defines_if([b4_complain([%defines does not make sense in Java])])
|
b4_defines_if([b4_complain([%defines does not make sense in Java])])
|
||||||
|
|
||||||
# We do not depend on %debug in Java, but pacify warnings about
|
|
||||||
# non-used flags.
|
|
||||||
b4_parse_trace_if
|
|
||||||
|
|
||||||
m4_define([b4_symbol_no_destructor_assert],
|
m4_define([b4_symbol_no_destructor_assert],
|
||||||
[b4_symbol_if([$1], [has_destructor],
|
[b4_symbol_if([$1], [has_destructor],
|
||||||
[b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])),
|
[b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])),
|
||||||
@@ -258,6 +254,7 @@ b4_locations_if([[
|
|||||||
]b4_parse_param_cons[
|
]b4_parse_param_cons[
|
||||||
}
|
}
|
||||||
|
|
||||||
|
]b4_parse_trace_if([[
|
||||||
private java.io.PrintStream yyDebugStream = System.err;
|
private java.io.PrintStream yyDebugStream = System.err;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,6 +282,7 @@ b4_locations_if([[
|
|||||||
* @@param level The verbosity level for debugging output.
|
* @@param level The verbosity level for debugging output.
|
||||||
*/
|
*/
|
||||||
public final void setDebugLevel(int level) { yydebug = level; }
|
public final void setDebugLevel(int level) { yydebug = level; }
|
||||||
|
]])[
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an error message via the lexer.
|
* Print an error message via the lexer.
|
||||||
@@ -314,12 +312,12 @@ b4_locations_if([[
|
|||||||
public final void yyerror (]b4_position_type[ pos, String msg)
|
public final void yyerror (]b4_position_type[ pos, String msg)
|
||||||
{
|
{
|
||||||
yylexer.yyerror (new ]b4_location_type[ (pos), msg);
|
yylexer.yyerror (new ]b4_location_type[ (pos), msg);
|
||||||
}]])
|
}]])[
|
||||||
|
]b4_parse_trace_if([[
|
||||||
[protected final void yycdebug (String s) {
|
protected final void yycdebug (String s) {
|
||||||
if (yydebug > 0)
|
if (0 < yydebug)
|
||||||
yyDebugStream.println (s);
|
yyDebugStream.println (s);
|
||||||
}
|
}]])[
|
||||||
|
|
||||||
private final class YYStack {
|
private final class YYStack {
|
||||||
private int[] stateStack = new int[16];
|
private int[] stateStack = new int[16];
|
||||||
@@ -463,17 +461,17 @@ b4_locations_if([[
|
|||||||
This behavior is undocumented and Bison
|
This behavior is undocumented and Bison
|
||||||
users should not rely upon it. */
|
users should not rely upon it. */
|
||||||
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);
|
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);
|
||||||
]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
|
]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[]b4_parse_trace_if([[
|
||||||
|
|
||||||
yyReducePrint (yyn, yystack);
|
yyReducePrint (yyn, yystack);]])[
|
||||||
|
|
||||||
switch (yyn)
|
switch (yyn)
|
||||||
{
|
{
|
||||||
]b4_user_actions[
|
]b4_user_actions[
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}]b4_parse_trace_if([[
|
||||||
|
|
||||||
yySymbolPrint ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
|
yySymbolPrint ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystack.pop (yylen);
|
yystack.pop (yylen);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
@@ -520,7 +518,7 @@ b4_locations_if([[
|
|||||||
return yystr;
|
return yystr;
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
]b4_parse_trace_if([[
|
||||||
/*--------------------------------.
|
/*--------------------------------.
|
||||||
| Print this symbol on YYOUTPUT. |
|
| Print this symbol on YYOUTPUT. |
|
||||||
`--------------------------------*/
|
`--------------------------------*/
|
||||||
@@ -529,12 +527,11 @@ b4_locations_if([[
|
|||||||
]b4_yystype[ yyvaluep]dnl
|
]b4_yystype[ yyvaluep]dnl
|
||||||
b4_locations_if([, Object yylocationp])[)
|
b4_locations_if([, Object yylocationp])[)
|
||||||
{
|
{
|
||||||
if (yydebug > 0)
|
|
||||||
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
|
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
|
||||||
+ yytname_[yytype] + " ("]b4_locations_if([
|
+ yytname_[yytype] + " ("]b4_locations_if([
|
||||||
+ yylocationp + ": "])[
|
+ yylocationp + ": "])[
|
||||||
+ (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
|
+ (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
|
||||||
}
|
}]])[
|
||||||
|
|
||||||
]b4_push_if([],[[
|
]b4_push_if([],[[
|
||||||
/**
|
/**
|
||||||
@@ -561,8 +558,8 @@ b4_locations_if([[
|
|||||||
]b4_locations_if([/* @@$. */
|
]b4_locations_if([/* @@$. */
|
||||||
b4_location_type yyloc;])[
|
b4_location_type yyloc;])[
|
||||||
]b4_push_if([],[[
|
]b4_push_if([],[[
|
||||||
]b4_define_state[
|
]b4_define_state[]b4_parse_trace_if([[
|
||||||
yycdebug ("Starting parse\n");
|
yycdebug ("Starting parse\n");]])[
|
||||||
yyerrstatus_ = 0;
|
yyerrstatus_ = 0;
|
||||||
|
|
||||||
/* Initialize the stack. */
|
/* Initialize the stack. */
|
||||||
@@ -581,8 +578,8 @@ b4_dollar_popdef[]dnl
|
|||||||
b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
|
b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
|
||||||
b4_user_initial_action
|
b4_user_initial_action
|
||||||
b4_dollar_popdef[]dnl
|
b4_dollar_popdef[]dnl
|
||||||
])[
|
])[]b4_parse_trace_if([[
|
||||||
yycdebug ("Starting parse\n");
|
yycdebug ("Starting parse\n");]])[
|
||||||
yyerrstatus_ = 0;
|
yyerrstatus_ = 0;
|
||||||
} else
|
} else
|
||||||
label = YYGETTOKEN;
|
label = YYGETTOKEN;
|
||||||
@@ -594,10 +591,10 @@ b4_dollar_popdef[]dnl
|
|||||||
{
|
{
|
||||||
/* New state. Unlike in the C/C++ skeletons, the state is already
|
/* New state. Unlike in the C/C++ skeletons, the state is already
|
||||||
pushed when we come here. */
|
pushed when we come here. */
|
||||||
case YYNEWSTATE:
|
case YYNEWSTATE:]b4_parse_trace_if([[
|
||||||
yycdebug ("Entering state " + yystate + "\n");
|
yycdebug ("Entering state " + yystate + "\n");
|
||||||
if (yydebug > 0)
|
if (0 < yydebug)
|
||||||
yystack.print (yyDebugStream);
|
yystack.print (yyDebugStream);]])[
|
||||||
|
|
||||||
/* Accept? */
|
/* Accept? */
|
||||||
if (yystate == yyfinal_)
|
if (yystate == yyfinal_)
|
||||||
@@ -619,14 +616,13 @@ b4_dollar_popdef[]dnl
|
|||||||
{
|
{
|
||||||
]b4_push_if([[
|
]b4_push_if([[
|
||||||
if (!push_token_consumed)
|
if (!push_token_consumed)
|
||||||
return YYPUSH_MORE;
|
return YYPUSH_MORE;]b4_parse_trace_if([[
|
||||||
yycdebug ("Reading a token: ");
|
yycdebug ("Reading a token: ");]])[
|
||||||
yychar = yylextoken;
|
yychar = yylextoken;
|
||||||
yylval = yylexval;]b4_locations_if([
|
yylval = yylexval;]b4_locations_if([
|
||||||
yylloc = yylexloc;])[
|
yylloc = yylexloc;])[
|
||||||
push_token_consumed = false;]])[
|
push_token_consumed = false;]], [b4_parse_trace_if([[
|
||||||
]b4_push_if([],[[
|
yycdebug ("Reading a token: ");]])[
|
||||||
yycdebug ("Reading a token: ");
|
|
||||||
yychar = yylexer.yylex ();
|
yychar = yylexer.yylex ();
|
||||||
yylval = yylexer.getLVal ();]b4_locations_if([
|
yylval = yylexer.getLVal ();]b4_locations_if([
|
||||||
yylloc = new b4_location_type (yylexer.getStartPos (),
|
yylloc = new b4_location_type (yylexer.getStartPos (),
|
||||||
@@ -637,14 +633,14 @@ b4_dollar_popdef[]dnl
|
|||||||
/* Convert token to internal form. */
|
/* Convert token to internal form. */
|
||||||
if (yychar <= Lexer.EOF)
|
if (yychar <= Lexer.EOF)
|
||||||
{
|
{
|
||||||
yychar = yytoken = Lexer.EOF;
|
yychar = yytoken = Lexer.EOF;]b4_parse_trace_if([[
|
||||||
yycdebug ("Now at end of input.\n");
|
yycdebug ("Now at end of input.\n");]])[
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yytoken = yytranslate_ (yychar);
|
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
|
||||||
yySymbolPrint ("Next token is", yytoken,
|
yySymbolPrint ("Next token is", yytoken,
|
||||||
yylval]b4_locations_if([, yylloc])[);
|
yylval]b4_locations_if([, yylloc])[);]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
||||||
@@ -667,10 +663,10 @@ b4_dollar_popdef[]dnl
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Shift the lookahead token. */
|
/* Shift the lookahead token. */]b4_parse_trace_if([[
|
||||||
yySymbolPrint ("Shifting", yytoken,
|
yySymbolPrint ("Shifting", yytoken,
|
||||||
yylval]b4_locations_if([, yylloc])[);
|
yylval]b4_locations_if([, yylloc])[);
|
||||||
|
]])[
|
||||||
/* Discard the token being shifted. */
|
/* Discard the token being shifted. */
|
||||||
yychar = yyempty_;
|
yychar = yyempty_;
|
||||||
|
|
||||||
@@ -779,9 +775,9 @@ b4_dollar_popdef[]dnl
|
|||||||
|
|
||||||
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
|
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
|
||||||
yystack.pop ();
|
yystack.pop ();
|
||||||
yystate = yystack.stateAt (0);
|
yystate = yystack.stateAt (0);]b4_parse_trace_if([[
|
||||||
if (yydebug > 0)
|
if (0 < yydebug)
|
||||||
yystack.print (yyDebugStream);
|
yystack.print (yyDebugStream);]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label == YYABORT)
|
if (label == YYABORT)
|
||||||
@@ -795,9 +791,9 @@ b4_dollar_popdef[]dnl
|
|||||||
yyloc = yylloc (yystack, 2);
|
yyloc = yylloc (yystack, 2);
|
||||||
yystack.pop (2);])[
|
yystack.pop (2);])[
|
||||||
|
|
||||||
/* Shift the error token. */
|
/* Shift the error token. */]b4_parse_trace_if([[
|
||||||
yySymbolPrint ("Shifting", yystos_[yyn],
|
yySymbolPrint ("Shifting", yystos_[yyn],
|
||||||
yylval]b4_locations_if([, yyloc])[);
|
yylval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystate = yyn;
|
yystate = yyn;
|
||||||
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
|
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
|
||||||
@@ -996,6 +992,7 @@ b4_dollar_popdef[]dnl
|
|||||||
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
|
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
|
||||||
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
||||||
|
|
||||||
|
]b4_parse_trace_if([[
|
||||||
]b4_integral_parser_table_define([rline], [b4_rline],
|
]b4_integral_parser_table_define([rline], [b4_rline],
|
||||||
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
|
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
|
||||||
|
|
||||||
@@ -1018,7 +1015,7 @@ b4_dollar_popdef[]dnl
|
|||||||
yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
|
yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
|
||||||
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
|
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
|
||||||
b4_rhs_location(yynrhs, yyi + 1)])[);
|
b4_rhs_location(yynrhs, yyi + 1)])[);
|
||||||
}
|
}]])[
|
||||||
|
|
||||||
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
||||||
as returned by yylex, with out-of-bounds checking. */
|
as returned by yylex, with out-of-bounds checking. */
|
||||||
|
|||||||
@@ -43,9 +43,11 @@ AT_BANNER([[Java Push Parsing Tests]])
|
|||||||
# Define a single copy of the trivial parser grammar.
|
# Define a single copy of the trivial parser grammar.
|
||||||
# This is missing main(), so two versions
|
# This is missing main(), so two versions
|
||||||
# are instantiated with different main() procedures.
|
# are instantiated with different main() procedures.
|
||||||
m4_define([AT_TRIVIAL_GRAMMAR],[[
|
m4_define([AT_TRIVIAL_GRAMMAR],
|
||||||
|
[[
|
||||||
%define api.parser.class {YYParser}
|
%define api.parser.class {YYParser}
|
||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
|
%define parse.trace
|
||||||
|
|
||||||
%code imports {
|
%code imports {
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -213,7 +215,8 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Trivial Push Parser with %initial-action])
|
AT_SETUP([Trivial Push Parser with %initial-action])
|
||||||
AT_BISON_OPTION_PUSHDEFS
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
AT_DATA([[input.y]],[[%language "Java"
|
AT_DATA([[input.y]],
|
||||||
|
[[%language "Java"
|
||||||
%initial-action {
|
%initial-action {
|
||||||
System.err.println("Initial action invoked");
|
System.err.println("Initial action invoked");
|
||||||
}
|
}
|
||||||
@@ -327,7 +330,8 @@ AT_BISON_OPTION_PUSHDEFS
|
|||||||
# may be incorrect and you will have
|
# may be incorrect and you will have
|
||||||
# to modify that file as well.
|
# to modify that file as well.
|
||||||
|
|
||||||
AT_DATA([input],[[1 + 2 * 3 = 7
|
AT_DATA([input],
|
||||||
|
[[1 + 2 * 3 = 7
|
||||||
1 + 2 * -3 = -5
|
1 + 2 * -3 = -5
|
||||||
|
|
||||||
-1^2 = -1
|
-1^2 = -1
|
||||||
@@ -343,10 +347,12 @@ AT_DATA([input],[[1 + 2 * 3 = 7
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
# Compose pieces to build the actual .y file.
|
# Compose pieces to build the actual .y file.
|
||||||
AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
|
AT_DATA([Calc.y],
|
||||||
|
[[/* Infix notation calculator--calc */
|
||||||
%language "Java"
|
%language "Java"
|
||||||
|
|
||||||
%define api.parser.class {Calc}
|
%define api.parser.class {Calc}
|
||||||
|
%define parse.trace
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
static class UserLexer implements Calc.Lexer
|
static class UserLexer implements Calc.Lexer
|
||||||
@@ -615,10 +621,12 @@ AT_CLEANUP
|
|||||||
AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
|
AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
|
||||||
AT_BISON_OPTION_PUSHDEFS
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
|
|
||||||
AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
|
AT_DATA([Calc.y],
|
||||||
|
[[/* Infix notation calculator--calc. */
|
||||||
%language "Java"
|
%language "Java"
|
||||||
|
|
||||||
%define api.parser.class {Calc}
|
%define api.parser.class {Calc}
|
||||||
|
%define parse.trace
|
||||||
%lex-param { Reader rdr }
|
%lex-param { Reader rdr }
|
||||||
%locations
|
%locations
|
||||||
|
|
||||||
@@ -826,7 +834,8 @@ Next token is token '\n' (14.0: 64)
|
|||||||
# may be incorrect and you will have
|
# may be incorrect and you will have
|
||||||
# to modify that file as well.
|
# to modify that file as well.
|
||||||
|
|
||||||
AT_DATA([input],[[1 + 2 * 3 = 7
|
AT_DATA([input],
|
||||||
|
[[1 + 2 * 3 = 7
|
||||||
1 + 2 * -3 = -5
|
1 + 2 * -3 = -5
|
||||||
|
|
||||||
-1^2 = -1
|
-1^2 = -1
|
||||||
|
|||||||
Reference in New Issue
Block a user