lalr1.cc

来自「bison 2.0 主要可以用来做语法分析用的」· CC 代码 · 共 1,373 行 · 第 1/3 页

CC
1,373
字号
#if YYDEBUG/*--------------------------------.| Print this symbol on YYOUTPUT.  |`--------------------------------*/voidyy::]b4_parser_class_name[::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")	     << ' ' << yyname_[yytype] << " ("             << *yylocationp << ": ";  switch (yytype)    {]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl[      default:        break;    }  *yycdebug_ << ')';}#endif /* ! YYDEBUG */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 (){  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_)    yylex_ ();  /* 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[    }]/* 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.  */  yyreport_syntax_error_ ();  yyerror_range_[0] = yylloc;  if (yyerrstatus_ == 3)    {      /* If just tried and failed to reuse look-ahead token after an	 error, discard it.  */      /* Return failure if at end of input.  */      if (yylooka_ <= yyeof_)        {          /* If at end of input, pop the error token,	     then the rest of the stack, then return failure.  */	  if (yylooka_ == yyeof_)	     for (;;)	       {                 yyerror_range_[0] = yylocation_stack_[0];                 yypop_ ();		 if (yystate_stack_.height () == 1)		   YYABORT;                 yydestruct_ ("Error: popping",                              yystos_[yystate_stack_[0]],                              &yysemantic_stack_[0],                              &yylocation_stack_[0]);	       }        }      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:#ifdef __GNUC__  /* Pacify GCC when the user code never invokes YYERROR and the label     yyerrorlab therefore never appears in user code.  */  if (0)     goto yyerrorlab;#endif  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:  return 0;  /* Abort.  */yyabortlab:  /* Free the lookahead. */  yydestruct_ ("Error: discarding lookahead", yyilooka_, &yylval, &yylloc);  yylooka_ = yyempty_;  return 1;}voidyy::]b4_parser_class_name[::yylex_ (){  YYCDEBUG << "Reading a token: ";#if YYLSP_NEEDED  yylooka_ = yylex (&yylval, &yylloc);#else  yylooka_ = yylex (&yylval);#endif}// Generate an error message, and invoke error.voidyy::]b4_parser_class_name[::yyreport_syntax_error_ (){  /* If not already recovering from an error, report this error.  */  if (!yyerrstatus_)    {      ++yynerrs_;      std::string message;#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;	  message = "syntax error, unexpected ";	  message += yyname_[yyilooka_];          if (count < 5)            {              count = 0;              for (int x = yyxbegin; x < yyxend; ++x)                if (yycheck_[x + yyn_] == x && x != yyterror_)                  {                    message += (!count++) ? ", expecting " : " or ";                    message += yyname_[x]; 	          }            }	}      else#endif	message = "syntax error";      error (yylloc, message);    }}/* 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[;

⌨️ 快捷键说明

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