X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/fc049e9cafa1322aa5cb1d7d64ad61ab2a41dd59..0d1c3a04b76293183f5b1a1dcd3ac99e71de66c6:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index c0403fbc..14864220 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -21,9 +21,6 @@ m4_divert(-1) ## Default values. ## ## ---------------- ## -# Stack parameters. -m4_define_default([b4_stack_depth_init], [200]) - # Default Parser class name. m4_define_default([b4_parser_class_name], [Parser]) @@ -140,8 +137,7 @@ b4_syncline([@oline@], [@ofile@])], b4_syncline([@oline@], [@ofile@])[ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; + Current.end = Rhs[N].end; #endif namespace yy @@ -249,7 +245,6 @@ namespace yy static const int terror_; static const int errcode_; static const int ntokens_; - static const int initdepth_; static const unsigned user_token_number_max_; static const TokenNumberType undef_token_; @@ -297,6 +292,11 @@ m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ # define YYCDEBUG if (0) cdebug_ #endif /* !YYDEBUG */ +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 + + int yy::]b4_parser_class_name[::parse () { @@ -429,8 +429,11 @@ yy::]b4_parser_class_name[::parse () #if YYDEBUG if (debug_) { + // Short files will use "unsigned char" for line numbers, + // in which case they will be output as character litterals + // by "<<". YYCDEBUG << "Reducing via rule " << n_ - 1 - << " (line " << rline_[n_] << "), "; + << " (line " << static_cast (rline_[n_]) << "), "; for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; 0 <= rhs_[i]; ++i) YYCDEBUG << name_[rhs_[i]] << ' '; @@ -516,7 +519,10 @@ b4_syncline([@oline@], [@ofile@])[ } goto yyerrlab1; - /* Error raised explicitly by an action. */ + + /*----------------------------------------------------. + | yyerrlab1 -- error raised explicitly by an action. | + `----------------------------------------------------*/ yyerrlab1: if (errstatus == 3) { @@ -526,8 +532,10 @@ b4_syncline([@oline@], [@ofile@])[ /* Return failure if at end of input. */ if (looka_ == eof_) goto yyabortlab; +#if YYDEBUG YYCDEBUG << "Discarding token " << looka_ - << " (" << name_[ilooka_] << ")." << std::endl; + << " (" << name_[ilooka_] << ")." << std::endl; +#endif looka_ = empty_; } @@ -761,7 +769,6 @@ const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[; const int yy::]b4_parser_class_name[::terror_ = 1; const int yy::]b4_parser_class_name[::errcode_ = 256; const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[; -const int yy::]b4_parser_class_name[::initdepth_ = ]b4_stack_depth_init[; const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[; const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[; @@ -769,7 +776,7 @@ const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::un ]b4_epilogue dnl @output stack.hh -b4_copyright([2002, 2003])[ +b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[ #ifndef BISON_STACK_HH # define BISON_STACK_HH @@ -866,24 +873,69 @@ namespace yy #endif // not BISON_STACK_HH] dnl @output location.hh -b4_copyright([2002, 2003])[ +b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[ #ifndef BISON_LOCATION_HH # define BISON_LOCATION_HH +# include +# include + namespace yy { - struct Position + class Position { + public: + Position () + : filename (), line (1), column (0) + {} + + std::string filename; int line; int column; }; - struct Location + inline std::ostream& + operator<< (std::ostream& ostr, const Position& pos) { - Position first; - Position last; + if (pos.filename != "") + ostr << pos.filename << ':'; + ostr << pos.line << '.' << pos.column; + return ostr; + } + + inline Position + operator- (const Position& pos, int col) + { + Position res (pos); + res.column -= col; + return res; + } + + + class Location + { + public: + Position begin; + Position end; }; + + /* Don't issue twice the line number when the location is on a single + line. */ + + inline std::ostream& + operator<< (std::ostream& ostr, const Location& pos) + { + ostr << pos.begin; + if (pos.begin.filename != pos.end.filename) + ostr << '-' << pos.end - 1; + else if (pos.begin.line != pos.end.line) + ostr << '-' << pos.end.line << '.' << pos.end.column - 1; + else if (pos.begin.column != pos.end.column - 1) + ostr << '-' << pos.end.column - 1; + return ostr; + } + } #endif // not BISON_LOCATION_HH]