mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33: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:
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user