X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/4b3847c3c0e161b85267d077adb256a880c0f3e3..623a5147e67ac2f657f23fcedb660df87515c806:/data/glr.c diff --git a/data/glr.c b/data/glr.c index ce611600..89a76e3e 100644 --- a/data/glr.c +++ b/data/glr.c @@ -18,7 +18,10 @@ # along with this program. If not, see . -m4_include(b4_pkgdatadir/[c.m4]) +# If we are loaded by glr.cc, do not override c++.m4 definitions by +# those of c.m4. +m4_if(b4_skeleton, ["glr.c"], + [m4_include(b4_pkgdatadir/[c.m4])]) ## ---------------- ## ## Default values. ## @@ -190,12 +193,8 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C], b4_percent_code_get([[top]])[ ]m4_if(b4_api_prefix, [yy], [], [[/* Substitute the type names. */ -#define YYSTYPE ]b4_api_PREFIX[STYPE -#define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL -#define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[ -#define YYLTYPE ]b4_api_PREFIX[LTYPE -#define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL -#define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[ +#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ +#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ ]m4_if(b4_prefix, [yy], [], [[/* Substitute the variable and function names. */ #define yyparse ]b4_prefix[parse @@ -224,11 +223,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([ +b4_yyloc_default_define])[ /* Copy the second part of user declarations. */ ]b4_user_post_prologue @@ -242,24 +241,24 @@ b4_percent_code_get[]dnl # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else ]b4_c_function_def([YYID], [static int], [[int i], [i]])[ { @@ -290,8 +289,9 @@ b4_percent_code_get[]dnl #ifndef YYSETJMP # include # define YYJMP_BUF jmp_buf -# define YYSETJMP(env) setjmp (env) -# define YYLONGJMP(env, val) longjmp (env, val) +# define YYSETJMP(Env) setjmp (Env) +// Pacify clang. +# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0)) #endif /*-----------------. @@ -314,7 +314,7 @@ b4_percent_code_get[]dnl #endif])[ #ifndef YYASSERT -# define YYASSERT(condition) ((void) ((condition) || (abort (), 0))) +# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) #endif /* YYFINAL -- State number of the termination state. */ @@ -349,7 +349,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = ]b4_translate[ }; -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const ]b4_int_type_for([b4_prhs])[ yyprhs[] = @@ -370,7 +370,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ +#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -471,34 +471,13 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = ]b4_stos[ }; - /* Error token number */ #define YYTERROR 1 -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - ]b4_locations_if([[ -#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) +]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 @@ -519,7 +498,6 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = # define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif - /* YYLEX -- calling `yylex' with the right arguments. */ #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[ @@ -553,7 +531,7 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ while (YYID (0)) -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG # ifndef YYFPRINTF # define YYFPRINTF fprintf @@ -581,12 +559,12 @@ do { \ multiple parsers can coexist. */ int yydebug; -#else /* !YYDEBUG */ +#else /* !]b4_api_PREFIX[DEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) -#endif /* !YYDEBUG */ +#endif /* !]b4_api_PREFIX[DEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH @@ -613,8 +591,8 @@ int yydebug; #ifndef YYSTACKEXPANDABLE # if (! defined __cplusplus \ - || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ - && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)) + || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \ + && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL)) # define YYSTACKEXPANDABLE 1 # else # define YYSTACKEXPANDABLE 0 @@ -825,7 +803,7 @@ yyMemoryExhausted (yyGLRStack* yystackp) YYLONGJMP (yystackp->yyexception_buffer, 2); } -#if YYDEBUG || YYERROR_VERBOSE +#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE /** A printable representation of TOKEN. */ static inline const char* yytokenName (yySymbol yytoken) @@ -962,7 +940,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[); else { -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG if (yydebug) { if (yys->yysemantics.yyfirstVal) @@ -995,8 +973,8 @@ yylhsNonterm (yyRuleNum yyrule) return yyr1[yyrule]; } -#define yypact_value_is_default(yystate) \ - ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_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). */ @@ -1013,8 +991,8 @@ yydefaultAction (yyStateNum yystate) return yydefact[yystate]; } -#define yytable_value_is_error(yytable_value) \ - ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_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 @@ -1391,7 +1369,7 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, } } -#if !YYDEBUG +#if !]b4_api_PREFIX[DEBUG # define YY_REDUCE_PRINT(Args) #else # define YY_REDUCE_PRINT(Args) \ @@ -1712,7 +1690,7 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, return yyflag; } -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG static void yyreportTree (yySemanticOption* yyx, int yyindent) { @@ -1767,7 +1745,7 @@ yyreportAmbiguity (yySemanticOption* yyx0, YYUSE (yyx0); YYUSE (yyx1); -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG YYFPRINTF (stderr, "Ambiguity detected.\n"); YYFPRINTF (stderr, "Option 1,\n"); yyreportTree (yyx0, 2); @@ -2317,20 +2295,13 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; - yylval = yyval_default; -]b4_locations_if([ -#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 -]) -m4_ifdef([b4_initial_action], [ -m4_pushdef([b4_at_dollar], [yylloc])dnl -m4_pushdef([b4_dollar_dollar], [yylval])dnl - /* User initialization code. */ - b4_user_initial_action -m4_popdef([b4_dollar_dollar])dnl -m4_popdef([b4_at_dollar])])dnl + 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 +b4_dollar_popdef])[]dnl [ if (! yyinitGLRStack (yystackp, YYINITDEPTH)) goto yyexhaustedlab; @@ -2551,7 +2522,7 @@ m4_popdef([b4_at_dollar])])dnl } /* DEBUGGING ONLY */ -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG static void yypstack (yyGLRStack* yystackp, size_t yyk) __attribute__ ((__unused__)); static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__)); @@ -2624,9 +2595,7 @@ yypdumpstack (yyGLRStack* yystackp) YYFPRINTF (stderr, "\n"); } #endif -] - -b4_epilogue +]b4_epilogue[]dnl dnl dnl glr.cc produces its own header. dnl @@ -2639,5 +2608,5 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C], ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]])]) +]])])dnl m4_divert_pop(0)