cex: display shifts before reductions

When reporting counterexamples for s/r conflicts, put the shift first.
This is more natural, and displays the default resolution first, which
is also what happens for r/r conflicts where the smallest rule number
is displayed first, and "wins".

* src/counterexample.c (counterexample): Add a shift_reduce member.
(new_counterexample): Adjust.
Swap the derivations when this is a s/r conflict.
(print_counterexample): For s/r conflicts, prefer "Shift derivation"
and "Reduce derivation" rather than "First/Second derivation".

* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* NEWS, doc/bison.texi: Ditto.
This commit is contained in:
Akim Demaille
2020-07-12 18:53:30 +02:00
parent 78f72a4516
commit 4f9ae5de07
7 changed files with 146 additions and 128 deletions

14
NEWS
View File

@@ -2,6 +2,8 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?]
Changes in the display of counterexamples.
** Documentation
*** Examples
@@ -45,8 +47,8 @@ GNU Bison NEWS
conflict. For example:
Example exp '+' exp • '/' exp
First derivation exp → [ exp → [ exp '+' exp • ] '/' exp ]
Second derivation exp → [ exp '+' exp → [ exp • '/' exp ] ]
Shift derivation exp → [ exp '+' exp → [ exp • '/' exp ] ]
Reduce derivation exp → [ exp → [ exp '+' exp • ] '/' exp ]
When Bison is installed with text styling enabled, the example is actually
shown twice, with colors highlighting the ambiguity.
@@ -56,10 +58,10 @@ GNU Bison NEWS
bison cannot find an example that can be derived in two ways, it instead
generates two examples that are the same up until the dot:
First example expr • ID $end
First derivation $accept → [ s → [ a → [ expr ] ID ] $end ]
Second example expr • ID ',' ID $end
Second derivation $accept → [ s → [ a → [ expr → [ expr • ID ',' ] ] ID ] $end ]
First example expr • ID ',' ID $end
Shift derivation $accept → [ s → [ a → [ expr → [ expr • ID ',' ] ] ID ] $end ]
Second example expr • ID $end
Reduce derivation $accept → [ s → [ a → [ expr ] ID ] $end ]
In these cases, the parser usually doesn't have enough lookahead to
differentiate the two given examples.