X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/49b6b48b990e55f2eef0fa5dcc9eb0b16fa92826..473013144def14af635adc1c47d3718d41ced23e:/data/yacc.c?ds=sidebyside diff --git a/data/yacc.c b/data/yacc.c index dc2d58d6..92c0ddec 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -58,8 +58,8 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) # b4_lex_param arrives quoted twice, but we want to keep only one level. m4_define([b4_lex_param], m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl -b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl -m4_ifdef([b4_lex_param], [, ]b4_lex_param))) +b4_location_if([, [[YYLTYPE *], [&yylloc]]])m4_ifdef([b4_lex_param], [, ])])dnl +m4_ifdef([b4_lex_param], b4_lex_param))) @@ -216,18 +216,25 @@ b4_syncline([@oline@], [@ofile@])[ #if ! defined (yyoverflow) || YYERROR_VERBOSE +# ifndef YYFREE +# define YYFREE free +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# endif + /* The parser invokes alloca or malloc; define the necessary symbols. */ -# if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# define YYSTACK_ALLOC alloca +# endif # else -# ifndef YYSTACK_USE_ALLOCA -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca -# else -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# endif +# if defined (alloca) || defined (_ALLOCA_H) +# define YYSTACK_ALLOC alloca +# else +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca # endif # endif # endif @@ -240,15 +247,16 @@ b4_syncline([@oline@], [@ofile@])[ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif -# define YYSTACK_ALLOC malloc -# define YYSTACK_FREE free +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE # endif #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ - || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL))) + || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ + && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -275,7 +283,7 @@ union yyalloc /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY -# if 1 < __GNUC__ +# if defined (__GNUC__) && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else @@ -465,7 +473,8 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 +#define YYERROR goto yyerrorlab + /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. @@ -499,11 +508,11 @@ while (0) are run). */ #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + ((Current).first_line = (Rhs)[1].first_line, \ + (Current).first_column = (Rhs)[1].first_column, \ + (Current).last_line = (Rhs)[N].last_line, \ + (Current).last_column = (Rhs)[N].last_column) #endif /* YYLEX -- calling `yylex' with the right arguments. */ @@ -575,9 +584,9 @@ do { \ [[int yyrule], [yyrule]])[ { int yyi; - unsigned int yylineno = yyrline[yyrule]; + unsigned int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", - yyrule - 1, yylineno); + yyrule - 1, yylno); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); @@ -614,7 +623,7 @@ int yydebug; SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ -#if YYMAXDEPTH == 0 +#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 # undef YYMAXDEPTH #endif @@ -981,7 +990,7 @@ yyreduce: ]b4_location_if( [ /* Default location. */ - YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[ + YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);])[ YY_REDUCE_PRINT (yyn); switch (yyn) ]{ @@ -1030,18 +1039,33 @@ yyerrlab: { YYSIZE_T yysize = 0; int yytype = YYTRANSLATE (yychar); + const char* yyprefix; char *yymsg; - int yyx, yycount; + int yyx; - yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 0; + + yyprefix = ", expecting "; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("syntax error, unexpected ") + 1; - yysize += yystrlen (yytname[yytype]); + { + yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); + yycount += 1; + if (yycount == 5) + { + yysize = 0; + break; + } + } + yysize += (sizeof ("syntax error, unexpected ") + + yystrlen (yytname[yytype])); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { @@ -1050,16 +1074,13 @@ yyerrlab: if (yycount < 5) { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) + yyprefix = ", expecting "; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yyprefix); yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; + yyprefix = " or "; } } yyerror (]b4_yyerror_args[yymsg); @@ -1080,56 +1101,59 @@ yyerrlab: /* If just tried and failed to reuse lookahead token after an error, discard it. */ - /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar <= YYEOF) { - /* Pop the error token. */ - YYPOPSTACK; - /* Pop the rest of the stack. */ - while (yyss < yyssp) - { - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); - YYPOPSTACK; - } - YYABORT; + /* If at end of input, pop the error token, + then the rest of the stack, then return failure. */ + if (yychar == YYEOF) + for (;;) + { + YYPOPSTACK; + if (yyssp == yyss) + YYABORT; + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); + } } - - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[); - yychar = YYEMPTY; -]b4_location_if([ *++yylerrsp = yylloc;])[ + else + { + YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); + yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[); + yychar = YYEMPTY; +]b4_location_if([ *++yylerrsp = yylloc;])[ + } } /* Else will try to reuse lookahead token after shifting the error token. */ - goto yyerrlab2; + goto yyerrlab1; -/*----------------------------------------------------. -| yyerrlab1 -- error raised explicitly by an action. | -`----------------------------------------------------*/ -yyerrlab1: +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: - /* Suppress GCC warning that yyerrlab1 is unused when no action - invokes YYERROR. MacOS 10.2.3's buggy "smart preprocessor" - insists on the trailing semicolon. */ -#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) - /* GNU C++ (as of version 3.2.1) does not allow attributes on labels. */ -# ifndef __cplusplus - __attribute__ ((__unused__)); -# endif +#ifdef __GNUC__ + /* Pacify GCC when the user code never invokes YYERROR and the label + yyerrorlab therefore never appears in user code. */ + if (0) + goto yyerrorlab; #endif -]b4_location_if([ yylerrsp = yylsp; - *++yylerrsp = yyloc;])[ - goto yyerrlab2; + yyvsp -= yylen; + yyssp -= yylen; + yystate = *yyssp; + ]b4_location_if([yylerrsp = yylsp; + *++yylerrsp = yyloc; + yylsp -= yylen; + ])[goto yyerrlab1; -/*---------------------------------------------------------------. -| yyerrlab2 -- pop states until the error token can be shifted. | -`---------------------------------------------------------------*/ -yyerrlab2: +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) @@ -1152,9 +1176,8 @@ yyerrlab2: YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[); - yyvsp--; - yystate = *--yyssp; -]b4_location_if([ yylsp--;])[ + YYPOPSTACK; + yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } @@ -1164,7 +1187,7 @@ yyerrlab2: YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; -]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, (yylerrsp - yylsp)); +]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, yylerrsp - yylsp); *++yylsp = yyloc;])[ yystate = yyn;