X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/bd187d7b6573a60ad56c3fbcaccb5c768bc8d7ba..786578e394700615f6a841614e1280bf6284ec8c:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 910a8ee1..6f1f7ee9 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1,8 +1,8 @@ -*- C -*- # GLR skeleton for Bison -# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, -# Inc. +# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free +# Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -158,7 +158,7 @@ m4_changecom() m4_divert_push(0)dnl @output(b4_parser_file_name@)@ b4_copyright([Skeleton implementation for Bison GLR parsers in C], - [2002, 2003, 2004, 2005, 2006]) + [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]) [ /* C GLR parser skeleton written by Paul Hilfinger. */ @@ -224,7 +224,7 @@ b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], /* Enabling traces. */ #ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ +# define YYDEBUG ]b4_parse_trace_if([1], [0])[ #endif /* Enabling verbose error messages. */ @@ -232,7 +232,7 @@ b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE ]b4_error_verbose_flag[ +# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ #endif /* Enabling the token table. */ @@ -367,19 +367,6 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const ]b4_int_type_for([b4_prhs])[ yyprhs[] = -{ - ]b4_prhs[ -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const ]b4_int_type_for([b4_rhs])[ yyrhs[] = -{ - ]b4_rhs[ -}; - /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const ]b4_int_type_for([b4_rline])[ yyrline[] = { @@ -396,17 +383,10 @@ static const char *const yytname[] = }; #endif -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const ]b4_int_type_for([b4_r1])[ yyr1[] = -{ - ]b4_r1[ -}; +#define YYPACT_NINF ]b4_pact_ninf[ +#define YYTABLE_NINF ]b4_table_ninf[ -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const ]b4_int_type_for([b4_r2])[ yyr2[] = -{ - ]b4_r2[ -}; +]b4_parser_tables_define[ /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ static const ]b4_int_type_for([b4_dprec])[ yydprec[] = @@ -420,44 +400,6 @@ static const ]b4_int_type_for([b4_merger])[ yymerger[] = ]b4_merger[ }; -/* 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. */ -static const ]b4_int_type_for([b4_defact])[ yydefact[] = -{ - ]b4_defact[ -}; - -/* YYPDEFGOTO[NTERM-NUM]. */ -static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] = -{ - ]b4_defgoto[ -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF ]b4_pact_ninf[ -static const ]b4_int_type_for([b4_pact])[ yypact[] = -{ - ]b4_pact[ -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] = -{ - ]b4_pgoto[ -}; - -/* 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. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF ]b4_table_ninf[ -static const ]b4_int_type_for([b4_table])[ yytable[] = -{ - ]b4_table[ -}; - /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of list of conflicting reductions corresponding to action entry for state STATE-NUM in yytable. 0 means no conflicts. The list in @@ -476,19 +418,6 @@ dnl We probably ought to introduce a type for confl. { ]b4_conflicting_rules[ }; - -static const ]b4_int_type_for([b4_check])[ yycheck[] = -{ - ]b4_check[ -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const ]b4_int_type_for([b4_stos])[ yystos[] = -{ - ]b4_stos[ -}; - /* Prevent warning if -Wmissing-prototypes. */ ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[ @@ -571,9 +500,12 @@ static const int YYEMPTY = -2; typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; -#define YYCHK(YYE) \ - do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ - while (YYID (0)) +#define YYCHK(YYE) \ + do { \ + YYRESULTTAG yyflag = YYE; \ + if (yyflag != yyok) \ + return yyflag; \ + } while (YYID (0)) #if YYDEBUG @@ -582,23 +514,23 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; # endif # define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) + do { \ + if (yydebug) \ + YYFPRINTF Args; \ + } while (YYID (0)) ]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, Type, \ - Value]b4_locations_if([, Location])[]b4_user_args[); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, Type, \ + Value]b4_locations_if([, Location])[]b4_user_args[); \ + YYFPRINTF (stderr, "\n"); \ + } \ + } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -1021,17 +953,15 @@ yylhsNonterm (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)])[ +#define yypact_value_is_default(yystate) \ + ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[ /** True iff LR state STATE has only a default reduction (regardless * of token). */ static inline yybool yyisDefaultedState (yyStateNum yystate) { - return yyis_pact_ninf (yypact[yystate]); + return yypact_value_is_default (yypact[yystate]); } /** The default reduction for STATE, assuming it has one. */ @@ -1041,10 +971,8 @@ yydefaultAction (yyStateNum yystate) return yydefact[yystate]; } -#define yyis_table_ninf(yytable_value) \ - ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1], - [YYID (0)], - [((yytable_value) == YYTABLE_NINF)])[ +#define yytable_value_is_error(yytable_value) \ + ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[ /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. * Result R means @@ -1059,12 +987,13 @@ yygetLRActions (yyStateNum yystate, int yytoken, int* yyaction, const short int** yyconflicts) { int yyindex = yypact[yystate] + yytoken; - if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) + if (yypact_value_is_default (yypact[yystate]) + || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) { *yyaction = -yydefact[yystate]; *yyconflicts = yyconfl; } - else if (! yyis_table_ninf (yytable[yyindex])) + else if (! yytable_value_is_error (yytable[yyindex])) { *yyaction = yytable[yyindex]; *yyconflicts = yyconfl + yyconflp[yyindex]; @@ -1079,8 +1008,7 @@ yygetLRActions (yyStateNum yystate, int yytoken, static inline yyStateNum yyLRgotoState (yyStateNum yystate, yySymbol yylhs) { - int yyr; - yyr = yypgoto[yylhs - YYNTOKENS] + yystate; + int yyr = yypgoto[yylhs - YYNTOKENS] + yystate; if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) return yytable[yyr]; else @@ -1121,11 +1049,11 @@ yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) * stack #K of *STACKP. */ static void yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate, - yyGLRState* rhs, yyRuleNum yyrule) + yyGLRState* yyrhs, yyRuleNum yyrule) { yySemanticOption* yynewOption = &yynewGLRStackItem (yystackp, yyfalse)->yyoption; - yynewOption->yystate = rhs; + yynewOption->yystate = yyrhs; yynewOption->yyrule = yyrule; if (yystackp->yytops.yylookaheadNeeds[yyk]) { @@ -1356,7 +1284,7 @@ yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, * semantic value of YYRHS under the action for YYRULE. */ static inline void yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, - size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule) + size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) { yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; @@ -1368,7 +1296,7 @@ yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, yystackp->yytops.yystates[yyk] = yynewState; /* Invokes YY_RESERVE_GLRSTACK. */ - yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule); + yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule); } /** Pop the symbols consumed by reduction #RULE from the top of stack @@ -1386,12 +1314,12 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, if (yystackp->yysplitPoint == NULL) { /* Standard special case: single stack. */ - yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; + yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; YYASSERT (yyk == 0); yystackp->yynextFree -= yynrhs; yystackp->yyspaceLeft += yynrhs; yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; - return yyuserAction (yyrule, yynrhs, rhs, + return yyuserAction (yyrule, yynrhs, yyrhs, yyvalp, yylocp, yystackp]b4_user_args[); } else @@ -1434,8 +1362,7 @@ do { \ `----------------------------------------------------------*/ /*ARGSUSED*/ static inline void -yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, - YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) +yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule]b4_user_formals[) { int yynrhs = yyrhsLength (yyrule); yybool yynormal __attribute__ ((__unused__)) = @@ -1443,8 +1370,6 @@ yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; int yylow = 1; int yyi; - YYUSE (yyvalp); - YYUSE (yylocp); ]b4_parse_param_use[]dnl [ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n", (unsigned long int) yyk, yyrule - 1, @@ -1453,7 +1378,8 @@ yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + yy_symbol_print (stderr, + ]yystos@{b4_rhs_data(yynrhs, yyi + 1).yylrState@}[, &]b4_rhs_value(yynrhs, yyi + 1)[ ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl b4_user_args[); @@ -1484,7 +1410,7 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, YYSTYPE yysval; YYLTYPE yyloc; - YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); + YY_REDUCE_PRINT ((yystackp, yyk, yyrule]b4_user_args[)); YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); @@ -1782,11 +1708,11 @@ yyreportTree (yySemanticOption* yyx, int yyindent) { if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) YYFPRINTF (stderr, "%*s%s \n", yyindent+2, "", - yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1])); + yytokenName (yystos[yystates[yyi-1]->yylrState])); else YYFPRINTF (stderr, "%*s%s \n", yyindent+2, "", - yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]), - (unsigned long int) (yystates[yyi - 1]->yyposn + 1), + yytokenName (yystos[yystates[yyi-1]->yylrState]), + (unsigned long int) (yystates[yyi-1]->yyposn + 1), (unsigned long int) yystates[yyi]->yyposn); } else @@ -2113,51 +2039,58 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yybool yysize_overflow = yyfalse; char* yymsg = NULL; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ 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. */ + YYCHECK. In other words, skip the first -YYN actions for this + state because they are default actions. */ int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - yyarg[0] = yytokenName (yytoken); - yyfmt = yystpcpy (yyformat, yyunexpected); + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + int yyx; + + yyarg[yycount++] = yytokenName (yytoken); for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) { if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { yycount = 1; yysize = yysize0; - 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); + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + yysize1 = yysize + strlen (yyformat); yysize_overflow |= yysize1 < yysize; yysize = yysize1; @@ -2168,17 +2101,17 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { char *yyp = yymsg; int yyi = 0; - while ((*yyp = *yyf)) + while ((*yyp = *yyformat)) { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) { yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; + yyformat += 2; } else { yyp++; - yyf++; + yyformat++; } } yyerror (]b4_lyyerror_args[yymsg); @@ -2240,7 +2173,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; - if (yyis_pact_ninf (yyj)) + if (yypact_value_is_default (yyj)) return; yyj += yytoken; if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) @@ -2248,7 +2181,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) return; } - else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj])) + else if (! yytable_value_is_error (yytable[yyj])) return; } @@ -2269,7 +2202,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { yyGLRState *yys = yystackp->yytops.yystates[0]; yyj = yypact[yys->yylrState]; - if (! yyis_pact_ninf (yyj)) + if (! yypact_value_is_default (yyj)) { yyj += YYTERROR; if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR @@ -2637,9 +2570,7 @@ yypdumpstack (yyGLRStack* yystackp) YYFPRINTF (stderr, "\n"); } #endif -] - -b4_epilogue +]b4_epilogue[]dnl dnl dnl glr.cc produces its own header. dnl @@ -2647,15 +2578,15 @@ m4_if(b4_skeleton, ["glr.c"], [b4_defines_if( [@output(b4_spec_defines_file@)@ b4_copyright([Skeleton interface for Bison GLR parsers in C], - [2002, 2003, 2004, 2005, 2006]) + [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]) b4_shared_declarations b4_pure_if([], -[[extern YYSTYPE b4_prefix][lval;]]) +[[extern YYSTYPE ]b4_prefix[lval;]]) b4_locations_if([b4_pure_if([], -[extern YYLTYPE b4_prefix[]lloc;]) +[extern YYLTYPE ]b4_prefix[lloc;]) ]) -])]) +])])[]dnl m4_divert_pop(0)