bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

switch back to Yacc-style conflict reports for Bison


From: Paul Eggert
Subject: switch back to Yacc-style conflict reports for Bison
Date: Sat, 28 Dec 2002 18:05:48 -0800 (PST)

In my 2002-12-26 change to conflicts.c I noticed that the code
generated conflict reports in a hard-to-translate manner, e.g., it
assumed that "," has the same meaning in all languages.  It's better
to translate the whole diagnostic at once, rather than translate each
piece separately; that lets the entire translation be more idiomatic.
While fixing this I ended up dedicing that it's better to revert to
the Yacc style of conflict reports: this is easily translated, and it
has the virtue of familiarity, at any rate.  So I installed this:

2002-12-28  Paul Eggert  <address@hidden>

        Switch back to the Yacc style of conflict reports, undoing some
        of the 2002-07-30 change.
        * doc/bison.texinfo (Understanding): Use Yacc style for
        conflict reports.  Also, use new way of locating rules.
        * src/conflicts.c (conflict_report):
        Renamed from conflict_report_yacc, removing the old
        'conflict_report'.  Translate the entire conflict report at once,
        so that we don't assume that "," has the same interpretation in
        all languages.
        (conflicts_output): Use Yacc-style conflict report for each state,
        instead of our more-complicated style.
        (conflicts_print): Use Yacc-style conflict report, except print
        the input file name when not emulating Yacc.
        * tests/conflicts.at (Unresolved SR Conflicts, Defaulted
        Conflicted Reduction, %expect not enough, %expect too much,
        %expect with reduce conflicts): Switch to Yacc-style conflict reports.
        * tests/existing.at (GNU Cim Grammar): Likewise.
        * tests/glr-regr1.at (Badly Collapsed GLR States): Likewise.

Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.96
diff -p -u -r1.96 bison.texinfo
--- doc/bison.texinfo   28 Dec 2002 08:37:17 -0000      1.96
+++ doc/bison.texinfo   29 Dec 2002 01:53:43 -0000
@@ -5609,8 +5609,8 @@ useless: STR;
 @example
 calc.y: warning: 1 useless nonterminal and 1 useless rule
 calc.y:11.1-7: warning: useless nonterminal: useless
-calc.y:11.8-12: warning: useless rule: useless: STR
-calc.y contains 7 shift/reduce conflicts.
+calc.y:11.10-12: warning: useless rule: useless: STR
+calc.y: conflicts: 7 shift/reduce
 @end example
 
 When given @option{--report=state}, in addition to @file{calc.tab.c}, it
@@ -5632,10 +5632,10 @@ Conflict in state 8 between rule 2 and t
 The next section lists states that still have conflicts.
 
 @example
-State 8 contains 1 shift/reduce conflict.
-State 9 contains 1 shift/reduce conflict.
-State 10 contains 1 shift/reduce conflict.
-State 11 contains 4 shift/reduce conflicts.
+State 8 conflicts: 1 shift/reduce
+State 9 conflicts: 1 shift/reduce
+State 10 conflicts: 1 shift/reduce
+State 11 conflicts: 4 shift/reduce
 @end example
 
 @noindent
@@ -5847,8 +5847,8 @@ state 7
     exp         go to state 11
 @end example
 
-As was announced in beginning of the report, @samp{State 8 contains 1
-shift/reduce conflict}:
+As was announced in beginning of the report, @samp{State 8 conflicts:
+1 shift/reduce}:
 
 @example
 state 8
Index: src/conflicts.c
===================================================================
RCS file: /cvsroot/bison/bison/src/conflicts.c,v
retrieving revision 1.101
diff -p -u -r1.101 conflicts.c
--- src/conflicts.c     26 Dec 2002 22:10:52 -0000      1.101
+++ src/conflicts.c     29 Dec 2002 01:53:43 -0000
@@ -387,60 +387,20 @@ count_rr_conflicts (state *s, int one_pe
 }
 
 
-/*--------------------------------------------------------------.
-| Return a human readable string which reports shift/reduce and |
-| reduce/reduce conflict numbers (SRC_NUM, RRC_NUM).            |
-`--------------------------------------------------------------*/
-
-static const char *
-conflict_report (int src_num, int rrc_num)
-{
-  static char res[4096];
-  char *cp = res;
-
-  if (src_num >= 1)
-    {
-      sprintf (cp, ngettext ("%d shift/reduce conflict",
-                            "%d shift/reduce conflicts", src_num), src_num);
-      cp += strlen (cp);
-    }
-
-  if (src_num > 0 && rrc_num > 0)
-    {
-      sprintf (cp, " %s ", _("and"));
-      cp += strlen (cp);
-    }
-
-  if (rrc_num >= 1)
-    {
-      sprintf (cp, ngettext ("%d reduce/reduce conflict",
-                            "%d reduce/reduce conflicts", rrc_num), rrc_num);
-      cp += strlen (cp);
-    }
-
-  *cp++ = '\0';
-
-  return res;
-}
-
-
-/*----------------------------------------------------------------.
-| Same as above, but report the number of conflicts a` la POSIX.  |
-`----------------------------------------------------------------*/
+/*--------------------------------------------------------.
+| Report the number of conflicts, using the Yacc format.  |
+`--------------------------------------------------------*/
 
 static void
-conflict_report_yacc (int src_num, int rrc_num)
+conflict_report (FILE *out, int src_num, int rrc_num)
 {
-  /* If invoked with `--yacc', use the output format specified by
-     POSIX.  */
-  fprintf (stderr, _("conflicts: "));
-  if (src_num > 0)
-    fprintf (stderr, _(" %d shift/reduce"), src_num);
-  if (src_num > 0 && rrc_num > 0)
-    fprintf (stderr, ",");
-  if (rrc_num > 0)
-    fprintf (stderr, _(" %d reduce/reduce"), rrc_num);
-  putc ('\n', stderr);
+  if (src_num && rrc_num)
+    fprintf (out, _("conflicts: %d shift/reduce, %d reduce/reduce\n"),
+            src_num, rrc_num);
+  else if (src_num)
+    fprintf (out, _("conflicts: %d shift/reduce\n"), src_num);
+  else if (rrc_num)
+    fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc_num);
 }
 
 
@@ -458,10 +418,9 @@ conflicts_output (FILE *out)
       state *s = states[i];
       if (conflicts[i])
        {
-         fprintf (out, _("State %d contains "), i);
-         fprintf (out, "%s.\n",
-                  conflict_report (count_sr_conflicts (s),
-                                   count_rr_conflicts (s, true)));
+         fprintf (out, _("State %d "), i);
+         conflict_report (out, count_sr_conflicts (s),
+                          count_rr_conflicts (s, true));
          printed_sth = true;
        }
     }
@@ -529,10 +488,9 @@ conflicts_print (void)
     return;
 
   /* Report the total number of conflicts on STDERR.  */
-  if (yacc_flag)
-    conflict_report_yacc (src_total, rrc_total);
-  else
-    warn ("%s", conflict_report (src_total, rrc_total));
+  if (! yacc_flag)
+    fprintf (stderr, "%s: ", current_file);
+  conflict_report (stderr, src_total, rrc_total);
 
   if (expected_conflicts != -1)
     {
Index: tests/conflicts.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/conflicts.at,v
retrieving revision 1.23
diff -p -u -r1.23 conflicts.at
--- tests/conflicts.at  26 Dec 2002 22:21:23 -0000      1.23
+++ tests/conflicts.at  29 Dec 2002 01:53:44 -0000
@@ -139,12 +139,12 @@ exp: exp OP exp | NUM;
 ]])
 
 AT_CHECK([bison -o input.c --report=all input.y], 0, [],
-[input.y: warning: 1 shift/reduce conflict
+[input.y: conflicts: 1 shift/reduce
 ])
 
 # Check the contents of the report.
 AT_CHECK([cat input.output], [],
-[[State 5 contains 1 shift/reduce conflict.
+[[State 5 conflicts: 1 shift/reduce
 
 
 Grammar
@@ -369,7 +369,7 @@ id : '0';
 ]])
 
 AT_CHECK([bison -o input.c --report=all input.y], 0, [],
-[[input.y: warning: 1 reduce/reduce conflict
+[[input.y: conflicts: 1 reduce/reduce
 input.y:4.6-8: warning: rule never reduced because of conflicts: id: '0'
 ]])
 
@@ -380,7 +380,7 @@ AT_CHECK([cat input.output], [],
     4 id: '0'
 
 
-State 1 contains 1 reduce/reduce conflict.
+State 1 conflicts: 1 reduce/reduce
 
 
 Grammar
@@ -486,7 +486,7 @@ exp: exp OP exp | NUM;
 ]])
 
 AT_CHECK([bison -o input.c input.y], 1, [],
-[input.y: warning: 1 shift/reduce conflict
+[input.y: conflicts: 1 shift/reduce
 input.y: expected 0 shift/reduce conflicts
 ])
 AT_CLEANUP
@@ -523,7 +523,7 @@ exp: exp OP exp | NUM;
 ]])
 
 AT_CHECK([bison -o input.c input.y], 1, [],
-[input.y: warning: 1 shift/reduce conflict
+[input.y: conflicts: 1 shift/reduce
 input.y: expected 2 shift/reduce conflicts
 ])
 AT_CLEANUP
@@ -543,7 +543,7 @@ a: 'a';
 ]])
 
 AT_CHECK([bison -o input.c input.y], 1, [],
-[input.y: warning: 1 reduce/reduce conflict
+[input.y: conflicts: 1 reduce/reduce
 input.y: expected 0 reduce/reduce conflicts
 ])
 AT_CLEANUP
Index: tests/existing.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/existing.at,v
retrieving revision 1.3
diff -p -u -r1.3 existing.at
--- tests/existing.at   30 Jul 2002 11:09:59 -0000      1.3
+++ tests/existing.at   29 Dec 2002 01:53:44 -0000
@@ -1191,19 +1191,19 @@ ARGUMENT_LIST   :       EXPRESSION      
 # don't actually check the output.  But SEGV is watching us, and
 # so might do dmalloc.
 AT_CHECK([[bison --verbose --defines input.y]], 0, [],
-[[input.y: warning: 78 shift/reduce conflicts and 10 reduce/reduce conflicts
+[[input.y: conflicts: 78 shift/reduce, 10 reduce/reduce
 ]])
 
-AT_CHECK([[grep '^State.*contains' input.output]], 0,
-[[State 64 contains 14 shift/reduce conflicts.
-State 164 contains 1 shift/reduce conflict.
-State 201 contains 33 shift/reduce conflicts and 4 reduce/reduce conflicts.
-State 206 contains 1 shift/reduce conflict.
-State 240 contains 1 shift/reduce conflict.
-State 335 contains 9 shift/reduce conflicts and 2 reduce/reduce conflicts.
-State 356 contains 1 shift/reduce conflict.
-State 360 contains 9 shift/reduce conflicts and 2 reduce/reduce conflicts.
-State 427 contains 9 shift/reduce conflicts and 2 reduce/reduce conflicts.
+AT_CHECK([[grep '^State.*conflicts:' input.output]], 0,
+[[State 64 conflicts: 14 shift/reduce
+State 164 conflicts: 1 shift/reduce
+State 201 conflicts: 33 shift/reduce, 4 reduce/reduce
+State 206 conflicts: 1 shift/reduce
+State 240 conflicts: 1 shift/reduce
+State 335 conflicts: 9 shift/reduce, 2 reduce/reduce
+State 356 conflicts: 1 shift/reduce
+State 360 conflicts: 9 shift/reduce, 2 reduce/reduce
+State 427 conflicts: 9 shift/reduce, 2 reduce/reduce
 ]])
 
 AT_CLEANUP
Index: tests/glr-regr1.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/glr-regr1.at,v
retrieving revision 1.5
diff -p -u -r1.5 glr-regr1.at
--- tests/glr-regr1.at  15 Nov 2002 08:56:40 -0000      1.5
+++ tests/glr-regr1.at  29 Dec 2002 01:53:44 -0000
@@ -89,7 +89,7 @@ yylex (void)
 ]])
 
 AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [],
-[glr-regr1.y: warning: 1 shift/reduce conflict
+[glr-regr1.y: conflicts: 1 shift/reduce
 ])
 AT_COMPILE([glr-regr1])
 AT_CHECK([[echo BPBPB | ./glr-regr1]], 0,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]