]> git.saurik.com Git - bison.git/blobdiff - data/yacc.c
* tests/atlocal.in (LDFLAGS, LIBS): New vars.
[bison.git] / data / yacc.c
index 18d3c5d40be4ccba4942e9584ded409b693b1e97..e562da0a8c2e771ce137630f4b62f4d84f4dfed5 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
@@ -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.
@@ -1031,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)
            {
@@ -1051,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 ";
@@ -1103,30 +1126,13 @@ yyerrlab:
 
   /* Else will try to reuse lookahead token after shifting the error
      token.  */
-  goto yyerrlab2;
+  goto yyerrlab1;
 
 
 /*----------------------------------------------------.
 | yyerrlab1 -- error raised explicitly by an action.  |
 `----------------------------------------------------*/
 yyerrlab1:
-
-  /* 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__)
-  __attribute__ ((__unused__));
-#endif
-
-]b4_location_if([  yylerrsp = yylsp;
-  *++yylerrsp = yyloc;])[
-  goto yyerrlab2;
-
-
-/*---------------------------------------------------------------.
-| yyerrlab2 -- pop states until the error token can be shifted.  |
-`---------------------------------------------------------------*/
-yyerrlab2:
   yyerrstatus = 3;     /* Each real token shifted decrements this.  */
 
   for (;;)
@@ -1205,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.