X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/dbcdae2d043dd79b31080d9c41a2ef2cab97b457..58b90cc2d82b068770bd38b5dff41e24a4bfeb37:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index be0a65ac..bc1bec12 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -19,95 +19,7 @@ m4_divert(-1) # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -## ---------------- ## -## Default values. ## -## ---------------- ## - -# Default parser class name. -m4_define_default([b4_parser_class_name], [parser]) - - - -## ----------------- ## -## Semantic Values. ## -## ----------------- ## - - -# b4_lhs_value([TYPE]) -# -------------------- -# Expansion of $$. -m4_define([b4_lhs_value], -[(yyval[]m4_ifval([$1], [.$1]))]) - - -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) -# -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. -m4_define([b4_rhs_value], -[(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))]) - -m4_define_default([b4_location_type], [location]) -m4_define_default([b4_filename_type], [std::string]) - -# b4_lhs_location() -# ----------------- -# Expansion of @$. -m4_define([b4_lhs_location], -[(yyloc)]) - - -# b4_rhs_location(RULE-LENGTH, NUM) -# --------------------------------- -# Expansion of @NUM, where the current rule has RULE-LENGTH symbols -# on RHS. -m4_define([b4_rhs_location], -[(yylocation_stack_@{m4_eval([$1 - $2])@})]) - - -# b4_parse_param_decl -# ------------------- -# Extra formal arguments of the constructor. -# Change the parameter names from "foo" into "foo_yyarg", so that -# there is no collision bw the user chosen attribute name, and the -# argument name in the constructor. -m4_define([b4_parse_param_decl], -[m4_ifset([b4_parse_param], - [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) - -m4_define([b4_parse_param_decl_1], -[$1_yyarg]) - - - -# b4_parse_param_cons -# ------------------- -# Extra initialisations of the constructor. -m4_define([b4_parse_param_cons], - [m4_ifset([b4_parse_param], - [, - b4_cc_constructor_calls(b4_parse_param)])]) -m4_define([b4_cc_constructor_calls], - [m4_map_sep([b4_cc_constructor_call], [, - ], [$@])]) -m4_define([b4_cc_constructor_call], - [$2 ($2_yyarg)]) - -# b4_parse_param_vars -# ------------------- -# Extra instance variables. -m4_define([b4_parse_param_vars], - [m4_ifset([b4_parse_param], - [ - /* User arguments. */ -b4_cc_var_decls(b4_parse_param)])]) -m4_define([b4_cc_var_decls], - [m4_map_sep([b4_cc_var_decl], [ -], [$@])]) -m4_define([b4_cc_var_decl], - [ $1;]) - - +m4_include(b4_pkgdatadir/[c++.m4]) # We do want M4 expansion after # for CPP macros. m4_changecom() @@ -133,7 +45,7 @@ namespace yy class location; } -]b4_token_defines(b4_tokens)[ +]b4_token_enums(b4_tokens)[ /* Copy the first part of user declarations. */ ]b4_pre_prologue[ @@ -157,6 +69,12 @@ b4_syncline([@oline@], [@ofile@])[ # define YYERROR_VERBOSE ]b4_error_verbose[ #endif +#if YYERROR_VERBOSE +# define YYERROR_VERBOSE_IF(x) x +#else +# define YYERROR_VERBOSE_IF(x) /* empty */ +#endif + /* Enabling the token table. */ #ifndef YYTOKEN_TABLE # define YYTOKEN_TABLE ]b4_token_table[ @@ -200,33 +118,14 @@ do { \ namespace yy { - class ]b4_parser_class_name[; - template - struct traits - { - }; - - template <> - struct traits<]b4_parser_class_name[> - { - typedef ]b4_int_type_for([b4_translate])[ token_number_type; - typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type; - typedef int state_type; - typedef YYSTYPE semantic_type; - typedef ]b4_location_type[ location_type; - }; -} - -namespace yy -{ /// A Bison parser. class ]b4_parser_class_name[ { /// Symbol semantic values. - typedef traits<]b4_parser_class_name[>::semantic_type semantic_type; + typedef YYSTYPE semantic_type; /// Symbol locations. - typedef traits<]b4_parser_class_name[>::location_type location_type; + typedef ]b4_location_type[ location_type; public: /// Build a parser object. @@ -264,7 +163,7 @@ namespace yy /// Generate an error message. /// \param tok the look-ahead token. - virtual std::string yysyntax_error_ (int tok); + virtual std::string yysyntax_error_ (YYERROR_VERBOSE_IF (int tok)); #if YYDEBUG /// \brief Report a symbol on the debug stream. @@ -278,7 +177,7 @@ namespace yy /// State numbers. - typedef traits<]b4_parser_class_name[>::state_type state_type; + typedef int state_type; /// State stack type. typedef stack state_stack_type; /// Semantic value stack type. @@ -294,7 +193,7 @@ namespace yy location_stack_type yylocation_stack_; /// Internal symbol numbers. - typedef traits<]b4_parser_class_name[>::token_number_type token_number_type; + typedef ]b4_int_type_for([b4_translate])[ token_number_type; /* Tables. */ /// For a state, the index in \a yytable_ of its portion. static const ]b4_int_type_for([b4_pact])[ yypact_[]; @@ -338,7 +237,7 @@ namespace yy #if YYDEBUG /// A type to store symbol numbers and -1. - typedef traits<]b4_parser_class_name[>::rhs_number_type rhs_number_type; + typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type; /// A `-1'-separated list of the rules' RHS. static const rhs_number_type yyrhs_[]; /// For each rule, the index of the first RHS symbol in \a yyrhs_. @@ -592,9 +491,9 @@ yy::]b4_parser_class_name[::set_debug_level (debug_level_type l) int yy::]b4_parser_class_name[::parse () { - /* Look-ahead and look-ahead in internal form. */ - int yylooka; - int yyilooka; + /// Look-ahead and look-ahead in internal form. + int yychar; + int yytoken; /// Semantic value of the look-ahead. semantic_type yylval; @@ -617,7 +516,7 @@ yy::]b4_parser_class_name[::parse () /* Start. */ yystate_ = 0; - yylooka = yyempty_; + yychar = yyempty_; ]m4_ifdef([b4_initial_action], [ m4_pushdef([b4_at_dollar], [yylloc])dnl @@ -654,10 +553,10 @@ yybackup: goto yydefault; /* Read a look-ahead token. */ - if (yylooka == yyempty_) + if (yychar == yyempty_) { YYCDEBUG << "Reading a token: "; - yylooka = ]b4_c_function_call([yylex], [int], + yychar = ]b4_c_function_call([yylex], [int], [[YYSTYPE*], [&yylval]][]dnl b4_location_if([, [[location*], [&yylloc]]])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; @@ -665,21 +564,21 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; /* Convert token to internal form. */ - if (yylooka <= yyeof_) + if (yychar <= yyeof_) { - yylooka = yyilooka = yyeof_; + yychar = yytoken = yyeof_; YYCDEBUG << "Now at end of input." << std::endl; } else { - yyilooka = yytranslate_ (yylooka); - YY_SYMBOL_PRINT ("Next token is", yyilooka, &yylval, &yylloc); + yytoken = yytranslate_ (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token ILOOKA_ is to reduce or to detect an error, take that action. */ - yyn_ += yyilooka; - if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yyilooka) + yyn_ += yytoken; + if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yytoken) goto yydefault; /* Reduce or error. */ @@ -702,11 +601,11 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; goto yyacceptlab; /* Shift the look-ahead token. */ - YY_SYMBOL_PRINT ("Shifting", yyilooka, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the token being shifted unless it is eof. */ - if (yylooka != yyeof_) - yylooka = yyempty_; + if (yychar != yyeof_) + yychar = yyempty_; yysemantic_stack_.push (yylval); yylocation_stack_.push (yylloc); @@ -783,7 +682,7 @@ yyerrlab: if (!yyerrstatus_) { ++yynerrs_; - error (yylloc, yysyntax_error_ (yyilooka)); + error (yylloc, yysyntax_error_ (YYERROR_VERBOSE_IF (yytoken))); } yyerror_range[0] = yylloc; @@ -792,16 +691,16 @@ yyerrlab: /* If just tried and failed to reuse look-ahead token after an error, discard it. */ - if (yylooka <= yyeof_) + if (yychar <= yyeof_) { /* Return failure if at end of input. */ - if (yylooka == yyeof_) + if (yychar == yyeof_) YYABORT; } else { - yydestruct_ ("Error: discarding", yyilooka, &yylval, &yylloc); - yylooka = yyempty_; + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; } } @@ -887,8 +786,8 @@ yyabortlab: goto yyreturn; yyreturn: - if (yylooka != yyeof_ && yylooka != yyempty_) - yydestruct_ ("Cleanup: discarding lookahead", yyilooka, &yylval, &yylloc); + if (yychar != yyeof_ && yychar != yyempty_) + yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); while (yystate_stack_.height () != 1) { @@ -904,7 +803,7 @@ yyreturn: // Generate an error message. std::string -yy::]b4_parser_class_name[::yysyntax_error_ (int tok) +yy::]b4_parser_class_name[::yysyntax_error_ (YYERROR_VERBOSE_IF (int tok)) { std::string res; #if YYERROR_VERBOSE