* 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.

* src/conflicts.c (conflicts_print): Unsatisfied %expectation are
errors.
* NEWS: Document this.
* doc/bison.texinfo (Expect Decl): Likewise.
This commit is contained in:
Paul Eggert
2005-11-18 18:16:44 +00:00
parent d1ff7a7cc6
commit 035aa4a0bb
5 changed files with 65 additions and 41 deletions

View File

@@ -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> 2005-11-16 Akim Demaille <akim@epita.fr>
Generalize the display of semantic values and locations in traces. Generalize the display of semantic values and locations in traces.

4
NEWS
View File

@@ -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. * GLR, YACC parsers.
The %parse-params are available in the %destructor's (and the The %parse-params are available in the %destructor's (and the
experimental %printer's) as per the documentation. experimental %printer's) as per the documentation.

View File

@@ -3913,19 +3913,18 @@ The declaration looks like this:
%expect @var{n} %expect @var{n}
@end example @end example
Here @var{n} is a decimal integer. The declaration says there should be Here @var{n} is a decimal integer. The declaration says there should
no warning if there are @var{n} shift/reduce conflicts and no be @var{n} shift/reduce conflicts and no reduce/reduce conflicts.
reduce/reduce conflicts. The usual warning is Bison reports an error if the number of shift/reduce conflicts differs
given if there are either more or fewer conflicts, or if there are any from @var{n}, or if there are any reduce/reduce conflicts.
reduce/reduce conflicts.
For normal @acronym{LALR}(1) parsers, reduce/reduce conflicts are more serious, For normal @acronym{LALR}(1) parsers, reduce/reduce conflicts are more
and should be eliminated entirely. Bison will always report serious, and should be eliminated entirely. Bison will always report
reduce/reduce conflicts for these parsers. With @acronym{GLR} parsers, however, reduce/reduce conflicts for these parsers. With @acronym{GLR}
both shift/reduce and reduce/reduce are routine (otherwise, there parsers, however, both kinds of conflicts are routine; otherwise,
would be no need to use @acronym{GLR} parsing). Therefore, it is also possible there would be no need to use @acronym{GLR} parsing. Therefore, it is
to specify an expected number of reduce/reduce conflicts in @acronym{GLR} also possible to specify an expected number of reduce/reduce conflicts
parsers, using the declaration: in @acronym{GLR} parsers, using the declaration:
@example @example
%expect-rr @var{n} %expect-rr @var{n}
@@ -3946,12 +3945,12 @@ go back to the beginning.
@item @item
Add an @code{%expect} declaration, copying the number @var{n} from the 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 Now Bison will warn you if you introduce an unexpected conflict, but
conflicts, but it will warn you again if changes in the grammar result will keep silent otherwise.
in more or fewer conflicts.
@node Start Decl @node Start Decl
@subsection The Start-Symbol @subsection The Start-Symbol

View 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. Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. 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 /* 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 not set, and then we want 0 SR, or else it is specified, in which
case we want equality. */ case we want equality. */
bool src_ok = false; bool src_ok;
bool rrc_ok = false; bool rrc_ok;
int src_total = 0; int src_total = 0;
int rrc_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_expected = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts;
src_total == (expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts); rrc_expected = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts;
rrc_ok = src_ok = src_total == src_expected;
rrc_total == (expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts); rrc_ok = rrc_total == rrc_expected;
/* If there are as many RR conflicts and SR conflicts as /* If there are as many RR conflicts and SR conflicts as
expected, then there is nothing to report. */ expected, then there is nothing to report. */
if (rrc_ok && src_ok) if (rrc_ok & src_ok)
return; return;
/* Report the total number of conflicts on STDERR. */ /* Report the total number of conflicts on STDERR. */
if (! yacc_flag) if (src_total | rrc_total)
fprintf (stderr, "%s: ", current_file); {
conflict_report (stderr, 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", complain (ngettext ("expected %d shift/reduce conflict",
"expected %d shift/reduce conflicts", "expected %d shift/reduce conflicts",
sr), sr); src_expected),
src_expected);
if (! rrc_ok) if (! rrc_ok)
warn (ngettext ("expected %d reduce/reduce conflict", complain (ngettext ("expected %d reduce/reduce conflict",
"expected %d reduce/reduce conflicts", "expected %d reduce/reduce conflicts",
rr), rr); rrc_expected),
rrc_expected);
} }
} }

View 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