Minor spelling and punctuation fix.
[bison.git] / data / yacc.c
index 29e13e9feb12d67f619140279a5212da2863e095..c6045e2091aa22b4258baec1256123b59bfd577a 100644 (file)
@@ -33,18 +33,58 @@ m4_define_default([b4_stack_depth_init],  [200])
 # Location type.
 m4_define_default([b4_location_type], [yyltype])
 
+
+## ------------------------ ##
+## Pure/impure interfaces.  ##
+## ------------------------ ##
+
+
+# b4_Pure_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
+m4_define([b4_Pure_if],
+[b4_pure_if([m4_ifset([b4_parse_param],
+                      [$1], [$2])],
+            [$2])])
+
+
+# b4_pure_args
+# ------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_pure_args],
+[b4_Pure_if([b4_location_if([, &yylloc])])[]b4_user_args])
+
+
+# b4_lex_param
+# ------------
 # Accumule in b4_lex_param all the yylex arguments.
-# Yes, this is quite ugly...
+# 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)))
 
-# Yes, this is quite ugly...
-m4_define_default([b4_parse_param])
-m4_ifdef([b4_parse_param],
-[m4_define([b4_parse_param],
-          b4_parse_param)])
+
+
+## ------------ ##
+## Data Types.  ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included).  We overwrite the version from c.m4 which relies
+# on "signed char" which is not portable to old K&R compilers.
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@,      [0],   [255]), [1], [unsigned char],
+       b4_ints_in($@,   [-128],   [127]), [1], [yysigned_char],
+
+       b4_ints_in($@,      [0], [65535]), [1], [unsigned short],
+       b4_ints_in($@, [-32768], [32767]), [1], [short],
+
+       m4_eval([0 <= $1]),                [1], [unsigned int],
+
+                                              [int])])
 
 
 ## ----------------- ##
@@ -125,16 +165,17 @@ m4_define([b4_symbol_actions],
 [m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
 m4_pushdef([b4_at_dollar], [yylocation])dnl
       case $4: /* $3 */
-#line $2 "$1"
+b4_syncline([$2], [$1])
         $5;
-#line __oline__ "__ofile__"
+b4_syncline([__oline__], [__ofile__])
         break;
 m4_popdef([b4_at_dollar])dnl
 m4_popdef([b4_dollar_dollar])dnl
 ])
 
 
-
+# We do want M4 expansion after # for CPP macros.
+m4_changecom()
 m4_divert(0)dnl
 #output "b4_output_parser_name"
 b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
@@ -155,15 +196,7 @@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
    define necessary library symbols; they are noted "INFRINGES ON
    USER NAME SPACE" below.  */
 
-/* Identify Bison output.  */
-#define YYBISON        1
-
-/* Pure parsers.  */
-#define YYPURE b4_pure
-
-/* Using locations.  */
-#define YYLSP_NEEDED b4_locations_flag
-
+b4_identification
 m4_if(b4_prefix[], [yy], [],
 [/* If NAME_PREFIX is specified substitute the variables and functions
    names.  */
@@ -196,10 +229,10 @@ b4_pre_prologue
 
 #ifndef YYSTYPE
 m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"],
+b4_syncline([__oline__], [__ofile__])],
 [typedef int yystype;])
 # define YYSTYPE yystype
 # define YYSTYPE_IS_TRIVIAL 1
@@ -221,7 +254,7 @@ typedef struct yyltype
 b4_post_prologue
 
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"
+b4_syncline([__oline__], [__ofile__])
 
 #if ! defined (yyoverflow) || YYERROR_VERBOSE
 
@@ -496,7 +529,7 @@ do                                                          \
     }                                                          \
   else                                                         \
     {                                                          \
-      yyerror ("syntax error: cannot back up");                        \
+      yyerror ("syntax error: cannot back up"b4_pure_args);    \
       YYERROR;                                                 \
     }                                                          \
 while (0)
@@ -1020,7 +1053,7 @@ yyreduce:
     }
 
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"
+b4_syncline([__oline__], [__ofile__])
 \f
 [  yyvsp -= yylen;
   yyssp -= yylen;
@@ -1102,15 +1135,15 @@ yyerrlab:
                        yycount++;
                      }
                }
-             yyerror (yymsg);
+             yyerror (yymsg]b4_pure_args[);
              YYSTACK_FREE (yymsg);
            }
          else
-           yyerror ("parse error; also virtual memory exhausted");
+           yyerror ("parse error; also virtual memory exhausted"]b4_pure_args[);
        }
       else
 #endif /* YYERROR_VERBOSE */
-       yyerror ("parse error");
+       yyerror ("parse error"]b4_pure_args[);
     }
   goto yyerrlab1;
 
@@ -1225,7 +1258,7 @@ yyabortlab:
 | yyoverflowlab -- parser overflow comes here.  |
 `----------------------------------------------*/
 yyoverflowlab:
-  yyerror ("parser stack overflow");
+  yyerror ("parser stack overflow"]b4_pure_args[);
   yyresult = 2;
   /* Fall through.  */
 #endif
@@ -1257,10 +1290,10 @@ b4_token_defines(b4_tokens)
 
 #ifndef YYSTYPE
 m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 /* Line __line__ of __file__.  */
-#line __oline__ "__ofile__"],
+b4_syncline([__oline__], [__ofile__])],
 [typedef int yystype;])
 # define YYSTYPE yystype
 #endif