Generalize the display of semantic values and locations in traces.

* data/glr.c (yy_reduce_print): Fix indices (again).
* data/c++.m4 (b4_rhs_value, b4_rhs_location): Don't expect
literal integers.
* data/lalr1.cc (yyreduce_print): Rename as...
(yy_reduce_print): this.
Display values and locations.
* data/yacc.c (yy_reduce_print): Likewise.
(YY_REDUCE_PRINT): Adjust to pass the required arguments.
(yysymprint): Move higher to be visible from yy_reduce_print).
(yyparse): Adjust.
* tests/calc.at: Adjust the expected length of the traces.
This commit is contained in:
Akim Demaille
2005-11-16 14:20:48 +00:00
parent 6de5398de3
commit d1ff7a7cc6
6 changed files with 75 additions and 47 deletions

View File

@@ -1,3 +1,18 @@
2005-11-16 Akim Demaille <akim@epita.fr>
Generalize the display of semantic values and locations in traces.
* data/glr.c (yy_reduce_print): Fix indices (again).
* data/c++.m4 (b4_rhs_value, b4_rhs_location): Don't expect
literal integers.
* data/lalr1.cc (yyreduce_print): Rename as...
(yy_reduce_print): this.
Display values and locations.
* data/yacc.c (yy_reduce_print): Likewise.
(YY_REDUCE_PRINT): Adjust to pass the required arguments.
(yysymprint): Move higher to be visible from yy_reduce_print).
(yyparse): Adjust.
* tests/calc.at: Adjust the expected length of the traces.
2005-11-14 Akim Demaille <akim@epita.fr> 2005-11-14 Akim Demaille <akim@epita.fr>
* data/glr.c (yy_reduce_print): The loop was quite wrong: type are * data/glr.c (yy_reduce_print): The loop was quite wrong: type are

View File

@@ -61,7 +61,7 @@ m4_define([b4_lhs_value],
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS. # symbols on RHS.
m4_define([b4_rhs_value], m4_define([b4_rhs_value],
[(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))]) [(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
# b4_lhs_location() # b4_lhs_location()
# ----------------- # -----------------
@@ -75,7 +75,7 @@ m4_define([b4_lhs_location],
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS. # on RHS.
m4_define([b4_rhs_location], m4_define([b4_rhs_location],
[(yylocation_stack_@{m4_eval([$1 - $2])@})]) [(yylocation_stack_@{($1) - ($2)@})])
# b4_parse_param_decl # b4_parse_param_decl

View File

@@ -1387,8 +1387,8 @@ yy_reduce_print (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
{ {
fprintf (stderr, " $%d = ", yyi + 1); fprintf (stderr, " $%d = ", yyi + 1);
yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi], yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
&]b4_rhs_value(yynrhs, yyi - 1)[ &]b4_rhs_value(yynrhs, yyi + 1)[
]b4_location_if([, &]b4_rhs_location(yynrhs, yyi - 1))[]dnl ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
b4_user_args[); b4_user_args[);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }

View File

@@ -232,7 +232,7 @@ b4_error_verbose_if([, int tok])[);
/// For each scanner token number, its symbol number. /// For each scanner token number, its symbol number.
static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
/// Report on the debug stream that the rule \a r is going to be reduced. /// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yyreduce_print_ (int r); virtual void yy_reduce_print_ (int r);
/// Print the state stack on the debug stream. /// Print the state stack on the debug stream.
virtual void yystack_print_ (); virtual void yystack_print_ ();
#endif #endif
@@ -328,7 +328,7 @@ b4_syncline([@oline@], [@ofile@])[
do { \ do { \
if (yydebug_) \ if (yydebug_) \
{ \ { \
*yycdebug_ << (Title) << ' '; \ *yycdebug_ << Title << ' '; \
yysymprint_ ((Type), (Value), (Location)); \ yysymprint_ ((Type), (Value), (Location)); \
*yycdebug_ << std::endl; \ *yycdebug_ << std::endl; \
} \ } \
@@ -337,7 +337,7 @@ do { \
# define YY_REDUCE_PRINT(Rule) \ # define YY_REDUCE_PRINT(Rule) \
do { \ do { \
if (yydebug_) \ if (yydebug_) \
yyreduce_print_ (Rule); \ yy_reduce_print_ (Rule); \
} while (false) } while (false)
# define YY_STACK_PRINT() \ # define YY_STACK_PRINT() \
@@ -655,9 +655,9 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
]b4_actions[ ]b4_actions[
default: break; default: break;
} }
YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
]/* Line __line__ of lalr1.cc. */ /* Line __line__ of lalr1.cc. */
b4_syncline([@oline@], [@ofile@])[ ]b4_syncline([@oline@], [@ofile@])[
yypop_ (yylen); yypop_ (yylen);
@@ -981,16 +981,19 @@ b4_error_verbose_if([, int tok])[)
// Report on the debug stream that the rule \a yyrule is going to be reduced. // Report on the debug stream that the rule \a yyrule is going to be reduced.
void void
]b4_parser_class_name[::yyreduce_print_ (int yyrule) ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
{ {
unsigned int yylno = yyrline_[yyrule]; unsigned int yylno = yyrline_[yyrule];
int yynrhs = yyr2_[yyrule];
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
*yycdebug_ << "Reducing stack by rule " << yyrule - 1 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
<< " (line " << yylno << "), "; << " (line " << yylno << "), ";
for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule]; /* The symbols being reduced. */
0 <= yyrhs_[i]; ++i) for (int yyi = 0; yyi < yynrhs; yyi++)
*yycdebug_ << yytname_[yyrhs_[i]] << ' '; YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
*yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl; yyrhs_[yyprhs_[yyrule] + yyi],
&]b4_rhs_value(yynrhs, yyi + 1)[,
&]b4_rhs_location(yynrhs, yyi + 1)[);
} }
#endif // YYDEBUG #endif // YYDEBUG

View File

@@ -102,7 +102,7 @@ m4_define([b4_lhs_value],
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS. # symbols on RHS.
m4_define([b4_rhs_value], m4_define([b4_rhs_value],
[(yyvsp@{m4_eval([$2 - $1])@}m4_ifval([$3], [.$3]))]) [(yyvsp@{($2) - ($1)@}m4_ifval([$3], [.$3]))])
@@ -122,7 +122,7 @@ m4_define([b4_lhs_location],
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS. # on RHS.
m4_define([b4_rhs_location], m4_define([b4_rhs_location],
[(yylsp@{m4_eval([$2 - $1])@})]) [(yylsp@{($2) - ($1)@})])
@@ -639,6 +639,8 @@ do { \
} \ } \
} while (/*CONSTCOND*/ 0) } while (/*CONSTCOND*/ 0)
]b4_yysymprint_generate([b4_c_function_def])[
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its | | yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). | | TOP (included). |
@@ -666,22 +668,32 @@ do { \
`------------------------------------------------*/ `------------------------------------------------*/
]b4_c_function_def([yy_reduce_print], [static void], ]b4_c_function_def([yy_reduce_print], [static void],
[[int yyrule], [yyrule]])[ [[YYSTYPE *yyvsp], [yyvsvp]],
b4_location_if([[[YYLTYPE *yylsp], [yyvlvp]],])
[[int yyrule], [yyrule]]
b4_parse_param)[
{ {
int yynrhs = yyr2[yyrule];
int yyi; int yyi;
unsigned long int yylno = yyrline[yyrule]; unsigned long int yylno = yyrline[yyrule];
YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ", YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
yyrule - 1, yylno); yyrule - 1, yylno);
/* Print the symbols being reduced, and their result. */ /* The symbols being reduced. */
for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) for (yyi = 0; yyi < yynrhs; yyi++)
YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); {
YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]); fprintf (stderr, " $%d = ", yyi + 1);
yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
&]b4_rhs_value(yynrhs, yyi + 1)[
]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
b4_user_args[);
fprintf (stderr, "\n");
}
} }
# define YY_REDUCE_PRINT(Rule) \ # define YY_REDUCE_PRINT(Args) \
do { \ do { \
if (yydebug) \ if (yydebug) \
yy_reduce_print (Rule); \ yy_reduce_print (yyvsp, ]b4_location_if([yylsp, ])[Args); \
} while (/*CONSTCOND*/ 0) } while (/*CONSTCOND*/ 0)
/* Nonzero means print parse trace. It is left uninitialized so that /* Nonzero means print parse trace. It is left uninitialized so that
@@ -691,7 +703,7 @@ int yydebug;
# define YYDPRINTF(Args) # define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top) # define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule) # define YY_REDUCE_PRINT(Args)
#endif /* !YYDEBUG */ #endif /* !YYDEBUG */
@@ -922,10 +934,7 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#endif /* YYERROR_VERBOSE */ #endif /* YYERROR_VERBOSE */
#if YYDEBUG ]b4_yydestruct_generate([b4_c_function_def])[
]b4_yysymprint_generate([b4_c_function_def])[
#endif /* ! YYDEBUG */
]b4_yydestruct_generate([b4_c_function_def])
/* Prevent warnings from -Wmissing-prototypes. */ /* Prevent warnings from -Wmissing-prototypes. */
@@ -937,11 +946,11 @@ int yyparse (void *YYPARSE_PARAM);
int yyparse (); int yyparse ();
# endif # endif
#else /* ! YYPARSE_PARAM */ #else /* ! YYPARSE_PARAM */
b4_c_function_decl([yyparse], [int], b4_parse_param) ]b4_c_function_decl([yyparse], [int], b4_parse_param)[
#endif /* ! YYPARSE_PARAM */ #endif /* ! YYPARSE_PARAM */
m4_divert_push([KILL])# ======================== M4 code. ]m4_divert_push([KILL])# ======================== M4 code.
# b4_declare_parser_variables # b4_declare_parser_variables
# --------------------------- # ---------------------------
# Declare the variables that are global, or local to YYPARSE if # Declare the variables that are global, or local to YYPARSE if
@@ -1252,17 +1261,18 @@ yyreduce:
]b4_location_if( ]b4_location_if(
[[ /* Default location. */ [[ /* Default location. */
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[ YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
YY_REDUCE_PRINT (yyn); YY_REDUCE_PRINT ((yyn]b4_user_args[));
switch (yyn) switch (yyn)
]{ {
b4_actions ]b4_actions[
default: break; default: break;
} }
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
/* Line __line__ of yacc.c. */ /* Line __line__ of yacc.c. */
b4_syncline([@oline@], [@ofile@]) ]b4_syncline([@oline@], [@ofile@])[
[ yyvsp -= yylen; yyvsp -= yylen;
yyssp -= yylen; yyssp -= yylen;
]b4_location_if([ yylsp -= yylen;])[ ]b4_location_if([ yylsp -= yylen;])[

View File

@@ -465,21 +465,21 @@ _AT_CHECK_CALC([$1],
2^2^3 = 256 2^2^3 = 256
(2^2)^3 = 64], (2^2)^3 = 64],
[571]) [842])
# Some syntax errors. # Some syntax errors.
_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [13], _AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15],
[1.2: syntax error, unexpected number]) [1.2: syntax error, unexpected number])
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [18], _AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
[1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!']) [1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
_AT_CHECK_CALC_ERROR([$1], [1], [error], [5], _AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
[1.0: syntax error, unexpected $undefined]) [1.0: syntax error, unexpected $undefined])
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [26], _AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
[1.6: syntax error, unexpected '=']) [1.6: syntax error, unexpected '='])
_AT_CHECK_CALC_ERROR([$1], [1], _AT_CHECK_CALC_ERROR([$1], [1],
[ [
+1], +1],
[16], [20],
[2.0: syntax error, unexpected '+']) [2.0: syntax error, unexpected '+'])
# Exercise error messages with EOF: work on an empty file. # Exercise error messages with EOF: work on an empty file.
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4], _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
@@ -503,7 +503,7 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
# #
_AT_CHECK_CALC_ERROR([$1], [0], _AT_CHECK_CALC_ERROR([$1], [0],
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1], [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
[189], [250],
[1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' [1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
@@ -512,10 +512,10 @@ calc: error: 4444 != 1])
# The same, but this time exercising explicitly triggered syntax errors. # The same, but this time exercising explicitly triggered syntax errors.
# POSIX says the look-ahead causing the error should not be discarded. # POSIX says the look-ahead causing the error should not be discarded.
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [76], _AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
[1.9: syntax error, unexpected number [1.9: syntax error, unexpected number
calc: error: 2222 != 1]) calc: error: 2222 != 1])
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [86], _AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113],
[1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' [1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
1.11: syntax error, unexpected number 1.11: syntax error, unexpected number
calc: error: 2222 != 1]) calc: error: 2222 != 1])