X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/25a648d8a6a00bb810844e375d0d15125ed7eaf8..b55b68608ff93cede27113663c6c0b0c82539ebc:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 93ed5128..f22a8f10 100644 --- a/data/glr.c +++ b/data/glr.c @@ -2,8 +2,7 @@ # GLR skeleton for Bison -# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, -# 2010 Free Software Foundation, Inc. +# Copyright (C) 2002-2011 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 @@ -36,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], @@ -159,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, 2007, 2008, 2009, 2010]) + [2002-2011]) [ /* C GLR parser skeleton written by Paul Hilfinger. */ @@ -1758,7 +1757,7 @@ yyreportAmbiguity (yySemanticOption* yyx0, yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); return yyabort; -} +}]b4_locations_if([[ /** Resolve the locations for each of the YYN1 states in *YYSTACKP, * ending at YYS1. Has no effect on previously resolved states. @@ -1816,7 +1815,7 @@ yyresolveLocations (yyGLRState* yys1, int yyn1, yylloc = yylloc_current; } } -} +}]])[ /** Resolve the ambiguity represented in state YYS in *YYSTACKP, * perform the indicated actions, and set the semantic value of YYS. @@ -1851,8 +1850,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: @@ -2081,11 +2080,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) #if ! YYERROR_VERBOSE yyerror (]b4_lyyerror_args[YY_("syntax error")); #else - int yyn; - yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; -if (YYPACT_NINF < yyn && yyn <= YYLAST) - { - yySymbol yytoken = YYTRANSLATE (yychar); + yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken)); size_t yysize = yysize0; size_t yysize1; @@ -2096,23 +2091,47 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST) 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) + { + 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; - - /* 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 && !yytable_value_is_error (yytable[yyx + yyn])) @@ -2128,6 +2147,8 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST) yysize_overflow |= yysize1 < yysize; yysize = yysize1; } + } + } switch (yycount) { @@ -2135,6 +2156,7 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST) 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")); @@ -2175,9 +2197,6 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST) yyerror (]b4_lyyerror_args[YY_("syntax error")); yyMemoryExhausted (yystackp); } - } -else - yyerror (]b4_lyyerror_args[YY_("syntax error")); #endif /* YYERROR_VERBOSE */ yynerrs += 1; } @@ -2629,7 +2648,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, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010]) + [2002-2011]) b4_shared_declarations