-*- C -*-
# GLR skeleton for Bison
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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
## ------------------------ ##
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])
+ [2002-2011])
[
/* C GLR parser skeleton written by Paul Hilfinger. */
#include <string.h>
#ifndef YY_
-# if YYENABLE_NLS
+# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if (! defined __GNUC__ || __GNUC__ < 2 \
- || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) \
+ || (defined __STRICT_ANSI__ && __STRICT_ANSI__))
# define __attribute__(Spec) /* empty */
# endif
#endif
]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. */
+/* YYDEFACT[S] -- default reduction number in state S. Performed 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[
/* 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. */
+ number is the opposite. If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF ]b4_table_ninf[
static const ]b4_int_type_for([b4_table])[ yytable[] =
{
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. */
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
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];
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
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
{
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:
/*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 };
- 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. */
- 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);
-
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- 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;
- }
+ 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;
+ }
+ }
+ }
+
+ 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_
+ }
- yyf = YY_(yyformat);
- yysize1 = yysize + strlen (yyf);
- 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 = *yyf))
- {
- if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyf += 2;
- }
- else
- {
- yyp++;
- yyf++;
- }
- }
- 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,
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)
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;
}
{
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
yychar = YYEMPTY;
yylval = yyval_default;
]b4_locations_if([
-#if YYLTYPE_IS_TRIVIAL
+#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
#endif
[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])
+ [2002-2011])
b4_shared_declarations