]> git.saurik.com Git - bison.git/commitdiff
* src/conflicts.c (conflicts_print): Don't print file name twice
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 18 Nov 2005 18:16:44 +0000 (18:16 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 18 Nov 2005 18:16:44 +0000 (18:16 +0000)
when %expect fails because there were no conflicts.
* doc/bison.texinfo (Expect Decl): Tighten up wording in previous
change.
* tests/conflicts.at (%expect not enough, %expect too much):
(%expect with reduce conflicts): Adjust to new behavior.

* src/conflicts.c (conflicts_print): Unsatisfied %expectation are
errors.
* NEWS: Document this.
* doc/bison.texinfo (Expect Decl): Likewise.

ChangeLog
NEWS
doc/bison.texinfo
src/conflicts.c
tests/conflicts.at

index b0fd56f8a189d859875bf64118c7fbb99cb990ed..c52dc0db877dd6e4ded7ff1cc8b72cab8db391cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-11-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * src/conflicts.c (conflicts_print): Don't print file name twice
+       when %expect fails because there were no conflicts.
+       * doc/bison.texinfo (Expect Decl): Tighten up wording in previous
+       change.
+       * tests/conflicts.at (%expect not enough, %expect too much):
+       (%expect with reduce conflicts): Adjust to new behavior.
+
+2005-11-18  Akim Demaille  <akim@epita.fr>
+
+       * src/conflicts.c (conflicts_print): Unsatisfied %expectation are
+       errors.
+       * NEWS: Document this.
+       * doc/bison.texinfo (Expect Decl): Likewise.
+
 2005-11-16  Akim Demaille  <akim@epita.fr>
 
        Generalize the display of semantic values and locations in traces.
 2005-11-16  Akim Demaille  <akim@epita.fr>
 
        Generalize the display of semantic values and locations in traces.
diff --git a/NEWS b/NEWS
index de75edb6dd7121692e04ae1543189bbdfb9dbb6f..ec0a8dec3d434a1295a4d8b19fc65f5ceeba26f4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ Bison News
 
 Changes in version 2.1a:
 
 
 Changes in version 2.1a:
 
+* %expect, %expect-rr
+  Incorrect numbers of expected conflicts are now actual errors,
+  instead of warnings.
+
 * GLR, YACC parsers.
   The %parse-params are available in the %destructor's (and the
   experimental %printer's) as per the documentation.
 * GLR, YACC parsers.
   The %parse-params are available in the %destructor's (and the
   experimental %printer's) as per the documentation.
index 47b6720ec93e7a6e438934e0dec09573756823a1..641e6db555dca6a21fddf0d7c4bba506f0ed9eb3 100644 (file)
@@ -3913,19 +3913,18 @@ The declaration looks like this:
 %expect @var{n}
 @end example
 
 %expect @var{n}
 @end example
 
-Here @var{n} is a decimal integer.  The declaration says there should be
-no warning if there are @var{n} shift/reduce conflicts and no
-reduce/reduce conflicts.  The usual warning is
-given if there are either more or fewer conflicts, or if there are any
-reduce/reduce conflicts.
+Here @var{n} is a decimal integer.  The declaration says there should
+be @var{n} shift/reduce conflicts and no reduce/reduce conflicts.
+Bison reports an error if the number of shift/reduce conflicts differs
+from @var{n}, or if there are any reduce/reduce conflicts.
 
 
-For normal @acronym{LALR}(1) parsers, reduce/reduce conflicts are more serious,
-and should be eliminated entirely.  Bison will always report
-reduce/reduce conflicts for these parsers.  With @acronym{GLR} parsers, however,
-both shift/reduce and reduce/reduce are routine (otherwise, there
-would be no need to use @acronym{GLR} parsing).  Therefore, it is also possible
-to specify an expected number of reduce/reduce conflicts in @acronym{GLR}
-parsers, using the declaration:
+For normal @acronym{LALR}(1) parsers, reduce/reduce conflicts are more
+serious, and should be eliminated entirely.  Bison will always report
+reduce/reduce conflicts for these parsers.  With @acronym{GLR}
+parsers, however, both kinds of conflicts are routine; otherwise,
+there would be no need to use @acronym{GLR} parsing.  Therefore, it is
+also possible to specify an expected number of reduce/reduce conflicts
+in @acronym{GLR} parsers, using the declaration:
 
 @example
 %expect-rr @var{n}
 
 @example
 %expect-rr @var{n}
@@ -3946,12 +3945,12 @@ go back to the beginning.
 
 @item
 Add an @code{%expect} declaration, copying the number @var{n} from the
 
 @item
 Add an @code{%expect} declaration, copying the number @var{n} from the
-number which Bison printed.
+number which Bison printed.  With @acronym{GLR} parsers, add an
+@code{%expect-rr} declaration as well.
 @end itemize
 
 @end itemize
 
-Now Bison will stop annoying you if you do not change the number of
-conflicts, but it will warn you again if changes in the grammar result
-in more or fewer conflicts.
+Now Bison will warn you if you introduce an unexpected conflict, but
+will keep silent otherwise.
 
 @node Start Decl
 @subsection The Start-Symbol
 
 @node Start Decl
 @subsection The Start-Symbol
index ede39690c3aaeb7fcc9604965f2b6060dc873bbb..374c4010156de0c8442d50b99e3dc75737b774fb 100644 (file)
@@ -1,6 +1,6 @@
 /* Find and resolve or report look-ahead conflicts for bison,
 
 /* Find and resolve or report look-ahead conflicts for bison,
 
-   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -464,11 +464,13 @@ conflicts_print (void)
   /* Is the number of SR conflicts OK?  Either EXPECTED_CONFLICTS is
      not set, and then we want 0 SR, or else it is specified, in which
      case we want equality.  */
   /* Is the number of SR conflicts OK?  Either EXPECTED_CONFLICTS is
      not set, and then we want 0 SR, or else it is specified, in which
      case we want equality.  */
-  bool src_ok = false;
-  bool rrc_ok = false;
+  bool src_ok;
+  bool rrc_ok;
 
   int src_total = 0;
   int rrc_total = 0;
 
   int src_total = 0;
   int rrc_total = 0;
+  int src_expected;
+  int rrc_expected;
 
   /* Conflicts by state.  */
   {
 
   /* Conflicts by state.  */
   {
@@ -488,33 +490,36 @@ conflicts_print (void)
       expected_rr_conflicts = -1;
     }
 
       expected_rr_conflicts = -1;
     }
 
-  src_ok =
-    src_total == (expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts);
-  rrc_ok =
-    rrc_total == (expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts);
+  src_expected = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts;
+  rrc_expected = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts;
+  src_ok = src_total == src_expected;
+  rrc_ok = rrc_total == rrc_expected;
 
   /* If there are as many RR conflicts and SR conflicts as
      expected, then there is nothing to report.  */
 
   /* If there are as many RR conflicts and SR conflicts as
      expected, then there is nothing to report.  */
-  if (rrc_ok && src_ok)
+  if (rrc_ok & src_ok)
     return;
 
   /* Report the total number of conflicts on STDERR.  */
     return;
 
   /* Report the total number of conflicts on STDERR.  */
-  if (! yacc_flag)
-    fprintf (stderr, "%s: ", current_file);
-  conflict_report (stderr, src_total, rrc_total);
+  if (src_total | rrc_total)
+    {
+      if (! yacc_flag)
+       fprintf (stderr, "%s: ", current_file);
+      conflict_report (stderr, src_total, rrc_total);
+    }
 
   if (expected_sr_conflicts != -1 || expected_rr_conflicts != -1)
     {
 
   if (expected_sr_conflicts != -1 || expected_rr_conflicts != -1)
     {
-      int sr = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts;
-      int rr = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts;
       if (! src_ok)
       if (! src_ok)
-       warn (ngettext ("expected %d shift/reduce conflict",
-                       "expected %d shift/reduce conflicts",
-                       sr), sr);
+       complain (ngettext ("expected %d shift/reduce conflict",
+                           "expected %d shift/reduce conflicts",
+                           src_expected),
+                 src_expected);
       if (! rrc_ok)
       if (! rrc_ok)
-       warn (ngettext ("expected %d reduce/reduce conflict",
-                       "expected %d reduce/reduce conflicts",
-                       rr), rr);
+       complain (ngettext ("expected %d reduce/reduce conflict",
+                           "expected %d reduce/reduce conflicts",
+                           rrc_expected),
+                 rrc_expected);
     }
 }
 
     }
 }
 
index 9b503b63ae299d3fec097ee56996b7af8608463e..1cbf23acb0f39c9eea5b7faf50ee669256a2d3d1 100644 (file)
@@ -482,9 +482,9 @@ AT_DATA([input.y],
 exp: exp OP exp | NUM;
 ]])
 
 exp: exp OP exp | NUM;
 ]])
 
-AT_CHECK([bison -o input.c input.y], 0, [],
+AT_CHECK([bison -o input.c input.y], 1, [],
 [input.y: conflicts: 1 shift/reduce
 [input.y: conflicts: 1 shift/reduce
-input.y: warning: expected 0 shift/reduce conflicts
+input.y: expected 0 shift/reduce conflicts
 ])
 AT_CLEANUP
 
 ])
 AT_CLEANUP
 
@@ -519,9 +519,9 @@ AT_DATA([input.y],
 exp: exp OP exp | NUM;
 ]])
 
 exp: exp OP exp | NUM;
 ]])
 
-AT_CHECK([bison -o input.c input.y], 0, [],
+AT_CHECK([bison -o input.c input.y], 1, [],
 [input.y: conflicts: 1 shift/reduce
 [input.y: conflicts: 1 shift/reduce
-input.y: warning: expected 2 shift/reduce conflicts
+input.y: expected 2 shift/reduce conflicts
 ])
 AT_CLEANUP
 
 ])
 AT_CLEANUP
 
@@ -539,9 +539,9 @@ program: a 'a' | a a;
 a: 'a';
 ]])
 
 a: 'a';
 ]])
 
-AT_CHECK([bison -o input.c input.y], 0, [],
+AT_CHECK([bison -o input.c input.y], 1, [],
 [input.y: conflicts: 1 reduce/reduce
 [input.y: conflicts: 1 reduce/reduce
-input.y: warning: expected 0 reduce/reduce conflicts
+input.y: expected 0 reduce/reduce conflicts
 ])
 AT_CLEANUP
 
 ])
 AT_CLEANUP