X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/1462fcee1ed295b24f47758b370068aa6304bb41..9874f80b2e813a8ad8e5562dbbaa30ecafd5e7d8:/data/glr.c diff --git a/data/glr.c b/data/glr.c index dcd56c23..17eff387 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1,7 +1,8 @@ -*- C -*- # GLR skeleton for Bison -# Copyright (C) 2002-2010 Free Software Foundation, Inc. + +# Copyright (C) 2002-2012 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 @@ -34,8 +35,8 @@ m4_define_default([b4_stack_depth_init], [200]) ## ------------------------ ## b4_define_flag_if([pure]) -# If glr.cc is including this file and thus has already set b4_pure_flag, don't -# change the value of b4_pure_flag, and don't record a use of api.pure. +# If glr.cc is including this file and thus has already set b4_pure_flag, +# do not change the value of b4_pure_flag, and do not record a use of api.pure. m4_ifndef([b4_pure_flag], [b4_percent_define_default([[api.pure]], [[false]]) m4_define([b4_pure_flag], @@ -149,7 +150,7 @@ m4_changecom() m4_divert_push(0)dnl @output(b4_parser_file_name@)@ b4_copyright([Skeleton implementation for Bison GLR parsers in C], - [2002-2010]) + [2002-2011]) [ /* C GLR parser skeleton written by Paul Hilfinger. */ @@ -1801,7 +1802,7 @@ yyreportAmbiguity (yySemanticOption* yyx0, yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); return yyabort; -} +}]b4_locations_if([[ /** Starting at and including state S1, resolve the location for each of the * previous N1 states that is unresolved. The first semantic option of a state @@ -1859,7 +1860,7 @@ yyresolveLocations (yyGLRState* yys1, int yyn1, yylloc = yylloc_current; } } -} +}]])[ /** Resolve the ambiguity represented in state S, perform the indicated * actions, and set the semantic value of S. If result != yyok, the chain of @@ -1893,8 +1894,8 @@ yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) { switch (yypreference (yybest, yyp)) { - case 0: - yyresolveLocations (yys, 1, yystackp]b4_user_args[); + case 0:]b4_locations_if([[ + yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[ return yyreportAmbiguity (yybest, yyp]b4_pure_args[); break; case 1: @@ -2087,109 +2088,130 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, /*ARGSUSED*/ static void yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { - if (yystackp->yyerrState == 0) + if (yystackp->yyerrState != 0) + return; +#if ! YYERROR_VERBOSE + yyerror (]b4_lyyerror_args[YY_("syntax error")); +#else + yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken)); + size_t yysize = yysize0; + size_t yysize1; + 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]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { -#if YYERROR_VERBOSE - int yyn; - yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; - if (YYPACT_NINF < yyn && yyn <= YYLAST) - { - yySymbol yytoken = YYTRANSLATE (yychar); - size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken)); - size_t yysize = yysize0; - size_t yysize1; - 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]; - - /* Start YYX at -YYN if negative to avoid negative indexes in - 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; - - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; + int yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; + yyarg[yycount++] = yytokenName (yytoken); + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + 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 yyx; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytokenName (yyx); + yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx)); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + } + } + } - yyarg[yycount++] = yytokenName (yytoken); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytokenName (yyx); - yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx)); - yysize_overflow |= yysize1 < yysize; - yysize = yysize1; - } - - 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")); + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + 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; + yysize1 = yysize + strlen (yyformat); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; - if (!yysize_overflow) - yymsg = (char *) YYMALLOC (yysize); + if (!yysize_overflow) + yymsg = (char *) YYMALLOC (yysize); - if (yymsg) - { - char *yyp = yymsg; - int yyi = 0; - while ((*yyp = *yyformat)) - { - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - yyerror (]b4_lyyerror_args[yymsg); - YYFREE (yymsg); - } - else - { - yyerror (]b4_lyyerror_args[YY_("syntax error")); - yyMemoryExhausted (yystackp); - } - } - else -#endif /* YYERROR_VERBOSE */ - yyerror (]b4_lyyerror_args[YY_("syntax error")); - yynerrs += 1; + if (yymsg) + { + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyformat)) + { + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + yyerror (]b4_lyyerror_args[yymsg); + YYFREE (yymsg); } + else + { + yyerror (]b4_lyyerror_args[YY_("syntax error")); + yyMemoryExhausted (yystackp); + } +#endif /* YYERROR_VERBOSE */ + yynerrs += 1; } /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, @@ -2642,7 +2664,7 @@ 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-2010]) + [2002-2011]) b4_shared_declarations