X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/4626a15dd155e1895262c48945a1c2b1d79b481f..4517da37570b39a3d4b3f523dd373abe7c622bb0:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index 1073e8d2..94fc9183 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -33,6 +33,8 @@ b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], [2002, 2003, 2004, 2005]) dnl FIXME: This is wrong, we want computed header guards. [ +/* C++ LALR(1) parser skeleton written by Akim Demaille. */ + #ifndef PARSER_HEADER_H # define PARSER_HEADER_H @@ -151,13 +153,20 @@ b4_syncline([@oline@], [@ofile@])], b4_error_verbose_if([, int tok])[); #if YYDEBUG + /// \brief Report a symbol value on the debug stream. + /// \param yytype The token type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + virtual void yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); /// \brief Report a symbol on the debug stream. /// \param yytype The token type. /// \param yyvaluep Its semantic value. /// \param yylocationp Its location. - virtual void yysymprint_ (int yytype, - const semantic_type* yyvaluep, - const location_type* yylocationp); + virtual void yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); #endif /* ! YYDEBUG */ @@ -232,7 +241,7 @@ b4_error_verbose_if([, int tok])[); /// For each scanner token number, its symbol 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. - virtual void yyreduce_print_ (int r); + virtual void yy_reduce_print_ (int r); /// Print the state stack on the debug stream. virtual void yystack_print_ (); #endif @@ -278,7 +287,7 @@ b4_error_verbose_if([, int tok])[); [b4_token_defines(b4_tokens) #ifndef YYSTYPE - /* Redirection for backward compatibility. */ + /* Redirection for backward compatibility. */ # define YYSTYPE yy::b4_parser_class_name::semantic_type #endif ])[ @@ -314,9 +323,9 @@ b4_syncline([@oline@], [@ofile@])[ #endif /* Suppress unused-variable warnings by "using" E. */ -#define YYUSE(e) do {;} while (false && (e)) +#define YYUSE(e) ((void) (e)) -/* A pseudo ostream that takes yydebug_ into account. */ +/* A pseudo ostream that takes yydebug_ into account. */ # define YYCDEBUG \ for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ (*yycdebug_) @@ -328,8 +337,8 @@ b4_syncline([@oline@], [@ofile@])[ do { \ if (yydebug_) \ { \ - *yycdebug_ << (Title) << ' '; \ - yysymprint_ ((Type), (Value), (Location)); \ + *yycdebug_ << Title << ' '; \ + yy_symbol_print_ ((Type), (Value), (Location)); \ *yycdebug_ << std::endl; \ } \ } while (false) @@ -337,7 +346,7 @@ do { \ # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug_) \ - yyreduce_print_ (Rule); \ + yy_reduce_print_ (Rule); \ } while (false) # define YY_STACK_PRINT() \ @@ -417,26 +426,29 @@ namespace yy | Print this symbol on YYOUTPUT. | `--------------------------------*/ - void - ]b4_parser_class_name[::yysymprint_ (int yytype, + inline void + ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype, const semantic_type* yyvaluep, const location_type* yylocationp) { - /* Backward compatibility, but should be removed eventually. */ - std::ostream& cdebug_ = *yycdebug_; - - YYUSE (!&cdebug_); YYUSE (yylocationp); YYUSE (yyvaluep); - - *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " (" - << *yylocationp << ": "; switch (yytype) { ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl [ default: break; } + } + + + void + ]b4_parser_class_name[::yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") + << ' ' << yytname_[yytype] << " (" + << *yylocationp << ": "; + yy_symbol_value_print_ (yytype, yyvaluep, yylocationp); *yycdebug_ << ')'; } #endif /* ! YYDEBUG */ @@ -502,10 +514,10 @@ namespace yy /* State. */ int yyn; - int yylen; + int yylen = 0; int yystate = 0; - /* Error handling. */ + /* Error handling. */ int yynerrs_ = 0; int yyerrstatus_ = 0; @@ -528,7 +540,7 @@ namespace yy ]m4_ifdef([b4_initial_action], [ m4_pushdef([b4_at_dollar], [yylloc])dnl m4_pushdef([b4_dollar_dollar], [yylval])dnl - /* User initialization code. */ + /* User initialization code. */ b4_initial_action m4_popdef([b4_dollar_dollar])dnl m4_popdef([b4_at_dollar])dnl @@ -634,7 +646,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; `-----------------------------*/ yyreduce: yylen = yyr2_[yyn]; - /* If LEN_ 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. Otherwise, the following line sets YYVAL to garbage. @@ -652,15 +664,15 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; YY_REDUCE_PRINT (yyn); switch (yyn) { - ]b4_actions[ + ]b4_actions + /* Line __line__ of lalr1.cc. */ +b4_syncline([@oline@], [@ofile@])[ default: break; } - - ]/* Line __line__ of lalr1.cc. */ - b4_syncline([@oline@], [@ofile@])[ + YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); yypop_ (yylen); - + yylen = 0; YY_STACK_PRINT (); yysemantic_stack_.push (yyval); @@ -724,7 +736,10 @@ b4_error_verbose_if([, yytoken])[)); goto yyerrorlab; yyerror_range[0] = yylocation_stack_[yylen - 1]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ yypop_ (yylen); + yylen = 0; yystate = yystate_stack_[0]; goto yyerrlab1; @@ -771,7 +786,7 @@ b4_error_verbose_if([, yytoken])[)); yysemantic_stack_.push (yylval); yylocation_stack_.push (yyloc); - /* Shift the error token. */ + /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], &yysemantic_stack_[0], &yylocation_stack_[0]); @@ -792,6 +807,9 @@ b4_error_verbose_if([, yytoken])[)); if (yychar != yyeof_ && yychar != yyempty_) yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); while (yystate_stack_.height () != 1) { yydestruct_ ("Cleanup: popping", @@ -937,7 +955,7 @@ b4_error_verbose_if([, int tok])[) #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at \a yyntokens_, nonterminals. */ + First, the terminals, then, starting at \a yyntokens_, nonterminals. */ const char* const ]b4_parser_class_name[::yytname_[] = { @@ -946,7 +964,7 @@ b4_error_verbose_if([, int tok])[) #endif #if YYDEBUG - /* YYRHS -- A `-1'-separated list of the rules' RHS. */ + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ const ]b4_parser_class_name[::rhs_number_type ]b4_parser_class_name[::yyrhs_[] = { @@ -981,16 +999,19 @@ b4_error_verbose_if([, int tok])[) // Report on the debug stream that the rule \a yyrule is going to be reduced. void - ]b4_parser_class_name[::yyreduce_print_ (int yyrule) + ]b4_parser_class_name[::yy_reduce_print_ (int yyrule) { unsigned int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; /* Print the symbols being reduced, and their result. */ *yycdebug_ << "Reducing stack by rule " << yyrule - 1 << " (line " << yylno << "), "; - for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule]; - 0 <= yyrhs_[i]; ++i) - *yycdebug_ << yytname_[yyrhs_[i]] << ' '; - *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl; + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + yyrhs_[yyprhs_[yyrule] + yyi], + &]b4_rhs_value(yynrhs, yyi + 1)[, + &]b4_rhs_location(yynrhs, yyi + 1)[); } #endif // YYDEBUG