X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/e757bb10bc149bd325ff935f8fb7454bd4c7a02a..ecfe33e7994d81620b332715d39ae35de7264e8b:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index e13965c6..74db24cf 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -115,42 +115,6 @@ m4_define([b4_cc_var_decl], [ $1;]) -# b4_yysymprint_generate(FUNCTION-DECLARATOR) -# ------------------------------------------- -# Generate the "symprint_" member function. -m4_define([b4_yysymprint_generate], -[[/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -]void -yy::b4_parser_class_name::symprint_ (int yytype, const SemanticType *yyvaluep, const LocationType *yylocationp)[ -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - (void) yylocationp; - - cdebug_ << (yytype < ntokens_ ? "token" : "nterm") - << ' ' << name_[yytype] << " ("; - switch (yytype) - { -]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl -[ default: - break; - } - cdebug_ << ')'; -} -]]) - - -# b4_cxx_destruct_def(IGNORED-ARGUMENTS) -# -------------------------------------- -# Declare the destruct_ method. -m4_define([b4_cxx_destruct_def], -[void -yy::b4_parser_class_name::destruct_ (int yytype, SemanticType *yyvaluep, LocationType *yylocationp)[]dnl -]) - # We do want M4 expansion after # for CPP macros. m4_changecom() @@ -316,8 +280,12 @@ namespace yy /* Even more tables. */ inline TokenNumberType translate_ (int token); - inline void destruct_ (int yytype, SemanticType *yyvaluep, - LocationType *yylocationp); + inline void destruct_ (const char *yymsg, + int yytype, + SemanticType *yyvaluep, LocationType *yylocationp); + + /// Pop \a n symbols the three stacks. + inline void pop (unsigned int n = 1); /* Constants. */ static const int eof_; @@ -419,9 +387,56 @@ do { \ #define YYERROR goto yyerrorlab #if YYDEBUG -]b4_yysymprint_generate([b4_cxx_symprint_def])[ +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +void +yy::]b4_parser_class_name[::symprint_ (int yytype, + const SemanticType *yyvaluep, const LocationType *yylocationp) +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + (void) yylocationp; + + cdebug_ << (yytype < ntokens_ ? "token" : "nterm") + << ' ' << name_[yytype] << " (" + << *yylocationp << ": "; + switch (yytype) + { +]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl +[ default: + break; + } + cdebug_ << ')'; +} #endif /* ! YYDEBUG */ -]b4_yydestruct_generate([b4_cxx_destruct_def])[ + +void +yy::]b4_parser_class_name[::destruct_ (const char *yymsg, + int yytype, SemanticType *yyvaluep, LocationType *yylocationp) +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + (void) yylocationp; + + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { +]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ + default: + break; + } +} + +void +yy::]b4_parser_class_name[::pop (unsigned int n) +{ + state_stack_.pop (n); + semantic_stack_.pop (n); + location_stack_.pop (n); +} int yy::]b4_parser_class_name[::parse () @@ -446,13 +461,13 @@ yy::]b4_parser_class_name[::parse () YYCDEBUG << "Starting parse" << std::endl; /* New state. */ - yynewstate: +yynewstate: state_stack_.push (state_); YYCDEBUG << "Entering state " << state_ << std::endl; goto yybackup; /* Backup. */ - yybackup: +yybackup: /* Try to take a decision without look-ahead. */ n_ = pact_[state_]; @@ -504,10 +519,7 @@ yy::]b4_parser_class_name[::parse () goto yyacceptlab; /* Shift the look-ahead token. */ -#if YYDEBUG - YYCDEBUG << "Shifting token " << looka_ - << " (" << name_[ilooka_] << "), "; -#endif + YY_SYMBOL_PRINT ("Shifting", ilooka_, &value, &location); /* Discard the token being shifted unless it is eof. */ if (looka_ != eof_) @@ -527,7 +539,7 @@ yy::]b4_parser_class_name[::parse () /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ - yydefault: +yydefault: n_ = defact_[state_]; if (n_ == 0) goto yyerrlab; @@ -536,7 +548,7 @@ yy::]b4_parser_class_name[::parse () /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ - yyreduce: +yyreduce: len_ = r2_[n_]; /* If LEN_ is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, use the top of the stack. @@ -569,9 +581,7 @@ yy::]b4_parser_class_name[::parse () ]/* Line __line__ of lalr1.cc. */ b4_syncline([@oline@], [@ofile@])[ - state_stack_.pop (len_); - semantic_stack_.pop (len_); - location_stack_.pop (len_); + pop (len_); YY_STACK_PRINT (); @@ -609,24 +619,18 @@ yyerrlab: for (;;) { error_start_ = location_stack_[0].begin; - state_stack_.pop (); - semantic_stack_.pop (); - location_stack_.pop (); + pop (); if (state_stack_.height () == 1) YYABORT; - YY_SYMBOL_PRINT ("Error: popping", - stos_[state_stack_[0]], - &semantic_stack_[0], - &location_stack_[0]); - destruct_ (stos_[state_stack_[0]], + destruct_ ("Error: popping", + stos_[state_stack_[0]], &semantic_stack_[0], &location_stack_[0]); } } else { - YY_SYMBOL_PRINT ("Error: discarding", ilooka_, &value, &location); - destruct_ (ilooka_, &value, &location); + destruct_ ("Error: discarding", ilooka_, &value, &location); looka_ = empty_; } } @@ -648,10 +652,8 @@ yyerrorlab: goto yyerrorlab; #endif - state_stack_.pop (len_); - semantic_stack_.pop (len_); error_start_ = location_stack_[len_ - 1].begin; - location_stack_.pop (len_); + pop (len_); state_ = state_stack_[0]; goto yyerrlab1; @@ -679,15 +681,11 @@ yyerrlab1: if (state_stack_.height () == 1) YYABORT; - YY_SYMBOL_PRINT ("Error: popping", - stos_[state_], - &semantic_stack_[0], &location_stack_[0]); - destruct_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]); + destruct_ ("Error: popping", + stos_[state_], &semantic_stack_[0], &location_stack_[0]); error_start_ = location_stack_[0].begin; - state_stack_.pop (); - semantic_stack_.pop (); - location_stack_.pop (); + pop (); state_ = state_stack_[0]; YY_STACK_PRINT (); } @@ -695,8 +693,6 @@ yyerrlab1: if (n_ == final_) goto yyacceptlab; - YYCDEBUG << "Shifting error token, "; - { Location errloc; errloc.begin = error_start_; @@ -705,6 +701,10 @@ yyerrlab1: location_stack_.push (errloc); } + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", stos_[n_], + &semantic_stack_[0], &location_stack_[0]); + state_ = n_; goto yynewstate; @@ -715,8 +715,7 @@ yyacceptlab: /* Abort. */ yyabortlab: /* Free the lookahead. */ - YY_SYMBOL_PRINT ("Error: discarding lookahead", ilooka_, &value, &location); - destruct_ (ilooka_, &value, &location); + destruct_ ("Error: discarding lookahead", ilooka_, &value, &location); looka_ = empty_; return 1; } @@ -890,8 +889,8 @@ yy::]b4_parser_class_name[::rline_[] = void yy::]b4_parser_class_name[::stack_print_ () { - cdebug_ << "state stack now"; - for (StateStack::ConstIterator i = state_stack_.begin (); + cdebug_ << "Stack now"; + for (StateStack::const_iterator i = state_stack_.begin (); i != state_stack_.end (); ++i) cdebug_ << ' ' << *i; cdebug_ << std::endl; @@ -904,7 +903,7 @@ yy::]b4_parser_class_name[::reduce_print_ (int yyrule) { unsigned int yylno = rline_[yyrule]; /* Print the symbols being reduced, and their result. */ - cdebug_ << "Reducing via rule " << n_ - 1 << " (line " << yylno << "), "; + cdebug_ << "Reducing stack by rule " << n_ - 1 << " (line " << yylno << "), "; for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; 0 <= rhs_[i]; ++i) cdebug_ << name_[rhs_[i]] << ' '; @@ -957,8 +956,9 @@ namespace yy { public: - typedef typename S::iterator Iterator; - typedef typename S::const_iterator ConstIterator; + // Hide our reversed order. + typedef typename S::reverse_iterator iterator; + typedef typename S::const_reverse_iterator const_iterator; Stack () : seq_ () { @@ -1004,8 +1004,8 @@ namespace yy return seq_.size (); } - inline ConstIterator begin () const { return seq_.begin (); } - inline ConstIterator end () const { return seq_.end (); } + inline const_iterator begin () const { return seq_.rbegin (); } + inline const_iterator end () const { return seq_.rend (); } private: