X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/180d45ba81510aee0de19f20fc6069b9681abe3c..a220f55509520a1a647803657537c0933dc31c09:/src/bison.simple diff --git a/src/bison.simple b/src/bison.simple index 9c1a8c12..9b627b1c 100644 --- a/src/bison.simple +++ b/src/bison.simple @@ -98,10 +98,31 @@ # endif /* alloca not defined */ #endif /* YYSTACK_USE_ALLOCA not defined */ +#ifndef YYSTACK_USE_ALLOCA +# define YYSTACK_USE_ALLOCA 0 +#endif + +/* Realloc WHAT from SIZE to YYSTACKSIZE elements of TYPE. + If WHAT was malloc'ed (not the original automatic ARRAY), free it. */ #if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca +# define YYSTACK_REALLOC(Type, What, Array) \ +do { \ + Type *old = What; \ + What = (Type *) malloc (yystacksize * sizeof (Type)); \ + __yy_memcpy ((char *) What, (char *) old, \ + (size) * (unsigned int) sizeof (Type)); \ + yyfree_stacks = 1; \ + if (old != Array) \ + free (old); \ +} while (0) #else -# define YYSTACK_ALLOC malloc +# define YYSTACK_REALLOC(Type, What, Array) \ +do { \ + Type *old = What; \ + What = (Type *) alloca (yystacksize * sizeof (Type)); \ + __yy_memcpy ((char *) What, (char *) old, \ + (size) * (unsigned int) sizeof (Type)); \ +} while (0) #endif #define YYBISON 1 /* Identify Bison output. */ @@ -113,7 +134,8 @@ #line %%input_line "%%filename" #ifndef YYSTYPE -typedef %%stype YYSTYPE; +typedef %%stype yystype; +# define YYSTYPE yystype #endif #ifndef YYLTYPE @@ -129,6 +151,9 @@ typedef struct yyltype #ifndef YYERROR_VERBOSE # define YYERROR_VERBOSE %%verbose +#else +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 #endif /* Tokens. */ @@ -447,7 +472,7 @@ yyparse (YYPARSE_PARAM_ARG) /* Three stacks and their tools: `yyss': related to states, - `yysv': related to semantic values, + `yyvs': related to semantic values, `yyls': related to locations. Refer to the stacks thru separate pointers, to allow yyoverflow @@ -512,51 +537,49 @@ yyparse (YYPARSE_PARAM_ARG) /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ -yynewstate: + yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. so pushing a state here evens the stacks. */ yyssp++; -yysetstate: + yysetstate: *yyssp = yystate; if (yyssp >= yyss + yystacksize - 1) { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into memory. - */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; -#if YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif - /* Get the current used size of the three stacks, in elements. */ int size = yyssp - yyss + 1; #ifdef yyoverflow - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. */ + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. */ # if YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow ("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); + YYLTYPE *yyls1 = yyls; + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow ("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); + yyls = yyls1; # else - yyoverflow ("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -# endif - - yyss = yyss1; yyvs = yyvs1; -# if YYLSP_NEEDED - yyls = yyls1; + yyoverflow ("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); # endif + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) @@ -575,19 +598,11 @@ yysetstate: yystacksize *= 2; if (yystacksize > YYMAXDEPTH) yystacksize = YYMAXDEPTH; -# if !YYSTACK_USE_ALLOCA - yyfree_stacks = 1; -# endif - yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); - __yy_memcpy ((char *)yyss, (char *)yyss1, - size * (unsigned int) sizeof (*yyssp)); - yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); - __yy_memcpy ((char *)yyvs, (char *)yyvs1, - size * (unsigned int) sizeof (*yyvsp)); + + YYSTACK_REALLOC (short, yyss, yyssa); + YYSTACK_REALLOC (YYSTYPE, yyvs, yyvsa); # if YYLSP_NEEDED - yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); - __yy_memcpy ((char *)yyls, (char *)yyls1, - size * (unsigned int) sizeof (*yylsp)); + YYSTACK_REALLOC (YYLTYPE, yyls, yylsa); # endif #endif /* no yyoverflow */ @@ -761,7 +776,7 @@ yyreduce: #endif switch (yyn) { - %%action /* The action file replaces this line. */ + %%action } #line %%line "%%skeleton" @@ -821,30 +836,29 @@ yyerrlab: int x, count; count = 0; - /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ - for (x = (yyn < 0 ? -yyn : 0); + /* Start X at -YYN if negative to avoid negative indexes in + YYCHECK. */ + for (x = yyn < 0 ? -yyn : 0; x < (int) (sizeof (yytname) / sizeof (char *)); x++) if (yycheck[x + yyn] == x) size += strlen (yytname[x]) + 15, count++; - size += strlen ("parse error, unexpected `") + 1; + size += strlen ("parse error, unexpected ") + 1; size += strlen (yytname[YYTRANSLATE (yychar)]); msg = (char *) malloc (size); if (msg != 0) { - strcpy (msg, "parse error, unexpected `"); + strcpy (msg, "parse error, unexpected "); strcat (msg, yytname[YYTRANSLATE (yychar)]); - strcat (msg, "'"); if (count < 5) { count = 0; - for (x = (yyn < 0 ? -yyn : 0); + for (x = yyn < 0 ? -yyn : 0; x < (int) (sizeof (yytname) / sizeof (char *)); x++) if (yycheck[x + yyn] == x) { - strcat (msg, count == 0 ? ", expecting `" : " or `"); + strcat (msg, count == 0 ? ", expecting " : " or "); strcat (msg, yytname[x]); - strcat (msg, "'"); count++; } } @@ -852,7 +866,7 @@ yyerrlab: free (msg); } else - yyerror ("parse error; also virtual memory exceeded"); + yyerror ("parse error; also virtual memory exhausted"); } else #endif /* YYERROR_VERBOSE */ @@ -995,4 +1009,3 @@ yyabortlab: #line %%input_line "%%filename" %%epilogue -