X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/327afc7c849accd5fd7f97bd061f6480c6961ed8..0e021770cc023c6a2e7ae132a3aab55bc7cbc058:/data/glr.c diff --git a/data/glr.c b/data/glr.c index a3a3f49d..37ba588c 100644 --- a/data/glr.c +++ b/data/glr.c @@ -21,6 +21,9 @@ m4_divert(-1) -*- C -*- m4_include(b4_pkgdatadir/[c.m4]) +b4_push_if([ +m4_fatal([Non-deterministic push parsers are not yet supported])]) + ## ---------------- ## ## Default values. ## ## ---------------- ## @@ -67,7 +70,7 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) # b4_lyyerror_args # ---------------- -# Same as above, but on the look-ahead, hence &yylloc instead of yylocp. +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. m4_define([b4_lyyerror_args], [b4_pure_if([b4_locations_if([&yylloc, ])])dnl m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) @@ -82,7 +85,7 @@ m4_define([b4_pure_args], # b4_lpure_args # ------------- -# Same as above, but on the look-ahead, hence &yylloc instead of yylocp. +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. m4_define([b4_lpure_args], [b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) @@ -142,7 +145,7 @@ m4_define([b4_rhs_location], # We do want M4 expansion after # for CPP macros. m4_changecom() m4_divert(0)dnl -@output @output_parser_name@ +@output b4_parser_file_name b4_copyright([Skeleton implementation for Bison GLR parsers in C], [2002, 2003, 2004, 2005, 2006]) [ @@ -159,28 +162,31 @@ m4_if(b4_prefix, [yy], [], #define yychar b4_prefix[]char #define yydebug b4_prefix[]debug #define yynerrs b4_prefix[]nerrs -#define yylloc b4_prefix[]lloc]) +#define yylloc b4_prefix[]lloc])[ + +/* Copy the first part of user declarations. */ +]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], -[b4_token_enums(b4_tokens)[ +[m4_ifdef([b4_requires], +[[/* Copy the %requires blocks. */ +]b4_user_requires])[]dnl -/* Copy the first part of user declarations. */ -]b4_pre_prologue[ +b4_token_enums(b4_tokens) -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +[#ifndef YYSTYPE ]m4_ifdef([b4_stype], -[typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ]) -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 @@ -198,10 +204,14 @@ typedef struct YYLTYPE # define YYLTYPE_IS_DECLARED 1 # define YYLTYPE_IS_TRIVIAL 1 #endif -]]) -b4_defines_if([#include @output_header_name@], - [b4_shared_declarations])[ +]m4_ifdef([b4_provides], +[[/* Copy the %provides blocks. */ +]b4_user_provides])[]dnl +]) + +b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], + [b4_shared_declarations])[ /* Enabling traces. */ #ifndef YYDEBUG @@ -229,15 +239,11 @@ 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[ -]/* Line __line__ of glr.c. */ -b4_syncline([@oline@], [@ofile@]) -[ #include #include #include -#include #ifndef YY_ # if YYENABLE_NLS @@ -342,8 +348,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[] = @@ -906,7 +911,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, # undef YYERROR # define YYERROR return yyerrok, yyerr # undef YYRECOVERING -# define YYRECOVERING (yystackp->yyerrState != 0) +# define YYRECOVERING() (yystackp->yyerrState != 0) # undef yyclearin # define yyclearin (yychar = YYEMPTY) # undef YYFILL @@ -926,9 +931,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; } @@ -1741,7 +1744,7 @@ yyreportTree (yySemanticOption* yyx, int yyindent) int yynrhs = yyrhsLength (yyx->yyrule); int yyi; yyGLRState* yys; - yyGLRState* yystates[YYMAXRHS]; + yyGLRState* yystates[1 + YYMAXRHS]; yyGLRState yyleftmost_state; for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) @@ -1757,11 +1760,11 @@ yyreportTree (yySemanticOption* yyx, int yyindent) if (yyx->yystate->yyposn < yys->yyposn + 1) YYFPRINTF (stderr, "%*s%s -> \n", yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), - yyx->yyrule); + yyx->yyrule - 1); else YYFPRINTF (stderr, "%*s%s -> \n", yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), - yyx->yyrule, (unsigned long int) (yys->yyposn + 1), + yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1), (unsigned long int) yyx->yystate->yyposn); for (yyi = 1; yyi <= yynrhs; yyi += 1) { @@ -1836,8 +1839,14 @@ yyresolveLocations (yyGLRState* yys1, int yyn1, } else { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ yyGLRState *yyprevious = yyoption->yystate; - YYASSERT (yyprevious->yyresolved); yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; } yychar_current = yychar; @@ -2032,11 +2041,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) @@ -2077,7 +2094,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) #if YYERROR_VERBOSE int yyn; yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; - if (YYPACT_NINF < yyn && yyn < YYLAST) + if (YYPACT_NINF < yyn && yyn <= YYLAST) { yySymbol yytoken = YYTRANSLATE (yychar); size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken)); @@ -2104,7 +2121,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn; + int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yycount = 1; @@ -2172,7 +2189,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, yylval, and yylloc are the syntactic category, semantic value, and location - of the look-ahead. */ + of the lookahead. */ /*ARGSUSED*/ static void yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { @@ -2202,8 +2219,16 @@ 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)) return; @@ -2253,7 +2278,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; @@ -2296,19 +2322,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; @@ -2356,19 +2380,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) @@ -2484,7 +2515,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[); @@ -2506,7 +2537,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; @@ -2517,7 +2549,8 @@ b4_syncline([@oline@], [@ofile@])])dnl yyfreeGLRStack (&yystack); } - return yyresult; + /* Make sure YYID is used. */ + return YYID (yyresult); } /* DEBUGGING ONLY */ @@ -2578,7 +2611,7 @@ yypdumpstack (yyGLRStack* yystackp) else { fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", - yyp->yyoption.yyrule, + yyp->yyoption.yyrule - 1, (long int) YYINDEX (yyp->yyoption.yystate), (long int) YYINDEX (yyp->yyoption.yynext)); } @@ -2594,8 +2627,12 @@ yypdumpstack (yyGLRStack* yystackp) ] b4_epilogue -b4_defines_if( -[@output @output_header_name@ +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]) @@ -2606,4 +2643,4 @@ extern YYSTYPE b4_prefix[]lval; b4_locations_if([b4_pure_if([], [extern YYLTYPE b4_prefix[]lloc;]) ]) -]) +])])