]> git.saurik.com Git - bison.git/blobdiff - data/yacc.c
* tests/regression.at (_AT_DATA_DANCER_Y): Fix the expected error
[bison.git] / data / yacc.c
index 51acf5e9c30109a7634c8b1f057f98c2d138729a..fca98e54dedad90de93483964425510456e68841 100644 (file)
@@ -1,7 +1,7 @@
 m4_divert(-1)                                                       -*- C -*-
 
 # 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
@@ -54,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
@@ -134,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.
@@ -465,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.
@@ -575,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]]);
@@ -767,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,17 +1039,34 @@ yyerrlab:
          YYSIZE_T yysize = 0;
          int yytype = YYTRANSLATE (yychar);
          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 yyxbase = yyn < 0 ? -yyn : 0;
+
+         /* Stay within bounds of both yycheck and yytname.  */
+         int yychecklim = YYLAST - yyn;
+         int yynsyms = sizeof (yytname) / sizeof (yytname[0]);
+         int yyxlim = yychecklim < yynsyms ? yychecklim : yynsyms;
+         int yycount = 0;
+
+         for (yyx = yyxbase; yyx < yyxlim; 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 += (! yycount
+                          ? sizeof (", expecting ") - 1
+                          : sizeof (" or ") - 1);
+               yysize += yystrlen (yytname[yyx]);
+               yycount++;
+               if (yycount == 5)
+                 {
+                   yysize = 0;
+                   break;
+                 }             
+             }
+         yysize += (sizeof ("syntax error, unexpected ")
+                    + yystrlen (yytname[yytype]));
          yymsg = (char *) YYSTACK_ALLOC (yysize);
          if (yymsg != 0)
            {
@@ -1050,9 +1076,7 @@ yyerrlab:
              if (yycount < 5)
                {
                  yycount = 0;
-                 for (yyx = yyn < 0 ? -yyn : 0;
-                      yyx < (int) (sizeof (yytname) / sizeof (char *));
-                      yyx++)
+                 for (yyx = yyxbase; yyx < yyxlim; yyx++)
                    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
                      {
                        const char *yyq = ! yycount ? ", expecting " : " or ";
@@ -1072,6 +1096,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
@@ -1095,6 +1121,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
@@ -1140,7 +1167,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;
@@ -1183,7 +1211,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.