# 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
## ------------------------ ##
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],
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. */
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.
yylloc = yylloc_current;
}
}
-}
+}]])[
/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
* perform the indicated actions, and set the semantic value of YYS.
{
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:
#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;
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]))
yysize_overflow |= yysize1 < yysize;
yysize = yysize1;
}
+ }
+ }
switch (yycount)
{
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"));
yyerror (]b4_lyyerror_args[YY_("syntax error"));
yyMemoryExhausted (yystackp);
}
- }
-else
- yyerror (]b4_lyyerror_args[YY_("syntax error"));
#endif /* YYERROR_VERBOSE */
yynerrs += 1;
}
[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