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

📄 glr.c

📁 GNU的词法/语法分析器bison源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		    yyformat[sizeof yyunexpected - 1] = '\0';		    break;		  }		yyarg[yycount++] = yytokenName (yyx);		yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx));		yysize_overflow |= yysize1 < yysize;		yysize = yysize1;		yyfmt = yystpcpy (yyfmt, yyprefix);		yyprefix = yyor;	      }	  yyf = YY_(yyformat);	  yysize1 = yysize + strlen (yyf);	  yysize_overflow |= yysize1 < yysize;	  yysize = yysize1;	  if (!yysize_overflow)	    yymsg = (char *) YYMALLOC (yysize);	  if (yymsg)	    {	      char *yyp = yymsg;	      int yyi = 0;	      while ((*yyp = *yyf))		{		  if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)		    {		      yyp += yytnamerr (yyp, yyarg[yyi++]);		      yyf += 2;		    }		  else		    {		      yyp++;		      yyf++;		    }		}	      yyerror (]b4_lyyerror_args[yymsg);	      YYFREE (yymsg);	    }	  else	    {	      yyerror (]b4_lyyerror_args[YY_("syntax error"));	      yyMemoryExhausted (yystack);	    }	}      else#endif /* YYERROR_VERBOSE */	yyerror (]b4_lyyerror_args[YY_("syntax error"));      yynerrs += 1;    }}/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,   YYLVALP, and YYLLOCP point to the syntactic category, semantic   value, and location of the look-ahead.  */static voidyyrecoverSyntaxError (yyGLRStack* yystack,		      YYSTYPE* yylvalp,		      YYLTYPE* YYOPTIONAL_LOC (yyllocp)		      ]b4_user_formals[){  yySymbol* const yytokenp = yystack->yytokenp;  size_t yyk;  int yyj;  if (yystack->yyerrState == 3)    /* We just shifted the error token and (perhaps) took some       reductions.  Skip tokens until we can proceed.  */    while (yytrue)      {	if (*yytokenp == YYEOF)	  yyFail (yystack][]b4_lpure_args[, NULL);	if (*yytokenp != YYEMPTY)	  {]b4_location_if([[	    /* We throw away the lookahead, but the error range	       of the shifted error token must take it into account. */	    yyGLRState *yys = yystack->yytops.yystates[0];	    yyGLRStackItem yyerror_range[3];	    yyerror_range[1].yystate.yyloc = yys->yyloc;	    yyerror_range[2].yystate.yyloc = *yyllocp;	    YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[	    yydestruct ("Error: discarding",			*yytokenp, yylvalp]b4_location_if([, yyllocp])[);	  }	YYDPRINTF ((stderr, "Reading a token: "));	yychar = YYLEX;	*yytokenp = YYTRANSLATE (yychar);	YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);	yyj = yypact[yystack->yytops.yystates[0]->yylrState];	if (yyis_pact_ninf (yyj))	  return;	yyj += *yytokenp;	if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)	  {	    if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)	      return;	  }	else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))	  return;      }  /* Reduce to one stack.  */  for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)    if (yystack->yytops.yystates[yyk] != NULL)      break;  if (yyk >= yystack->yytops.yysize)    yyFail (yystack][]b4_lpure_args[, NULL);  for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1)    yymarkStackDeleted (yystack, yyk);  yyremoveDeletes (yystack);  yycompressStack (yystack);  /* Now pop stack until we find a state that shifts the error token. */  yystack->yyerrState = 3;  while (yystack->yytops.yystates[0] != NULL)    {      yyGLRState *yys = yystack->yytops.yystates[0];      yyj = yypact[yys->yylrState];      if (! yyis_pact_ninf (yyj))	{	  yyj += YYTERROR;	  if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR	      && yyisShiftAction (yytable[yyj]))	    {	      /* Shift the error token having adjusted its location.  */	      YYLTYPE yyerrloc;]b4_location_if([[	      yystack->yyerror_range[2].yystate.yyloc = *yyllocp;	      YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[	      YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],			       yylvalp, &yyerrloc);	      yyglrShift (yystack, 0, yytable[yyj],			  yys->yyposn, *yylvalp, &yyerrloc);	      yys = yystack->yytops.yystates[0];	      break;	    }	}]b4_location_if([[      yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[      yydestroyGLRState ("Error: popping", yys);      yystack->yytops.yystates[0] = yys->yypred;      yystack->yynextFree -= 1;      yystack->yyspaceLeft += 1;    }  if (yystack->yytops.yystates[0] == NULL)    yyFail (yystack][]b4_lpure_args[, NULL);}#define YYCHK1(YYE)							     \  do {									     \    switch (YYE) {							     \    case yyok:								     \      break;								     \    case yyabort:							     \      goto yyabortlab;							     \    case yyaccept:							     \      goto yyacceptlab;							     \    case yyerr:								     \      goto yyuser_error;						     \    default:								     \      goto yybuglab;							     \    }									     \  } while (0)/*----------.| yyparse.  |`----------*/]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[{  int yyresult;  yySymbol yytoken;  yyGLRStack yystack;  size_t yyposn;]b4_pure_if([  YYSTYPE yylval;  YYLTYPE yylloc;  #undef yychar  #define yychar (yystack.yyrawchar)])[  YYSTYPE* const yylvalp = &yylval;  YYLTYPE* const yyllocp = &yylloc;  YYDPRINTF ((stderr, "Starting parse\n"));  yytoken = YYEMPTY;  yylval = yyval_default;]b4_location_if([#if YYLTYPE_IS_TRIVIAL  yylloc.first_line   = yylloc.last_line   = 1;  yylloc.first_column = yylloc.last_column = 0;#endif])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 glr.c.  */b4_syncline([@oline@], [@ofile@])])dnl[  if (! yyinitGLRStack (&yystack, YYINITDEPTH))    goto yyexhaustedlab;  switch (YYSETJMP (yystack.yyexception_buffer))    {    case 0: break;    case 1: goto yyabortlab;    case 2: goto yyexhaustedlab;    default: goto yybuglab;    }  yystack.yytokenp = &yytoken;  yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc);  yyposn = 0;  while (yytrue)    {      /* For efficiency, we have two loops, the first of which is	 specialized to deterministic operation (single stack, no	 potential ambiguity).  */      /* Standard mode */      while (yytrue)	{	  yyRuleNum yyrule;	  int yyaction;	  const short int* yyconflicts;	  yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;          YYDPRINTF ((stderr, "Entering state %d\n", yystate));	  if (yystate == YYFINAL)	    goto yyacceptlab;	  if (yyisDefaultedState (yystate))	    {	      yyrule = yydefaultAction (yystate);	      if (yyrule == 0)		{]b4_location_if([[		  yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[		  yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);		  goto yyuser_error;		}	      YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));	    }	  else	    {	      if (yytoken == YYEMPTY)		{		  YYDPRINTF ((stderr, "Reading a token: "));		  yychar = YYLEX;		  yytoken = YYTRANSLATE (yychar);                  YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp);		}	      yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);	      if (*yyconflicts != 0)		break;	      if (yyisShiftAction (yyaction))		{		  YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp);		  if (yytoken != YYEOF)		    yytoken = YYEMPTY;		  yyposn += 1;		  yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);		  if (0 < yystack.yyerrState)		    yystack.yyerrState -= 1;		}	      else if (yyisErrorAction (yyaction))		{]b4_location_if([[		  yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[		  yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);		  goto yyuser_error;		}	      else		YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));	    }	}      while (yytrue)	{	  size_t yys;	  size_t yyn = yystack.yytops.yysize;	  for (yys = 0; yys < yyn; yys += 1)	    YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,				       yylvalp, yyllocp]b4_lpure_args[));	  yytoken = YYEMPTY;	  yyposn += 1;	  yyremoveDeletes (&yystack);	  if (yystack.yytops.yysize == 0)	    {	      yyundeleteLastStack (&yystack);	      if (yystack.yytops.yysize == 0)		yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));	      YYCHK1 (yyresolveStack (&yystack]b4_user_args[));	      YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));]b4_location_if([[	      yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[	      yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);	      goto yyuser_error;	    }	  else if (yystack.yytops.yysize == 1)	    {	      YYCHK1 (yyresolveStack (&yystack]b4_user_args[));	      YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));	      yycompressStack (&yystack);	      break;	    }	}      continue;    yyuser_error:      yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);      yyposn = yystack.yytops.yystates[0]->yyposn;    } yyacceptlab:  yyresult = 0;  goto yyreturn; yybuglab:  YYASSERT (yyfalse);  /* Fall through.  */ yyabortlab:  yyresult = 1;  goto yyreturn; yyexhaustedlab:  yyerror (]b4_lyyerror_args[YY_("memory exhausted"));  yyresult = 2;  /* Fall through.  */ yyreturn:  if (yytoken != YYEOF && yytoken != YYEMPTY)    yydestruct ("Cleanup: discarding lookahead",                yytoken, yylvalp]b4_location_if([, yyllocp])[);  /* If the stack is well-formed, pop the stack until it is empty,     destroying its entries as we go.  But free the stack regardless     of whether it is well-formed.  */  if (yystack.yyitems)    {      yyGLRState** yystates = yystack.yytops.yystates;      if (yystates)	while (yystates[0])	  {	    yyGLRState *yys = yystates[0];]b4_location_if([[	  yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[	    yydestroyGLRState ("Cleanup: popping", yys);	    yystates[0] = yys->yypred;	    yystack.yynextFree -= 1;	    yystack.yyspaceLeft += 1;	  }      yyfreeGLRStack (&yystack);    }  return yyresult;}/* DEBUGGING ONLY */#ifdef YYDEBUGstatic void yypstack (yyGLRStack* yystack, size_t yyk)  __attribute__ ((__unused__));static void yypdumpstack (yyGLRStack* yystack) __attribute__ ((__unused__));static voidyy_yypstack (yyGLRState* yys){  if (yys->yypred)    {      yy_yypstack (yys->yypred);      fprintf (stderr, " -> ");    }  fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);}static voidyypstates (yyGLRState* yyst){  if (yyst == NULL)    fprintf (stderr, "<null>");  else    yy_yypstack (yyst);  fprintf (stderr, "\n");}static voidyypstack (yyGLRStack* yystack, size_t yyk){  yypstates (yystack->yytops.yystates[yyk]);}#define YYINDEX(YYX)							     \    ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)static voidyypdumpstack (yyGLRStack* yystack){  yyGLRStackItem* yyp;  size_t yyi;  for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)    {      fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystack->yyitems));      if (*(yybool *) yyp)	{	  fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",		   yyp->yystate.yyresolved, yyp->yystate.yylrState,		   (unsigned long int) yyp->yystate.yyposn,		   (long int) YYINDEX (yyp->yystate.yypred));	  if (! yyp->yystate.yyresolved)	    fprintf (stderr, ", firstVal: %ld",		     (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));	}      else	{	  fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",		   yyp->yyoption.yyrule,		   (long int) YYINDEX (yyp->yyoption.yystate),		   (long int) YYINDEX (yyp->yyoption.yynext));	}      fprintf (stderr, "\n");    }  fprintf (stderr, "Tops:");  for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)    fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,	     (long int) YYINDEX (yystack->yytops.yystates[yyi]));  fprintf (stderr, "\n");}#endif]b4_epiloguem4_if(b4_defines_flag, 0, [],[@output @output_header_name@b4_copyright([Skeleton parser for GLR parsing with Bison],  [2002, 2003, 2004, 2005])b4_token_enums_defines(b4_tokens)#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)m4_ifdef([b4_stype],[b4_syncline([b4_stype_line], [b4_file_name])typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;/* Line __line__ of glr.c.  */b4_syncline([@oline@], [@ofile@])],[typedef int YYSTYPE;])# define YYSTYPE_IS_DECLARED 1# define YYSTYPE_IS_TRIVIAL 1#endifb4_pure_if([],[extern YYSTYPE b4_prefix[]lval;])#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)typedef struct YYLTYPE{b4_location_if([  int first_line;  int first_column;  int last_line;  int last_column;],[  char yydummy;])} YYLTYPE;# define YYLTYPE_IS_DECLARED 1# define YYLTYPE_IS_TRIVIAL 1#endifb4_location_if([b4_pure_if([]

⌨️ 快捷键说明

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