X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/d0a304384f4207bdf7f8b1038c2226c312f5e954..ae7cd18c98d9bad7e95d4f4070d2d09e8db675f8:/data/glr.c diff --git a/data/glr.c b/data/glr.c index e2363a20..8ef35534 100644 --- a/data/glr.c +++ b/data/glr.c @@ -2,7 +2,7 @@ # GLR skeleton for Bison -# Copyright (C) 2002-2012 Free Software Foundation, Inc. +# Copyright (C) 2002-2013 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 @@ -55,16 +55,6 @@ m4_define([b4_user_formals], [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) -# b4_lex_param -# ------------ -# Accumule in b4_lex_param all the yylex arguments. -# Yes, this is quite ugly... -m4_define([b4_lex_param], -m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl -b4_locations_if([, [[YYLTYPE *], [&yylloc]]])])dnl -m4_ifdef([b4_lex_param], [, ]b4_lex_param))) - - # b4_yyerror_args # --------------- # Optional effective arguments passed to yyerror: user args plus yylloc, and @@ -188,13 +178,10 @@ m4_if(b4_skeleton, ["glr.c"], ## Output files. ## ## -------------- ## -# We do want M4 expansion after # for CPP macros. -m4_changecom() -m4_divert_push(0)dnl -@output(b4_parser_file_name@)@ +b4_output_begin([b4_parser_file_name]) b4_copyright([Skeleton implementation for Bison GLR parsers in C], - [2002-2012]) -[ + [2002-2013])[ + /* C GLR parser skeleton written by Paul Hilfinger. */ ]b4_identification @@ -209,11 +196,12 @@ b4_percent_code_get([[top]])[ #define yyparse ]b4_prefix[parse #define yylex ]b4_prefix[lex #define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug +]]b4_pure_if([], [[ #define yylval ]b4_prefix[lval #define yychar ]b4_prefix[char -#define yydebug ]b4_prefix[debug #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ -#define yylloc ]b4_prefix[lloc]])])[ +#define yylloc ]b4_prefix[lloc]])]))[ /* First part of user declarations. */ ]b4_user_pre_prologue[ @@ -232,11 +220,11 @@ b4_percent_code_get([[top]])[ #endif /* Default (constant) value used for initialization for null - right-hand sides. Unlike the standard yacc.c template, - here we set the default value of $$ to a zeroed-out value. - Since the default value is undefined, this behavior is - technically correct. */ -static YYSTYPE yyval_default; + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ +static YYSTYPE yyval_default;]b4_locations_if([[ +static YYLTYPE yyloc_default][]b4_yyloc_default;])[ /* Copy the second part of user declarations. */ ]b4_user_post_prologue @@ -258,13 +246,6 @@ b4_percent_code_get[]dnl # endif #endif -/* Suppress unused-variable warnings by "using" E. */ -#ifdef __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - #ifndef YYFREE # define YYFREE free #endif @@ -289,28 +270,11 @@ b4_percent_code_get[]dnl # include # define YYJMP_BUF jmp_buf # define YYSETJMP(Env) setjmp (Env) -// Pacify clang. +/* Pacify clang. */ # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0)) #endif -/*-----------------. -| GCC extensions. | -`-----------------*/ - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if (! defined __GNUC__ || __GNUC__ < 2 \ - || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) -# define __attribute__(Spec) /* empty */ -# endif -#endif - -]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[ -#ifdef __cplusplus -# define YYOPTIONAL_LOC(Name) /* empty */ -#else -# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) -#endif])[ +]b4_attribute_define[ #ifndef YYASSERT # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) @@ -401,7 +365,7 @@ static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by 0, pointed into by YYCONFLP. */ ]dnl Do not use b4_int_type_for here, since there are places where -dnl pointers onto yyconfl are taken, which type is "short int *". +dnl pointers onto yyconfl are taken, whose type is "short int *". dnl We probably ought to introduce a type for confl. [static const short int yyconfl[] = { @@ -412,31 +376,9 @@ dnl We probably ought to introduce a type for confl. #define YYTERROR 1 ]b4_locations_if([[ -#ifndef YYLLOC_DEFAULT ]b4_yylloc_default_define[ # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ - -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -#endif -]],[ -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0) -#endif -])[ - -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - -/* YYLEX -- calling `yylex' with the right arguments. */ -#define YYLEX ]b4_function_call([yylex], [int], b4_lex_param)[ +]])[ ]b4_pure_if( [ @@ -477,6 +419,8 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; # define YYFPRINTF fprintf # endif +]b4_yy_location_print_define[ + # define YYDPRINTF(Args) \ do { \ if (yydebug) \ @@ -499,6 +443,12 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; multiple parsers can coexist. */ int yydebug; +struct yyGLRStack; +static void yypstack (struct yyGLRStack* yystackp, size_t yyk) + __attribute__ ((__unused__)); +static void yypdumpstack (struct yyGLRStack* yystackp) + __attribute__ ((__unused__)); + #else /* !]b4_api_PREFIX[DEBUG */ # define YYDPRINTF(Args) @@ -797,7 +747,7 @@ yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, * yyerr for YYERROR, yyabort for YYABORT. */ static YYRESULTTAG -yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, +yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp, yyGLRStack* yystackp, YYSTYPE* yyvalp]b4_locuser_formals[) { @@ -805,7 +755,8 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, (yystackp->yysplitPoint == YY_NULL); int yylow; ]b4_parse_param_use([yyvalp], [yylocp])dnl -[# undef yyerrok +[ YYUSE (yyrhslen); +# undef yyerrok # define yyerrok (yystackp->yyerrState = 0) # undef YYACCEPT # define YYACCEPT return yyaccept @@ -885,12 +836,10 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) if (yydebug) { if (yys->yysemantics.yyfirstVal) - YYFPRINTF (stderr, "%s unresolved ", yymsg); + YYFPRINTF (stderr, "%s unresolved", yymsg); else - YYFPRINTF (stderr, "%s incomplete ", yymsg); - yy_symbol_print (stderr, yystos[yys->yylrState], - YY_NULL]b4_locuser_args([&yys->yyloc])[); - YYFPRINTF (stderr, "\n"); + YYFPRINTF (stderr, "%s incomplete", yymsg); + YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULL, &yys->yyloc); } #endif @@ -1015,6 +964,7 @@ yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate, { yySemanticOption* yynewOption = &yynewGLRStackItem (yystackp, yyfalse)->yyoption; + YYASSERT (!yynewOption->yyisState); yynewOption->yystate = yyrhs; yynewOption->yyrule = yyrule; if (yystackp->yytops.yylookaheadNeeds[yyk]) @@ -1131,7 +1081,7 @@ yyexpandGLRStack (yyGLRStack* yystackp) } if (yystackp->yysplitPoint != YY_NULL) yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, - yystackp->yysplitPoint, yystate); + yystackp->yysplitPoint, yystate); for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) if (yystackp->yytops.yystates[yyn] != YY_NULL) @@ -1250,6 +1200,7 @@ yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) { yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + YYASSERT (yynewState->yyisState); yynewState->yylrState = yylrState; yynewState->yyposn = yyposn; @@ -1369,11 +1320,10 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, if (yyforceEval || yystackp->yysplitPoint == YY_NULL) { - YYRESULTTAG yyflag; - YYSTYPE yysval;]b4_locations_if([ - YYLTYPE yyloc;])[ + YYSTYPE yysval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ - yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[); + YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[); if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULL) { YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n", @@ -1947,7 +1897,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; } if (yychar <= YYEOF) @@ -2025,10 +1975,10 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) #if ! YYERROR_VERBOSE yyerror (]b4_lyyerror_args[YY_("syntax error")); #else + { yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken)); size_t yysize = yysize0; - size_t yysize1; yybool yysize_overflow = yyfalse; char* yymsg = YY_NULL; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; @@ -2088,9 +2038,11 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) break; } yyarg[yycount++] = yytokenName (yyx); - yysize1 = yysize + yytnamerr (YY_NULL, yytokenName (yyx)); - yysize_overflow |= yysize1 < yysize; - yysize = yysize1; + { + size_t yysz = yysize + yytnamerr (YY_NULL, yytokenName (yyx)); + yysize_overflow |= yysz < yysize; + yysize = yysz; + } } } } @@ -2110,9 +2062,11 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) #undef YYCASE_ } - yysize1 = yysize + strlen (yyformat); - yysize_overflow |= yysize1 < yysize; - yysize = yysize1; + { + size_t yysz = yysize + strlen (yyformat); + yysize_overflow |= yysz < yysize; + yysize = yysz; + } if (!yysize_overflow) yymsg = (char *) YYMALLOC (yysize); @@ -2142,6 +2096,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yyerror (]b4_lyyerror_args[YY_("syntax error")); yyMemoryExhausted (yystackp); } + } #endif /* YYERROR_VERBOSE */ yynerrs += 1; } @@ -2177,7 +2132,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yytoken, &yylval]b4_locuser_args([&yylloc])[); } YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; if (yychar <= YYEOF) { yychar = yytoken = YYEOF; @@ -2278,14 +2233,9 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; - yylval = yyval_default; -]b4_locations_if([ -#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL - 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], [ + yylval = yyval_default;]b4_locations_if([ + yylloc = yyloc_default;])[ +]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([yylval], [], [yylloc])dnl /* User initialization code. */ b4_user_initial_action @@ -2336,7 +2286,7 @@ b4_dollar_popdef])[]dnl if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; } if (yychar <= YYEOF) @@ -2510,10 +2460,6 @@ b4_dollar_popdef])[]dnl /* DEBUGGING ONLY */ #if ]b4_api_PREFIX[DEBUG -static void yypstack (yyGLRStack* yystackp, size_t yyk) - __attribute__ ((__unused__)); -static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__)); - static void yy_yypstack (yyGLRState* yys) { @@ -2557,6 +2503,8 @@ yypdumpstack (yyGLRStack* yystackp) (unsigned long int) (yyp - yystackp->yyitems)); if (*(yybool *) yyp) { + YYASSERT (yyp->yystate.yyisState); + YYASSERT (yyp->yyoption.yyisState); YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", yyp->yystate.yyresolved, yyp->yystate.yylrState, (unsigned long int) yyp->yystate.yyposn, @@ -2568,6 +2516,8 @@ yypdumpstack (yyGLRStack* yystackp) } else { + YYASSERT (!yyp->yystate.yyisState); + YYASSERT (!yyp->yyoption.yyisState); YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld", yyp->yyoption.yyrule - 1, (long int) YYINDEX (yyp->yyoption.yystate), @@ -2582,18 +2532,35 @@ yypdumpstack (yyGLRStack* yystackp) YYFPRINTF (stderr, "\n"); } #endif + +#undef yylval +#undef yychar +#undef yynerrs]b4_locations_if([ +#undef yylloc]) + +m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define yyparse ]b4_prefix[parse +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char +#define yydebug ]b4_prefix[debug +#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])])[ + ]b4_epilogue[]dnl -dnl -dnl glr.cc produces its own header. -dnl +b4_output_end() + +# glr.cc produces its own header. m4_if(b4_skeleton, ["glr.c"], [b4_defines_if( -[@output(b4_spec_defines_file@)@ +[b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C], - [2002-2012])[ + [2002-2013])[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]])])dnl -m4_divert_pop(0) +]b4_output_end() +])])