[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
cex: reformat the s/r and r/r reports
From: |
Akim Demaille |
Subject: |
cex: reformat the s/r and r/r reports |
Date: |
Sun, 7 Jun 2020 08:30:36 +0200 |
commit 13eac11f506d8cc4be981bf6aaf1a5b2a3bfceb4
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Sun Jun 7 07:32:59 2020 +0200
cex: reformat the s/r and r/r reports
In Bison we refer to "shift/reduce" conflicts, not "shift-reduce" (in
Bison 3.6.3 186 occurrences vs 15). Enforce consistency on this.
Instead of "spending" a second line for each conflict to report the
lookaheads, put that on the same line as the type of conflict. Also,
prefer "token" to "symbol". Maybe we should even prefer "lookahead".
While at it, enable internationalization, with plurals where
appropriate.
As a consequence, instead of
Shift-Reduce Conflict:
6: 3 b: . %empty
6: 6 d: c . A
On Symbol: A
display
Shift/reduce conflict on token A:
6: 3 b: . %empty
6: 6 d: c . A
* NEWS, doc/bison.texi, src/conflicts.c: Spell it "shift/reduce", not
"shift-reduce".
* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Reformat and internationalize
output.
* tests/counterexample.at: Adjust expectations.
diff --git a/NEWS b/NEWS
index 4c77cedd..712b2b7a 100644
--- a/NEWS
+++ b/NEWS
@@ -848,11 +848,11 @@ GNU Bison NEWS
...
- Looking at the output from -v, one can see that the shift-reduce conflict
+ Looking at the output from -v, one can see that the shift/reduce conflict
here is due to the fact that the parser does not know whether to reduce
arguments to argument_list until it sees the token _after_ the following
','. By marking the rule with %expect 1 (because there is a conflict in
- one state), we document the source of the 1 overall shift-reduce conflict.
+ one state), we document the source of the 1 overall shift/reduce conflict.
In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
conflicts. In this case, we mark each of the conflicting rules. For
@@ -967,7 +967,7 @@ GNU Bison NEWS
** Bug fixes
-*** Incorrect number of reduce-reduce conflicts
+*** Incorrect number of reduce/reduce conflicts
On a grammar such as
diff --git a/doc/bison.texi b/doc/bison.texi
index cc71a69b..5a08fa92 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -5618,13 +5618,13 @@ Specify the grammar's start symbol (@pxref{Start Decl}).
@end deffn
@deffn {Directive} %expect
-Declare the expected number of shift-reduce conflicts, either overall or
+Declare the expected number of shift/reduce conflicts, either overall or
for a given rule
(@pxref{Expect Decl}).
@end deffn
@deffn {Directive} %expect-rr
-Declare the expected number of reduce-reduce conflicts, either overall or
+Declare the expected number of reduce/reduce conflicts, either overall or
for a given rule
(@pxref{Expect Decl}).
@end deffn
@@ -9172,7 +9172,7 @@ Ambiguous grammars, since they have strings with more
than one possible
sequence of reductions cannot have deterministic parsers in this sense.
The same is true of languages that require more than one symbol of
lookahead, since the parser lacks the information necessary to make a
-decision at the point it must be made in a shift-reduce parser.
+decision at the point it must be made in a shift/reduce parser.
Finally, as previously mentioned (@pxref{Mysterious Conflicts}),
there are languages where Bison's default choice of how to
summarize the input seen so far loses necessary information.
@@ -9182,9 +9182,9 @@ Bison generates a parser that uses a different algorithm,
called
Generalized LR (or GLR). A Bison GLR
parser uses the same basic
algorithm for parsing as an ordinary Bison parser, but behaves
-differently in cases where there is a shift-reduce conflict that has not
+differently in cases where there is a shift/reduce conflict that has not
been resolved by precedence rules (@pxref{Precedence}) or a
-reduce-reduce conflict. When a GLR parser encounters such a
+reduce/reduce conflict. When a GLR parser encounters such a
situation, it
effectively @emph{splits} into a several parsers, one for each possible
shift or reduction. These parsers then proceed as usual, consuming
@@ -13885,7 +13885,7 @@ associated with any of the symbols in the current rule).
There was also the command @samp{%expect @var{n}} which said not to mention the
conflicts if there are @var{n} shift/reduce conflicts and no reduce/reduce
conflicts. In more recent versions of Bison, @code{%expect} and its
-@code{%expect-rr} variant for reduce-reduce conflicts can be applied to
+@code{%expect-rr} variant for reduce/reduce conflicts can be applied to
individual rules.
Later versions of Bison added many more new features.
diff --git a/src/conflicts.c b/src/conflicts.c
index ddea8366..2f8b7c53 100644
--- a/src/conflicts.c
+++ b/src/conflicts.c
@@ -220,7 +220,7 @@ log_resolution (rule *r, symbol_number token,
/*------------------------------------------------------------------.
| Turn off the shift recorded for the specified token in the |
-| specified state. Used when we resolve a shift-reduce conflict in |
+| specified state. Used when we resolve a shift/reduce conflict in |
| favor of the reduction or as an error (%nonassoc). |
`------------------------------------------------------------------*/
@@ -239,7 +239,7 @@ flush_shift (state *s, int token)
/*--------------------------------------------------------------------.
| Turn off the reduce recorded for the specified token in the |
-| specified lookahead set. Used when we resolve a shift-reduce |
+| specified lookahead set. Used when we resolve a shift/reduce |
| conflict in favor of the shift or as an error (%nonassoc). |
`--------------------------------------------------------------------*/
@@ -251,7 +251,7 @@ flush_reduce (bitset lookahead_tokens, int token)
/*------------------------------------------------------------------.
-| Attempt to resolve shift-reduce conflict for one rule by means of |
+| Attempt to resolve shift/reduce conflict for one rule by means of |
| precedence declarations. It has already been checked that the |
| rule has a precedence. A conflict is resolved by modifying the |
| shift or reduce tables so that there is no longer a conflict. |
@@ -276,7 +276,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors,
int *nerrs)
&& bitset_test (lookahead_set, i)
&& symbols[i]->content->prec)
{
- /* Shift-reduce conflict occurs for token number i
+ /* Shift/reduce conflict occurs for token number i
and it has a precedence.
The precedence of shifting is that of token i. */
if (symbols[i]->content->prec < redprec)
@@ -358,7 +358,7 @@ set_conflicts (state *s, symbol **errors)
}
/* Loop over all rules which require lookahead in this state. First
- check for shift-reduce conflict, and try to resolve using
+ check for shift/reduce conflict, and try to resolve using
precedence. */
for (int i = 0; i < reds->num; ++i)
if (reds->rules[i]->prec
diff --git a/src/counterexample.c b/src/counterexample.c
index 1eb83451..ebef6d5d 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -21,6 +21,8 @@
#include "counterexample.h"
+#include "system.h"
+
#include <gl_linked_list.h>
#include <gl_rbtreehash_list.h>
#include <hash.h>
@@ -1214,10 +1216,9 @@ counterexample_report_shift_reduce (state_item_number
itm1, state_item_number it
symbol_number next_sym)
{
FILE *out = stderr;
- fputs ("Shift-Reduce Conflict:\n", out);
+ fprintf (out, _("Shift/reduce conflict on token %s:\n"),
symbols[next_sym]->tag);
print_state_item (&state_items[itm1], out);
print_state_item (&state_items[itm2], out);
- fprintf (out, "On Symbol: %s\n", symbols[next_sym]->tag);
counterexample_report (itm1, itm2, next_sym, true);
}
@@ -1226,18 +1227,21 @@ counterexample_report_reduce_reduce (state_item_number
itm1, state_item_number i
bitset conflict_syms)
{
FILE *out = stderr;
- fputs ("Reduce-Reduce Conflict:\n", out);
+ {
+ fputs (ngettext ("Reduce/reduce conflict on token",
+ "Reduce/reduce conflict on tokens",
+ bitset_count (conflict_syms)), out);
+ bitset_iterator biter;
+ state_item_number sym;
+ const char *sep = " ";
+ BITSET_FOR_EACH (biter, conflict_syms, sym, 0)
+ {
+ fprintf (out, "%s%s", sep, symbols[sym]->tag);
+ sep = ", ";
+ }
+ fputs (_(":\n"), out);
+ }
print_state_item (&state_items[itm1], out);
print_state_item (&state_items[itm2], out);
- fputs ("On Symbols: ", out);
- bitset_iterator biter;
- state_item_number sym;
- const char *sep = "";
- BITSET_FOR_EACH (biter, conflict_syms, sym, 0)
- {
- fprintf (out, "%s%s", sep, symbols[sym]->tag);
- sep = ", ";
- }
- fputs ("\n", out);
counterexample_report (itm1, itm2, bitset_first (conflict_syms), false);
}
diff --git a/tests/counterexample.at b/tests/counterexample.at
index d8582000..a90cc70d 100644
--- a/tests/counterexample.at
+++ b/tests/counterexample.at
@@ -44,10 +44,9 @@ y: A | A B;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token B:
1: 3 a: A .
1: 8 y: A . B
-On Symbol: B
Example A • B C
First derivation s ::=[ a ::=[ A • ] x ::=[ B C ] ]
Second derivation s ::=[ y ::=[ A • B ] c ::=[ C ] ]
@@ -76,10 +75,9 @@ bc: B bc C | B C;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token B:
1: 7 a: A .
1: 5 b: . B
-On Symbol: B
Example A • B C
First derivation s ::=[ a ::=[ A • ] bc ::=[ B C ] ]
Second derivation s ::=[ ac ::=[ A ac ::=[ b ::=[ • B ] ] C ] ]
@@ -109,18 +107,16 @@ xby: B | X xby Y;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token B:
1: 4 x: . %empty
1: 9 xby: . B
-On Symbol: B
Example A • B y
First derivation s ::=[ ax ::=[ A x ::=[ • ] ] by ::=[ B y ] ]
Second derivation s ::=[ A xby ::=[ • B ] ]
-Shift-Reduce Conflict:
+Shift/reduce conflict on token B:
5: 4 x: . %empty
5: 9 xby: . B
-On Symbol: B
First Example A X • B y $end
First derivation $accept ::=[ s ::=[ ax ::=[ A x ::=[ X x ::=[ • ] ] ] by
::=[ B y ] ] $end ]
Second Example A X • B Y $end
@@ -151,10 +147,9 @@ bc: B C;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token C:
2: 7 b: B .
2: 9 bc: B . C
-On Symbol: C
First Example B • C D $end
First derivation $accept ::=[ g ::=[ x ::=[ b ::=[ B • ] cd ::=[ C D ] ]
] $end ]
Second Example B • C $end
@@ -183,10 +178,9 @@ y: A A B;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token A:
1: 5 x: A .
1: 6 y: A . A B
-On Symbol: A
First Example A • A $end
First derivation $accept ::=[ s ::=[ s ::=[ t ::=[ x ::=[ A • ] ] ] t ::=[
x ::=[ A ] ] ] $end ]
Second Example A • A B $end
@@ -219,18 +213,16 @@ y: Y;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token A:
4: 3 r: b .
4: 7 s: b . A xx y
-On Symbol: A
Example b • A X X Y
First derivation a ::=[ r ::=[ b • ] t ::=[ A x ::=[ X ] xy ::=[ X Y ]
] ]
Second derivation a ::=[ s ::=[ b • xx ::=[ A X X ] y ::=[ Y ] ] ]
-Shift-Reduce Conflict:
+Shift/reduce conflict on token X:
10: 8 x: X .
10: 9 xx: X . X
-On Symbol: X
First Example X • X xy
First derivation a ::=[ x ::=[ X • ] t ::=[ X xy ] ]
Second Example A X • X
@@ -258,10 +250,9 @@ b : A | b;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Reduce-Reduce Conflict:
+[[Reduce/reduce conflict on token $end:
4: 1 a: A b .
4: 3 b: b .
-On Symbols: $end
Example A b •
First derivation a ::=[ A b • ]
Second derivation a ::=[ A b ::=[ b • ] ]
@@ -288,10 +279,9 @@ b: D;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Reduce-Reduce Conflict:
+[[Reduce/reduce conflict on tokens A, C:
2: 5 a: D .
2: 6 b: D .
-On Symbols: A, C
First Example D • A $end
First derivation $accept ::=[ s ::=[ a ::=[ D • ] A ] $end ]
Second Example B D • A $end
@@ -319,11 +309,10 @@ i: X | i J K;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token J:
5: 2 a: H i .
5: 4 i: i . J K
-On Symbol: J
-time limit exceeded: 6.000000
+time limit exceeded: XXX
First Example H i • J $end
First derivation $accept ::=[ s ::=[ a ::=[ H i • ] J ] $end ]
Second Example H i • J K $end
@@ -355,10 +344,9 @@ b: A B C | A B D;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token B:
4: 7 a: A .
4: 8 b: A . B C
-On Symbol: B
Example N A • B C
First derivation s ::=[ n ::=[ N a ::=[ A • ] B ] C ]
Second derivation s ::=[ n ::=[ N b ::=[ A • B C ] ] ]
@@ -390,18 +378,16 @@ C : A c A;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Reduce-Reduce Conflict:
+[[Reduce/reduce conflict on tokens b, c:
3: 3 A: B .
3: 5 A: . %empty
-On Symbols: b, c
Example B • b A A c A
First derivation S ::=[ B ::=[ A ::=[ B • ] b A ] C ::=[ A c A ] ]
Second derivation S ::=[ B C ::=[ A ::=[ B ::=[ A ::=[ • ] b A ] ] c A ]
]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on tokens b, c:
4: 4 A: C .
4: 5 A: . %empty
-On Symbols: b, c
Example C • c A A b A
First derivation S ::=[ C ::=[ A ::=[ C • ] c A ] B ::=[ A b A ] ]
Second derivation S ::=[ C B ::=[ A ::=[ C ::=[ A ::=[ • ] c A ] ] b A ]
]
@@ -428,75 +414,67 @@ d : a | c A | d;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Reduce-Reduce Conflict:
+[[Reduce/reduce conflict on token A:
0: 3 b: . %empty
0: 4 c: . %empty
-On Symbols: A
First Example • c A A $end
First derivation $accept ::=[ a ::=[ b ::=[ • ] d ::=[ c A A ] ] $end ]
Second Example • c A A $end
Second derivation $accept ::=[ a ::=[ c ::=[ • ] d ::=[ c A A ] ] $end ]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on token A:
2: 3 b: . %empty
2: 4 c: . %empty
-On Symbols: A
-time limit exceeded: 6.000000
+time limit exceeded: XXX
First Example b • c A A $end
First derivation $accept ::=[ a ::=[ b d ::=[ a ::=[ b ::=[ • ] d ::=[ c
A A ] ] ] ] $end ]
Second Example b • A $end
Second derivation $accept ::=[ a ::=[ b d ::=[ c ::=[ • ] A ] ] $end ]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on token A:
3: 3 b: . %empty
3: 4 c: . %empty
-On Symbols: A
-time limit exceeded: 6.000000
+time limit exceeded: XXX
First Example c • c A A $end
First derivation $accept ::=[ a ::=[ c d ::=[ a ::=[ b ::=[ • ] d ::=[ c
A A ] ] ] ] $end ]
Second Example c • A $end
Second derivation $accept ::=[ a ::=[ c d ::=[ c ::=[ • ] A ] ] $end ]
-Shift-Reduce Conflict:
+Shift/reduce conflict on token A:
6: 3 b: . %empty
6: 6 d: c . A
-On Symbol: A
-time limit exceeded: 6.000000
+time limit exceeded: XXX
First Example b c • c A A $end
First derivation $accept ::=[ a ::=[ b d ::=[ a ::=[ c d ::=[ a ::=[ b
::=[ • ] d ::=[ c A A ] ] ] ] ] ] $end ]
Second Example b c • A
Second derivation a ::=[ b d ::=[ c • A ] ]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on token A:
6: 3 b: . %empty
6: 4 c: . %empty
-On Symbols: A
First Example b c • c A A $end
First derivation $accept ::=[ a ::=[ b d ::=[ a ::=[ c d ::=[ a ::=[ b
::=[ • ] d ::=[ c A A ] ] ] ] ] ] $end ]
Second Example b c • A $end
Second derivation $accept ::=[ a ::=[ b d ::=[ a ::=[ c d ::=[ c ::=[ • ]
A ] ] ] ] $end ]
-Shift-Reduce Conflict:
+Shift/reduce conflict on token A:
6: 4 c: . %empty
6: 6 d: c . A
-On Symbol: A
First Example b c • A $end
First derivation $accept ::=[ a ::=[ b d ::=[ a ::=[ c d ::=[ c ::=[ • ]
A ] ] ] ] $end ]
Second Example b c • A
Second derivation a ::=[ b d ::=[ c • A ] ]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on token $end:
7: 1 a: b d .
7: 7 d: d .
-On Symbols: $end
Example b d •
First derivation a ::=[ b d • ]
Second derivation a ::=[ b d ::=[ d • ] ]
-Reduce-Reduce Conflict:
+Reduce/reduce conflict on token $end:
8: 2 a: c d .
8: 7 d: d .
-On Symbols: $end
Example c d •
First derivation a ::=[ c d • ]
Second derivation a ::=[ c d ::=[ d • ] ]
@@ -528,10 +506,9 @@ i: %empty | i J;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token J:
7: 5 i: i J .
7: 3 a: H i J . J
-On Symbol: J
Example H i J • J J
First derivation s ::=[ a ::=[ H i ::=[ i J • ] J J ] ]
Second derivation s ::=[ a ::=[ H i J • J ] J ]
@@ -563,10 +540,9 @@ D: d;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token d:
3: 5 C: . %empty
3: 6 D: . d
-On Symbol: d
Example a A • d
First derivation S ::=[ a A A ::=[ B ::=[ C ::=[ • ] ] ] D ::=[ d ] ]
Second derivation S ::=[ a A D ::=[ • d ] ]
@@ -596,10 +572,9 @@ D: d;
]])
AT_BISON_CHECK_CEX([input.y], [], [],
-[[Shift-Reduce Conflict:
+[[Shift/reduce conflict on token d:
3: 5 C: . %empty
3: 6 D: . d
-On Symbol: d
First Example a A • d e $end
First derivation $accept ::=[ S ::=[ a A A ::=[ B ::=[ C ::=[ • ] ] ] D
::=[ d ] e ] $end ]
Second Example a A • d $end
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- cex: reformat the s/r and r/r reports,
Akim Demaille <=