📄 glr.c
字号:
#endif /* !YYDEBUG *//* YYINITDEPTH -- initial size of the parser's stacks. */#ifndef YYINITDEPTH# define YYINITDEPTH ]b4_stack_depth_init[#endif/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) evaluated with infinite-precision integer arithmetic. */#ifndef YYMAXDEPTH# define YYMAXDEPTH ]b4_stack_depth_max[#endif/* Minimum number of free items on the stack allowed after an allocation. This is to allow allocation and initialization to be completed by functions that call expandGLRStack before the stack is expanded, thus insuring that all necessary pointers get properly redirected to new data. */#define YYHEADROOM 2#if (! defined (YYSTACKEXPANDABLE) \ && (! defined (__cplusplus) \ || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))#define YYSTACKEXPANDABLE 1#else#define YYSTACKEXPANDABLE 0#endif/** State numbers, as in LALR(1) machine */typedef int yyStateNum;/** Rule numbers, as in LALR(1) machine */typedef int yyRuleNum;/** Grammar symbol */typedef short int yySymbol;/** Item references, as in LALR(1) machine */typedef short int yyItemNum;typedef struct yyGLRState yyGLRState;typedef struct yySemanticOption yySemanticOption;typedef union yyGLRStackItem yyGLRStackItem;typedef struct yyGLRStack yyGLRStack;typedef struct yyGLRStateSet yyGLRStateSet;struct yyGLRState { yybool yyisState; yybool yyresolved; yyStateNum yylrState; yyGLRState* yypred; size_t yyposn; union { yySemanticOption* yyfirstVal; YYSTYPE yysval; } yysemantics; YYLTYPE yyloc;};struct yyGLRStateSet { yyGLRState** yystates; size_t yysize, yycapacity;};struct yySemanticOption { yybool yyisState; yyRuleNum yyrule; yyGLRState* yystate; yySemanticOption* yynext;};union yyGLRStackItem { yyGLRState yystate; yySemanticOption yyoption;};struct yyGLRStack { int yyerrflag; int yyerrState;]b4_location_if([[ /* To compute the location of the error token. */ yyGLRStackItem yyerror_range[3];]])[]b4_pure_if([ int yyerrcnt; int yyrawchar;])[ yySymbol* yytokenp; jmp_buf yyexception_buffer; yyGLRStackItem* yyitems; yyGLRStackItem* yynextFree; int yyspaceLeft; yyGLRState* yysplitPoint; yyGLRState* yylastDeleted; yyGLRStateSet yytops;};static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize);static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[);static void yyfreeGLRStack (yyGLRStack* yystack);static voidyyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...){ yystack->yyerrflag = 1; if (yyformat != NULL) { char yymsg[256]; va_list yyap; va_start (yyap, yyformat); vsprintf (yymsg, yyformat, yyap); yyerror (]b4_yyerror_args[yymsg); } longjmp (yystack->yyexception_buffer, 1);}#if YYDEBUG || YYERROR_VERBOSE/** A printable representation of TOKEN. Valid until next call to * tokenName. */static inline const char*yytokenName (yySymbol yytoken){ if (yytoken == YYEMPTY) return ""; return yytname[yytoken];}#endif/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred * containing the pointer to the next state in the chain. Assumes * YYLOW1 < YYLOW0. */static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED;static voidyyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1){ yyGLRState* s; int i; s = yyvsp[yylow0].yystate.yypred; for (i = yylow0-1; i >= yylow1; i -= 1) { YYASSERT (s->yyresolved); yyvsp[i].yystate.yyresolved = yytrue; yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; yyvsp[i].yystate.yyloc = s->yyloc; s = yyvsp[i].yystate.yypred = s->yypred; }}/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. For convenience, always return YYLOW1. */static inline int yyfill (yyGLRStackItem *, int *, int, yybool) ATTRIBUTE_UNUSED;static inline intyyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal){ if (!yynormal && yylow1 < *yylow) { yyfillin (yyvsp, *yylow, yylow1); *yylow = yylow1; } return yylow1;}/** Perform user action for rule number YYN, with RHS length YYRHSLEN, * and top stack item YYVSP. YYLVALP points to place to put semantic * value ($$), and yylocp points to place for location information * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, * yyerr for YYERROR, yyabort for YYABORT. */static YYRESULTTAGyyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_location_if(, [ ATTRIBUTE_UNUSED])[, yyGLRStack* yystack ]b4_user_formals[){ yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL); int yylow;# undef yyerrok# define yyerrok (yystack->yyerrState = 0)# undef YYACCEPT# define YYACCEPT return yyaccept# undef YYABORT# define YYABORT return yyabort# undef YYERROR# define YYERROR return yyerrok, yyerr# undef YYRECOVERING# define YYRECOVERING (yystack->yyerrState != 0)# undef yyclearin# define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)# undef YYFILL# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)# undef YYBACKUP# define YYBACKUP(Token, Value) \ return yyerror (]b4_yyerror_args["syntax error: cannot back up"), \ yyerrok, yyerr yylow = 1; if (yyrhslen == 0) *yyvalp = yyval_default; else *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval; YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);] switch (yyn) { b4_actions } return yyok;# undef yyerrok# undef YYABORT# undef YYACCEPT# undef YYERROR# undef YYBACKUP# undef yyclearin# undef YYRECOVERING/* Line __line__ of glr.c. */b4_syncline([@oline@], [@ofile@])}static voidyyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1){ /* `Use' the arguments. */ (void) yy0; (void) yy1; switch (yyn) { b4_mergers }}[ /* Bison grammar-table manipulation. */]b4_yydestruct_generate([b4_c_ansi_function_def])[/** Number of symbols composing the right hand side of rule #RULE. */static inline intyyrhsLength (yyRuleNum yyrule){ return yyr2[yyrule];}/** Left-hand-side symbol for rule #RULE. */static inline yySymbolyylhsNonterm (yyRuleNum yyrule){ return yyr1[yyrule];}#define yyis_pact_ninf(yystate) \ ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1, 0, ((yystate) == YYPACT_NINF))[/** True iff LR state STATE has only a default reduction (regardless * of token). */static inline yyboolyyisDefaultedState (yyStateNum yystate){ return yyis_pact_ninf (yypact[yystate]);}/** The default reduction for STATE, assuming it has one. */static inline yyRuleNumyydefaultAction (yyStateNum yystate){ return yydefact[yystate];}#define yyis_table_ninf(yytable_value) \ ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1, 0, ((yytable_value) == YYTABLE_NINF))[/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. * Result R means * R < 0: Reduce on rule -R. * R = 0: Error. * R > 0: Shift to state R. * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of * conflicting reductions. */static inline voidyygetLRActions (yyStateNum yystate, int yytoken, int* yyaction, const short int** yyconflicts){ int yyindex = yypact[yystate] + yytoken; if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) { *yyaction = -yydefact[yystate]; *yyconflicts = yyconfl; } else if (! yyis_table_ninf (yytable[yyindex])) { *yyaction = yytable[yyindex]; *yyconflicts = yyconfl + yyconflp[yyindex]; } else { *yyaction = 0; *yyconflicts = yyconfl + yyconflp[yyindex]; }}static inline yyStateNumyyLRgotoState (yyStateNum yystate, yySymbol yylhs){ int yyr; yyr = yypgoto[yylhs - YYNTOKENS] + yystate; if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) return yytable[yyr]; else return yydefgoto[yylhs - YYNTOKENS];}static inline yyboolyyisShiftAction (int yyaction){ return 0 < yyaction;}static inline yyboolyyisErrorAction (int yyaction){ return yyaction == 0;} /* GLRStates */static voidyyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[){ yySemanticOption* yynewItem; yynewItem = &yystack->yynextFree->yyoption; yystack->yyspaceLeft -= 1; yystack->yynextFree += 1; yynewItem->yyisState = yyfalse; yynewItem->yystate = rhs; yynewItem->yyrule = yyrule; yynewItem->yynext = yystate->yysemantics.yyfirstVal; yystate->yysemantics.yyfirstVal = yynewItem; if (yystack->yyspaceLeft < YYHEADROOM) yyexpandGLRStack (yystack]b4_pure_args[);} /* GLRStacks *//** Initialize SET to a singleton set containing an empty stack. */static voidyyinitStateSet (yyGLRStateSet* yyset){ yyset->yysize = 1; yyset->yycapacity = 16; yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]); yyset->yystates[0] = NULL;}static void yyfreeStateSet (yyGLRStateSet* yyset){ YYFREE (yyset->yystates);}/** Initialize STACK to a single empty stack, with total maximum * capacity for all stacks of SIZE. */static voidyyinitGLRStack (yyGLRStack* yystack, size_t yysize){ yystack->yyerrflag = 0; yystack->yyerrState = 0; yynerrs = 0; yystack->yyspaceLeft = yysize; yystack->yynextFree = yystack->yyitems = (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]); yystack->yysplitPoint = NULL; yystack->yylastDeleted = NULL; yyinitStateSet (&yystack->yytops);}#define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE/** If STACK is expandable, extend it. WARNING: Pointers into the stack from outside should be considered invalid after this call. We always expand when there are 1 or fewer items left AFTER an allocation, so that we can avoid having external pointers exist across an allocation. */static voidyyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[){#if YYSTACKEXPANDABLE yyGLRStack yynewStack; yyGLRStackItem* yyp0, *yyp1; size_t yysize, yynewSize; size_t yyn; yysize = yystack->yynextFree - yystack->yyitems; if (YYMAXDEPTH <= yysize) yyFail (yystack][]b4_pure_args[, "parser stack overflow"); yynewSize = 2*yysize; if (YYMAXDEPTH < yynewSize) yynewSize = YYMAXDEPTH; yyinitGLRStack (&yynewStack, yynewSize); for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize; 0 < yyn; yyn -= 1, yyp0 += 1, yyp1 += 1) { *yyp1 = *yyp0; if (*(yybool *) yyp0) { yyGLRState* yys0 = &yyp0->yystate; yyGLRState* yys1 = &yyp1->yystate; if (yys0->yypred != NULL) yys1->yypred = YYRELOC (yyp0, yyp1, yys0->yypred, yystate); if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL) yys1->yysemantics.yyfirstVal = YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); } else { yySemanticOption* yyv0 = &yyp0->yyoption; yySemanticOption* yyv1 = &yyp1->yyoption; if (yyv0->yystate != NULL) yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); if (yyv0->yynext != NULL) yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); } } if (yystack->yysplitPoint != NULL) yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems, yystack->yysplitPoint, yystate); for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1) if (yystack->yytops.yystates[yyn] != NULL) yystack->yytops.yystates[yyn] = YYRELOC (yystack->yyitems, yynewStack.yyitems, yystack->yytops.yystates[yyn], yystate); YYFREE (yystack->yyitems); yystack->yyitems = yynewStack.yyitems; yystack->yynextFree = yynewStack.yynextFree + yysize; yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;#else yyFail (yystack][]b4_pure_args[, "parser stack overflow");#endif}static voidyyfreeGLRStack (yyGLRStack* yystack){ YYFREE (yystack->yyitems); yyfreeStateSet (&yystack->yytops);}/** Assuming that S is a GLRState somewhere on STACK, update the * splitpoint of STACK, if needed, so that it is at least as deep as * S. */static inline voidyyupdateSplit (yyGLRStack* yystack, yyGLRState* yys){ if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys) yystack->yysplitPoint = yys;}/** Invalidate stack #K in STACK. */static inline voidyymarkStackDeleted (yyGLRStack* yystack, int yyk){ if (yystack->yytops.yystates[yyk] != NULL) yystack->yylastDeleted = yystack->yytops.yystates[yyk]; yystack->yytops.yystates[yyk] = NULL;}/** Undelete the last stack that was marked as deleted. Can only be done once after a deletion, and only when all other stacks have been deleted. */static voidyyundeleteLastStack (yyGLRStack* yystack){ if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0) return; yystack->yytops.yystates[0] = yystack->yylastDeleted; yystack->yytops.yysize = 1; YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); yystack->yylastDeleted = NULL;}static inline voidyyremoveDeletes (yyGLRStack* yystack){ size_t yyi, yyj; yyi = yyj = 0; while (yyj < yystack->yytops.yysize) { if (yystack->yytops.yystates[yyi] == NULL) { if (yyi == yyj) { YYDPRINTF ((stderr, "Removing dead stacks.\n")); } yystack->yytops.yysize -= 1; } else { yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi]; if (yyj != yyi) { YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n", (unsigned long int) yyi, (unsigned long int) yyj));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -