mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
cex: display derivations as trees
Sometimes, understanding the derivations is difficult, because they
are serialized to fit in one line. For instance, the example taken
from the NEWS file:
%token ID
%%
s: a ID
a: expr
expr: expr ID ',' | "expr"
gave
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 ]
Printing as trees, it gives:
First example expr • ID ',' ID $end
Shift derivation
$accept
↳ s $end
↳ a ID
↳ expr
↳ expr • ID ','
Second example expr • ID $end
Reduce derivation
$accept
↳ s $end
↳ a ID
↳ expr •
* src/glyphs.h, src/glyphs.c (down_arrow, empty, derivation_separator):
New.
* src/derivation.c (derivation_print, derivation_print_impl): Rename
as...
(derivation_print_flat, derivation_print_flat_impl): These.
(fputs_if, derivation_depth, derivation_width, derivation_print_tree)
(derivation_print_tree_impl, derivation_print): New.
* src/counterexample.c (print_counterexample): Adjust.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
This commit is contained in:
119
tests/report.at
119
tests/report.at
@@ -1539,39 +1539,74 @@ AT_CHECK([LC_ALL="$locale" bison -fno-caret -o input.cc -rall -Wcex --graph=inpu
|
||||
input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
Shift/reduce conflict on token "⊕":
|
||||
Example exp "+" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "+" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "+" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
Reduce/reduce conflict on tokens $end, "+", "⊕":
|
||||
Example exp "+" exp •
|
||||
First derivation exp → [ exp "+" exp • ]
|
||||
Second derivation exp → [ exp "+" exp • ]
|
||||
First derivation
|
||||
exp
|
||||
↳ exp "+" exp •
|
||||
Second derivation
|
||||
exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
Shift/reduce conflict on token "⊕":
|
||||
Example exp "+" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "+" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "+" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
Shift/reduce conflict on token "⊕":
|
||||
Example exp "⊕" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
Example exp "⊕" exp • "+" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "+" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "+" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "+" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
Example exp "⊕" exp • "+" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "+" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "+" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "+" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
input.y:6.3-13: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
# Check the contents of the report.
|
||||
AT_CHECK([cat input.output], [],
|
||||
# FIXME: Avoid trailing white spaces.
|
||||
AT_CHECK([sed -e 's/ *$//' input.output], [],
|
||||
[[Rules useless in parser due to conflicts
|
||||
|
||||
3 exp: exp "+" exp
|
||||
@@ -1714,22 +1749,38 @@ State 7
|
||||
2 exp: exp "+" exp •
|
||||
1 exp: exp • "⊕" exp
|
||||
Example exp "+" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "+" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "+" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
Reduce/reduce conflict on tokens $end, "+", "⊕":
|
||||
2 exp: exp "+" exp •
|
||||
3 exp: exp "+" exp •
|
||||
Example exp "+" exp •
|
||||
First derivation exp → [ exp "+" exp • ]
|
||||
Second derivation exp → [ exp "+" exp • ]
|
||||
First derivation
|
||||
exp
|
||||
↳ exp "+" exp •
|
||||
Second derivation
|
||||
exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
Shift/reduce conflict on token "⊕":
|
||||
3 exp: exp "+" exp •
|
||||
1 exp: exp • "⊕" exp
|
||||
Example exp "+" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "+" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "+" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "+" exp •
|
||||
|
||||
|
||||
|
||||
@@ -1751,22 +1802,40 @@ State 8
|
||||
1 exp: exp "⊕" exp •
|
||||
1 exp: exp • "⊕" exp
|
||||
Example exp "⊕" exp • "⊕" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "⊕" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "⊕" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "⊕" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
1 exp: exp "⊕" exp •
|
||||
2 exp: exp • "+" exp
|
||||
Example exp "⊕" exp • "+" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "+" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "+" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "+" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
1 exp: exp "⊕" exp •
|
||||
3 exp: exp • "+" exp
|
||||
Example exp "⊕" exp • "+" exp
|
||||
Shift derivation exp → [ exp "⊕" exp → [ exp • "+" exp ] ]
|
||||
Reduce derivation exp → [ exp → [ exp "⊕" exp • ] "+" exp ]
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp "⊕" exp
|
||||
↳ exp • "+" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp "+" exp
|
||||
↳ exp "⊕" exp •
|
||||
|
||||
]])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user