X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/9bc0dd679f19b79f7250d2b16563b590a3b032bb..786578e394700615f6a841614e1280bf6284ec8c:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 16ced04f..6f1f7ee9 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1,22 +1,21 @@ -m4_divert(-1) -*- C -*- + -*- C -*- # GLR skeleton for Bison -# Copyright (C) 2002, 2003, 2004, 2005, 2006 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 +# 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 -# the Free Software Foundation; either version 2 of the License, or +# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 USA +# along with this program. If not, see . m4_include(b4_pkgdatadir/[c.m4]) @@ -35,6 +34,13 @@ m4_define_default([b4_stack_depth_init], [200]) ## Pure/impure interfaces. ## ## ------------------------ ## +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. +m4_ifndef([b4_pure_flag], +[b4_percent_define_default([[api.pure]], [[false]]) + m4_define([b4_pure_flag], + [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])]) # b4_user_formals # --------------- @@ -103,7 +109,15 @@ m4_define([b4_pure_formals], # -------------------- # Expansion of $$. m4_define([b4_lhs_value], -[((*yyvalp)[]m4_ifval([$1], [.$1]))]) +[b4_symbol_value([(*yyvalp)], [$1])]) + + +# b4_rhs_data(RULE-LENGTH, NUM) +# ----------------------------- +# Expand to the semantic stack place that contains value and location +# of symbol number NUM in a rule of length RULE-LENGTH. +m4_define([b4_rhs_data], +[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) @@ -111,7 +125,7 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))]) +[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])]) @@ -131,7 +145,7 @@ m4_define([b4_lhs_location], # Expansion of @NUM, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yyloc)]) +[(b4_rhs_data([$1], [$2]).yyloc)]) @@ -141,15 +155,16 @@ m4_define([b4_rhs_location], # We do want M4 expansion after # for CPP macros. m4_changecom() -m4_divert(0)dnl -@output @output_parser_name@ +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. */ ]b4_identification +b4_percent_code_get([[top]])[]dnl m4_if(b4_prefix, [yy], [], [/* Substitute the variable and function names. */ #define yyparse b4_prefix[]parse @@ -162,29 +177,27 @@ m4_if(b4_prefix, [yy], [], #define yylloc b4_prefix[]lloc])[ /* Copy the first part of user declarations. */ -]b4_pre_prologue +]b4_user_pre_prologue dnl # b4_shared_declarations dnl # ---------------------- dnl # Declaration that might either go into the header (if --defines) dnl # or open coded in the parser body. m4_define([b4_shared_declarations], -[m4_ifdef([b4_before_definitions], -[[/* Copy the %before-definitions blocks. */ -]b4_before_definitions])[]dnl +[b4_percent_code_get([[requires]])[]dnl b4_token_enums(b4_tokens) -[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +[#ifndef YYSTYPE ]m4_ifdef([b4_stype], -[typedef union b4_union_name -b4_stype -/* Line __line__ of glr.c. */ -b4_syncline([@oline@], [@ofile@]) - YYSTYPE;], -[typedef int YYSTYPE;])[ -# define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 +[[typedef union ]b4_union_name[ +{ +]b4_user_stype[ +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1]], +[m4_if(b4_tag_seen_flag, 0, +[[typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1]])])[ #endif #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED @@ -203,17 +216,15 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif -]m4_ifdef([b4_after_definitions], -[[/* Copy the %after-definitions blocks. */ -]b4_after_definitions])[]dnl +]b4_percent_code_get([[provides]])[]dnl ]) -b4_defines_if([#include @output_header_name@], +b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], [b4_shared_declarations])[ /* Enabling traces. */ #ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ +# define YYDEBUG ]b4_parse_trace_if([1], [0])[ #endif /* Enabling verbose error messages. */ @@ -221,7 +232,7 @@ b4_defines_if([#include @output_header_name@], # 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. */ @@ -237,15 +248,12 @@ b4_defines_if([#include @output_header_name@], static YYSTYPE yyval_default; /* Copy the second part of user declarations. */ -]b4_post_prologue[ +]b4_user_post_prologue +b4_percent_code_get[]dnl -]/* Line __line__ of glr.c. */ -b4_syncline([@oline@], [@ofile@]) -[ -#include +[#include #include #include -#include #ifndef YY_ # if YYENABLE_NLS @@ -350,8 +358,7 @@ b4_syncline([@oline@], [@ofile@]) #define YYMAXUTOK ]b4_user_token_number_max[ #define YYTRANSLATE(YYX) \ - ((YYX <= 0) ? YYEOF : \ - (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = @@ -360,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[] = { @@ -389,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[] = @@ -413,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 @@ -469,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)[ @@ -564,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 @@ -575,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. */ @@ -934,9 +873,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, ]])[ switch (yyn) { - ]b4_actions -/* Line __line__ of glr.c. */ -b4_syncline([@oline@], [@ofile@])[ + ]b4_user_actions[ default: break; } @@ -1016,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. */ @@ -1036,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 @@ -1054,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]; @@ -1074,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 @@ -1116,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]) { @@ -1351,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; @@ -1363,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 @@ -1381,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 @@ -1429,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__)) = @@ -1438,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, @@ -1447,12 +1377,13 @@ yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { - fprintf (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + YYFPRINTF (stderr, " $%d = ", yyi + 1); + 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[); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, "\n"); } } #endif @@ -1479,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); @@ -1777,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 @@ -2046,11 +1977,19 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } - else - yytoken = YYTRANSLATE (yychar); + yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); while (*yyconflicts != 0) @@ -2100,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; @@ -2155,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); @@ -2216,10 +2162,18 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) } YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + 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) @@ -2227,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; } @@ -2248,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 @@ -2267,7 +2221,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) } } ]b4_locations_if([[ yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ - yydestroyGLRState ("Error: popping", yys]b4_user_args[); + if (yys->yypred != NULL) + yydestroyGLRState ("Error: popping", yys]b4_user_args[); yystackp->yytops.yystates[0] = yys->yypred; yystackp->yynextFree -= 1; yystackp->yyspaceLeft += 1; @@ -2310,19 +2265,17 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yylval = yyval_default; ]b4_locations_if([ #if YYLTYPE_IS_TRIVIAL - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 0; + yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; + yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; #endif ]) m4_ifdef([b4_initial_action], [ m4_pushdef([b4_at_dollar], [yylloc])dnl m4_pushdef([b4_dollar_dollar], [yylval])dnl /* User initialization code. */ - b4_initial_action + b4_user_initial_action m4_popdef([b4_dollar_dollar])dnl -m4_popdef([b4_at_dollar])dnl -/* Line __line__ of glr.c. */ -b4_syncline([@oline@], [@ofile@])])dnl +m4_popdef([b4_at_dollar])])dnl [ if (! yyinitGLRStack (yystackp, YYINITDEPTH)) goto yyexhaustedlab; @@ -2370,19 +2323,26 @@ b4_syncline([@oline@], [@ofile@])])dnl { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } - else - yytoken = YYTRANSLATE (yychar); + yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); if (*yyconflicts != 0) break; if (yyisShiftAction (yyaction)) { YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - if (yychar != YYEOF) - yychar = YYEMPTY; + yychar = YYEMPTY; yyposn += 1; yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc); if (0 < yystack.yyerrState) @@ -2498,7 +2458,7 @@ b4_syncline([@oline@], [@ofile@])])dnl goto yyreturn; yyreturn: - if (yychar != YYEOF && yychar != YYEMPTY) + if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", YYTRANSLATE (yychar), &yylval]b4_locations_if([, &yylloc])[]b4_user_args[); @@ -2520,7 +2480,8 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[yyk]; ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); +)[ if (yys->yypred != NULL) + yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); yystates[yyk] = yys->yypred; yystack.yynextFree -= 1; yystack.yyspaceLeft += 1; @@ -2536,7 +2497,7 @@ b4_syncline([@oline@], [@ofile@])])dnl } /* DEBUGGING ONLY */ -#ifdef YYDEBUG +#if YYDEBUG static void yypstack (yyGLRStack* yystackp, size_t yyk) __attribute__ ((__unused__)); static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__)); @@ -2547,19 +2508,20 @@ yy_yypstack (yyGLRState* yys) if (yys->yypred) { yy_yypstack (yys->yypred); - fprintf (stderr, " -> "); + YYFPRINTF (stderr, " -> "); } - fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn); + YYFPRINTF (stderr, "%d@@%lu", yys->yylrState, + (unsigned long int) yys->yyposn); } static void yypstates (yyGLRState* yyst) { if (yyst == NULL) - fprintf (stderr, ""); + YYFPRINTF (stderr, ""); else yy_yypstack (yyst); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, "\n"); } static void @@ -2579,46 +2541,52 @@ yypdumpstack (yyGLRStack* yystackp) size_t yyi; for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) { - fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystackp->yyitems)); + YYFPRINTF (stderr, "%3lu. ", + (unsigned long int) (yyp - yystackp->yyitems)); if (*(yybool *) yyp) { - fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", - yyp->yystate.yyresolved, yyp->yystate.yylrState, - (unsigned long int) yyp->yystate.yyposn, - (long int) YYINDEX (yyp->yystate.yypred)); + YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", + yyp->yystate.yyresolved, yyp->yystate.yylrState, + (unsigned long int) yyp->yystate.yyposn, + (long int) YYINDEX (yyp->yystate.yypred)); if (! yyp->yystate.yyresolved) - fprintf (stderr, ", firstVal: %ld", - (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal)); + YYFPRINTF (stderr, ", firstVal: %ld", + (long int) YYINDEX (yyp->yystate + .yysemantics.yyfirstVal)); } else { - fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", - yyp->yyoption.yyrule - 1, - (long int) YYINDEX (yyp->yyoption.yystate), - (long int) YYINDEX (yyp->yyoption.yynext)); + YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld", + yyp->yyoption.yyrule - 1, + (long int) YYINDEX (yyp->yyoption.yystate), + (long int) YYINDEX (yyp->yyoption.yynext)); } - fprintf (stderr, "\n"); + YYFPRINTF (stderr, "\n"); } - fprintf (stderr, "Tops:"); + YYFPRINTF (stderr, "Tops:"); for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) - fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi, - (long int) YYINDEX (yystackp->yytops.yystates[yyi])); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi, + (long int) YYINDEX (yystackp->yytops.yystates[yyi])); + YYFPRINTF (stderr, "\n"); } #endif -] - -b4_epilogue -b4_defines_if( -[@output @output_header_name@ +]b4_epilogue[]dnl +dnl +dnl glr.cc produces its own header. +dnl +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 -extern YYSTYPE b4_prefix[]lval; +b4_pure_if([], +[[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)