mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
%expect-rr: fix the computation of the overall number of conflicts
On a grammar such as
exp: "num" | "num" | "num"
we currently report only one RR conflict, instead of two.
This bug is present since the origins of Bison
commit 08089d5d35
Author: David MacKenzie <djm@djmnet.org>
Date: Tue Apr 20 05:42:52 1993 +0000
Initial revision
and was preserved in
commit 676385e29c
Author: Paul Hilfinger <Hilfinger@CS.Berkeley.EDU>
Date: Fri Jun 28 02:26:44 2002 +0000
Initial check-in introducing experimental GLR parsing. See entry in
ChangeLog dated 2002-06-27 from Paul Hilfinger for details.
See
https://lists.gnu.org/archive/html/bison-patches/2018-11/msg00011.html
* src/conflicts.h, src/conflicts.c (count_state_rr_conflicts)
(count_rr_conflicts): Use only the correct count of conflicts.
* tests/glr-regression.at: Fix expectations.
This commit is contained in:
14
NEWS
14
NEWS
@@ -26,6 +26,20 @@ GNU Bison NEWS
|
||||
The use of the %error-verbose directive is deprecated in favor of "%define
|
||||
parse.error verbose" since Bison 3.0, but no warning was issued.
|
||||
|
||||
** Bug fixes
|
||||
|
||||
*** Incorrect number of reduce-reduce conflicts
|
||||
|
||||
On a grammar such as
|
||||
|
||||
exp: "num" | "num" | "num"
|
||||
|
||||
bison used report a single RR conflict, instead of two. This is now
|
||||
fixed. This was the oldest (known) bug in Bison: it was there when Bison
|
||||
was entered in the RCS version control system, in December 1987.
|
||||
|
||||
Some grammar files might have to adjust their %expect-rr.
|
||||
|
||||
* Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
@@ -467,15 +467,13 @@ count_sr_conflicts (void)
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------.
|
||||
| Count the number of reduce/reduce conflicts. If ONE_PER_TOKEN, |
|
||||
| count one conflict for each token that has any reduce/reduce |
|
||||
| conflicts. Otherwise, count one conflict for each reduction |
|
||||
| after the first for a given token. |
|
||||
`----------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------.
|
||||
| Count the number of reduce/reduce conflicts. Count one conflict |
|
||||
| for each reduction after the first for a given token. |
|
||||
`-----------------------------------------------------------------*/
|
||||
|
||||
static size_t
|
||||
count_state_rr_conflicts (state *s, bool one_per_token)
|
||||
count_state_rr_conflicts (state *s)
|
||||
{
|
||||
reductions *reds = s->reductions;
|
||||
size_t res = 0;
|
||||
@@ -486,20 +484,20 @@ count_state_rr_conflicts (state *s, bool one_per_token)
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
count += bitset_test (reds->lookahead_tokens[j], i);
|
||||
if (count >= 2)
|
||||
res += one_per_token ? 1 : count-1;
|
||||
res += count-1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static size_t
|
||||
count_rr_conflicts (bool one_per_token)
|
||||
count_rr_conflicts (void)
|
||||
{
|
||||
size_t res = 0;
|
||||
/* Conflicts by state. */
|
||||
for (state_number i = 0; i < nstates; ++i)
|
||||
if (conflicts[i])
|
||||
res += count_state_rr_conflicts (states[i], one_per_token);
|
||||
res += count_state_rr_conflicts (states[i]);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -591,7 +589,7 @@ conflicts_output (FILE *out)
|
||||
if (conflicts[i])
|
||||
{
|
||||
int src = count_state_sr_conflicts (s);
|
||||
int rrc = count_state_rr_conflicts (s, true);
|
||||
int rrc = count_state_rr_conflicts (s);
|
||||
fprintf (out, _("State %d "), i);
|
||||
if (src && rrc)
|
||||
fprintf (out,
|
||||
@@ -608,17 +606,14 @@ conflicts_output (FILE *out)
|
||||
fputs ("\n\n", out);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------.
|
||||
| Total the number of S/R and R/R conflicts. Unlike the |
|
||||
| code in conflicts_output, however, count EACH pair of |
|
||||
| reductions for the same state and lookahead as one |
|
||||
| conflict. |
|
||||
`--------------------------------------------------------*/
|
||||
/*--------------------------------------------.
|
||||
| Total the number of S/R and R/R conflicts. |
|
||||
`--------------------------------------------*/
|
||||
|
||||
int
|
||||
conflicts_total_count (void)
|
||||
{
|
||||
return count_sr_conflicts () + count_rr_conflicts (false);
|
||||
return count_sr_conflicts () + count_rr_conflicts ();
|
||||
}
|
||||
|
||||
/*------------------------------.
|
||||
@@ -692,7 +687,7 @@ conflicts_print (void)
|
||||
}
|
||||
|
||||
{
|
||||
int total = count_rr_conflicts (true);
|
||||
int total = count_rr_conflicts ();
|
||||
/* If %expect-rr is not used, but %expect is, then expect 0 rr. */
|
||||
int expected =
|
||||
(expected_rr_conflicts == -1 && expected_sr_conflicts != -1)
|
||||
|
||||
@@ -44,4 +44,5 @@ void conflicts_free (void);
|
||||
/* Were there conflicts? */
|
||||
extern int expected_sr_conflicts;
|
||||
extern int expected_rr_conflicts;
|
||||
|
||||
#endif /* !CONFLICTS_H_ */
|
||||
|
||||
@@ -342,7 +342,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr3.c -rall glr-regr3.y]], 0, [],
|
||||
[[glr-regr3.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
glr-regr3.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr3.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
]])
|
||||
AT_COMPILE([glr-regr3])
|
||||
|
||||
@@ -437,7 +437,7 @@ merge (YYSTYPE s1, YYSTYPE s2)
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr4.c -rall glr-regr4.y]], 0, [],
|
||||
[[glr-regr4.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
[[glr-regr4.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
]])
|
||||
AT_COMPILE([glr-regr4])
|
||||
|
||||
@@ -799,7 +799,7 @@ main (void)
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr9.c -rall glr-regr9.y]], 0, [],
|
||||
[[glr-regr9.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
[[glr-regr9.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
]])
|
||||
AT_COMPILE([glr-regr9])
|
||||
|
||||
@@ -1363,7 +1363,7 @@ main (void)
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr14.c -rall glr-regr14.y]], 0, [],
|
||||
[[glr-regr14.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
[[glr-regr14.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
]])
|
||||
AT_COMPILE([glr-regr14])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user