X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/050c471b8e388201f40283dd29a1a5abd52385b8..265d1ec4033b97a5edae18e83e85f5eb23bf5a96:/data/yacc.c diff --git a/data/yacc.c b/data/yacc.c index 1f1572db..eb0b7b30 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -1,8 +1,7 @@ m4_divert(-1) -*- C -*- -m4_include([c.m4]) # Yacc compatible skeleton for Bison -# Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 +# Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 # Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -55,7 +54,7 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) # b4_lex_param # ------------ -# Accumule in b4_lex_param all the yylex arguments. +# Accumulate in b4_lex_param all the yylex arguments. # 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 @@ -135,7 +134,7 @@ m4_changecom() m4_divert(0)dnl @output @output_parser_name@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison], - [1984, 1989, 1990, 2000, 2001, 2002])[ + [1984, 1989, 1990, 2000, 2001, 2002, 2003])[ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. @@ -466,7 +465,15 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 +#define YYERROR ]b4_location_if([do \ + { \ + yylerrsp = yylsp; \ + *++yylerrsp = yyloc; \ + goto yyerrlab1; \ + } \ + while (0)], + [goto yyerrlab1])[ + /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. @@ -576,9 +583,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]]); @@ -768,7 +775,8 @@ b4_c_function_def([yyparse], [int], b4_parse_param) [[ /* The location stack. */ YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp;]])[ + YYLTYPE *yylsp; + YYLTYPE *yylerrsp;]])[ #define YYPOPSTACK (yyvsp--, yyssp--]b4_location_if([, yylsp--])[) @@ -1030,18 +1038,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 +1073,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); @@ -1073,6 +1093,8 @@ yyerrlab: yyerror (]b4_yyerror_args["syntax error"); } +]b4_location_if([ yylerrsp = yylsp;])[ + if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -1096,6 +1118,7 @@ yyerrlab: 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 @@ -1141,7 +1164,8 @@ yyerrlab1: YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; -]b4_location_if([ *++yylsp = yylloc;])[ +]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, (yylerrsp - yylsp)); + *++yylsp = yyloc;])[ yystate = yyn; goto yynewstate; @@ -1184,7 +1208,7 @@ b4_epilogue m4_if(b4_defines_flag, 0, [], [@output @output_header_name@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison], - [1984, 1989, 1990, 2000, 2001, 2002]) + [1984, 1989, 1990, 2000, 2001, 2002, 2003]) /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction.