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

📄 glr.c

📁 GNU的词法/语法分析器bison源码
💻 C
📖 第 1 页 / 共 5 页
字号:
					    * sizeof yynewStates[0])))))	yyMemoryExhausted (yystack);      yystack->yytops.yystates = yynewStates;    }  yystack->yytops.yystates[yystack->yytops.yysize]    = yystack->yytops.yystates[yyk];  yystack->yytops.yysize += 1;  return yystack->yytops.yysize-1;}/** True iff Y0 and Y1 represent identical options at the top level. *  That is, they represent the same rule applied to RHS symbols *  that produce the same terminal symbols. */static yyboolyyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1){  if (yyy0->yyrule == yyy1->yyrule)    {      yyGLRState *yys0, *yys1;      int yyn;      for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,	   yyn = yyrhsLength (yyy0->yyrule);	   yyn > 0;	   yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)	if (yys0->yyposn != yys1->yyposn)	  return yyfalse;      return yytrue;    }  else    return yyfalse;}/** Assuming identicalOptions (Y0,Y1), destructively merge the *  alternative semantic values for the RHS-symbols of Y1 and Y0. */static voidyymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1){  yyGLRState *yys0, *yys1;  int yyn;  for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,       yyn = yyrhsLength (yyy0->yyrule);       yyn > 0;       yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)    {      if (yys0 == yys1)	break;      else if (yys0->yyresolved)	{	  yys1->yyresolved = yytrue;	  yys1->yysemantics.yysval = yys0->yysemantics.yysval;	}      else if (yys1->yyresolved)	{	  yys0->yyresolved = yytrue;	  yys0->yysemantics.yysval = yys1->yysemantics.yysval;	}      else	{	  yySemanticOption** yyz0p;	  yySemanticOption* yyz1;	  yyz0p = &yys0->yysemantics.yyfirstVal;	  yyz1 = yys1->yysemantics.yyfirstVal;	  while (yytrue)	    {	      if (yyz1 == *yyz0p || yyz1 == NULL)		break;	      else if (*yyz0p == NULL)		{		  *yyz0p = yyz1;		  break;		}	      else if (*yyz0p < yyz1)		{		  yySemanticOption* yyz = *yyz0p;		  *yyz0p = yyz1;		  yyz1 = yyz1->yynext;		  (*yyz0p)->yynext = yyz;		}	      yyz0p = &(*yyz0p)->yynext;	    }	  yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;	}    }}/** Y0 and Y1 represent two possible actions to take in a given *  parsing state; return 0 if no combination is possible, *  1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */static intyypreference (yySemanticOption* y0, yySemanticOption* y1){  yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;  int p0 = yydprec[r0], p1 = yydprec[r1];  if (p0 == p1)    {      if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])	return 0;      else	return 1;    }  if (p0 == 0 || p1 == 0)    return 0;  if (p0 < p1)    return 3;  if (p1 < p0)    return 2;  return 0;}static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,				   yyGLRStack* yystack, YYSTYPE* yyvalp,				   YYLTYPE* yylocp]b4_user_formals[);static YYRESULTTAGyyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[){  YYRESULTTAG yyflag;  if (0 < yyn)    {      YYASSERT (yys->yypred);      yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[);      if (yyflag != yyok)	return yyflag;      if (! yys->yyresolved)	{	  yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,				   &yys->yysemantics.yysval, &yys->yyloc				  ]b4_user_args[);	  if (yyflag != yyok)	    return yyflag;	  yys->yyresolved = yytrue;	}    }  return yyok;}static YYRESULTTAGyyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,	         YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[){  yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];  int yynrhs;  yynrhs = yyrhsLength (yyopt->yyrule);  YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));  yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;  return yyuserAction (yyopt->yyrule, yynrhs,		       yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,		       yyvalp, yylocp, yystack]b4_user_args[);}#if YYDEBUGstatic voidyyreportTree (yySemanticOption* yyx, int yyindent){  int yynrhs = yyrhsLength (yyx->yyrule);  int yyi;  yyGLRState* yys;  yyGLRState* yystates[YYMAXRHS];  yyGLRState yyleftmost_state;  for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)    yystates[yyi] = yys;  if (yys == NULL)    {      yyleftmost_state.yyposn = 0;      yystates[0] = &yyleftmost_state;    }  else    yystates[0] = yys;  if (yyx->yystate->yyposn < yys->yyposn + 1)    YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",	       yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),	       yyx->yyrule);  else    YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",	       yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),	       yyx->yyrule, (unsigned long int) (yys->yyposn + 1),	       (unsigned long int) yyx->yystate->yyposn);  for (yyi = 1; yyi <= yynrhs; yyi += 1)    {      if (yystates[yyi]->yyresolved)	{	  if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)	    YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",		       yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));	  else	    YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",		       yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),		       (unsigned long int) (yystates[yyi - 1]->yyposn + 1),		       (unsigned long int) yystates[yyi]->yyposn);	}      else	yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);    }}#endifstatic void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,			       yyGLRStack* yystack]b4_pure_formals[)  __attribute__ ((__noreturn__));static voidyyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,		   yyGLRStack* yystack]b4_pure_formals[){  /* `Unused' warnings.  */  (void) yyx0;  (void) yyx1;#if YYDEBUG  YYFPRINTF (stderr, "Ambiguity detected.\n");  YYFPRINTF (stderr, "Option 1,\n");  yyreportTree (yyx0, 2);  YYFPRINTF (stderr, "\nOption 2,\n");  yyreportTree (yyx1, 2);  YYFPRINTF (stderr, "\n");#endif  yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous"));}/** Resolve the ambiguity represented by OPTIONLIST, perform the indicated *  actions, and return the result. */static YYRESULTTAGyyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,		YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[){  yySemanticOption* yybest;  yySemanticOption** yypp;  yybool yymerge;  yybest = yyoptionList;  yymerge = yyfalse;  for (yypp = &yyoptionList->yynext; *yypp != NULL; )    {      yySemanticOption* yyp = *yypp;      if (yyidenticalOptions (yybest, yyp))	{	  yymergeOptionSets (yybest, yyp);	  *yypp = yyp->yynext;	}      else	{	  switch (yypreference (yybest, yyp))	    {	    case 0:	      yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);	      break;	    case 1:	      yymerge = yytrue;	      break;	    case 2:	      break;	    case 3:	      yybest = yyp;	      yymerge = yyfalse;	      break;	    default:	      /* This cannot happen so it is not worth a YYASSERT (yyfalse),	         but some compilers complain if the default case is		 omitted.  */	      break;	    }	  yypp = &yyp->yynext;	}    }  if (yymerge)    {      yySemanticOption* yyp;      int yyprec = yydprec[yybest->yyrule];      YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));      for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)	{	  if (yyprec == yydprec[yyp->yyrule])	    {	      YYSTYPE yyval1;	      YYLTYPE yydummy;	      YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[));	      yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);	    }	}      return yyok;    }  else    return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[);}static YYRESULTTAGyyresolveStack (yyGLRStack* yystack]b4_user_formals[){  if (yystack->yysplitPoint != NULL)    {      yyGLRState* yys;      int yyn;      for (yyn = 0, yys = yystack->yytops.yystates[0];	   yys != yystack->yysplitPoint;	   yys = yys->yypred, yyn += 1)	continue;      YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack			     ]b4_user_args[));    }  return yyok;}static voidyycompressStack (yyGLRStack* yystack){  yyGLRState* yyp, *yyq, *yyr;  if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)    return;  for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;       yyp != yystack->yysplitPoint;       yyr = yyp, yyp = yyq, yyq = yyp->yypred)    yyp->yypred = yyr;  yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;  yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;  yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;  yystack->yysplitPoint = NULL;  yystack->yylastDeleted = NULL;  while (yyr != NULL)    {      yystack->yynextFree->yystate = *yyr;      yyr = yyr->yypred;      yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;      yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;      yystack->yynextFree += 1;      yystack->yyspaceLeft -= 1;    }}static YYRESULTTAGyyprocessOneStack (yyGLRStack* yystack, size_t yyk,	           size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp		  ]b4_pure_formals[){  int yyaction;  const short int* yyconflicts;  yyRuleNum yyrule;  yySymbol* const yytokenp = yystack->yytokenp;  while (yystack->yytops.yystates[yyk] != NULL)    {      yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;      YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",		  (unsigned long int) yyk, yystate));      YYASSERT (yystate != YYFINAL);      if (yyisDefaultedState (yystate))	{	  yyrule = yydefaultAction (yystate);	  if (yyrule == 0)	    {	      YYDPRINTF ((stderr, "Stack %lu dies.\n",			  (unsigned long int) yyk));	      yymarkStackDeleted (yystack, yyk);	      return yyok;	    }	  YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_user_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)	    {	      size_t yynewStack = yysplitStack (yystack, yyk);	      YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",			  (unsigned long int) yynewStack,			  (unsigned long int) yyk));	      YYCHK (yyglrReduce (yystack, yynewStack,				  *yyconflicts, yyfalse]b4_user_args[));	      YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,					yylvalp, yyllocp]b4_pure_args[));	      yyconflicts += 1;	    }	  if (yyisShiftAction (yyaction))	    {	      YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yyk));	      YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp);	      yyglrShift (yystack, yyk, yyaction, yyposn+1,			  *yylvalp, yyllocp);	      YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",			  (unsigned long int) yyk,			  yystack->yytops.yystates[yyk]->yylrState));	      break;	    }	  else if (yyisErrorAction (yyaction))	    {	      YYDPRINTF ((stderr, "Stack %lu dies.\n",			  (unsigned long int) yyk));	      yymarkStackDeleted (yystack, yyk);	      break;	    }	  else	    YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_user_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 yysize0 = yytnamerr (NULL, yytokenName (*yytokenp));	  size_t yysize = yysize0;	  size_t yysize1;	  yybool yysize_overflow = yyfalse;	  char* yymsg = NULL;	  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };	  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];	  int yyx;	  char *yyfmt;	  char const *yyf;	  static char const yyunexpected[] = "syntax error, unexpected %s";	  static char const yyexpecting[] = ", expecting %s";	  static char const yyor[] = " or %s";	  char yyformat[sizeof yyunexpected			+ sizeof yyexpecting - 1			+ ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)			   * (sizeof yyor - 1))];	  char const *yyprefix = yyexpecting;	  /* 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 = 1;	  yyarg[0] = yytokenName (*yytokenp);	  yyfmt = yystpcpy (yyformat, yyunexpected);	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)	      {		if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)		  {		    yycount = 1;		    yysize = yysize0;

⌨️ 快捷键说明

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