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

📄 lalr1.cc

📁 GNU的词法/语法分析器bison源码
💻 CC
📖 第 1 页 / 共 3 页
字号:
voidyy::]b4_parser_class_name[::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)    {]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[      default:        break;    }}voidyy::]b4_parser_class_name[::yypop_ (unsigned int n){  yystate_stack_.pop (n);  yysemantic_stack_.pop (n);  yylocation_stack_.pop (n);}std::ostream&yy::]b4_parser_class_name[::debug_stream () const{  return *yycdebug_;}voidyy::]b4_parser_class_name[::set_debug_stream (std::ostream& o){  yycdebug_ = &o;}yy::]b4_parser_class_name[::debug_level_typeyy::]b4_parser_class_name[::debug_level () const{  return yydebug_;}voidyy::]b4_parser_class_name[::set_debug_level (debug_level_type l){  yydebug_ = l;}intyy::]b4_parser_class_name[::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_;]m4_ifdef([b4_initial_action], [m4_pushdef([b4_at_dollar],     [yylloc])dnlm4_pushdef([b4_dollar_dollar], [yylval])dnl  /* User initialization code. */  b4_initial_actionm4_popdef([b4_dollar_dollar])dnlm4_popdef([b4_at_dollar])dnl/* Line __line__ of yacc.c.  */b4_syncline([@oline@], [@ofile@])])dnl[  /* 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 = ]b4_c_function_call([yylex], [int],[[YYSTYPE*], [&yylval]][]dnlb4_location_if([, [[location*], [&yylloc]]])dnlm4_ifdef([b4_lex_param], [, ]b4_lex_param))[;    }  /* 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_)    {      ]b4_actions[      default: break;    }]/* Line __line__ of lalr1.cc.  */b4_syncline([@oline@], [@ofile@])[  yypop_ (yylen_);  YY_STACK_PRINT ();  yysemantic_stack_.push (yyval);  yylocation_stack_.push (yyloc);  /* Shift the result of the reduction.  */  yyn_ = yyr1_[yyn_];  yystate_ = yypgoto_[yyn_ - yyntokens_] + yystate_stack_[0];  if (0 <= yystate_ && yystate_ <= yylast_      && yycheck_[yystate_] == yystate_stack_[0])    yystate_ = yytable_[yystate_];  else    yystate_ = yydefgoto_[yyn_ - yyntokens_];  goto yynewstate;/*------------------------------------.| yyerrlab -- here on detecting error |`------------------------------------*/yyerrlab:  /* If not already recovering from an error, report this error.  */  if (!yyerrstatus_)    {      ++yynerrs_;      error (yylloc, yysyntax_error_ (YYERROR_VERBOSE_IF (yyilooka)));    }  yyerror_range[0] = yylloc;  if (yyerrstatus_ == 3)    {      /* If just tried and failed to reuse look-ahead token after an	 error, discard it.  */      if (yylooka <= yyeof_)        {	  /* Return failure if at end of input.  */	  if (yylooka == yyeof_)	    YYABORT;        }      else        {          yydestruct_ ("Error: discarding", yyilooka, &yylval, &yylloc);          yylooka = yyempty_;        }    }  /* Else will try to reuse look-ahead token after shifting the error     token.  */  goto yyerrlab1;/*---------------------------------------------------.| yyerrorlab -- error raised explicitly by YYERROR.  |`---------------------------------------------------*/yyerrorlab:  /* Pacify compilers like GCC when the user code never invokes     YYERROR and the label yyerrorlab therefore never appears in user     code.  */  if (false)    goto yyerrorlab;  yyerror_range[0] = yylocation_stack_[yylen_ - 1];  yypop_ (yylen_);  yystate_ = yystate_stack_[0];  goto yyerrlab1;/*-------------------------------------------------------------.| yyerrlab1 -- common code for both syntax error and YYERROR.  |`-------------------------------------------------------------*/yyerrlab1:  yyerrstatus_ = 3;	/* Each real token shifted decrements this.  */  for (;;)    {      yyn_ = yypact_[yystate_];      if (yyn_ != yypact_ninf_)	{	  yyn_ += yyterror_;	  if (0 <= yyn_ && yyn_ <= yylast_ && yycheck_[yyn_] == yyterror_)	    {	      yyn_ = yytable_[yyn_];	      if (0 < yyn_)		break;	    }	}      /* Pop the current state because it cannot handle the error token.  */      if (yystate_stack_.height () == 1)	YYABORT;      yyerror_range[0] = yylocation_stack_[0];      yydestruct_ ("Error: popping",                   yystos_[yystate_],                   &yysemantic_stack_[0], &yylocation_stack_[0]);      yypop_ ();      yystate_ = yystate_stack_[0];      YY_STACK_PRINT ();    }  if (yyn_ == yyfinal_)    goto yyacceptlab;  yyerror_range[1] = yylloc;  // Using YYLLOC is tempting, but would change the location of  // the look-ahead.  YYLOC is available though.  YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);  yysemantic_stack_.push (yylval);  yylocation_stack_.push (yyloc);  /* Shift the error token. */  YY_SYMBOL_PRINT ("Shifting", yystos_[yyn_],		   &yysemantic_stack_[0], &yylocation_stack_[0]);  yystate_ = yyn_;  goto yynewstate;  /* Accept.  */yyacceptlab:  yyresult_ = 0;  goto yyreturn;  /* Abort.  */yyabortlab:  yyresult_ = 1;  goto yyreturn;yyreturn:  if (yylooka != yyeof_ && yylooka != yyempty_)    yydestruct_ ("Cleanup: discarding lookahead", yyilooka, &yylval, &yylloc);  while (yystate_stack_.height () != 1)    {      yydestruct_ ("Cleanup: popping",		   yystos_[yystate_stack_[0]],		   &yysemantic_stack_[0],		   &yylocation_stack_[0]);      yypop_ ();    }  return yyresult_;}// Generate an error message.std::stringyy::]b4_parser_class_name[::yysyntax_error_ (YYERROR_VERBOSE_IF (int tok)){  std::string res;#if YYERROR_VERBOSE  yyn_ = yypact_[yystate_];  if (yypact_ninf_ < yyn_ && yyn_ < yylast_)    {      /* Start YYX at -YYN if negative to avoid negative indexes in         YYCHECK.  */      int yyxbegin = yyn_ < 0 ? -yyn_ : 0;      /* Stay within bounds of both yycheck and yytname.  */      int yychecklim = yylast_ - yyn_;      int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;      int count = 0;      for (int x = yyxbegin; x < yyxend; ++x)        if (yycheck_[x + yyn_] == x && x != yyterror_)          ++count;      // FIXME: This method of building the message is not compatible      // with internationalization.  It should work like yacc.c does it.      // That is, first build a string that looks like this:      // "syntax error, unexpected %s or %s or %s"      // Then, invoke YY_ on this string.      // Finally, use the string as a format to output      // yytname_[tok], etc.      // Until this gets fixed, this message appears in English only.      res = "syntax error, unexpected ";      res += yytnamerr_ (yytname_[tok]);      if (count < 5)        {          count = 0;          for (int x = yyxbegin; x < yyxend; ++x)            if (yycheck_[x + yyn_] == x && x != yyterror_)              {                res += (!count++) ? ", expecting " : " or ";                res += yytnamerr_ (yytname_[x]);              }        }    }  else#endif    res = YY_("syntax error");  return res;}/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing   STATE-NUM.  */const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;const ]b4_int_type_for([b4_pact])[yy::]b4_parser_class_name[::yypact_[] ={  ]b4_pact[};/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE   doesn't specify something else to do.  Zero means the default is an   error.  */const ]b4_int_type_for([b4_defact])[yy::]b4_parser_class_name[::yydefact_[] ={  ]b4_defact[};/* YYPGOTO[NTERM-NUM].  */const ]b4_int_type_for([b4_pgoto])[yy::]b4_parser_class_name[::yypgoto_[] ={  ]b4_pgoto[};/* YYDEFGOTO[NTERM-NUM].  */const ]b4_int_type_for([b4_defgoto])[yy::]b4_parser_class_name[::yydefgoto_[] ={  ]b4_defgoto[};/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If   positive, shift that token.  If negative, reduce the rule which   number is the opposite.  If zero, do what YYDEFACT says.  */const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;const ]b4_int_type_for([b4_table])[yy::]b4_parser_class_name[::yytable_[] ={

⌨️ 快捷键说明

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