⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calc++-parser.cc

📁 GNU的词法/语法分析器bison源码
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* A Bison parser, made by GNU Bison 2.1.  *//* C++ Skeleton parser for LALR(1) parsing with Bison,   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2, or (at your option)   any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 51 Franklin Street, Fifth Floor,   Boston, MA 02110-1301, USA.  */#include "./calc++-parser.hh"#ifndef YY_# if YYENABLE_NLS#  if ENABLE_NLS#   include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */#   define YY_(msgid) dgettext ("bison-runtime", msgid)#  endif# endif# ifndef YY_#  define YY_(msgid) msgid# endif#endif/* A pseudo ostream that takes yydebug_ into account. */# define YYCDEBUG							\  for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false)	\    (*yycdebug_)/* Enable debugging if requested.  */#if YYDEBUG# define YY_SYMBOL_PRINT(Title, Type, Value, Location)	\do {							\  if (yydebug_)						\    {							\      *yycdebug_ << (Title) << ' ';			\      yysymprint_ ((Type), (Value), (Location));	\      *yycdebug_ << std::endl;				\    }							\} while (0)# define YY_REDUCE_PRINT(Rule)		\do {					\  if (yydebug_)				\    yyreduce_print_ (Rule);		\} while (0)# define YY_STACK_PRINT()		\do {					\  if (yydebug_)				\    yystack_print_ ();			\} while (0)#else /* !YYDEBUG */# define YY_SYMBOL_PRINT(Title, Type, Value, Location)# define YY_REDUCE_PRINT(Rule)# define YY_STACK_PRINT()#endif /* !YYDEBUG */#define YYACCEPT	goto yyacceptlab#define YYABORT		goto yyabortlab#define YYERROR		goto yyerrorlab#if YYERROR_VERBOSE/* Return YYSTR after stripping away unnecessary quotes and   backslashes, so that it's suitable for yyerror.  The heuristic is   that double-quoting is unnecessary unless the string contains an   apostrophe, a comma, or backslash (other than backslash-backslash).   YYSTR is taken from yytname.  */std::stringyy::calcxx_parser::yytnamerr_ (const char *yystr){  if (*yystr == '"')    {      std::string yyr = "";      char const *yyp = yystr;      for (;;)	switch (*++yyp)	  {	  case '\'':	  case ',':	    goto do_not_strip_quotes;	  case '\\':	    if (*++yyp != '\\')	      goto do_not_strip_quotes;	    /* Fall through.  */	  default:	    yyr += *yyp;	    break;	  case '"':	    return yyr;	  }    do_not_strip_quotes: ;    }  return yystr;}#endif#if YYDEBUG/*--------------------------------.| Print this symbol on YYOUTPUT.  |`--------------------------------*/voidyy::calcxx_parser::yysymprint_ (int yytype,                         const semantic_type* yyvaluep, const location_type* yylocationp){  /* Pacify ``unused variable'' warnings.  */  (void) yyvaluep;  (void) yylocationp;  /* Backward compatibility, but should be removed eventually. */  std::ostream& cdebug_ = *yycdebug_;  (void) cdebug_;  *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")	     << ' ' << yytname_[yytype] << " ("             << *yylocationp << ": ";  switch (yytype)    {      case 4: /* "\"identifier\"" */#line 7379 "../../doc/bison.texinfo"        { debug_stream () << *(yyvaluep->sval); };#line 144 "./calc++-parser.cc"        break;      case 5: /* "\"number\"" */#line 7382 "../../doc/bison.texinfo"        { debug_stream () << (yyvaluep->ival); };#line 149 "./calc++-parser.cc"        break;      case 6: /* "\"expression\"" */#line 7382 "../../doc/bison.texinfo"        { debug_stream () << (yyvaluep->ival); };#line 154 "./calc++-parser.cc"        break;      default:        break;    }  *yycdebug_ << ')';}#endif /* ! YYDEBUG */voidyy::calcxx_parser::yydestruct_ (const char* yymsg,                         int yytype, semantic_type* yyvaluep, location_type* yylocationp){  /* Pacify ``unused variable'' warnings.  */  (void) yymsg;  (void) yyvaluep;  (void) yylocationp;  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);  switch (yytype)    {      case 4: /* "\"identifier\"" */#line 7380 "../../doc/bison.texinfo"        { delete (yyvaluep->sval); };#line 179 "./calc++-parser.cc"        break;      default:        break;    }}voidyy::calcxx_parser::yypop_ (unsigned int n){  yystate_stack_.pop (n);  yysemantic_stack_.pop (n);  yylocation_stack_.pop (n);}std::ostream&yy::calcxx_parser::debug_stream () const{  return *yycdebug_;}voidyy::calcxx_parser::set_debug_stream (std::ostream& o){  yycdebug_ = &o;}yy::calcxx_parser::debug_level_typeyy::calcxx_parser::debug_level () const{  return yydebug_;}voidyy::calcxx_parser::set_debug_level (debug_level_type l){  yydebug_ = l;}intyy::calcxx_parser::parse (){  /* Look-ahead and look-ahead in internal form.  */  int yylooka;  int yyilooka;  /// Semantic value of the look-ahead.  semantic_type yylval;  /// Location of the look-ahead.  location_type yylloc;  /// The locations where the error started and ended.  location yyerror_range[2];  /// $$.  semantic_type yyval;  /// @$.  location_type yyloc;  int yyresult_;  YYCDEBUG << "Starting parse" << std::endl;  yynerrs_ = 0;  yyerrstatus_ = 0;  /* Start.  */  yystate_ = 0;  yylooka = yyempty_;  /* User initialization code. */  #line 7327 "../../doc/bison.texinfo"{  // Initialize the initial location.  yylloc.begin.filename = yylloc.end.filename = &driver.file;}/* Line 548 of yacc.c.  */#line 259 "./calc++-parser.cc"  /* Initialize the stacks.  The initial state will be pushed in     yynewstate, since the latter expects the semantical and the     location values to have been already stored, initialize these     stacks with a primary value.  */  yystate_stack_ = state_stack_type (0);  yysemantic_stack_ = semantic_stack_type (0);  yylocation_stack_ = location_stack_type (0);  yysemantic_stack_.push (yylval);  yylocation_stack_.push (yylloc);  /* New state.  */yynewstate:  yystate_stack_.push (yystate_);  YYCDEBUG << "Entering state " << yystate_ << std::endl;  goto yybackup;  /* Backup.  */yybackup:  /* Try to take a decision without look-ahead.  */  yyn_ = yypact_[yystate_];  if (yyn_ == yypact_ninf_)    goto yydefault;  /* Read a look-ahead token.  */  if (yylooka == yyempty_)    {      YYCDEBUG << "Reading a token: ";      yylooka = yylex (&yylval, &yylloc, driver);    }  /* Convert token to internal form.  */  if (yylooka <= yyeof_)    {      yylooka = yyilooka = yyeof_;      YYCDEBUG << "Now at end of input." << std::endl;    }  else    {      yyilooka = yytranslate_ (yylooka);      YY_SYMBOL_PRINT ("Next token is", yyilooka, &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)    goto yydefault;  /* Reduce or error.  */  yyn_ = yytable_[yyn_];  if (yyn_ < 0)    {      if (yyn_ == yytable_ninf_)	goto yyerrlab;      else	{	  yyn_ = -yyn_;	  goto yyreduce;	}    }  else if (yyn_ == 0)    goto yyerrlab;  /* Accept?  */  if (yyn_ == yyfinal_)    goto yyacceptlab;  /* Shift the look-ahead token.  */  YY_SYMBOL_PRINT ("Shifting", yyilooka, &yylval, &yylloc);  /* Discard the token being shifted unless it is eof.  */  if (yylooka != yyeof_)    yylooka = yyempty_;  yysemantic_stack_.push (yylval);  yylocation_stack_.push (yylloc);  /* Count tokens shifted since error; after three, turn off error     status.  */  if (yyerrstatus_)    --yyerrstatus_;  yystate_ = yyn_;  goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state.  |`-----------------------------------------------------------*/yydefault:  yyn_ = yydefact_[yystate_];  if (yyn_ == 0)    goto yyerrlab;  goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction.  |`-----------------------------*/yyreduce:  yylen_ = yyr2_[yyn_];  /* If LEN_ 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.     This behavior is undocumented and Bison     users should not rely upon it.  */  if (yylen_)    yyval = yysemantic_stack_[yylen_ - 1];  else    yyval = yysemantic_stack_[0];  {    slice<location_type, location_stack_type> slice (yylocation_stack_, yylen_);    YYLLOC_DEFAULT (yyloc, slice, yylen_);  }  YY_REDUCE_PRINT (yyn_);  switch (yyn_)    {        case 2:#line 7392 "../../doc/bison.texinfo"    { driver.result = (yysemantic_stack_[0].ival); ;}    break;  case 3:#line 7394 "../../doc/bison.texinfo"    {;}    break;  case 4:#line 7395 "../../doc/bison.texinfo"    {;}    break;  case 5:#line 7397 "../../doc/bison.texinfo"    { driver.variables[*(yysemantic_stack_[2].sval)] = (yysemantic_stack_[0].ival); ;}    break;  case 6:#line 7401 "../../doc/bison.texinfo"    { (yyval.ival) = (yysemantic_stack_[2].ival) + (yysemantic_stack_[0].ival); ;}    break;  case 7:#line 7402 "../../doc/bison.texinfo"    { (yyval.ival) = (yysemantic_stack_[2].ival) - (yysemantic_stack_[0].ival); ;}    break;  case 8:#line 7403 "../../doc/bison.texinfo"    { (yyval.ival) = (yysemantic_stack_[2].ival) * (yysemantic_stack_[0].ival); ;}    break;  case 9:#line 7404 "../../doc/bison.texinfo"    { (yyval.ival) = (yysemantic_stack_[2].ival) / (yysemantic_stack_[0].ival); ;}    break;  case 10:#line 7405 "../../doc/bison.texinfo"    { (yyval.ival) = driver.variables[*(yysemantic_stack_[0].sval)]; ;}    break;  case 11:#line 7406 "../../doc/bison.texinfo"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -