]> git.saurik.com Git - bison.git/blobdiff - data/yacc.c
Use #define to handle the %name-prefix.
[bison.git] / data / yacc.c
index a5fb4e6965da1a34caded589783022bcd909e62a..7331b65c3e3296183af281715173b338cb91abb3 100644 (file)
@@ -153,8 +153,7 @@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
 
 ]b4_identification
 m4_if(b4_prefix[], [yy], [],
-[/* If NAME_PREFIX is specified substitute the variables and functions
-   names.  */
+[/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
 #define yylex   b4_prefix[]lex
 #define yyerror b4_prefix[]error
@@ -506,14 +505,29 @@ while (0)
 #define YYERRCODE      256
 
 
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].  */
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
 
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)               \
-   ((Current).first_line   = (Rhs)[1].first_line,      \
-    (Current).first_column = (Rhs)[1].first_column,    \
-    (Current).last_line    = (Rhs)[N].last_line,       \
-    (Current).last_column  = (Rhs)[N].last_column)
+# define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+    do                                                                 \
+      if (N)                                                           \
+       {                                                               \
+         (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;         \
+         (Current).first_column = YYRHSLOC(Rhs, 1).first_column;       \
+         (Current).last_line    = YYRHSLOC(Rhs, N).last_line;          \
+         (Current).last_column  = YYRHSLOC(Rhs, N).last_column;        \
+       }                                                               \
+      else                                                             \
+       {                                                               \
+         (Current).first_line   = (Current).last_line   =              \
+           YYRHSLOC(Rhs, 0).last_line;                                 \
+         (Current).first_column = (Current).last_column =              \
+           YYRHSLOC(Rhs, 0).last_column;                               \
+       }                                                               \
+    while (0)
 #endif
 
 
@@ -527,9 +541,9 @@ while (0)
      fprintf (File, "%d.%d-%d.%d",                     \
               (Loc).first_line, (Loc).first_column,    \
               (Loc).last_line,  (Loc).last_column)
+# else
+#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 # endif
-#else
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 #endif
 
 
@@ -1021,10 +1035,7 @@ yyreduce:
 
 ]b4_location_if(
 [[  /* Default location. */
-  if (yylen)
-    YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
-  else
-    yyloc = yylsp[0];]])[
+  YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
   YY_REDUCE_PRINT (yyn);
   switch (yyn)
     ]{