From: Akim Demaille Date: Mon, 25 Aug 2003 08:29:27 +0000 (+0000) Subject: * data/lalr1.cc (Parser::reduce_print_): New. X-Git-Tag: BISON-2_0~217 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/5348bfbe2923560fe0e03a486466a738a392626c * data/lalr1.cc (Parser::reduce_print_): New. Use it. --- diff --git a/ChangeLog b/ChangeLog index 2596b4b3..a59c0ca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-08-25 Akim Demaille + + * data/lalr1.cc (Parser::reduce_print_): New. + Use it. + 2003-08-25 Akim Demaille Have lalr1.cc catch with Paul Eggert's patch to fix the infinite diff --git a/data/lalr1.cc b/data/lalr1.cc index 1d7b2431..cb1274d6 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -263,6 +263,7 @@ namespace yy static const ]b4_int_type_for([b4_rline])[ rline_[]; static const ]b4_int_type_for([b4_stos])[ stos_[]; static const ]b4_int_type_for([b4_toknum])[ token_number_[]; + virtual void reduce_print_ (int yyrule); #endif /* Even more tables. */ @@ -322,8 +323,14 @@ m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ /* Enable debugging if requested. */ #if YYDEBUG # define YYCDEBUG if (debug_) cdebug_ +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (debug_) \ + reduce_print_ (Rule); \ +} while (0) #else /* !YYDEBUG */ # define YYCDEBUG if (0) cdebug_ +# define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ #define YYACCEPT goto yyacceptlab @@ -472,28 +479,12 @@ yy::]b4_parser_class_name[::parse () yyloc = location_stack_[0]; } -#if YYDEBUG - if (debug_) - { - // Short files will use "unsigned char" for line numbers, - // in which case they will be output as character litterals - // by "<<". - unsigned yylno = rline_[n_]; - YYCDEBUG << "Reducing via rule " << n_ - 1 - << " (line " << yylno << "), "; - for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; - 0 <= rhs_[i]; ++i) - YYCDEBUG << name_[rhs_[i]] << ' '; - YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl; - } -#endif - if (len_) { Slice< LocationType, LocationStack > slice (location_stack_, len_); YYLLOC_DEFAULT (yyloc, slice, len_); } - + YY_REDUCE_PRINT (n_); switch (n_) { ]b4_actions[ @@ -715,6 +706,7 @@ yy::]b4_parser_class_name[::lex_ () #endif } + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[; @@ -828,7 +820,22 @@ yy::]b4_parser_class_name[::rline_[] = { ]b4_rline[ }; -#endif + +/** Report that the YYRULE is going to be reduced. */ + +void +yy::]b4_parser_class_name[::reduce_print_ (int yyrule) +{ + int yyi; + unsigned int yylno = rline_[yyrule]; + /* Print the symbols being reduced, and their result. */ + cdebug_ << "Reducing via rule " << n_ - 1 << " (line " << yylno << "), "; + for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; + 0 <= rhs_[i]; ++i) + cdebug_ << name_[rhs_[i]] << ' '; + cdebug_ << "-> " << name_[r1_[n_]] << std::endl; +} +#endif // YYDEBUG /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ yy::]b4_parser_class_name[::TokenNumberType diff --git a/data/yacc.c b/data/yacc.c index 92c0ddec..845077eb 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -556,7 +556,7 @@ do { \ /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (cinluded). | +| TOP (included). | `------------------------------------------------------------------*/ ]b4_c_function_def([yy_stack_print], [static void],