]> git.saurik.com Git - bison.git/blobdiff - data/yacc.c
Alexandre Duret-Lutz <adl@gnu.org>
[bison.git] / data / yacc.c
index dcc060e2195aa1c4ea791e930603c4259cb0e80f..2e9c9fd0b0d04859b5fa1f8fad95e97b3b19fb82 100644 (file)
@@ -506,14 +506,26 @@ 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).  */
 
 #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   = (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;                        \
+    }                                                                       \
+  else                                                                      \
+    {                                                                       \
+      (Current).first_line   = (Current).last_line   = (Rhs)[0].last_line;   \
+      (Current).first_column = (Current).last_column = (Rhs)[0].last_column; \
+    }                                                                       \
+} while(0)
 #endif
 
 
@@ -527,9 +539,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
 
 
@@ -826,8 +838,8 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
 #endif
 ]])
 m4_ifdef([b4_initial_action], [
-m4_pushdef([b4_at_dollar],     [(yylloc)])dnl
-m4_pushdef([b4_dollar_dollar], [(yylval)])dnl
+m4_pushdef([b4_at_dollar],     [yylloc])dnl
+m4_pushdef([b4_dollar_dollar], [yylval])dnl
   /* User initialization code. */
   b4_initial_action
 m4_popdef([b4_dollar_dollar])dnl
@@ -1021,10 +1033,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)
     ]{