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

📄 glr.c

📁 bison 2.0 主要可以用来做语法分析用的
💻 C
📖 第 1 页 / 共 4 页
字号:
	    }	  YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[));	}      else	{	  if (*yytokenp == YYEMPTY)	    {	      YYDPRINTF ((stderr, "Reading a token: "));	      yychar = YYLEX;	      *yytokenp = YYTRANSLATE (yychar);	      YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);	    }	  yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);	  while (*yyconflicts != 0)	    {	      int yynewStack = yysplitStack (yystack, yyk);	      YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",			  yynewStack, yyk));	      YYCHK (yyglrReduce (yystack, yynewStack,				  *yyconflicts, yyfalse]b4_lpure_args[));	      YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,					yylvalp, yyllocp]b4_user_args[));	      yyconflicts += 1;	    }	  if (yyisShiftAction (yyaction))	    {	      YYDPRINTF ((stderr, "On stack %d, ", yyk));	      YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp);	      yyglrShift (yystack, yyk, yyaction, yyposn+1,			  *yylvalp, yyllocp]b4_user_args[);	      YYDPRINTF ((stderr, ", now in state #%d\n",			  yystack->yytops.yystates[yyk]->yylrState));	      break;	    }	  else if (yyisErrorAction (yyaction))	    {	      YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));	      yymarkStackDeleted (yystack, yyk);	      break;	    }	  else	    YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[));	}    }  return yyok;}static voidyyreportSyntaxError (yyGLRStack* yystack,		     YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[){  /* `Unused' warnings. */  (void) yylvalp;  (void) yyllocp;  if (yystack->yyerrState == 0)    {#if YYERROR_VERBOSE      yySymbol* const yytokenp = yystack->yytokenp;      int yyn;      yyn = yypact[yystack->yytops.yystates[0]->yylrState];      if (YYPACT_NINF < yyn && yyn < YYLAST)	{	  size_t yysize = 0;	  const char* yyprefix;	  char* yymsg;	  int yyx;	  /* 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 yycount = 0;	  yyprefix = ", expecting ";	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)	      {		yysize += strlen (yyprefix) + strlen (yytokenName (yyx));		yycount += 1;		if (yycount == 5)		  {		    yysize = 0;		    break;		  }		yyprefix = " or ";	      }	  yysize += (sizeof ("syntax error, unexpected ")		     + strlen (yytokenName (*yytokenp)));	  yymsg = (char*) YYMALLOC (yysize);	  if (yymsg != 0)	    {	      char* yyp = yymsg;	      sprintf (yyp, "syntax error%s%s",		       (*yytokenp == YYEMPTY ? "" : ", unexpected "),		       yytokenName (*yytokenp));	      yyp += strlen (yyp);	      if (yycount < 5)		{		  yyprefix = ", expecting ";		  for (yyx = yyxbegin; yyx < yyxend; ++yyx)		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)		      {			sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));			yyp += strlen (yyp);			yyprefix = " or ";		      }		}	      yyerror (]b4_lyyerror_args[yymsg);	      YYFREE (yymsg);	    }	  else	    yyerror (]b4_lyyerror_args["syntax error; also virtual memory exhausted");	}      else#endif /* YYERROR_VERBOSE */	yyerror (]b4_lyyerror_args["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* yyllocp]b4_location_if(, [ ATTRIBUTE_UNUSED])[		      ]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)	  {	    /* Now pop stack until empty and fail. */	    while (yystack->yytops.yystates[0] != NULL)	      {		yyGLRState *yys = yystack->yytops.yystates[0];]b4_location_if([[		yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[		yydestruct ("Error: popping",                            yystos[yys->yylrState],			    &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);		yystack->yytops.yystates[0] = yys->yypred;		yystack->yynextFree -= 1;		yystack->yyspaceLeft += 1;	      }	    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]b4_user_args[);	      yys = yystack->yytops.yystates[0];	      break;	    }	}]b4_location_if([[      yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[      yydestruct ("Error: popping",		  yystos[yys->yylrState],	          &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);      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) {							     \    default:								     \      break;								     \    case yyabort:							     \      yystack.yyerrflag = 1;						     \      goto yyDone;							     \    case yyaccept:							     \      yystack.yyerrflag = 0;						     \      goto yyDone;							     \    case yyerr:								     \      goto yyuser_error;						     \    }									     \  } while (0)/*----------.| yyparse.  |`----------*/]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[{  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;  yyinitGLRStack (&yystack, YYINITDEPTH);  yystack.yytokenp = &yytoken;  YYDPRINTF ((stderr, "Starting parse\n"));  if (setjmp (yystack.yyexception_buffer) != 0)    goto yyDone;  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],     [yylval])dnlm4_pushdef([b4_dollar_dollar], [yylloc])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[  yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc]b4_user_args[);  yytoken = YYEMPTY;  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 yyDone;	  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_lpure_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]b4_user_args[);		  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_lpure_args[));	    }	}      while (yytrue)	{	  int yys;	  int yyn = yystack.yytops.yysize;	  for (yys = 0; yys < yyn; yys += 1)	    YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,				       yylvalp, yyllocp]b4_user_args[));	  yytoken = YYEMPTY;	  yyposn += 1;	  yyremoveDeletes (&yystack);	  if (yystack.yytops.yysize == 0)	    {	      yyundeleteLastStack (&yystack);	      if (yystack.yytops.yysize == 0)		yyFail (&yystack][]b4_lpure_args[, "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;    } yyDone:  /* On YYABORT, free the lookahead. */  if (yystack.yyerrflag == 1 && yytoken != YYEMPTY)    yydestruct ("Error: discarding lookahead",                yytoken, yylvalp]b4_location_if([, yyllocp])[);  yyfreeGLRStack (&yystack);  return yystack.yyerrflag;}/* DEBUGGING ONLY */#ifdef YYDEBUGstatic void yypstack (yyGLRStack* yystack, int 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, int 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])b4_token_defines(b4_tokens)#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)m4_ifdef([b4_stype],[b4_syncline([b4_stype_line], [b4_filename])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([],[extern YYLTYPE b4_prefix[]lloc;])])])

⌨️ 快捷键说明

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