mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-23 11:13:03 +00:00
java: style changes
* data/skeletons/lalr1.java: Use more conventional function names for Java. Prefer < and <= to => and >. Use the same approach for m4 quotation as in the other skeletons. Fix indentation issues. * tests/calc.at, tests/java.at, tests/javapush.at: Fix quotation style. (main): Use 'args', not 'argv', the former seems more conventional and is used elsewhere in Bison. Prefer character literals to integers to denote characters. * examples/java/Calc.y: Likewise.
This commit is contained in:
@@ -21,7 +21,7 @@ b4_defines_if([b4_complain([%defines does not make sense in Java])])
|
|||||||
|
|
||||||
# We do not depend on %debug in Java, but pacify warnings about
|
# We do not depend on %debug in Java, but pacify warnings about
|
||||||
# non-used flags.
|
# non-used flags.
|
||||||
b4_parse_trace_if([0], [0])
|
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],
|
||||||
@@ -70,19 +70,19 @@ m4_define([b4_define_state],[[
|
|||||||
|
|
||||||
/* Error handling. */
|
/* Error handling. */
|
||||||
int yynerrs_ = 0;
|
int yynerrs_ = 0;
|
||||||
]b4_locations_if([/* The location where the error started. */
|
]b4_locations_if([[/* The location where the error started. */
|
||||||
b4_location_type yyerrloc = null;
|
]b4_location_type[ yyerrloc = null;
|
||||||
|
|
||||||
/* Location. */
|
/* Location. */
|
||||||
b4_location_type yylloc = new b4_location_type (null, null);])[
|
]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);]])[
|
||||||
|
|
||||||
/* Semantic value of the lookahead. */
|
/* Semantic value of the lookahead. */
|
||||||
]b4_yystype[ yylval = null;
|
]b4_yystype[ yylval = null;
|
||||||
]])
|
]])[
|
||||||
|
|
||||||
b4_output_begin([b4_parser_file_name])[
|
]b4_output_begin([b4_parser_file_name])[
|
||||||
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
||||||
[2007-2015, 2018])[
|
[2007-2015, 2018-2019])[
|
||||||
]b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);[
|
]b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);[
|
||||||
]])[
|
]])[
|
||||||
]b4_user_pre_prologue[
|
]b4_user_pre_prologue[
|
||||||
@@ -103,7 +103,7 @@ b4_output_begin([b4_parser_file_name])[
|
|||||||
private boolean yyErrorVerbose = true;
|
private boolean yyErrorVerbose = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether verbose error messages are enabled.
|
* Whether verbose error messages are enabled.
|
||||||
*/
|
*/
|
||||||
public final boolean getErrorVerbose() { return yyErrorVerbose; }
|
public final boolean getErrorVerbose() { return yyErrorVerbose; }
|
||||||
|
|
||||||
@@ -165,12 +165,12 @@ b4_locations_if([[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
]])
|
]])[
|
||||||
|
|
||||||
b4_locations_if([[
|
]b4_locations_if([[
|
||||||
private ]b4_location_type[ yylloc (YYStack rhs, int n)
|
private ]b4_location_type[ yylloc (YYStack rhs, int n)
|
||||||
{
|
{
|
||||||
if (n > 0)
|
if (0 < n)
|
||||||
return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end);
|
return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end);
|
||||||
else
|
else
|
||||||
return new ]b4_location_type[ (rhs.locationAt (0).end);
|
return new ]b4_location_type[ (rhs.locationAt (0).end);
|
||||||
@@ -220,10 +220,11 @@ b4_locations_if([[
|
|||||||
* error message is related]])[
|
* error message is related]])[
|
||||||
* @@param msg The string for the error message.
|
* @@param msg The string for the error message.
|
||||||
*/
|
*/
|
||||||
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
|
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
b4_lexer_if([[private class YYLexer implements Lexer {
|
]b4_lexer_if([[
|
||||||
|
private class YYLexer implements Lexer {
|
||||||
]b4_percent_code_get([[lexer]])[
|
]b4_percent_code_get([[lexer]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,10 +232,10 @@ b4_locations_if([[
|
|||||||
* The object doing lexical analysis for us.
|
* The object doing lexical analysis for us.
|
||||||
*/
|
*/
|
||||||
private Lexer yylexer;
|
private Lexer yylexer;
|
||||||
]
|
|
||||||
b4_parse_param_vars
|
|
||||||
|
|
||||||
b4_lexer_if([[
|
]b4_parse_param_vars[
|
||||||
|
|
||||||
|
]b4_lexer_if([[
|
||||||
/**
|
/**
|
||||||
* Instantiates the Bison-generated parser.
|
* Instantiates the Bison-generated parser.
|
||||||
*/
|
*/
|
||||||
@@ -244,13 +245,13 @@ b4_lexer_if([[
|
|||||||
this.yylexer = new YYLexer(]b4_lex_param_call[);
|
this.yylexer = new YYLexer(]b4_lex_param_call[);
|
||||||
]b4_parse_param_cons[
|
]b4_parse_param_cons[
|
||||||
}
|
}
|
||||||
]])
|
]])[
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates the Bison-generated parser.
|
* Instantiates the Bison-generated parser.
|
||||||
* @@param yylexer The scanner that will supply tokens to the parser.
|
* @@param yylexer The scanner that will supply tokens to the parser.
|
||||||
*/
|
*/
|
||||||
b4_lexer_if([[protected]], [[public]]) b4_parser_class[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
|
]b4_lexer_if([[protected]], [[public]]) b4_parser_class[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
|
||||||
{
|
{
|
||||||
]b4_percent_code_get([[init]])[
|
]b4_percent_code_get([[init]])[
|
||||||
this.yylexer = yylexer;
|
this.yylexer = yylexer;
|
||||||
@@ -260,8 +261,7 @@ b4_lexer_if([[
|
|||||||
private java.io.PrintStream yyDebugStream = System.err;
|
private java.io.PrintStream yyDebugStream = System.err;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the <tt>PrintStream</tt> on which the debugging output is
|
* The <tt>PrintStream</tt> on which the debugging output is printed.
|
||||||
* printed.
|
|
||||||
*/
|
*/
|
||||||
public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
|
public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ b4_lexer_if([[
|
|||||||
|
|
||||||
public final void pop (int num) {
|
public final void pop (int num) {
|
||||||
// Avoid memory leaks... garbage collection is a white lie!
|
// Avoid memory leaks... garbage collection is a white lie!
|
||||||
if (num > 0) {
|
if (0 < num) {
|
||||||
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
|
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
|
||||||
]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
|
]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
|
||||||
}
|
}
|
||||||
@@ -430,10 +430,9 @@ b4_lexer_if([[
|
|||||||
|
|
||||||
private int yyerrstatus_ = 0;
|
private int yyerrstatus_ = 0;
|
||||||
|
|
||||||
]b4_push_if([dnl
|
]b4_push_if([b4_define_state])[
|
||||||
b4_define_state])[
|
|
||||||
/**
|
/**
|
||||||
* Return whether error recovery is being done. In this state, the parser
|
* Whether error recovery is being done. In this state, the parser
|
||||||
* reads token until it reaches a known state, and then restarts normal
|
* reads token until it reaches a known state, and then restarts normal
|
||||||
* operation.
|
* operation.
|
||||||
*/
|
*/
|
||||||
@@ -446,7 +445,7 @@ b4_define_state])[
|
|||||||
* @@param yystate the current state
|
* @@param yystate the current state
|
||||||
* @@param yysym the nonterminal to push on the stack
|
* @@param yysym the nonterminal to push on the stack
|
||||||
*/
|
*/
|
||||||
private int yy_lr_goto_state_ (int yystate, int yysym)
|
private int yyLRGotoState (int yystate, int yysym)
|
||||||
{
|
{
|
||||||
int yyr = yypgoto_[yysym - yyntokens_] + yystate;
|
int yyr = yypgoto_[yysym - yyntokens_] + yystate;
|
||||||
if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
|
if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
|
||||||
@@ -457,21 +456,16 @@ b4_define_state])[
|
|||||||
|
|
||||||
private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
|
private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
|
||||||
{
|
{
|
||||||
]b4_yystype[ yyval;
|
|
||||||
]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
|
|
||||||
|
|
||||||
/* If YYLEN is nonzero, implement the default value of the action:
|
/* If YYLEN is nonzero, implement the default value of the action:
|
||||||
'$$ = $1'. Otherwise, use the top of the stack.
|
'$$ = $1'. Otherwise, use the top of the stack.
|
||||||
|
|
||||||
Otherwise, the following line sets YYVAL to garbage.
|
Otherwise, the following line sets YYVAL to garbage.
|
||||||
This behavior is undocumented and Bison
|
This behavior is undocumented and Bison
|
||||||
users should not rely upon it. */
|
users should not rely upon it. */
|
||||||
if (yylen > 0)
|
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);
|
||||||
yyval = yystack.valueAt (yylen - 1);
|
]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
|
||||||
else
|
|
||||||
yyval = yystack.valueAt (0);
|
|
||||||
|
|
||||||
yy_reduce_print (yyn, yystack);
|
yyReducePrint (yyn, yystack);
|
||||||
|
|
||||||
switch (yyn)
|
switch (yyn)
|
||||||
{
|
{
|
||||||
@@ -479,13 +473,13 @@ b4_define_state])[
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
yy_symbol_print ("-> $$ =", 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;
|
||||||
|
|
||||||
/* Shift the result of the reduction. */
|
/* Shift the result of the reduction. */
|
||||||
int yystate = yy_lr_goto_state_ (yystack.stateAt (0), yyr1_[yyn]);
|
int yystate = yyLRGotoState (yystack.stateAt (0), yyr1_[yyn]);
|
||||||
yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
|
yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
|
||||||
return YYNEWSTATE;
|
return YYNEWSTATE;
|
||||||
}
|
}
|
||||||
@@ -531,9 +525,9 @@ b4_define_state])[
|
|||||||
| Print this symbol on YYOUTPUT. |
|
| Print this symbol on YYOUTPUT. |
|
||||||
`--------------------------------*/
|
`--------------------------------*/
|
||||||
|
|
||||||
private void yy_symbol_print (String s, int yytype,
|
private void yySymbolPrint (String s, int yytype,
|
||||||
]b4_yystype[ yyvaluep]dnl
|
]b4_yystype[ yyvaluep]dnl
|
||||||
b4_locations_if([, Object yylocationp])[)
|
b4_locations_if([, Object yylocationp])[)
|
||||||
{
|
{
|
||||||
if (yydebug > 0)
|
if (yydebug > 0)
|
||||||
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
|
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
|
||||||
@@ -550,7 +544,7 @@ b4_define_state])[
|
|||||||
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
|
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
|
||||||
* imply that there were no syntax errors.
|
* imply that there were no syntax errors.
|
||||||
*/
|
*/
|
||||||
public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
|
public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
|
||||||
]b4_push_if([
|
]b4_push_if([
|
||||||
/**
|
/**
|
||||||
* Push Parse input from external lexer
|
* Push Parse input from external lexer
|
||||||
@@ -612,7 +606,7 @@ b4_dollar_popdef[]dnl
|
|||||||
|
|
||||||
/* Take a decision. First try without lookahead. */
|
/* Take a decision. First try without lookahead. */
|
||||||
yyn = yypact_[yystate];
|
yyn = yypact_[yystate];
|
||||||
if (yy_pact_value_is_default_ (yyn))
|
if (yyPactValueIsDefault (yyn))
|
||||||
{
|
{
|
||||||
label = YYDEFAULT;
|
label = YYDEFAULT;
|
||||||
break;
|
break;
|
||||||
@@ -649,8 +643,8 @@ b4_dollar_popdef[]dnl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
yytoken = yytranslate_ (yychar);
|
yytoken = yytranslate_ (yychar);
|
||||||
yy_symbol_print ("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
|
||||||
@@ -662,7 +656,7 @@ b4_dollar_popdef[]dnl
|
|||||||
/* <= 0 means reduce or error. */
|
/* <= 0 means reduce or error. */
|
||||||
else if ((yyn = yytable_[yyn]) <= 0)
|
else if ((yyn = yytable_[yyn]) <= 0)
|
||||||
{
|
{
|
||||||
if (yy_table_value_is_error_ (yyn))
|
if (yyTableValueIsError (yyn))
|
||||||
label = YYERRLAB;
|
label = YYERRLAB;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -674,8 +668,8 @@ b4_dollar_popdef[]dnl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Shift the lookahead token. */
|
/* Shift the lookahead token. */
|
||||||
yy_symbol_print ("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_;
|
||||||
@@ -727,17 +721,17 @@ b4_dollar_popdef[]dnl
|
|||||||
]b4_locations_if([yyerrloc = yylloc;])[
|
]b4_locations_if([yyerrloc = yylloc;])[
|
||||||
if (yyerrstatus_ == 3)
|
if (yyerrstatus_ == 3)
|
||||||
{
|
{
|
||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse lookahead token after an
|
||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
if (yychar <= Lexer.EOF)
|
if (yychar <= Lexer.EOF)
|
||||||
{
|
{
|
||||||
/* Return failure if at end of input. */
|
/* Return failure if at end of input. */
|
||||||
if (yychar == Lexer.EOF)
|
if (yychar == Lexer.EOF)
|
||||||
]b4_push_if([{label = YYABORT; break;}],[return false;])[
|
]b4_push_if([{label = YYABORT; break;}], [return false;])[
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yychar = yyempty_;
|
yychar = yyempty_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse lookahead token after shifting the error
|
||||||
@@ -749,7 +743,6 @@ b4_dollar_popdef[]dnl
|
|||||||
| errorlab -- error raised explicitly by YYERROR. |
|
| errorlab -- error raised explicitly by YYERROR. |
|
||||||
`-------------------------------------------------*/
|
`-------------------------------------------------*/
|
||||||
case YYERROR:
|
case YYERROR:
|
||||||
|
|
||||||
]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
|
]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
|
||||||
/* Do not reclaim the symbols of the rule which action triggered
|
/* Do not reclaim the symbols of the rule which action triggered
|
||||||
this YYERROR. */
|
this YYERROR. */
|
||||||
@@ -768,7 +761,7 @@ b4_dollar_popdef[]dnl
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
yyn = yypact_[yystate];
|
yyn = yypact_[yystate];
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
if (!yyPactValueIsDefault (yyn))
|
||||||
{
|
{
|
||||||
yyn += yyterror_;
|
yyn += yyterror_;
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
|
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
|
||||||
@@ -803,8 +796,8 @@ b4_dollar_popdef[]dnl
|
|||||||
yystack.pop (2);])[
|
yystack.pop (2);])[
|
||||||
|
|
||||||
/* Shift the error token. */
|
/* Shift the error token. */
|
||||||
yy_symbol_print ("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])[);
|
||||||
@@ -870,9 +863,9 @@ b4_dollar_popdef[]dnl
|
|||||||
{
|
{
|
||||||
return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
|
return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
|
||||||
}
|
}
|
||||||
])[]])
|
])[]])[
|
||||||
|
|
||||||
b4_both_if([[
|
]b4_both_if([[
|
||||||
/**
|
/**
|
||||||
* Parse input from the scanner that was specified at object construction
|
* Parse input from the scanner that was specified at object construction
|
||||||
* time. Return whether the end of the input was reached successfully.
|
* time. Return whether the end of the input was reached successfully.
|
||||||
@@ -881,21 +874,21 @@ b4_both_if([[
|
|||||||
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
|
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
|
||||||
* imply that there were no syntax errors.
|
* imply that there were no syntax errors.
|
||||||
*/
|
*/
|
||||||
public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
|
public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
|
||||||
{
|
{
|
||||||
if (yylexer == null)
|
if (yylexer == null)
|
||||||
throw new NullPointerException("Null Lexer");
|
throw new NullPointerException("Null Lexer");
|
||||||
int status;
|
int status;
|
||||||
do {
|
do {
|
||||||
int token = yylexer.yylex();
|
int token = yylexer.yylex();
|
||||||
]b4_yystype[ lval = yylexer.getLVal();
|
]b4_yystype[ lval = yylexer.getLVal();
|
||||||
]b4_locations_if([dnl
|
]b4_locations_if([dnl
|
||||||
b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
|
b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
|
||||||
yylexer.getEndPos ());])[
|
yylexer.getEndPos ());])[
|
||||||
]b4_locations_if([status = push_parse(token,lval,yyloc);],[
|
]b4_locations_if([status = push_parse(token,lval,yyloc);],[
|
||||||
status = push_parse(token,lval);])[
|
status = push_parse(token,lval);])[
|
||||||
} while (status == YYPUSH_MORE);
|
} while (status == YYPUSH_MORE);
|
||||||
return (status == YYACCEPT);
|
return (status == YYACCEPT);
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
@@ -938,7 +931,7 @@ b4_both_if([[
|
|||||||
new StringBuffer ("syntax error, unexpected ");
|
new StringBuffer ("syntax error, unexpected ");
|
||||||
res.append (yytnamerr_ (yytname_[tok]));
|
res.append (yytnamerr_ (yytname_[tok]));
|
||||||
int yyn = yypact_[yystate];
|
int yyn = yypact_[yystate];
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
if (!yyPactValueIsDefault (yyn))
|
||||||
{
|
{
|
||||||
/* Start YYX at -YYN if negative to avoid negative
|
/* Start YYX at -YYN if negative to avoid negative
|
||||||
indexes in YYCHECK. In other words, skip the first
|
indexes in YYCHECK. In other words, skip the first
|
||||||
@@ -951,14 +944,14 @@ b4_both_if([[
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
for (int x = yyxbegin; x < yyxend; ++x)
|
||||||
if (yycheck_[x + yyn] == x && x != yyterror_
|
if (yycheck_[x + yyn] == x && x != yyterror_
|
||||||
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
&& !yyTableValueIsError (yytable_[x + yyn]))
|
||||||
++count;
|
++count;
|
||||||
if (count < 5)
|
if (count < 5)
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
for (int x = yyxbegin; x < yyxend; ++x)
|
||||||
if (yycheck_[x + yyn] == x && x != yyterror_
|
if (yycheck_[x + yyn] == x && x != yyterror_
|
||||||
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
&& !yyTableValueIsError (yytable_[x + yyn]))
|
||||||
{
|
{
|
||||||
res.append (count++ == 0 ? ", expecting " : " or ");
|
res.append (count++ == 0 ? ", expecting " : " or ");
|
||||||
res.append (yytnamerr_ (yytname_[x]));
|
res.append (yytnamerr_ (yytname_[x]));
|
||||||
@@ -976,7 +969,7 @@ b4_both_if([[
|
|||||||
* Whether the given <code>yypact_</code> value indicates a defaulted state.
|
* Whether the given <code>yypact_</code> value indicates a defaulted state.
|
||||||
* @@param yyvalue the value to check
|
* @@param yyvalue the value to check
|
||||||
*/
|
*/
|
||||||
private static boolean yy_pact_value_is_default_ (int yyvalue)
|
private static boolean yyPactValueIsDefault (int yyvalue)
|
||||||
{
|
{
|
||||||
return yyvalue == yypact_ninf_;
|
return yyvalue == yypact_ninf_;
|
||||||
}
|
}
|
||||||
@@ -986,7 +979,7 @@ b4_both_if([[
|
|||||||
* value indicates a syntax error.
|
* value indicates a syntax error.
|
||||||
* @@param yyvalue the value to check
|
* @@param yyvalue the value to check
|
||||||
*/
|
*/
|
||||||
private static boolean yy_table_value_is_error_ (int yyvalue)
|
private static boolean yyTableValueIsError (int yyvalue)
|
||||||
{
|
{
|
||||||
return yyvalue == yytable_ninf_;
|
return yyvalue == yytable_ninf_;
|
||||||
}
|
}
|
||||||
@@ -1008,7 +1001,7 @@ b4_both_if([[
|
|||||||
|
|
||||||
|
|
||||||
// Report on the debug stream that the rule yyrule is going to be reduced.
|
// Report on the debug stream that the rule yyrule is going to be reduced.
|
||||||
private void yy_reduce_print (int yyrule, YYStack yystack)
|
private void yyReducePrint (int yyrule, YYStack yystack)
|
||||||
{
|
{
|
||||||
if (yydebug == 0)
|
if (yydebug == 0)
|
||||||
return;
|
return;
|
||||||
@@ -1021,10 +1014,10 @@ b4_both_if([[
|
|||||||
|
|
||||||
/* The symbols being reduced. */
|
/* The symbols being reduced. */
|
||||||
for (int yyi = 0; yyi < yynrhs; yyi++)
|
for (int yyi = 0; yyi < yynrhs; yyi++)
|
||||||
yy_symbol_print (" $" + (yyi + 1) + " =",
|
yySymbolPrint (" $" + (yyi + 1) + " =",
|
||||||
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
|
||||||
@@ -1033,7 +1026,7 @@ b4_both_if([[
|
|||||||
|
|
||||||
private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
|
private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
|
||||||
{
|
{
|
||||||
if (t >= 0 && t <= yyuser_token_number_max_)
|
if (0 <= t && t <= yyuser_token_number_max_)
|
||||||
return yytranslate_table_[t];
|
return yytranslate_table_[t];
|
||||||
else
|
else
|
||||||
return yyundef_token_;
|
return yyundef_token_;
|
||||||
@@ -1050,8 +1043,8 @@ b4_both_if([[
|
|||||||
private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
|
private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
|
||||||
private static final int yyundef_token_ = ]b4_undef_token_number[;
|
private static final int yyundef_token_ = ]b4_undef_token_number[;
|
||||||
|
|
||||||
]/* User implementation code. */
|
/* User implementation code. */
|
||||||
b4_percent_code_get[]dnl
|
]b4_percent_code_get[]dnl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
st = new StreamTokenizer (new InputStreamReader (is));
|
st = new StreamTokenizer (new InputStreamReader (is));
|
||||||
st.resetSyntax ();
|
st.resetSyntax ();
|
||||||
st.eolIsSignificant (true);
|
st.eolIsSignificant (true);
|
||||||
st.whitespaceChars (9, 9);
|
st.whitespaceChars ('\t', '\t');
|
||||||
st.whitespaceChars (32, 32);
|
st.whitespaceChars (' ', ' ');
|
||||||
st.wordChars (48, 57);
|
st.wordChars ('0', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -598,7 +598,7 @@ AT_DATA_CALC_Y([$1])
|
|||||||
AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
|
AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
|
||||||
AT_CHECK_SPACES([calc.AT_LANG_EXT AT_DEFINES_IF([calc.AT_LANG_HDR])])
|
AT_CHECK_SPACES([calc.AT_LANG_EXT AT_DEFINES_IF([calc.AT_LANG_HDR])])
|
||||||
|
|
||||||
# Test the priorities.
|
# Test the precedences.
|
||||||
_AT_CHECK_CALC([$1],
|
_AT_CHECK_CALC([$1],
|
||||||
[1 + 2 * 3 = 7
|
[1 + 2 * 3 = 7
|
||||||
1 + 2 * -3 = -5
|
1 + 2 * -3 = -5
|
||||||
|
|||||||
@@ -127,17 +127,17 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
]])[
|
]])[
|
||||||
StreamTokenizer st;
|
StreamTokenizer st;
|
||||||
|
|
||||||
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is)
|
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
|
||||||
{
|
{
|
||||||
st = new StreamTokenizer (new InputStreamReader (is));
|
st = new StreamTokenizer (new InputStreamReader (is));
|
||||||
st.resetSyntax ();
|
st.resetSyntax ();
|
||||||
st.eolIsSignificant (true);
|
st.eolIsSignificant (true);
|
||||||
st.whitespaceChars (9, 9);
|
st.whitespaceChars ('\t', '\t');
|
||||||
st.whitespaceChars (32, 32);
|
st.whitespaceChars (' ', ' ');
|
||||||
st.wordChars (48, 57);
|
st.wordChars ('0', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_LOCATION_IF([[
|
]AT_LOCATION_IF([[
|
||||||
Position yypos = new Position (1, 0);
|
Position yypos = new Position (1, 0);
|
||||||
|
|
||||||
public Position getStartPos() {
|
public Position getStartPos() {
|
||||||
@@ -157,15 +157,14 @@ AT_LOCATION_IF([[
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int yylex () throws IOException {
|
public int yylex () throws IOException {
|
||||||
int ttype = st.nextToken ();
|
int ttype = st.nextToken ();]AT_LOCATION_IF([[
|
||||||
]AT_LOCATION_IF([[yypos = new Position (yypos.lineno (),
|
yypos = new Position (yypos.lineno (), yypos.token () + 1);]])[
|
||||||
yypos.token () + 1);]])[
|
|
||||||
if (ttype == st.TT_EOF)
|
if (ttype == st.TT_EOF)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
|
||||||
else if (ttype == st.TT_EOL)
|
else if (ttype == st.TT_EOL)
|
||||||
{
|
{]AT_LOCATION_IF([[
|
||||||
]AT_LOCATION_IF([[yypos = new Position (yypos.lineno () + 1, 0);]])[
|
yypos = new Position (yypos.lineno () + 1, 0);]])[
|
||||||
return (int) '\n';
|
return (int) '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +250,7 @@ $2
|
|||||||
AT_BISON_CHECK([-Wno-deprecated -o Calc.java Calc.y])
|
AT_BISON_CHECK([-Wno-deprecated -o Calc.java Calc.y])
|
||||||
AT_JAVA_COMPILE([Calc.java])
|
AT_JAVA_COMPILE([Calc.java])
|
||||||
|
|
||||||
# Test the priorities.
|
# Test the precedences.
|
||||||
AT_DATA([[input]],
|
AT_DATA([[input]],
|
||||||
[[1 + 2 * 3 = 7
|
[[1 + 2 * 3 = 7
|
||||||
1 + 2 * -3 = -5
|
1 + 2 * -3 = -5
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ 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
|
||||||
|
|
||||||
@@ -57,11 +57,11 @@ import java.util.*;
|
|||||||
start: 'a' 'b' 'c' ;
|
start: 'a' 'b' 'c' ;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
])
|
]])
|
||||||
|
|
||||||
# Define comon code across to be included in
|
# Define comon code across to be included in
|
||||||
# class Main for the trivial parser tests.
|
# class Main for the trivial parser tests.
|
||||||
m4_define([AT_TRIVIAL_COMMON],[
|
m4_define([AT_TRIVIAL_COMMON],[[
|
||||||
static class YYerror implements YYParser.Lexer
|
static class YYerror implements YYParser.Lexer
|
||||||
{
|
{
|
||||||
public Object getLVal() {return null;}
|
public Object getLVal() {return null;}
|
||||||
@@ -82,29 +82,30 @@ m4_define([AT_TRIVIAL_COMMON],[
|
|||||||
teststate = -1;
|
teststate = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String[[]] teststatename
|
static String[] teststatename
|
||||||
= new String[[]]{"YYACCEPT","YYABORT","YYERROR","UNKNOWN","YYPUSH_MORE"};
|
= new String[]{"YYACCEPT","YYABORT","YYERROR","UNKNOWN","YYPUSH_MORE"};
|
||||||
|
|
||||||
static void check(int teststate, int expected, String msg)
|
static void check(int teststate, int expected, String msg)
|
||||||
{
|
{
|
||||||
System.err.println("teststate="+teststatename[[teststate]]
|
System.err.println("teststate="+teststatename[teststate]
|
||||||
+"; expected="+teststatename[[expected]]);
|
+"; expected="+teststatename[expected]);
|
||||||
if (teststate == expected)
|
if (teststate != expected)
|
||||||
return;
|
{
|
||||||
System.err.println("unexpected state: "+msg);
|
System.err.println("unexpected state: "+msg);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
])
|
]])
|
||||||
|
|
||||||
m4_define([AT_TRIVIAL_PARSER],[
|
m4_define([AT_TRIVIAL_PARSER],[[
|
||||||
AT_TRIVIAL_GRAMMAR
|
]AT_TRIVIAL_GRAMMAR[
|
||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
|
|
||||||
AT_TRIVIAL_COMMON
|
]AT_TRIVIAL_COMMON[
|
||||||
|
|
||||||
static public void main (String[[]] argv)
|
static public void main (String[] args)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
@@ -131,17 +132,17 @@ m4_define([AT_TRIVIAL_PARSER],[
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
])
|
]])
|
||||||
|
|
||||||
m4_define([AT_TRIVIAL_PARSER_INITIAL_ACTION],[
|
m4_define([AT_TRIVIAL_PARSER_INITIAL_ACTION],[[
|
||||||
AT_TRIVIAL_GRAMMAR
|
]AT_TRIVIAL_GRAMMAR[
|
||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
|
|
||||||
AT_TRIVIAL_COMMON
|
]AT_TRIVIAL_COMMON[
|
||||||
|
|
||||||
static public void main (String[[]] argv)
|
static public void main (String[] args)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
@@ -159,7 +160,7 @@ m4_define([AT_TRIVIAL_PARSER_INITIAL_ACTION],[
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
])
|
]])
|
||||||
|
|
||||||
## ----------------------------------------------------- ##
|
## ----------------------------------------------------- ##
|
||||||
## Trivial Push Parser with api.push-pull verification. ##
|
## Trivial Push Parser with api.push-pull verification. ##
|
||||||
@@ -359,9 +360,9 @@ AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
|
|||||||
st = new StreamTokenizer(rdr);
|
st = new StreamTokenizer(rdr);
|
||||||
st.resetSyntax();
|
st.resetSyntax();
|
||||||
st.eolIsSignificant(true);
|
st.eolIsSignificant(true);
|
||||||
st.whitespaceChars(9, 9);
|
st.whitespaceChars('\t', '\t');
|
||||||
st.whitespaceChars(32, 32);
|
st.whitespaceChars(' ', ' ');
|
||||||
st.wordChars(48, 57);
|
st.wordChars('0', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer yylval;
|
Integer yylval;
|
||||||
@@ -385,10 +386,10 @@ AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
|
|||||||
}
|
}
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
public static void main (String[] argv)
|
public static void main (String[] args)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
StringReader reader = getinput(argv[0]);
|
StringReader reader = getinput(args[0]);
|
||||||
UserLexer lexer = new UserLexer(reader);
|
UserLexer lexer = new UserLexer(reader);
|
||||||
Calc calc = new Calc(lexer);
|
Calc calc = new Calc(lexer);
|
||||||
calc.setDebugLevel(1);
|
calc.setDebugLevel(1);
|
||||||
@@ -634,9 +635,9 @@ AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
|
|||||||
st = new StreamTokenizer(rdr);
|
st = new StreamTokenizer(rdr);
|
||||||
st.resetSyntax();
|
st.resetSyntax();
|
||||||
st.eolIsSignificant(true);
|
st.eolIsSignificant(true);
|
||||||
st.whitespaceChars(9, 9);
|
st.whitespaceChars('\t', '\t');
|
||||||
st.whitespaceChars(32, 32);
|
st.whitespaceChars(' ', ' ');
|
||||||
st.wordChars(48, 57);
|
st.wordChars('0', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
Position yypos = new Position (1, 0);
|
Position yypos = new Position (1, 0);
|
||||||
@@ -673,10 +674,10 @@ AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
|
|||||||
%code { ]AT_JAVA_POSITION_DEFINE[ }
|
%code { ]AT_JAVA_POSITION_DEFINE[ }
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
public static void main (String[] argv)
|
public static void main (String[] args)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
StringReader reader = getinput(argv[0]);
|
StringReader reader = getinput(args[0]);
|
||||||
Calc calc = new Calc(reader);
|
Calc calc = new Calc(reader);
|
||||||
calc.setDebugLevel(1);
|
calc.setDebugLevel(1);
|
||||||
calc.parse();
|
calc.parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user