mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-08-09 10:45:15 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a11a9308c | ||
|
|
d8cc6b073e | ||
|
|
0264b4bca0 | ||
|
|
8b424b865e | ||
|
|
f4431ea115 | ||
|
|
fe8c36ddca | ||
|
|
21c147b6e5 | ||
|
|
d3c575a6c6 | ||
|
|
d8b49e2b73 | ||
|
|
14c65a35f0 | ||
|
|
c47bb87f9f | ||
|
|
98c35e0025 | ||
|
|
bd6b046ce7 | ||
|
|
7c6e7bd300 | ||
|
|
3cba59dd7f | ||
|
|
a15879c623 | ||
|
|
5d501ee728 | ||
|
|
bc5e4541da | ||
|
|
567d1eaa19 | ||
|
|
c08e0863be | ||
|
|
541943ee04 | ||
|
|
dcdd119f69 | ||
|
|
a0bc06b703 | ||
|
|
5e33dfe59d | ||
|
|
2a4e9a358f | ||
|
|
f7b642cff7 | ||
|
|
3da17724ad | ||
|
|
68e3e442f9 | ||
|
|
e432619d11 | ||
|
|
a1b7fef045 | ||
|
|
067e35a8be | ||
|
|
0522047c96 | ||
|
|
3724b50ef9 | ||
|
|
b801b7b670 | ||
|
|
b7aab2dbad | ||
|
|
89e42ffb4b | ||
|
|
6aae4a7378 | ||
|
|
7d4a4300c2 | ||
|
|
31d4ec28bd | ||
|
|
0a5bfb4fda | ||
|
|
12d0b15679 | ||
|
|
cb7dcb011e | ||
|
|
71579c7219 | ||
|
|
2f8a874215 | ||
|
|
ad6f600bb1 | ||
|
|
de4f41eab7 | ||
|
|
e73f086b0d | ||
|
|
8cf098415e | ||
|
|
977e19840d | ||
|
|
d975c2f76e | ||
|
|
0676801b8c | ||
|
|
82aa96e9b1 | ||
|
|
cb65553449 | ||
|
|
f47a1bd622 | ||
|
|
205d372c68 | ||
|
|
07a1243b40 | ||
|
|
ece343d2c2 | ||
|
|
be95a4fe29 | ||
|
|
6accee7716 | ||
|
|
e63f22703e | ||
|
|
fa390dc311 | ||
|
|
17fdf5eca2 | ||
|
|
72b3c1a673 | ||
|
|
6675d36e25 | ||
|
|
d0bec3175f | ||
|
|
79e68b6c4d | ||
|
|
5cb74cacd8 | ||
|
|
9c8e6e05b6 | ||
|
|
431774d1f6 | ||
|
|
7d5474e979 | ||
|
|
6b78e50cef | ||
|
|
28769d608e | ||
|
|
a22588bcb9 | ||
|
|
b8c5e5609f | ||
|
|
b81229e1f9 | ||
|
|
815a76f558 | ||
|
|
ea138cd1f1 | ||
|
|
9922f1f877 | ||
|
|
1438b79e80 | ||
|
|
01f3e2969b | ||
|
|
744da03955 | ||
|
|
b28d67b6b0 | ||
|
|
cf890692f1 | ||
|
|
6932023f4d | ||
|
|
fff17fe8fe | ||
|
|
5544615a59 | ||
|
|
346ba14f15 | ||
|
|
4d18195ebc | ||
|
|
dd3e7b3895 | ||
|
|
64a3b6546a | ||
|
|
bad07a7f66 | ||
|
|
88bd814bf1 | ||
|
|
4f9ae5de07 | ||
|
|
78f72a4516 | ||
|
|
c04693d651 | ||
|
|
12191911ba | ||
|
|
d7f27477f4 | ||
|
|
5bad15d7ea | ||
|
|
cd099edf2d | ||
|
|
1e12219775 | ||
|
|
d8c2af56c1 | ||
|
|
cc11bb037c | ||
|
|
121dd98508 | ||
|
|
2eddbd0ac4 | ||
|
|
ee86ea8839 | ||
|
|
a2ad33dca6 | ||
|
|
5b2b7b1ffb | ||
|
|
dc72b3566d | ||
|
|
c47e1174d4 | ||
|
|
093eeb27e9 | ||
|
|
dab23c4a21 | ||
|
|
38a169bec1 | ||
|
|
dc77d6500f | ||
|
|
8262c7dc22 | ||
|
|
44f28d10ee | ||
|
|
44ad466a32 | ||
|
|
a839f4c461 | ||
|
|
9a51c6a128 | ||
|
|
2608b0cf12 | ||
|
|
aa766d1560 | ||
|
|
a7ed13b25f |
+1
-1
@@ -1 +1 @@
|
||||
3.6.90
|
||||
3.7.3
|
||||
|
||||
+4
-1
@@ -50,6 +50,7 @@ jobs:
|
||||
- make -j2 dist-xz
|
||||
# Can help understanding why we get "dirty" tarballs.
|
||||
- git status
|
||||
- git diff
|
||||
- dist=$(echo bison*.xz)
|
||||
|
||||
# Unfortunately we cannot deterministically know the name of the tarball without the full
|
||||
@@ -119,6 +120,8 @@ jobs:
|
||||
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
|
||||
- PART=2
|
||||
|
||||
# See https://github.com/simd-everywhere/simde/blob/master/.travis.yml
|
||||
# and https://software.intel.com/content/www/us/en/develop/documentation/get-started-with-intel-oneapi-render-linux/top/configure-your-system.html.
|
||||
- name: "ICC"
|
||||
stage: check
|
||||
os: linux
|
||||
@@ -127,7 +130,7 @@ jobs:
|
||||
- CC=icc
|
||||
- CXX=icpc
|
||||
install:
|
||||
- source /opt/intel/inteloneapi/compiler/latest/env/vars.sh
|
||||
- source /opt/intel/oneapi/compiler/latest/env/vars.sh
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
||||
@@ -1,13 +1,84 @@
|
||||
GNU Bison NEWS
|
||||
|
||||
* Noteworthy changes in release 3.6.91 (2020-07-09) [beta]
|
||||
* Noteworthy changes in release 3.7.4 (2020-11-14) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Portability issues.
|
||||
*** Bug fixes in yacc.c
|
||||
|
||||
In Yacc mode, all the tokens are defined twice: once as an enum, and then
|
||||
as a macro. YYEMPTY was missing its macro.
|
||||
|
||||
*** Bug fixes in lalr1.cc
|
||||
|
||||
The lalr1.cc skeleton used to emit internal assertions (using YY_ASSERT)
|
||||
even when the `parse.assert` %define variable is not enabled. It no
|
||||
longer does.
|
||||
|
||||
The private internal macro YY_ASSERT now obeys the `api.prefix` %define
|
||||
variable.
|
||||
|
||||
When there is a very large number of tokens, some assertions could be long
|
||||
enough to hit arbitrary limits in Visual C++. They have been rewritten to
|
||||
work around this limitation.
|
||||
|
||||
** Changes
|
||||
|
||||
The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
|
||||
skeleton) used to be defined to 1. It is now defined to the version of
|
||||
Bison as an integer (e.g., 30704 for version 3.7.4).
|
||||
|
||||
* Noteworthy changes in release 3.7.3 (2020-10-13) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Fix concurrent build issues.
|
||||
|
||||
The bison executable is no longer linked uselessly against libreadline.
|
||||
|
||||
Fix incorrect use of yytname in glr.cc.
|
||||
|
||||
* Noteworthy changes in release 3.7.2 (2020-09-05) [stable]
|
||||
|
||||
This release of Bison fixes all known bugs reported for Bison in MITRE's
|
||||
Common Vulnerabilities and Exposures (CVE) system. These vulnerabilities
|
||||
are only about bison-the-program itself, not the generated code.
|
||||
|
||||
Although these bugs are typically irrelevant to how Bison is used, they
|
||||
are worth fixing if only to give users peace of mind.
|
||||
|
||||
There is no known vulnerability in the generated parsers.
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Fix concurrent build issues (introduced in Bison 3.5).
|
||||
|
||||
Push parsers always use YYMALLOC/YYFREE (no direct calls to malloc/free).
|
||||
|
||||
Fix portability issues of the test suite, and of bison itself.
|
||||
|
||||
Some unlikely crashes found by fuzzing have been fixed. This is only
|
||||
about bison itself, not the generated parsers.
|
||||
|
||||
|
||||
* Noteworthy changes in release 3.6.90 (2020-07-04) [beta]
|
||||
* Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Crash when a token alias contains a NUL byte.
|
||||
|
||||
Portability issues with libtextstyle.
|
||||
|
||||
Portability issues of Bison itself with MSVC.
|
||||
|
||||
** Changes
|
||||
|
||||
Improvements and fixes in the documentation.
|
||||
|
||||
More precise location about symbol type redefinitions.
|
||||
|
||||
|
||||
* Noteworthy changes in release 3.7 (2020-07-23) [stable]
|
||||
|
||||
** Deprecated features
|
||||
|
||||
@@ -25,35 +96,114 @@ GNU Bison NEWS
|
||||
|
||||
Contributed by Vincent Imbimbo.
|
||||
|
||||
When given `--report=counterexamples` or `-Wcounterexamples`, bison will
|
||||
now output counterexamples for conflicts in the grammar. These are
|
||||
strings in the grammar which can be parsed in two ways due to the
|
||||
conflict. For example:
|
||||
When given `-Wcounterexamples`/`-Wcex`, bison will now output
|
||||
counterexamples for conflicts.
|
||||
|
||||
Example exp '+' exp • '/' exp
|
||||
First derivation exp ::=[ exp ::=[ exp '+' exp • ] '/' exp ]
|
||||
Second derivation exp ::=[ exp '+' exp ::=[ exp • '/' exp ] ]
|
||||
**** Unifying Counterexamples
|
||||
|
||||
When Bison is installed with text styling enabled, the example is actually
|
||||
shown twice, with colors highlighting the ambiguity.
|
||||
Unifying counterexamples are strings which can be parsed in two ways due
|
||||
to the conflict. For example on a grammar that contains the usual
|
||||
"dangling else" ambiguity:
|
||||
|
||||
This is a shift/reduce conflict caused by none of the operators having
|
||||
precedence, so the example can be parsed in the two ways shown. When
|
||||
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:
|
||||
$ bison else.y
|
||||
else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
else.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
|
||||
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 ]
|
||||
$ bison else.y -Wcex
|
||||
else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
else.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples]
|
||||
Example: "if" exp "then" "if" exp "then" exp • "else" exp
|
||||
Shift derivation
|
||||
exp
|
||||
↳ "if" exp "then" exp
|
||||
↳ "if" exp "then" exp • "else" exp
|
||||
Example: "if" exp "then" "if" exp "then" exp • "else" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ "if" exp "then" exp "else" exp
|
||||
↳ "if" exp "then" exp •
|
||||
|
||||
When text styling is enabled, colors are used in the examples and the
|
||||
derivations to highlight the structure of both analyses. In this case,
|
||||
|
||||
"if" exp "then" [ "if" exp "then" exp • ] "else" exp
|
||||
|
||||
vs.
|
||||
|
||||
"if" exp "then" [ "if" exp "then" exp • "else" exp ]
|
||||
|
||||
|
||||
The counterexamples are "focused", in two different ways. First, they do
|
||||
not clutter the output with all the derivations from the start symbol,
|
||||
rather they start on the "conflicted nonterminal". They go straight to the
|
||||
point. Second, they don't "expand" nonterminal symbols uselessly.
|
||||
|
||||
**** Nonunifying Counterexamples
|
||||
|
||||
In the case of the dangling else, Bison found an example that can be
|
||||
parsed in two ways (therefore proving that the grammar is ambiguous).
|
||||
When it cannot find such an example, it instead generates two examples
|
||||
that are the same up until the dot:
|
||||
|
||||
$ bison foo.y
|
||||
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
foo.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
|
||||
4 | a: expr
|
||||
| ^~~~
|
||||
|
||||
$ bison -Wcex foo.y
|
||||
foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
foo.y: warning: shift/reduce conflict on token ID [-Wcounterexamples]
|
||||
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 •
|
||||
foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
|
||||
4 | a: expr
|
||||
| ^~~~
|
||||
|
||||
In these cases, the parser usually doesn't have enough lookahead to
|
||||
differentiate the two given examples.
|
||||
|
||||
The counterexamples are "focused": in two different ways. First, they do
|
||||
not clutter the output with all the derivations from the start symbol,
|
||||
rather they start on the "conflicted nonterminal". They go straight to the
|
||||
point. Second, they don't "expand" nonterminal symbols uselessly.
|
||||
**** Reports
|
||||
|
||||
Counterexamples are also included in the report when given
|
||||
`--report=counterexamples`/`-rcex` (or `--report=all`), with more
|
||||
technical details:
|
||||
|
||||
State 7
|
||||
|
||||
1 exp: "if" exp "then" exp • [$end, "then", "else"]
|
||||
2 | "if" exp "then" exp • "else" exp
|
||||
|
||||
"else" shift, and go to state 8
|
||||
|
||||
"else" [reduce using rule 1 (exp)]
|
||||
$default reduce using rule 1 (exp)
|
||||
|
||||
shift/reduce conflict on token "else":
|
||||
1 exp: "if" exp "then" exp •
|
||||
2 exp: "if" exp "then" exp • "else" exp
|
||||
Example: "if" exp "then" "if" exp "then" exp • "else" exp
|
||||
Shift derivation
|
||||
exp
|
||||
↳ "if" exp "then" exp
|
||||
↳ "if" exp "then" exp • "else" exp
|
||||
Example: "if" exp "then" "if" exp "then" exp • "else" exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ "if" exp "then" exp "else" exp
|
||||
↳ "if" exp "then" exp •
|
||||
|
||||
*** File prefix mapping
|
||||
|
||||
@@ -67,6 +217,11 @@ GNU Bison NEWS
|
||||
|
||||
** Changes
|
||||
|
||||
*** Diagnostics
|
||||
|
||||
When text styling is enabled and the terminal supports it, the warnings
|
||||
now include hyperlinks to the documentation.
|
||||
|
||||
*** Relocatable installation
|
||||
|
||||
When installed to be relocatable (via `configure --enable-relocatable`),
|
||||
@@ -107,6 +262,18 @@ GNU Bison NEWS
|
||||
Now the parser state can be examined when parsing is finished. The parser
|
||||
state is reset when starting a new parse.
|
||||
|
||||
** Documentation
|
||||
|
||||
*** Examples
|
||||
|
||||
The bistromathic demonstrates %param and how to quote sources in the error
|
||||
messages:
|
||||
|
||||
> 123 456
|
||||
1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
|
||||
1 | 123 456
|
||||
| ^~~
|
||||
|
||||
** Bug fixes
|
||||
|
||||
*** Include the generated header (yacc.c)
|
||||
@@ -448,7 +615,8 @@ GNU Bison NEWS
|
||||
\005) with incorrect styling. Fixes for similar issues with unexpectedly
|
||||
short lines (e.g., the file was changed between parsing and diagnosing).
|
||||
|
||||
Several unlikely crashes found by fuzzing have been fixed.
|
||||
Some unlikely crashes found by fuzzing have been fixed. This is only
|
||||
about bison itself, not the generated parsers.
|
||||
|
||||
|
||||
* Noteworthy changes in release 3.5.2 (2020-02-13) [stable]
|
||||
@@ -4372,7 +4540,7 @@ LocalWords: yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
|
||||
LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
|
||||
LocalWords: autocompletion bistromathic submessages Cayuela lexcalc hoc
|
||||
LocalWords: yytoken YYUNDEF YYerror basename Automake's UTF ifdef ffile
|
||||
LocalWords: gotos readline Imbimbo Wcounterexamples
|
||||
LocalWords: gotos readline Imbimbo Wcounterexamples Wcex Nonunifying rcex
|
||||
|
||||
Local Variables:
|
||||
ispell-dictionary: "american"
|
||||
|
||||
@@ -27,7 +27,7 @@ Bison from the git repo. Roughly, run:
|
||||
then proceed with the usual `configure && make` steps.
|
||||
|
||||
## Build from tarball
|
||||
See the [INSTALL file](INSTALL] for generic compilation and installation
|
||||
See the [INSTALL file](INSTALL) for generic compilation and installation
|
||||
instructions.
|
||||
|
||||
Bison requires GNU m4 1.4.6 or later. See
|
||||
@@ -42,9 +42,11 @@ installing it. In that case, do not use `src/bison`: it would use the
|
||||
As an experimental feature, diagnostics are now colored, controlled by the
|
||||
`--color` and `--style` options.
|
||||
|
||||
To use them, install the libtextstyle library before configuring Bison. It
|
||||
is available from https://alpha.gnu.org/gnu/gettext/, for instance
|
||||
https://alpha.gnu.org/pub/gnu/gettext/libtextstyle-0.20.5.tar.gz.
|
||||
To use them, install the libtextstyle library, 0.20.5 or newer, before
|
||||
configuring Bison. It is available from https://alpha.gnu.org/gnu/gettext/,
|
||||
for instance https://alpha.gnu.org/gnu/gettext/libtextstyle-0.20.5.tar.gz,
|
||||
or as part of Gettext 0.21 or newer, for instance
|
||||
https://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.gz.
|
||||
|
||||
The option --color supports the following arguments:
|
||||
- always, yes: Enable colors.
|
||||
@@ -61,6 +63,13 @@ To customize the styles, create a CSS file, say `bison-bw.css`, similar to
|
||||
then invoke bison with `--style=bison-bw.css`, or set the `BISON_STYLE`
|
||||
environment variable to `bison-bw.css`.
|
||||
|
||||
In some diagnostics, bison uses libtextstyle to emit special escapes to
|
||||
generate clickable hyperlinks. The environment variable
|
||||
`NO_TERM_HYPERLINKS` can be used to suppress them. This may be useful for
|
||||
terminal emulators which produce garbage output when they receive the escape
|
||||
sequence for a hyperlink. Currently (as of 2020), this affects some versions
|
||||
of emacs, guake, konsole, lxterminal, rxvt, yakuake.
|
||||
|
||||
## Relocatability
|
||||
If you pass `--enable-relocatable` to `configure`, Bison is relocatable.
|
||||
|
||||
|
||||
+1
-1
@@ -444,7 +444,7 @@ added the `[-Wother]` part to all the warnings). Part of the update can be
|
||||
done with a crude tool: `build-aux/update-test`.
|
||||
|
||||
Once you ran the test suite, and therefore have many `testsuite.log` files,
|
||||
run, from the source tree:
|
||||
run `make update-tests`. Or, by hand, from the *source* tree:
|
||||
|
||||
$ ./build-aux/update-test $build/tests/testsuite.dir/*/testsuite.log
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ Csaba Raduly [email protected]
|
||||
Dagobert Michelsen [email protected]
|
||||
Daniel Frużyński [email protected]
|
||||
Daniel Galloway [email protected]
|
||||
Daniela Becker [email protected]
|
||||
Daniel Hagerty [email protected]
|
||||
David Barto [email protected]
|
||||
David J. MacKenzie [email protected]
|
||||
@@ -105,9 +106,11 @@ Keith Browne [email protected]
|
||||
Ken Moffat [email protected]
|
||||
Kiyoshi Kanazawa [email protected]
|
||||
Lars Maier [email protected]
|
||||
Lars Wendler [email protected]
|
||||
László Várady [email protected]
|
||||
Laurent Mascherpa [email protected]
|
||||
Lie Yan [email protected]
|
||||
Maarten De Braekeleer [email protected]
|
||||
Magnus Fromreide [email protected]
|
||||
Marc Autret [email protected]
|
||||
Marc Mendiola [email protected]
|
||||
@@ -184,6 +187,7 @@ Simon Sobisch [email protected]
|
||||
Stefano Lattarini [email protected]
|
||||
Stephen Cameron [email protected]
|
||||
Steve Murphy [email protected]
|
||||
Suhwan Song [email protected]
|
||||
Sum Wu [email protected]
|
||||
Théophile Ranquet [email protected]
|
||||
Thiru Ramakrishnan [email protected]
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
* Bison 3.7
|
||||
* Soon
|
||||
** gnulib
|
||||
Bruno notes:
|
||||
|
||||
> I haven't looked deeply, but it strikes me that gnulib/lib/bitset/array.c
|
||||
> does not make use of the 'ffsl' function, nor or the 'integer_length_l'
|
||||
> function. Maybe because in Bison, all bitsets are so dense that it does
|
||||
> not give a performance advantage?
|
||||
|
||||
** Cex
|
||||
*** Improve gnulib
|
||||
Don't do this (counterexample.c):
|
||||
@@ -36,8 +44,6 @@ Unless we play it dumb (little structure).
|
||||
- How about not evaluating incomplete lines when the text is not finished
|
||||
(as shells do).
|
||||
|
||||
- Caret diagnostics
|
||||
|
||||
** Questions
|
||||
*** Java
|
||||
- Should i18n be part of the Lexer? Currently it's a static method of
|
||||
@@ -50,13 +56,6 @@ Unless we play it dumb (little structure).
|
||||
|
||||
- promote YYEOF rather than EOF.
|
||||
|
||||
*** D
|
||||
- is there a way to attach yysymbol_name to the enum itself? As we did
|
||||
in Java.
|
||||
|
||||
- It would be better to have TokenKind as return value. Can we use
|
||||
reflection to support both output types?
|
||||
|
||||
** YYerror
|
||||
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
|
||||
|
||||
@@ -69,7 +68,7 @@ Stop hard-coding "Calc". Adjust local.at (look for FIXME).
|
||||
|
||||
** A dev warning for b4_
|
||||
Maybe we should check for m4_ and b4_ leaking out of the m4 processing, as
|
||||
Autoconf does. It would have caught overquotation issues.
|
||||
Autoconf does. It would have caught over-quotation issues.
|
||||
|
||||
** doc
|
||||
I feel it's ugly to use the GNU style to declare functions in the doc. It
|
||||
@@ -90,7 +89,7 @@ push parsers on top of pull parser. Which is currently not relevant, since
|
||||
push parsers are measurably slower.
|
||||
|
||||
** %define parse.error formatted
|
||||
How about pushing bistromathics' yyreport_syntax_error as another standard
|
||||
How about pushing Bistromathic's yyreport_syntax_error as another standard
|
||||
way to generate the error message, and leave to the user the task of
|
||||
providing the message formats? Currently in bistro, it reads:
|
||||
|
||||
@@ -204,18 +203,282 @@ The "automaton" and "set" categories are not so useful. We should probably
|
||||
introduce lr(0) and lalr, just the way we have ielr categories. The
|
||||
"closure" function is too verbose, it should probably have its own category.
|
||||
|
||||
"set" can still be used for summariring the important sets. That would make
|
||||
"set" can still be used for summarizing the important sets. That would make
|
||||
tests easy to maintain.
|
||||
|
||||
*** complain.*
|
||||
Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the
|
||||
name they have in gcc, clang, etc. Likewise for the complain_* series of
|
||||
name they have in GCC, clang, etc. Likewise for the complain_* series of
|
||||
functions.
|
||||
|
||||
*** ritem
|
||||
states/nstates, rules/nrules, ..., ritem/nritems
|
||||
Fix the latter.
|
||||
|
||||
* D programming language
|
||||
There's a number of features that are missing, here sorted in _suggested_
|
||||
order of implementation.
|
||||
|
||||
When copying code from other skeletons, keep the comments exactly as they
|
||||
are. Keep the same variable names. If you change the wording in one place,
|
||||
do it in the others too. In other words: make sure to keep the
|
||||
maintenance *simple* by avoiding any gratuitous difference.
|
||||
|
||||
** Rename the D example
|
||||
Move the current content of examples/d into examples/d/simple.
|
||||
|
||||
** Create a second example
|
||||
Duplicate examples/d/simple into examples/d/calc.
|
||||
|
||||
** Add location tracking to d/calc
|
||||
Look at the examples in the other languages to see how to do that.
|
||||
|
||||
** yysymbol_name
|
||||
The SymbolKind is an enum. For a given SymbolKind we want to get its string
|
||||
representation. Currently it's a separate table in the parser that does
|
||||
that:
|
||||
|
||||
/* Symbol kinds. */
|
||||
public enum SymbolKind
|
||||
{
|
||||
S_YYEMPTY = -2, /* No symbol. */
|
||||
S_YYEOF = 0, /* "end of file" */
|
||||
S_YYerror = 1, /* error */
|
||||
S_YYUNDEF = 2, /* "invalid token" */
|
||||
S_EQ = 3, /* "=" */
|
||||
...
|
||||
S_input = 14, /* input */
|
||||
S_line = 15, /* line */
|
||||
S_exp = 16, /* exp */
|
||||
};
|
||||
|
||||
...
|
||||
|
||||
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
|
||||
private static immutable string[] yytname_ =
|
||||
[
|
||||
"\"end of file\"", "error", "\"invalid token\"", "\"=\"", "\"+\"",
|
||||
"\"-\"", "\"*\"", "\"/\"", "\"(\"", "\")\"", "\"end of line\"",
|
||||
"\"number\"", "UNARY", "$accept", "input", "line", "exp", null
|
||||
];
|
||||
|
||||
...
|
||||
|
||||
So to get a symbol kind, one runs `yytname_[yykind]`.
|
||||
|
||||
Is there a way to attach this conversion to string to SymbolKind? In Java
|
||||
for instance, we have:
|
||||
|
||||
public enum SymbolKind
|
||||
{
|
||||
S_YYEOF(0), /* "end of file" */
|
||||
S_YYerror(1), /* error */
|
||||
S_YYUNDEF(2), /* "invalid token" */
|
||||
...
|
||||
S_input(16), /* input */
|
||||
S_line(17), /* line */
|
||||
S_exp(18); /* exp */
|
||||
|
||||
private final int yycode_;
|
||||
|
||||
SymbolKind (int n) {
|
||||
this.yycode_ = n;
|
||||
}
|
||||
...
|
||||
/* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||
private static final String[] yynames_ = yynames_init();
|
||||
private static final String[] yynames_init()
|
||||
{
|
||||
return new String[]
|
||||
{
|
||||
i18n("end of file"), i18n("error"), i18n("invalid token"), "!", "+", "-", "*",
|
||||
"/", "^", "(", ")", "=", i18n("end of line"), i18n("number"), "NEG",
|
||||
"$accept", "input", "line", "exp", null
|
||||
};
|
||||
}
|
||||
|
||||
/* The user-facing name of this symbol. */
|
||||
public final String getName() {
|
||||
return yynames_[yycode_];
|
||||
}
|
||||
};
|
||||
|
||||
which allows to write more naturally `yykind.getName()` rather than
|
||||
`yytname_[yykind]`. Is there something comparable in (idiomatic) D?
|
||||
|
||||
** Change the return value of yylex
|
||||
Historically people were allowed to return any int from the scanner (which
|
||||
is convenient and allows `return '+'` from the scanner). Akim tends to see
|
||||
this as an error, we should restrict the return values to TokenKind (not to
|
||||
be confused with SymbolKind).
|
||||
|
||||
In the case of D, without the history, we have the choice to support or not
|
||||
`int`. If we want to _keep_ `int`, is there a way, say via introspection,
|
||||
to support both signatures of yylex? If we don't keep `int`, just move to
|
||||
TokenKind.
|
||||
|
||||
** Documentation
|
||||
Write documentation about D support in doc/bison.texi. Imitate the Java
|
||||
documentation. You should be more succinct IMHO.
|
||||
|
||||
** Complete Symbols
|
||||
The current interface from the scanner to the parser is somewhat clumsy: the
|
||||
token kind is returned by yylex, but the value and location are stored in
|
||||
the scanner. This reflects the fact that the implementation of the parser
|
||||
uses three variables to deal with each parsed symbol: its kind, its value,
|
||||
its location.
|
||||
|
||||
So today the scanner of examples/d/calc.d (no locations) looks like:
|
||||
|
||||
if (input.front.isNumber)
|
||||
{
|
||||
import std.conv : parse;
|
||||
semanticVal_.ival = input.parse!int;
|
||||
return TokenKind.NUM;
|
||||
}
|
||||
|
||||
and the generated parser:
|
||||
|
||||
/* Read a lookahead token. */
|
||||
if (yychar == TokenKind.YYEMPTY)
|
||||
{
|
||||
yychar = yylex ();
|
||||
yylval = yylexer.semanticVal;
|
||||
}
|
||||
|
||||
The parser class should feature a `Symbol` type which binds together kind,
|
||||
value and location, and the scanner should be able to return an instance of
|
||||
that type. Something like
|
||||
|
||||
if (input.front.isNumber)
|
||||
{
|
||||
import std.conv : parse;
|
||||
return parser.Symbol (TokenKind.NUM, input.parse!int);
|
||||
}
|
||||
|
||||
** Token Constructors
|
||||
In the previous example it is possible to mix incorrectly kinds and values,
|
||||
and for instance:
|
||||
|
||||
return parser.Symbol (TokenKind.NUM, "Hello, World!\n");
|
||||
|
||||
attaches a string value to NUM kind (wrong, of course). When
|
||||
api.token.constructor is set, in C++, Bison generated "token constructors":
|
||||
parser.make_NUM. parser.make_PLUS, parser.make_STRING, etc. The previous
|
||||
example becomes
|
||||
|
||||
return parser.make_NUM ("Hello, World!\n");
|
||||
|
||||
which would easily be caught by the type checker.
|
||||
|
||||
** Lookahead Correction
|
||||
Add support for LAC to the D skeleton. It should not be too hard: look how
|
||||
this is done in lalr1.cc, and mock it.
|
||||
|
||||
** Push Parser
|
||||
Add support for push parser. Do not start a nice skeleton, just enhance the
|
||||
current one to support push parsers. This is going to be a tougher nut to
|
||||
crack.
|
||||
|
||||
First, you need to understand well how the push parser is expected to work.
|
||||
To this end:
|
||||
- read the doc
|
||||
- look at examples/c/pushcalc
|
||||
- create an example of a Java push parser.
|
||||
- have a look at the generated parser in Java, which has the advantage of
|
||||
being already based on a parser object, instead of just a function.
|
||||
|
||||
The C case is harder to read, but it may help too. Keep in mind that
|
||||
because there's no object to maintain state, the C push parser uses some
|
||||
struct (yypstate) to preserve this state. We don't need this in D, the
|
||||
parser object will suffice.
|
||||
|
||||
I think working directly on the skeleton to add push-parser support is not
|
||||
the simplest path. I suggest that you (1) transform a generated parser into
|
||||
a push parser by hand, and then (2) transform lalr1.d to generate such a
|
||||
parser.
|
||||
|
||||
Use `git commit` frequently to make sure you keep track of your progress.
|
||||
|
||||
*** (1.a) Prepare pull parser by hand
|
||||
Copy again one of the D examples into say examples/d/pushcalc. Also
|
||||
check-in the generated parser to facilitate experimentation.
|
||||
|
||||
- find local variables of yyparse should become members of the parser object
|
||||
(so that we preserve state from one call to the next).
|
||||
|
||||
- do it in your generated D parser. We don't need an equivalent for
|
||||
yypstate, because we already have it: that the parser object itself.
|
||||
|
||||
- have your *pull*-parser (i.e., the good old yy::parser::parse()) work
|
||||
properly this way. Write and run tests. That's one of the reasons I
|
||||
suggest using examples/d/calc as a starting point: it already has tests,
|
||||
you can/should add more.
|
||||
|
||||
At this point you have a pull-parser which you prepared to turn into a
|
||||
push-parser.
|
||||
|
||||
*** (1.b) Turn pull parser into push parser by hand
|
||||
|
||||
- look again at how push parsers are implemented in Java/C to see what needs
|
||||
to change in yyparse so that the control is inverted: parse() will
|
||||
be *given* the tokens, instead of having to call yylex itself. When I say
|
||||
"look at C", I think your best option are (i) yacc.c (look for b4_push_if)
|
||||
and (ii) examples/c/pushcalc.
|
||||
|
||||
- rename parse() as push_parse(Symbol yyla) (or push_parse(TokenKind, Value,
|
||||
Location)) that takes the symbol as argument. That's the push parser we
|
||||
are looking for.
|
||||
|
||||
- define a new parse() function which has the same signature as the usual
|
||||
pull-parser, that repeatedly calls the push_parse function. Something
|
||||
like this:
|
||||
|
||||
int parse ()
|
||||
{
|
||||
int status = 0;
|
||||
do {
|
||||
status = this->push_parse (yylex());
|
||||
} while (status == YYPUSH_MORE);
|
||||
return status;
|
||||
}
|
||||
|
||||
- show me that parser, so that we can validate the approach.
|
||||
|
||||
*** (2) Port that into the skeleton
|
||||
- once we agree on the API of the push parser, implement it into lalr1.d.
|
||||
You will probaby need help on this regard, but imitation, again, should
|
||||
help.
|
||||
|
||||
- have example/d/pushcalc work properly and pass tests
|
||||
|
||||
- add tests in the "real" test suite. Do that in tests/calc.at. I can
|
||||
help.
|
||||
|
||||
- document
|
||||
|
||||
** GLR Parser
|
||||
This is very ambitious. That's the final boss. There are currently no
|
||||
"clean" implementation to get inspiration from.
|
||||
|
||||
glr.c is very clean but:
|
||||
- is low-level C
|
||||
- is a different skeleton from yacc.c
|
||||
|
||||
glr.cc is (currently) an ugly hack: a C++ shell around glr.c. Valentin
|
||||
Tolmer is currently rewriting glr.cc to be clean C++, but he is not
|
||||
finished. There will be a lot a common code between lalr1.cc and glr.cc, so
|
||||
eventually I would like them to be fused into a single skeleton, supporting
|
||||
both deterministic and generalized parsing.
|
||||
|
||||
It would be great for D to also support this.
|
||||
|
||||
The basic ideas of GLR are explained here:
|
||||
|
||||
https://www.codeproject.com/Articles/5259825/GLR-Parsing-in-Csharp-How-to-Use-The-Most-Powerful
|
||||
|
||||
* Better error messages
|
||||
The users are not provided with enough tools to forge their error messages.
|
||||
See for instance "Is there an option to change the message produced by
|
||||
@@ -233,7 +496,7 @@ and older C++ compilers. Currently the code defaults to defining it to
|
||||
define it to the same type as the C ptrdiff_t type.
|
||||
|
||||
* Completion
|
||||
Several features are not available in all the backends.
|
||||
Several features are not available in all the back-ends.
|
||||
|
||||
- lac: D, Java (easy)
|
||||
- push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
|
||||
@@ -303,7 +566,7 @@ opposite side we have some use of \l, which is graphviz-specific, in what
|
||||
should be generic code.
|
||||
|
||||
Little effort seems to have been given to factoring these files and their
|
||||
rint{,-xml} counterpart. We would very much like to re-use the pretty format
|
||||
print{,-xml} counterpart. We would very much like to re-use the pretty format
|
||||
of states from .output for the graphs, etc.
|
||||
|
||||
Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
|
||||
@@ -581,14 +844,39 @@ to bison. If you're interested, I'll work on a patch.
|
||||
Equip the parser with a means to create the (visual) parse tree.
|
||||
|
||||
|
||||
-----
|
||||
|
||||
# LocalWords: Cex gnulib gl Bistromathic TokenKinds yylex enum YYEOF EOF
|
||||
# LocalWords: YYerror gettext af hb YYERRCODE undef calc FIXME dev yyerror
|
||||
# LocalWords: Autoconf YYUNDEFTOK lexemes parsers Bistromathic's yyreport
|
||||
# LocalWords: const argc yacc yyclearin lookahead destructor Rici incluent
|
||||
# LocalWords: yydestruct yydiscardin catégories d'avertissements sr activé
|
||||
# LocalWords: conflits défaut rr l'alias chaîne n'est attaché un symbole
|
||||
# LocalWords: obsolète règle vide midrule valeurs de intermédiaire ou avec
|
||||
# LocalWords: définies inutilisées priorité associativité inutiles POSIX
|
||||
# LocalWords: incompatibilités tous les autres avertissements sauf dans rp
|
||||
# LocalWords: désactiver CATEGORIE traiter comme des erreurs glr Akim bool
|
||||
# LocalWords: Demaille arith lalr goto struct pathlen nullable ntokens lr
|
||||
# LocalWords: nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ
|
||||
# LocalWords: SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed
|
||||
# LocalWords: nonterminals yykind yycode YYNAMES yynames init getName conv
|
||||
# LocalWords: TokenKind semanticVal ival yychar yylval yylexer Tolmer hoc
|
||||
# LocalWords: Sobisch YYPTRDIFF ptrdiff Autotest YYPRINT toknum yytoknum
|
||||
# LocalWords: sym Wother stderr FP fixits xgettext fdiagnostics Graphviz
|
||||
# LocalWords: graphviz VCG bitset xml bw maint yytoken YYABORT deps
|
||||
# LocalWords: YYACCEPT yytranslate nonnegative destructors yyerrlab repo
|
||||
# LocalWords: backends stmt expr yy Mardle baz qux Vadim Maslow CPP cpp
|
||||
# LocalWords: yydebug gcc UCHAR EBCDIC gung PDP NUL Pre Florian Krohm utf
|
||||
# LocalWords: YYACT YYLLOC YYLSP yyval yyvsp yylen yyloc yylsp endif
|
||||
# LocalWords: ispell american
|
||||
|
||||
Local Variables:
|
||||
mode: outline
|
||||
coding: utf-8
|
||||
fill-column: 76
|
||||
ispell-dictionary: "american"
|
||||
End:
|
||||
|
||||
-----
|
||||
|
||||
Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2020 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
|
||||
+3
-1
@@ -44,7 +44,9 @@ gnulib_modules='
|
||||
realloc-posix
|
||||
relocatable-prog relocatable-script
|
||||
rename
|
||||
spawn-pipe stdbool stpcpy strdup-posix strerror strverscmp
|
||||
spawn-pipe stdbool stpcpy stpncpy strdup-posix strerror strverscmp
|
||||
sys_ioctl
|
||||
termios
|
||||
timevar
|
||||
unicodeio unistd unistd-safer unlink unlocked-io
|
||||
update-copyright unsetenv verify
|
||||
|
||||
@@ -126,7 +126,7 @@ _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
|
||||
|
||||
_space_before_paren_exempt =? \\n\\$$
|
||||
_space_before_paren_exempt = \
|
||||
(^ *\#|(LA)?LR\([01]\)|percent_(code|define)|b4_syncline|m4_(define|init)|symbol)
|
||||
(^ *\#|(LA)?LR\([01]\)|percent_(code|define)|b4_syncline|m4_(define|init))
|
||||
# Ensure that there is a space before each open parenthesis in C code.
|
||||
sc_space_before_open_paren:
|
||||
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
|
||||
@@ -156,6 +156,7 @@ exclude = \
|
||||
$(call exclude, \
|
||||
bindtextdomain=^lib/main.c$$ \
|
||||
cast_of_argument_to_free=^src/muscle-tab.c$$ \
|
||||
error_message_uppercase=etc/bench.pl.in$$ \
|
||||
po_check=^tests|(^po/POTFILES.in|.md)$$ \
|
||||
preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \
|
||||
program_name=^lib/main.c$$ \
|
||||
|
||||
@@ -60,6 +60,9 @@ AC_PROG_CXX
|
||||
# Gnulib (early checks).
|
||||
gl_EARLY
|
||||
|
||||
# We want ostream_printf and hyperlink support.
|
||||
gl_LIBTEXTSTYLE_OPTIONAL([0.20.5])
|
||||
|
||||
# Gnulib uses '#pragma GCC diagnostic push' to silence some
|
||||
# warnings, but older gcc doesn't support this.
|
||||
AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
.cex-5 { color: orange; }
|
||||
.cex-6 { color: brown; }
|
||||
.cex-7 { color: mauve; }
|
||||
.cex-8 { color: #013220; } /* Dark green. */
|
||||
.cex-9 { color: #e75480; } /* Dark pink. */
|
||||
.cex-10 { color: cyan; }
|
||||
.cex-11 { color: orange; }
|
||||
|
||||
/* Cex: derivation rewriting steps. */
|
||||
.cex-step { font-style: italic; }
|
||||
|
||||
@@ -49,7 +49,7 @@ m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
|
||||
# b4_generated_by
|
||||
# ---------------
|
||||
m4_define([b4_generated_by],
|
||||
[b4_comment([A Bison parser, made by GNU Bison b4_version.])
|
||||
[b4_comment([A Bison parser, made by GNU Bison b4_version_string.])
|
||||
])
|
||||
|
||||
# b4_copyright(TITLE, [YEARS])
|
||||
@@ -633,11 +633,11 @@ m4_define([_b4_type_action],
|
||||
|
||||
])])
|
||||
|
||||
# b4_type_foreach(MACRO)
|
||||
# ----------------------
|
||||
# b4_type_foreach(MACRO, [SEP])
|
||||
# -----------------------------
|
||||
# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
|
||||
m4_define([b4_type_foreach],
|
||||
[m4_map([$1], m4_defn([b4_type_names]))])
|
||||
[m4_map_sep([$1], [$2], m4_defn([b4_type_names]))])
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -321,8 +321,9 @@ m4_define([b4_symbol_type_define],
|
||||
/// Copy constructor.
|
||||
basic_symbol (const basic_symbol& that);]b4_variant_if([[
|
||||
|
||||
/// Constructor for valueless symbols, and symbols from each type.
|
||||
]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
|
||||
/// Constructors for typed symbols.
|
||||
]b4_type_foreach([b4_basic_symbol_constructor_define], [
|
||||
])], [[
|
||||
/// Constructor for valueless symbols.
|
||||
basic_symbol (typename Base::kind_type t]b4_locations_if([,
|
||||
YY_MOVE_REF (location_type) l])[);
|
||||
|
||||
+8
-7
@@ -58,11 +58,11 @@ m4_define([b4_cpp_guard_close],
|
||||
# b4_pull_flag if they use the values of the %define variables api.pure or
|
||||
# api.push-pull.
|
||||
m4_define([b4_identification],
|
||||
[[/* Identify Bison output. */
|
||||
#define YYBISON 1
|
||||
[[/* Identify Bison output, and Bison version. */
|
||||
#define YYBISON ]b4_version[
|
||||
|
||||
/* Bison version. */
|
||||
#define YYBISON_VERSION "]b4_version["
|
||||
/* Bison version string. */
|
||||
#define YYBISON_VERSION "]b4_version_string["
|
||||
|
||||
/* Skeleton name. */
|
||||
#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
|
||||
@@ -509,10 +509,11 @@ m4_define([b4_token_define],
|
||||
# ----------------
|
||||
# Output the definition of the tokens.
|
||||
m4_define([b4_token_defines],
|
||||
[b4_any_token_visible_if([/* Token kinds. */
|
||||
m4_join([
|
||||
[[/* Token kinds. */
|
||||
#define ]b4_symbol([-2], [id])[ -2
|
||||
]m4_join([
|
||||
], b4_symbol_map([b4_token_define]))
|
||||
])])
|
||||
])
|
||||
|
||||
|
||||
# b4_token_enum(TOKEN-NUM)
|
||||
|
||||
+4
-4
@@ -103,12 +103,12 @@ m4_define([b4_location_type_if],
|
||||
# b4_identification
|
||||
# -----------------
|
||||
m4_define([b4_identification],
|
||||
[/** Version number for the Bison executable that generated this parser. */
|
||||
public static immutable string yy_bison_version = "b4_version";
|
||||
[[/** Version number for the Bison executable that generated this parser. */
|
||||
public static immutable string yy_bison_version = "]b4_version_string[";
|
||||
|
||||
/** Name of the skeleton that generated this parser. */
|
||||
public static immutable string yy_bison_skeleton = b4_skeleton;
|
||||
])
|
||||
public static immutable string yy_bison_skeleton = ]b4_skeleton[;
|
||||
]])
|
||||
|
||||
|
||||
## ------------ ##
|
||||
|
||||
@@ -172,7 +172,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
const location_type* yylocationp]])[) const
|
||||
{
|
||||
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
|
||||
<< ' ' << yytname[yykind] << " ("]b4_locations_if([[
|
||||
<< ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[
|
||||
<< *yylocationp << ": "]])[;
|
||||
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
|
||||
*yycdebug_ << ')';
|
||||
|
||||
@@ -71,12 +71,12 @@ m4_define([b4_lexer_if],
|
||||
# b4_identification
|
||||
# -----------------
|
||||
m4_define([b4_identification],
|
||||
[ /** Version number for the Bison executable that generated this parser. */
|
||||
public static final String bisonVersion = "b4_version";
|
||||
[[ /** Version number for the Bison executable that generated this parser. */
|
||||
public static final String bisonVersion = "]b4_version_string[";
|
||||
|
||||
/** Name of the skeleton that generated this parser. */
|
||||
public static final String bisonSkeleton = b4_skeleton;
|
||||
])
|
||||
public static final String bisonSkeleton = ]b4_skeleton[;
|
||||
]])
|
||||
|
||||
|
||||
## ------------ ##
|
||||
|
||||
@@ -22,7 +22,7 @@ m4_pushdef([b4_copyright_years],
|
||||
# b4_position_file
|
||||
# ----------------
|
||||
# Name of the file containing the position class, if we want this file.
|
||||
b4_defines_if([b4_required_version_if([302], [],
|
||||
b4_defines_if([b4_required_version_if([30200], [],
|
||||
[m4_define([b4_position_file], [position.hh])])])])
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# b4_stack_file
|
||||
# -------------
|
||||
# Name of the file containing the stack class, if we want this file.
|
||||
b4_defines_if([b4_required_version_if([302], [],
|
||||
b4_defines_if([b4_required_version_if([30200], [],
|
||||
[m4_define([b4_stack_file], [stack.hh])])])
|
||||
|
||||
|
||||
|
||||
+101
-41
@@ -20,6 +20,13 @@
|
||||
## variant. ##
|
||||
## --------- ##
|
||||
|
||||
# b4_assert
|
||||
# ---------
|
||||
# The name of YY_ASSERT.
|
||||
m4_define([b4_assert],
|
||||
[b4_api_PREFIX[]_ASSERT])
|
||||
|
||||
|
||||
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
|
||||
# ------------------------------------------------
|
||||
# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
|
||||
@@ -71,12 +78,12 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl
|
||||
# -------------------
|
||||
# The needed includes for variants support.
|
||||
m4_define([b4_variant_includes],
|
||||
[b4_parse_assert_if([[#include <typeinfo>]])[
|
||||
#ifndef YY_ASSERT
|
||||
[b4_parse_assert_if([[#include <typeinfo>
|
||||
#ifndef ]b4_assert[
|
||||
# include <cassert>
|
||||
# define YY_ASSERT assert
|
||||
# define ]b4_assert[ assert
|
||||
#endif
|
||||
]])
|
||||
]])])
|
||||
|
||||
|
||||
|
||||
@@ -110,8 +117,8 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([
|
||||
: yytypeid_ (&typeid (T))])[
|
||||
{
|
||||
YY_ASSERT (sizeof (T) <= size);
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (sizeof (T) <= size);]])[
|
||||
new (yyas_<T> ()) T (YY_MOVE (t));
|
||||
}
|
||||
|
||||
@@ -125,7 +132,7 @@ m4_define([b4_value_type_declare],
|
||||
/// Destruction, allowed only if empty.
|
||||
~semantic_type () YY_NOEXCEPT
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (!yytypeid_);
|
||||
]b4_assert[ (!yytypeid_);
|
||||
])[}
|
||||
|
||||
# if 201103L <= YY_CPLUSPLUS
|
||||
@@ -133,10 +140,10 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T, typename... U>
|
||||
T&
|
||||
emplace (U&&... u)
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (!yytypeid_);
|
||||
YY_ASSERT (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (!yytypeid_);
|
||||
]b4_assert[ (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);]])[
|
||||
return *new (yyas_<T> ()) T (std::forward <U>(u)...);
|
||||
}
|
||||
# else
|
||||
@@ -144,10 +151,10 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
T&
|
||||
emplace ()
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (!yytypeid_);
|
||||
YY_ASSERT (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (!yytypeid_);
|
||||
]b4_assert[ (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);]])[
|
||||
return *new (yyas_<T> ()) T ();
|
||||
}
|
||||
|
||||
@@ -155,10 +162,10 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
T&
|
||||
emplace (const T& t)
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (!yytypeid_);
|
||||
YY_ASSERT (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (!yytypeid_);
|
||||
]b4_assert[ (sizeof (T) <= size);
|
||||
yytypeid_ = & typeid (T);]])[
|
||||
return *new (yyas_<T> ()) T (t);
|
||||
}
|
||||
# endif
|
||||
@@ -185,10 +192,10 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
T&
|
||||
as () YY_NOEXCEPT
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (yytypeid_);
|
||||
YY_ASSERT (*yytypeid_ == typeid (T));
|
||||
YY_ASSERT (sizeof (T) <= size);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (yytypeid_);
|
||||
]b4_assert[ (*yytypeid_ == typeid (T));
|
||||
]b4_assert[ (sizeof (T) <= size);]])[
|
||||
return *yyas_<T> ();
|
||||
}
|
||||
|
||||
@@ -196,10 +203,10 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
const T&
|
||||
as () const YY_NOEXCEPT
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (yytypeid_);
|
||||
YY_ASSERT (*yytypeid_ == typeid (T));
|
||||
YY_ASSERT (sizeof (T) <= size);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (yytypeid_);
|
||||
]b4_assert[ (*yytypeid_ == typeid (T));
|
||||
]b4_assert[ (sizeof (T) <= size);]])[
|
||||
return *yyas_<T> ();
|
||||
}
|
||||
|
||||
@@ -214,9 +221,9 @@ m4_define([b4_value_type_declare],
|
||||
template <typename T>
|
||||
void
|
||||
swap (self_type& that) YY_NOEXCEPT
|
||||
{]b4_parse_assert_if([
|
||||
YY_ASSERT (yytypeid_);
|
||||
YY_ASSERT (*yytypeid_ == *that.yytypeid_);])[
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (yytypeid_);
|
||||
]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[
|
||||
std::swap (as<T> (), that.as<T> ());
|
||||
}
|
||||
|
||||
@@ -388,11 +395,67 @@ m4_define([_b4_token_maker_define],
|
||||
])])
|
||||
|
||||
|
||||
m4_define([_b4_type_clause],
|
||||
[b4_symbol_if([$1], [is_token],
|
||||
[b4_symbol_if([$1], [has_id],
|
||||
[tok == token::b4_symbol([$1], [id])],
|
||||
[tok == b4_symbol([$1], [code])])])])
|
||||
# b4_token_kind(SYMBOL-NUM)
|
||||
# -------------------------
|
||||
# Some tokens don't have an ID.
|
||||
m4_define([b4_token_kind],
|
||||
[b4_symbol_if([$1], [has_id],
|
||||
[token::b4_symbol([$1], [id])],
|
||||
[b4_symbol([$1], [code])])])
|
||||
|
||||
|
||||
# _b4_tok_in(SYMBOL-NUM, ...)
|
||||
# ---------------------------
|
||||
# See b4_tok_in below. The SYMBOL-NUMs... are tokens only.
|
||||
#
|
||||
# We iterate over the tokens to group them by "range" of token numbers (not
|
||||
# symbols numbers!).
|
||||
#
|
||||
# b4_fst is the start of that range.
|
||||
# b4_prev is the previous value.
|
||||
# b4_val is the current value.
|
||||
# If b4_val is the successor of b4_prev in token numbers, update the latter,
|
||||
# otherwise emit the code for range b4_fst .. b4_prev.
|
||||
# $1 is also used as a terminator in the foreach, but it will not be printed.
|
||||
#
|
||||
m4_define([_b4_tok_in],
|
||||
[m4_pushdef([b4_prev], [$1])dnl
|
||||
m4_pushdef([b4_fst], [$1])dnl
|
||||
m4_pushdef([b4_sep], [])dnl
|
||||
m4_foreach([b4_val], m4_dquote(m4_shift($@, $1)),
|
||||
[m4_if(b4_symbol(b4_val, [code]), m4_eval(b4_symbol(b4_prev, [code]) + 1), [],
|
||||
[b4_sep[]m4_if(b4_fst, b4_prev,
|
||||
[tok == b4_token_kind(b4_fst)],
|
||||
[(b4_token_kind(b4_fst) <= tok && tok <= b4_token_kind(b4_prev))])[]dnl
|
||||
m4_define([b4_fst], b4_val)dnl
|
||||
m4_define([b4_sep], [
|
||||
|| ])])dnl
|
||||
m4_define([b4_prev], b4_val)])dnl
|
||||
m4_popdef([b4_sep])dnl
|
||||
m4_popdef([b4_fst])dnl
|
||||
m4_popdef([b4_prev])dnl
|
||||
])
|
||||
|
||||
|
||||
# _b4_filter_tokens(SYMBOL-NUM, ...)
|
||||
# ----------------------------------
|
||||
# Expand as the list of tokens amongst SYMBOL-NUM.
|
||||
m4_define([_b4_filter_tokens],
|
||||
[m4_pushdef([b4_sep])dnl
|
||||
m4_foreach([b4_val], [$@],
|
||||
[b4_symbol_if(b4_val, [is_token], [b4_sep[]b4_val[]m4_define([b4_sep], [,])])])dnl
|
||||
m4_popdef([b4_sep])dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_tok_in(SYMBOL-NUM, ...)
|
||||
# ---------------------------
|
||||
# A C++ conditional that checks that `tok` is a member of this list of symbol
|
||||
# numbers.
|
||||
m4_define([b4_tok_in],
|
||||
[_$0(_b4_filter_tokens($@))])
|
||||
|
||||
|
||||
|
||||
|
||||
# _b4_token_constructor_define(SYMBOL-NUM...)
|
||||
@@ -410,9 +473,6 @@ m4_define([_b4_token_constructor_define],
|
||||
: super_type(]b4_join([token_type (tok)],
|
||||
b4_symbol_if([$1], [has_type], [std::move (v)]),
|
||||
b4_locations_if([std::move (l)]))[)
|
||||
{
|
||||
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
|
||||
}
|
||||
#else
|
||||
symbol_type (]b4_join(
|
||||
[int tok],
|
||||
@@ -422,10 +482,10 @@ m4_define([_b4_token_constructor_define],
|
||||
: super_type(]b4_join([token_type (tok)],
|
||||
b4_symbol_if([$1], [has_type], [v]),
|
||||
b4_locations_if([l]))[)
|
||||
{
|
||||
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
|
||||
}
|
||||
#endif
|
||||
{]b4_parse_assert_if([[
|
||||
]b4_assert[ (]b4_tok_in($@)[);
|
||||
]])[}
|
||||
]])])
|
||||
|
||||
|
||||
|
||||
@@ -1486,7 +1486,7 @@ yypstate_new (void)
|
||||
yypstate *yyps;]b4_pure_if([], [[
|
||||
if (yypstate_allocated)
|
||||
return YY_NULLPTR;]])[
|
||||
yyps = YY_CAST (yypstate *, malloc (sizeof *yyps));
|
||||
yyps = YY_CAST (yypstate *, YYMALLOC (sizeof *yyps));
|
||||
if (!yyps)
|
||||
return YY_NULLPTR;]b4_pure_if([], [[
|
||||
yypstate_allocated = 1;]])[
|
||||
@@ -1515,7 +1515,7 @@ yypstate_delete (yypstate *yyps)
|
||||
#endif]b4_lac_if([[
|
||||
if (yyes != yyesa)
|
||||
YYSTACK_FREE (yyes);]])[
|
||||
free (yyps);]b4_pure_if([], [[
|
||||
YYFREE (yyps);]b4_pure_if([], [[
|
||||
yypstate_allocated = 0;]])[
|
||||
}
|
||||
}
|
||||
|
||||
+14
-6
@@ -52,7 +52,7 @@
|
||||
<xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
|
||||
<xsl:text>Nonterminals useless in grammar </xsl:text>
|
||||
<xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:for-each>
|
||||
@@ -65,7 +65,7 @@
|
||||
<xsl:text>Terminals unused in grammar </xsl:text>
|
||||
<xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
|
||||
<xsl:sort select="@symbol-number" data-type="number"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:for-each>
|
||||
@@ -136,6 +136,7 @@
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="terminal">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:call-template name="line-wrap">
|
||||
<xsl:with-param name="first-line-length">
|
||||
@@ -148,6 +149,9 @@
|
||||
</xsl:with-param>
|
||||
<xsl:with-param name="line-length" select="66" />
|
||||
<xsl:with-param name="text">
|
||||
<xsl:if test="string-length(@type) != 0">
|
||||
<xsl:value-of select="concat(' <', @type, '>')"/>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat(' (', @token-number, ')')"/>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
<xsl:value-of select="concat(' ', @number)"/>
|
||||
@@ -157,14 +161,18 @@
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="nonterminal">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:if test="string-length(@type) != 0">
|
||||
<xsl:value-of select="concat(' <', @type, '>')"/>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:variable name="output">
|
||||
<xsl:call-template name="line-wrap">
|
||||
<xsl:with-param name="line-length" select="66" />
|
||||
<xsl:with-param name="text">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:if test="key('bison:ruleByLhs', @name)">
|
||||
<xsl:text>on@left:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByLhs', @name)">
|
||||
@@ -173,7 +181,7 @@
|
||||
</xsl:if>
|
||||
<xsl:if test="key('bison:ruleByRhs', @name)">
|
||||
<xsl:if test="key('bison:ruleByLhs', @name)">
|
||||
<xsl:text>, </xsl:text>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:text>on@right:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
@@ -348,11 +356,11 @@
|
||||
<!-- RHS -->
|
||||
<xsl:for-each select="rhs/*">
|
||||
<xsl:if test="position() = $dot + 1">
|
||||
<xsl:text> .</xsl:text>
|
||||
<xsl:text> •</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:apply-templates select="."/>
|
||||
<xsl:if test="position() = last() and position() = $dot">
|
||||
<xsl:text> .</xsl:text>
|
||||
<xsl:text> •</xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
<xsl:if test="$lookaheads">
|
||||
|
||||
+72
-48
@@ -227,6 +227,7 @@
|
||||
<xsl:text> </xsl:text>
|
||||
<p class="pre">
|
||||
<xsl:call-template name="style-rule-set">
|
||||
<xsl:with-param name="anchor" select="'true'" />
|
||||
<xsl:with-param
|
||||
name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
|
||||
/>
|
||||
@@ -238,9 +239,11 @@
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="style-rule-set">
|
||||
<xsl:param name="anchor"/>
|
||||
<xsl:param name="rule-set"/>
|
||||
<xsl:for-each select="$rule-set">
|
||||
<xsl:apply-templates select=".">
|
||||
<xsl:with-param name="anchor" select="$anchor"/>
|
||||
<xsl:with-param name="pad" select="'3'"/>
|
||||
<xsl:with-param name="prev-lhs">
|
||||
<xsl:if test="position()>1">
|
||||
@@ -306,9 +309,10 @@
|
||||
<xsl:text> Terminals, with rules where they appear</xsl:text>
|
||||
</h3>
|
||||
<xsl:text> </xsl:text>
|
||||
<p class="pre">
|
||||
<ul>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:apply-templates select="terminal"/>
|
||||
</p>
|
||||
</ul>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:template>
|
||||
|
||||
@@ -318,41 +322,64 @@
|
||||
<xsl:text> Nonterminals, with rules where they appear</xsl:text>
|
||||
</h3>
|
||||
<xsl:text> </xsl:text>
|
||||
<p class="pre">
|
||||
<ul>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:apply-templates
|
||||
select="nonterminal[@usefulness!='useless-in-grammar']"
|
||||
/>
|
||||
</p>
|
||||
</ul>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="terminal">
|
||||
<b><xsl:value-of select="@name"/></b>
|
||||
<xsl:value-of select="concat(' (', @token-number, ')')"/>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
<xsl:text> </xsl:text>
|
||||
<li>
|
||||
<b><xsl:value-of select="@name"/></b>
|
||||
<xsl:if test="string-length(@type) != 0">
|
||||
<xsl:value-of select="concat(' <', @type, '>')"/>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat(' (', @token-number, ')')"/>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
</li>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="nonterminal">
|
||||
<b><xsl:value-of select="@name"/></b>
|
||||
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:if test="key('bison:ruleByLhs', @name)">
|
||||
<xsl:text>on left:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByLhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
</xsl:if>
|
||||
<xsl:if test="key('bison:ruleByRhs', @name)">
|
||||
<xsl:if test="key('bison:ruleByLhs', @name)">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:text> </xsl:text>
|
||||
<li>
|
||||
<b><xsl:value-of select="@name"/></b>
|
||||
<xsl:if test="string-length(@type) != 0">
|
||||
<xsl:value-of select="concat(' <', @type, '>')"/>
|
||||
</xsl:if>
|
||||
<xsl:text>on right:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<ul>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:if test="key('bison:ruleByLhs', @name)">
|
||||
<xsl:text> </xsl:text>
|
||||
<li>
|
||||
<xsl:text>on left:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByLhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
</li>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="key('bison:ruleByRhs', @name)">
|
||||
<xsl:text> </xsl:text>
|
||||
<li>
|
||||
<xsl:text>on right:</xsl:text>
|
||||
<xsl:for-each select="key('bison:ruleByRhs', @name)">
|
||||
<xsl:apply-templates select="." mode="number-link"/>
|
||||
</xsl:for-each>
|
||||
</li>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:text> </xsl:text>
|
||||
</ul>
|
||||
<xsl:text> </xsl:text>
|
||||
</li>
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:template>
|
||||
|
||||
@@ -385,7 +412,7 @@
|
||||
<xsl:value-of select="concat('state_', @number)"/>
|
||||
</xsl:attribute>
|
||||
</a>
|
||||
<xsl:text>state </xsl:text>
|
||||
<xsl:text>State </xsl:text>
|
||||
<xsl:value-of select="@number"/>
|
||||
</h3>
|
||||
<xsl:text> </xsl:text>
|
||||
@@ -464,7 +491,12 @@
|
||||
</xsl:apply-templates>
|
||||
</xsl:template>
|
||||
|
||||
<!--
|
||||
anchor = 'true': define as an <a> anchor.
|
||||
itemset = 'true': show the items.
|
||||
-->
|
||||
<xsl:template match="rule">
|
||||
<xsl:param name="anchor"/>
|
||||
<xsl:param name="itemset"/>
|
||||
<xsl:param name="pad"/>
|
||||
<xsl:param name="prev-lhs"/>
|
||||
@@ -475,17 +507,21 @@
|
||||
<xsl:text> </xsl:text>
|
||||
</xsl:if>
|
||||
|
||||
<xsl:if test="$itemset != 'true'">
|
||||
<a>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="concat('rule_', @number)"/>
|
||||
</xsl:attribute>
|
||||
</a>
|
||||
</xsl:if>
|
||||
<xsl:text> </xsl:text>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$itemset = 'true'">
|
||||
<xsl:when test="$anchor = 'true'">
|
||||
<a>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="concat('rule_', @number)"/>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name="lpad">
|
||||
<xsl:with-param name="str" select="string(@number)"/>
|
||||
<xsl:with-param name="pad" select="number($pad)"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<a>
|
||||
<xsl:attribute name="href">
|
||||
<xsl:value-of select="concat('#rule_', @number)"/>
|
||||
@@ -495,25 +531,13 @@
|
||||
<xsl:with-param name="pad" select="number($pad)"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="lpad">
|
||||
<xsl:with-param name="str" select="string(@number)"/>
|
||||
<xsl:with-param name="pad" select="number($pad)"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:text> </xsl:text>
|
||||
|
||||
<!-- LHS -->
|
||||
<xsl:choose>
|
||||
<xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
|
||||
<xsl:call-template name="lpad">
|
||||
<xsl:with-param name="str" select="'|'"/>
|
||||
<xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
|
||||
<xsl:when test="$prev-lhs = lhs[text()]">
|
||||
<xsl:call-template name="lpad">
|
||||
<xsl:with-param name="str" select="'|'"/>
|
||||
<xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
|
||||
|
||||
+327
-154
@@ -57,44 +57,57 @@
|
||||
\gdef\colorPurple{%
|
||||
\setcolor{\rgbPurple}%
|
||||
}
|
||||
\gdef\colorOff{%
|
||||
\setcolor{\maincolor}%
|
||||
}
|
||||
|
||||
\gdef\rgbError{0.80 0 0}
|
||||
\gdef\colorError{%
|
||||
\gdef\diagError{%
|
||||
\setcolor{\rgbError}%
|
||||
}
|
||||
\gdef\rgbNotice{0 0 0.80}
|
||||
\gdef\colorNotice{%
|
||||
\gdef\diagNotice{%
|
||||
\setcolor{\rgbNotice}%
|
||||
}
|
||||
\gdef\colorOff{%
|
||||
\gdef\rgbWarning{0.50 0 0.50}
|
||||
\gdef\diagWarning{%
|
||||
\setcolor{\rgbWarning}%
|
||||
}
|
||||
\gdef\diagOff{%
|
||||
\setcolor{\maincolor}%
|
||||
}
|
||||
@end tex
|
||||
|
||||
@ifnottex
|
||||
@macro colorGreen
|
||||
@inlineraw{html, <b style="color:green">}
|
||||
@inlineraw{html, <span style="color:green">}
|
||||
@end macro
|
||||
@macro colorYellow
|
||||
@inlineraw{html, <b style="color:#ff8000">}
|
||||
@inlineraw{html, <span style="color:#ff8000">}
|
||||
@end macro
|
||||
@macro colorRed
|
||||
@inlineraw{html, <b style="color:red">}
|
||||
@inlineraw{html, <span style="color:red">}
|
||||
@end macro
|
||||
@macro colorBlue
|
||||
@inlineraw{html, <b style="color:blue">}
|
||||
@inlineraw{html, <span style="color:blue">}
|
||||
@end macro
|
||||
@macro colorPurple
|
||||
@inlineraw{html, <b style="color:darkviolet">}
|
||||
@end macro
|
||||
|
||||
@macro colorError
|
||||
@inlineraw{html, <b style="color:red">}
|
||||
@end macro
|
||||
@macro colorNotice
|
||||
@inlineraw{html, <b style="color:darkcyan">}
|
||||
@inlineraw{html, <span style="color:darkviolet">}
|
||||
@end macro
|
||||
@macro colorOff
|
||||
@inlineraw{html, </span>}
|
||||
@end macro
|
||||
|
||||
@macro diagError
|
||||
@inlineraw{html, <b style="color:red">}
|
||||
@end macro
|
||||
@macro diagNotice
|
||||
@inlineraw{html, <b style="color:darkcyan">}
|
||||
@end macro
|
||||
@macro diagWarning
|
||||
@inlineraw{html, <b style="color:darkviolet">}
|
||||
@end macro
|
||||
@macro diagOff
|
||||
@inlineraw{html, </b>}
|
||||
@end macro
|
||||
@end ifnottex
|
||||
@@ -120,15 +133,15 @@
|
||||
@end macro
|
||||
|
||||
@macro dwarning{text}
|
||||
@purple{\text\}
|
||||
@diagWarning{}\text\@diagOff{}
|
||||
@end macro
|
||||
|
||||
@macro derror{text}
|
||||
@colorError{}\text\@colorOff{}
|
||||
@diagError{}\text\@diagOff{}
|
||||
@end macro
|
||||
|
||||
@macro dnotice{text}
|
||||
@colorNotice{}\text\@colorOff{}
|
||||
@diagNotice{}\text\@diagOff{}
|
||||
@end macro
|
||||
|
||||
@finalout
|
||||
@@ -263,7 +276,6 @@ Writing GLR Parsers
|
||||
* Merging GLR Parses:: Using GLR parsers to resolve ambiguities.
|
||||
* GLR Semantic Actions:: Considerations for semantic values and deferred actions.
|
||||
* Semantic Predicates:: Controlling a parse with arbitrary computations.
|
||||
* Compiler Requirements for GLR:: GLR parsers require a modern C compiler.
|
||||
|
||||
Examples
|
||||
|
||||
@@ -291,7 +303,7 @@ Grammar Rules for @code{rpcalc}
|
||||
|
||||
* Rpcalc Input:: Explanation of the @code{input} nonterminal
|
||||
* Rpcalc Line:: Explanation of the @code{line} nonterminal
|
||||
* Rpcalc Expr:: Explanation of the @code{expr} nonterminal
|
||||
* Rpcalc Exp:: Explanation of the @code{exp} nonterminal
|
||||
|
||||
Location Tracking Calculator: @code{ltcalc}
|
||||
|
||||
@@ -943,7 +955,6 @@ on the resulting values to produce an arbitrary merged result.
|
||||
* Merging GLR Parses:: Using GLR parsers to resolve ambiguities.
|
||||
* GLR Semantic Actions:: Considerations for semantic values and deferred actions.
|
||||
* Semantic Predicates:: Controlling a parse with arbitrary computations.
|
||||
* Compiler Requirements for GLR:: GLR parsers require a modern C compiler.
|
||||
@end menu
|
||||
|
||||
@node Simple GLR Parsers
|
||||
@@ -1372,14 +1383,14 @@ widget:
|
||||
@noindent
|
||||
is one way to allow the same parser to handle two different syntaxes for
|
||||
widgets. The clause preceded by @code{%?} is treated like an ordinary
|
||||
action, except that its text is treated as an expression and is always
|
||||
midrule action, except that its text is handled as an expression and is always
|
||||
evaluated immediately (even when in nondeterministic mode). If the
|
||||
expression yields 0 (false), the clause is treated as a syntax error,
|
||||
which, in a nondeterministic parser, causes the stack in which it is reduced
|
||||
to die. In a deterministic parser, it acts like YYERROR.
|
||||
to die. In a deterministic parser, it acts like @code{YYERROR}.
|
||||
|
||||
As the example shows, predicates otherwise look like semantic actions, and
|
||||
therefore you must be take them into account when determining the numbers
|
||||
therefore you must take them into account when determining the numbers
|
||||
to use for denoting the semantic values of right-hand side symbols.
|
||||
Predicate actions, however, have no defined value, and may not be given
|
||||
labels.
|
||||
@@ -1393,7 +1404,7 @@ widget:
|
||||
@{ if (!new_syntax) YYERROR; @}
|
||||
"widget" id new_args @{ $$ = f($3, $4); @}
|
||||
| @{ if (new_syntax) YYERROR; @}
|
||||
"widget" id old_args @{ $$ = f($3, $4); @}
|
||||
"widget" id old_args @{ $$ = f($3, $4); @}
|
||||
;
|
||||
@end example
|
||||
|
||||
@@ -1411,36 +1422,6 @@ reports an error.
|
||||
Finally, be careful in writing predicates: deferred actions have not been
|
||||
evaluated, so that using them in a predicate will have undefined effects.
|
||||
|
||||
@node Compiler Requirements for GLR
|
||||
@subsection Considerations when Compiling GLR Parsers
|
||||
@cindex @code{inline}
|
||||
@cindex GLR parsers and @code{inline}
|
||||
|
||||
The GLR parsers require a compiler for ISO C89 or
|
||||
later. In addition, they use the @code{inline} keyword, which is not
|
||||
C89, but is C99 and is a common extension in pre-C99 compilers. It is
|
||||
up to the user of these parsers to handle
|
||||
portability issues. For instance, if using Autoconf and the Autoconf
|
||||
macro @code{AC_C_INLINE}, a mere
|
||||
|
||||
@example
|
||||
%@{
|
||||
#include <config.h>
|
||||
%@}
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
will suffice. Otherwise, we suggest
|
||||
|
||||
@example
|
||||
%@{
|
||||
#if (__STDC_VERSION__ < 199901 && ! defined __GNUC__ \
|
||||
&& ! defined inline)
|
||||
# define inline
|
||||
#endif
|
||||
%@}
|
||||
@end example
|
||||
|
||||
@node Locations
|
||||
@section Locations
|
||||
@cindex location
|
||||
@@ -1807,7 +1788,7 @@ rule are referred to as @code{$1}, @code{$2}, and so on.
|
||||
@menu
|
||||
* Rpcalc Input:: Explanation of the @code{input} nonterminal
|
||||
* Rpcalc Line:: Explanation of the @code{line} nonterminal
|
||||
* Rpcalc Expr:: Explanation of the @code{expr} nonterminal
|
||||
* Rpcalc Exp:: Explanation of the @code{exp} nonterminal
|
||||
@end menu
|
||||
|
||||
@node Rpcalc Input
|
||||
@@ -1872,8 +1853,8 @@ uninitialized (its value will be unpredictable). This would be a bug if
|
||||
that value were ever used, but we don't use it: once rpcalc has printed the
|
||||
value of the user's input line, that value is no longer needed.
|
||||
|
||||
@node Rpcalc Expr
|
||||
@subsubsection Explanation of @code{expr}
|
||||
@node Rpcalc Exp
|
||||
@subsubsection Explanation of @code{exp}
|
||||
|
||||
The @code{exp} grouping has several rules, one for each kind of expression.
|
||||
The first rule handles the simplest expressions: those that are just
|
||||
@@ -6315,7 +6296,10 @@ Introduced in Bison 3.3 to replace @code{parser_class_name}.
|
||||
|
||||
@item Default Value: @code{YY} for Java, @code{yy} otherwise.
|
||||
|
||||
@item History: introduced in Bison 2.6
|
||||
@item History:
|
||||
introduced in Bison 2.6, with its argument in double quotes. Uses braces
|
||||
since Bison 3.0 (double quotes are still supported for backward
|
||||
compatibility).
|
||||
@end itemize
|
||||
@end deffn
|
||||
|
||||
@@ -8334,7 +8318,53 @@ write an unambiguous grammar, but that is very hard to do in this case.)
|
||||
This particular ambiguity was first encountered in the specifications of
|
||||
Algol 60 and is called the ``dangling @code{else}'' ambiguity.
|
||||
|
||||
To avoid warnings from Bison about predictable, legitimate shift/reduce
|
||||
To assist the grammar author in understanding the nature of each conflict,
|
||||
Bison can be asked to generate ``counterexamples''. In the present case it
|
||||
actually even proves that the grammar is ambiguous by exhibiting a string
|
||||
with two different parses:
|
||||
|
||||
@macro danglingElseCex
|
||||
@group
|
||||
@ifnottex
|
||||
Example: @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Shift derivation
|
||||
@yellow{if_stmt}
|
||||
@yellow{↳ "if" expr "then"} @green{stmt}
|
||||
@green{↳} @blue{if_stmt}
|
||||
@blue{↳ "if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Example: @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @yellow{"else" stmt}
|
||||
Reduce derivation
|
||||
@yellow{if_stmt}
|
||||
@yellow{↳ "if" expr "then"} @green{stmt} @yellow{"else" stmt}
|
||||
@green{↳} @blue{if_stmt}
|
||||
@blue{↳ "if" expr "then" stmt} @red{•}
|
||||
@end ifnottex
|
||||
@iftex
|
||||
Example: @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Shift derivation
|
||||
@yellow{if_stmt}
|
||||
@yellow{@arrow{} "if" expr "then"} @green{stmt}
|
||||
@green{@arrow{}} @blue{if_stmt}
|
||||
@blue{@arrow{} "if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Example: @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @yellow{"else" stmt}
|
||||
Reduce derivation
|
||||
@yellow{if_stmt}
|
||||
@yellow{@arrow{} "if" expr "then"} @green{stmt} @yellow{"else" stmt}
|
||||
@green{@arrow{}} @blue{if_stmt}
|
||||
@blue{@arrow{} "if" expr "then" stmt} @red{•}
|
||||
@end iftex
|
||||
@end group
|
||||
@end macro
|
||||
@example
|
||||
@danglingElseCex
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@xref{Counterexamples}, for more details.
|
||||
|
||||
@sp 1
|
||||
|
||||
To avoid warnings from Bison about predictable, @emph{legitimate} shift/reduce
|
||||
conflicts, you can use the @code{%expect @var{n}} declaration.
|
||||
There will be no warning as long as the number of shift/reduce conflicts
|
||||
is exactly @var{n}, and Bison will report an error if there is a
|
||||
@@ -8725,7 +8755,8 @@ maybeword:
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
The error is an ambiguity: there is more than one way to parse a single
|
||||
The error is an ambiguity: as counterexample generation would demonstrate
|
||||
(@pxref{Counterexamples}), there is more than one way to parse a single
|
||||
@code{word} into a @code{sequence}. It could be reduced to a
|
||||
@code{maybeword} and then into a @code{sequence} via the second rule.
|
||||
Alternatively, nothing-at-all could be reduced into a @code{sequence}
|
||||
@@ -8922,12 +8953,14 @@ name_list:
|
||||
It would seem that this grammar can be parsed with only a single token of
|
||||
lookahead: when a @code{param_spec} is being read, an @code{"id"} is a
|
||||
@code{name} if a comma or colon follows, or a @code{type} if another
|
||||
@code{"id"} follows. In other words, this grammar is LR(1).
|
||||
@code{"id"} follows. In other words, this grammar is LR(1). Yet Bison
|
||||
finds one reduce/reduce conflict, for which counterexample generation
|
||||
(@pxref{Counterexamples}) would find a @emph{nonunifying} example.
|
||||
|
||||
@cindex LR
|
||||
@cindex LALR
|
||||
However, for historical reasons, Bison cannot by default handle all
|
||||
LR(1) grammars.
|
||||
This is because Bison does not handle all LR(1) grammars @emph{by default},
|
||||
for historical reasons.
|
||||
In this grammar, two contexts, that after an @code{"id"} at the beginning
|
||||
of a @code{param_spec} and likewise at the beginning of a
|
||||
@code{return_spec}, are similar enough that Bison assumes they are the
|
||||
@@ -9902,6 +9935,9 @@ and understand the parser run-time traces (@pxref{Tracing}).
|
||||
|
||||
@node Counterexamples
|
||||
@section Generation of Counterexamples
|
||||
@cindex cex
|
||||
@cindex counterexamples
|
||||
@cindex conflict counterexamples
|
||||
|
||||
Solving conflicts is probably the most delicate part of the design of an LR
|
||||
parser, as demonstrated by the number of sections devoted to them in this
|
||||
@@ -9909,22 +9945,24 @@ very documentation. To solve a conflict, one must understand it: when does
|
||||
it occur? Is it because of a flaw in the grammar? Is it rather because
|
||||
LR(1) cannot cope with this grammar?
|
||||
|
||||
On difficulty is that conflicts occur in the @emph{automaton}, and it can be
|
||||
tricky to related them to issues in the @emph{grammar} itself. With
|
||||
experience and patience, analysis the detailed description of the automaton
|
||||
(@pxref{Understanding}) allows to find example strings that reach these conflicts.
|
||||
One difficulty is that conflicts occur in the @emph{automaton}, and it can
|
||||
be tricky to relate them to issues in the @emph{grammar} itself. With
|
||||
experience and patience, analysis of the detailed description of the
|
||||
automaton (@pxref{Understanding}) allows one to find example strings that
|
||||
reach these conflicts.
|
||||
|
||||
That task is made much easier thanks to the generation of counterexamples,
|
||||
initially developed by Chinawat Isradisaikul and Andrew Myers
|
||||
@pcite{Isradisaikul 2015}.
|
||||
|
||||
As a first example, see the example grammar of @ref{Shift/Reduce}, which
|
||||
features on shift/reduce conflict:
|
||||
As a first example, see the grammar of @ref{Shift/Reduce}, which features
|
||||
one shift/reduce conflict:
|
||||
|
||||
@c see doc/if-then-else.y
|
||||
@example
|
||||
$ @kbd{bison if-then-else.y}
|
||||
if-then-else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
if-then-else.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
if-then-else.y: @dwarning{warning}: 1 shift/reduce conflict [@dwarning{-Wconflicts-sr}]
|
||||
if-then-else.y: @dnotice{note}: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -9932,41 +9970,21 @@ Let's rerun @command{bison} with the option
|
||||
@option{-Wcex}/@option{-Wcounterexamples}@inlinefmt{info, (the following
|
||||
output is actually in color)}:
|
||||
|
||||
@ifhtml
|
||||
@example
|
||||
Shift/reduce conflict on token "else":
|
||||
@group
|
||||
Example @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @yellow{"else" stmt}
|
||||
First derivation @yellow{if_stmt ::=[ "if" expr "then"} @green{stmt ::=[} @blue{if_stmt ::=[ "if" expr "then" stmt} @red{•} @blue{]} @green{]} @yellow{"else" stmt ]}
|
||||
Example @yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Second derivation @yellow{if_stmt ::=[ "if" expr "then"} @green{stmt ::=[} @blue{if_stmt ::=[ "if" expr "then" stmt} @red{•} @blue{"else" stmt ]} @green{]} @yellow{]}
|
||||
@end group
|
||||
if-then-else.y: @dwarning{warning}: 1 shift/reduce conflict [@dwarning{-Wconflicts-sr}]
|
||||
if-then-else.y: @dwarning{warning}: shift/reduce conflict on token "else" [@dwarning{-Wcounterexamples}]
|
||||
@danglingElseCex
|
||||
@end example
|
||||
@end ifhtml
|
||||
@ifnothtml
|
||||
@smallexample
|
||||
Shift/reduce conflict on token "else":
|
||||
@group
|
||||
Example
|
||||
@yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @yellow{"else" stmt}
|
||||
First derivation
|
||||
@yellow{if_stmt ::=[ "if" expr "then"} @green{stmt ::=[} @blue{if_stmt ::=[ "if" expr "then" stmt} @red{•} @blue{]} @green{]} @yellow{"else" stmt ]}
|
||||
Example
|
||||
@yellow{"if" expr "then"} @blue{"if" expr "then" stmt} @red{•} @blue{"else" stmt}
|
||||
Second derivation
|
||||
@yellow{if_stmt ::=[ "if" expr "then"} @green{stmt ::=[} @blue{if_stmt ::=[ "if" expr "then" stmt} @red{•} @blue{"else" stmt ]} @green{]} @yellow{]}
|
||||
@end group
|
||||
@end smallexample
|
||||
@end ifnothtml
|
||||
|
||||
This shows two different derivations for one single expression. That
|
||||
demonstrates that the grammar is ambiguous.
|
||||
This shows two different derivations for one single expression, which proves
|
||||
that the grammar is ambiguous.
|
||||
|
||||
@sp 1
|
||||
|
||||
As a more delicate example, consider the example grammar of
|
||||
@ref{Reduce/Reduce}, which features a reduce/reduce conflict:
|
||||
|
||||
@c doc/sequence.y
|
||||
@example
|
||||
%%
|
||||
sequence:
|
||||
@@ -9983,35 +10001,108 @@ maybeword:
|
||||
Bison generates the following counterexamples:
|
||||
|
||||
@example
|
||||
@group
|
||||
$ @kbd{bison -Wcex sequence.y}
|
||||
sequence.y: @dwarning{warning}: 1 shift/reduce conflict [@dwarning{-Wconflicts-sr}]
|
||||
sequence.y: @dwarning{warning}: 2 reduce/reduce conflicts [@dwarning{-Wconflicts-rr}]
|
||||
Shift/reduce conflict on token "word":
|
||||
Example @red{•} @yellow{"word"}
|
||||
First derivation @yellow{sequence ::=[} @green{sequence ::=[} @red{•} @green{]} @yellow{"word" ]}
|
||||
Example @red{•} @green{"word"}
|
||||
Second derivation @yellow{sequence ::=[} @green{maybeword ::=[} @red{•} @green{"word" ]} @yellow{]}
|
||||
|
||||
Reduce/reduce conflict on tokens $end, "word":
|
||||
Example @red{•}
|
||||
First derivation @yellow{sequence ::=[} @red{•} @yellow{]}
|
||||
Example @red{•}
|
||||
Second derivation @yellow{sequence ::=[} @green{maybeword ::=[} @red{•} @green{]} @yellow{]}
|
||||
|
||||
Shift/reduce conflict on token "word":
|
||||
Example @red{•} @yellow{"word"}
|
||||
First derivation @yellow{sequence ::=[} @green{sequence ::=[} @blue{maybeword ::=[} @red{•} @blue{]} @green{]} @yellow{"word" ]}
|
||||
Example @red{•} @green{"word"}
|
||||
Second derivation @yellow{sequence ::=[} @green{maybeword ::=[} @red{•} @green{"word" ]} @yellow{]}
|
||||
|
||||
@end group
|
||||
@ifnottex
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: shift/reduce conflict on token "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•} @green{"word"}
|
||||
Shift derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @green{maybeword}
|
||||
@green{↳} @red{•} @green{"word"}
|
||||
Example: @red{•} @yellow{"word"}
|
||||
Reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @green{sequence} @yellow{"word"}
|
||||
@green{↳} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: reduce/reduce conflict on tokens $end, "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•}
|
||||
First reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @red{•}
|
||||
Example: @red{•}
|
||||
Second reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @green{maybeword}
|
||||
@green{↳} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: shift/reduce conflict on token "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•} @green{"word"}
|
||||
Shift derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @green{maybeword}
|
||||
@green{↳} @red{•} @green{"word"}
|
||||
Example: @red{•} @yellow{"word"}
|
||||
Reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{↳} @green{sequence} @yellow{"word"}
|
||||
@green{↳} @blue{maybeword}
|
||||
@blue{↳} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y:8.3-45: @dwarning{warning}: rule useless in parser due to conflicts [@dwarning{-Wother}]
|
||||
8 | @dwarning{%empty @{ printf ("empty maybeword\n"); @}}
|
||||
| @dwarning{^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
|
||||
@end group
|
||||
@end ifnottex
|
||||
@iftex
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: shift/reduce conflict on token "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•} @green{"word"}
|
||||
Shift derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @green{maybeword}
|
||||
@green{@arrow{}} @red{•} @green{"word"}
|
||||
Example: @red{•} @yellow{"word"}
|
||||
Reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @green{sequence} @yellow{"word"}
|
||||
@green{@arrow{}} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: reduce/reduce conflict on tokens $end, "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•}
|
||||
First reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @red{•}
|
||||
Example: @red{•}
|
||||
Second reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @green{maybeword}
|
||||
@green{@arrow{}} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y: @dwarning{warning}: shift/reduce conflict on token "word" [@dwarning{-Wcounterexamples}]
|
||||
Example: @red{•} @green{"word"}
|
||||
Shift derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @green{maybeword}
|
||||
@green{@arrow{}} @red{•} @green{"word"}
|
||||
Example: @red{•} @yellow{"word"}
|
||||
Reduce derivation
|
||||
@yellow{sequence}
|
||||
@yellow{@arrow{}} @green{sequence} @yellow{"word"}
|
||||
@green{@arrow{}} @blue{maybeword}
|
||||
@blue{@arrow{}} @red{•}
|
||||
@end group
|
||||
@group
|
||||
sequence.y:8.3-45: @dwarning{warning}: rule useless in parser due to conflicts [@dwarning{-Wother}]
|
||||
8 | @dwarning{%empty @{ printf ("empty maybeword\n"); @}}
|
||||
| @dwarning{^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
|
||||
@end group
|
||||
@end iftex
|
||||
@end example
|
||||
|
||||
Each of these three conflicts, again, prove that the grammar is ambiguous.
|
||||
For instance, the second conflict (the reduce/reduce one) shows that the
|
||||
grammar accept the empty input in two different ways.
|
||||
grammar accepts the empty input in two different ways.
|
||||
|
||||
@sp 1
|
||||
|
||||
@@ -10021,6 +10112,7 @@ that are the same up until the dot. Most notably, this will happen when
|
||||
your grammar requires a stronger parser (more lookahead, LR instead of
|
||||
LALR). The following example isn't LR(1):
|
||||
|
||||
@c doc/ids.y
|
||||
@example
|
||||
%token ID
|
||||
%%
|
||||
@@ -10031,13 +10123,54 @@ expr: %empty | expr ID ','
|
||||
|
||||
@command{bison} reports:
|
||||
|
||||
@smallexample
|
||||
Shift/reduce conflict on token ID:
|
||||
First example @blue{expr} @red{•} @green{ID} @yellow{$end}
|
||||
First derivation @yellow{$accept ::=[} @green{s ::=[} @blue{a ::=[ expr} @red{•} @blue{]} @green{ID ]} @yellow{$end ]}
|
||||
Second example @purple{expr} @red{•} @purple{ID ','} @green{ID} @yellow{$end}
|
||||
Second derivation @yellow{$accept ::=[} @green{s ::=[} @blue{a ::=[} @purple{expr ::=[ expr} @red{•} @purple{ID ',' ]} @blue{]} @green{ID ]} @yellow{$end ]}
|
||||
@end smallexample
|
||||
@example
|
||||
ids.y: @dwarning{warning}: 1 shift/reduce conflict [@dwarning{-Wconflicts-sr}]
|
||||
ids.y: @dwarning{warning}: shift/reduce conflict on token ID [@dwarning{-Wcounterexamples}]
|
||||
@ifnottex
|
||||
@group
|
||||
First example: @purple{expr} @red{•} @purple{ID ','} @green{ID} @yellow{$end}
|
||||
Shift derivation
|
||||
@yellow{$accept}
|
||||
@yellow{↳} @green{s} @yellow{$end}
|
||||
@green{↳} @blue{a} @green{ID}
|
||||
@blue{↳} @purple{expr}
|
||||
@purple{↳ expr} @red{•} @purple{ID ','}
|
||||
Second example: @blue{expr} @red{•} @green{ID} @yellow{$end}
|
||||
Reduce derivation
|
||||
@yellow{$accept}
|
||||
@yellow{↳} @green{s} @yellow{$end}
|
||||
@green{↳} @blue{a} @green{ID}
|
||||
@blue{↳ expr} @red{•}
|
||||
@end group
|
||||
@group
|
||||
ids.y:4.4-7: @dwarning{warning}: rule useless in parser due to conflicts [@dwarning{-Wother}]
|
||||
4 | a: expr
|
||||
| ^~~~
|
||||
@end group
|
||||
@end ifnottex
|
||||
@iftex
|
||||
@group
|
||||
First example: @purple{expr} @red{•} @purple{ID ','} @green{ID} @yellow{$end}
|
||||
Shift derivation
|
||||
@yellow{$accept}
|
||||
@yellow{@arrow{}} @green{s} @yellow{$end}
|
||||
@green{@arrow{}} @blue{a} @green{ID}
|
||||
@blue{@arrow{}} @purple{expr}
|
||||
@purple{@arrow{} expr} @red{•} @purple{ID ','}
|
||||
Second example: @blue{expr} @red{•} @green{ID} @yellow{$end}
|
||||
Reduce derivation
|
||||
@yellow{$accept}
|
||||
@yellow{@arrow{}} @green{s} @yellow{$end}
|
||||
@green{@arrow{}} @blue{a} @green{ID}
|
||||
@blue{@arrow{} expr} @red{•}
|
||||
@end group
|
||||
@group
|
||||
ids.y:4.4-7: @dwarning{warning}: rule useless in parser due to conflicts [@dwarning{-Wother}]
|
||||
4 | a: expr
|
||||
| ^~~~
|
||||
@end group
|
||||
@end iftex
|
||||
@end example
|
||||
|
||||
This conflict is caused by the parser not having enough information to know
|
||||
the difference between these two examples. The parser would need an
|
||||
@@ -10073,6 +10206,7 @@ by default. As a consequence, the verbose output file is called
|
||||
|
||||
The following grammar file, @file{calc.y}, will be used in the sequel:
|
||||
|
||||
@c doc/calc.y
|
||||
@example
|
||||
@group
|
||||
%union
|
||||
@@ -10116,7 +10250,7 @@ calc.y:19.1-7: @dwarning{warning}: nonterminal useless in grammar: useless [@dwa
|
||||
19 | @dwarning{useless: STR;}
|
||||
| @dwarning{^~~~~~~}
|
||||
calc.y: @dwarning{warning}: 7 shift/reduce conflicts [@dwarning{-Wconflicts-sr}]
|
||||
calc.y: @dwarning{warning}: rerun with option '-Wcounterexamples' to generate conflict counterexamples [@dwarning{-Wother}]
|
||||
calc.y: @dnotice{note}: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
@end smallexample
|
||||
|
||||
Going back to the calc example, when given @option{--report=state},
|
||||
@@ -10428,15 +10562,44 @@ When given @option{--report=counterexamples}, @command{bison} will generate
|
||||
counterexamples within the report, augmented with the corresponding items
|
||||
(@pxref{Counterexamples}).
|
||||
|
||||
@ifnottex
|
||||
@example
|
||||
Shift/reduce conflict on token '/':
|
||||
shift/reduce conflict on token '/':
|
||||
1 exp: exp '+' exp •
|
||||
4 exp: exp • '/' exp
|
||||
Example @green{exp '+' exp} @red{•} @yellow{'/' exp}
|
||||
First derivation @yellow{exp ::=[} @green{exp ::=[ exp '+' exp} @red{•} @green{]} @yellow{'/' exp ]}
|
||||
Example @yellow{exp '+'} @green{exp} @red{•} @green{'/' exp}
|
||||
Second derivation @yellow{exp ::=[ exp '+'} @green{exp ::=[ exp} @red{•} @green{'/' exp ]} @yellow{]}
|
||||
@group
|
||||
Example: exp '+' exp • '/' exp
|
||||
Shift derivation
|
||||
exp
|
||||
↳ exp '+' exp
|
||||
↳ exp • '/' exp
|
||||
Example: exp '+' exp • '/' exp
|
||||
Reduce derivation
|
||||
exp
|
||||
↳ exp '/' exp
|
||||
↳ exp '+' exp •
|
||||
@end group
|
||||
@end example
|
||||
@end ifnottex
|
||||
@iftex
|
||||
@example
|
||||
shift/reduce conflict on token '/':
|
||||
1 exp: exp '+' exp •
|
||||
4 exp: exp • '/' exp
|
||||
@group
|
||||
Example: exp '+' exp • '/' exp
|
||||
Shift derivation
|
||||
exp
|
||||
@arrow{} exp '+' exp
|
||||
@arrow{} exp • '/' exp
|
||||
Example: exp '+' exp • '/' exp
|
||||
Reduce derivation
|
||||
exp
|
||||
@arrow{} exp '/' exp
|
||||
@arrow{} exp '+' exp •
|
||||
@end group
|
||||
@end example
|
||||
@end iftex
|
||||
|
||||
This shows two separate derivations in the grammar for the same @code{exp}:
|
||||
@samp{e1 + e2 / e3}. The derivations show how your rules would parse the
|
||||
@@ -11047,7 +11210,7 @@ The exit status of @command{bison} is:
|
||||
@item 0 (success)
|
||||
when there were no errors. Warnings, which are diagnostics about dubious
|
||||
constructs, do not change the exit status, unless they are turned into
|
||||
errors (@pxref{-Werror,,@option{-Werror}}).
|
||||
errors (@pxref{Werror,,@option{-Werror}}).
|
||||
|
||||
@item 1 (failure)
|
||||
when there were errors. No file was generated (except the reports generated
|
||||
@@ -11284,22 +11447,22 @@ Options controlling the diagnostics.
|
||||
Output warnings falling in @var{category}. @var{category} can be one
|
||||
of:
|
||||
@table @code
|
||||
@item conflicts-sr
|
||||
@itemx conflicts-rr
|
||||
@item @anchor{Wconflicts-sr}conflicts-sr
|
||||
@itemx @anchor{Wconflicts-rr}conflicts-rr
|
||||
S/R and R/R conflicts. These warnings are enabled by default. However, if
|
||||
the @code{%expect} or @code{%expect-rr} directive is specified, an
|
||||
unexpected number of conflicts is an error, and an expected number of
|
||||
conflicts is not reported, so @option{-W} and @option{--warning} then have
|
||||
no effect on the conflict report.
|
||||
|
||||
@item counterexamples
|
||||
@item @anchor{Wcounterexamples}counterexamples
|
||||
@itemx cex
|
||||
Provide counterexamples for conflicts. @xref{Counterexamples}.
|
||||
Counterexamples take time to compute. The option @option{-Wcex} should be
|
||||
used by the developer when working on the grammar; it hardly makes sense to
|
||||
use it in a CI.
|
||||
|
||||
@item dangling-alias
|
||||
@item @anchor{Wdangling-alias}dangling-alias
|
||||
Report string literals that are not bound to a token symbol.
|
||||
|
||||
String literals, which allow for better error messages, are (too) liberally
|
||||
@@ -11345,16 +11508,16 @@ foo: "baz" @{@}
|
||||
| @dwarning{^~~~~}
|
||||
@end example
|
||||
|
||||
@item deprecated
|
||||
@item @anchor{Wdeprecated}deprecated
|
||||
Deprecated constructs whose support will be removed in future versions of
|
||||
Bison.
|
||||
|
||||
@item empty-rule
|
||||
@item @anchor{Wempty-rule}empty-rule
|
||||
Empty rules without @code{%empty}. @xref{Empty Rules}. Disabled by
|
||||
default, but enabled by uses of @code{%empty}, unless
|
||||
@option{-Wno-empty-rule} was specified.
|
||||
|
||||
@item midrule-values
|
||||
@item @anchor{Wmidrule-values}midrule-values
|
||||
Warn about midrule values that are set but not used within any of the actions
|
||||
of the parent rule.
|
||||
For example, warn about unused @code{$2} in:
|
||||
@@ -11374,7 +11537,7 @@ These warnings are not enabled by default since they sometimes prove to
|
||||
be false alarms in existing grammars employing the Yacc constructs
|
||||
@code{$0} or @code{$-@var{n}} (where @var{n} is some positive integer).
|
||||
|
||||
@item precedence
|
||||
@item @anchor{Wprecedence}precedence
|
||||
Useless precedence and associativity directives. Disabled by default.
|
||||
|
||||
Consider for instance the following grammar:
|
||||
@@ -11435,20 +11598,21 @@ One would get the exact same parser with the following directives instead:
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@item yacc
|
||||
@item @anchor{Wyacc}yacc
|
||||
Incompatibilities with POSIX Yacc.
|
||||
|
||||
@item other
|
||||
@item @anchor{Wother}other
|
||||
All warnings not categorized above. These warnings are enabled by default.
|
||||
|
||||
This category is provided merely for the sake of completeness. Future
|
||||
releases of Bison may move warnings from this category to new, more specific
|
||||
categories.
|
||||
|
||||
@item all
|
||||
All the warnings except @code{dangling-alias} and @code{yacc}.
|
||||
@item @anchor{Wall}all
|
||||
All the warnings except @code{counterexamples}, @code{dangling-alias} and
|
||||
@code{yacc}.
|
||||
|
||||
@item none
|
||||
@item @anchor{Wnone}none
|
||||
Turn off all the warnings.
|
||||
|
||||
@item error
|
||||
@@ -11459,8 +11623,7 @@ A category can be turned off by prefixing its name with @samp{no-}. For
|
||||
instance, @option{-Wno-yacc} will hide the warnings about
|
||||
POSIX Yacc incompatibilities.
|
||||
|
||||
@item -Werror
|
||||
@anchor{-Werror}
|
||||
@item @anchor{Werror}-Werror
|
||||
Turn enabled warnings for every @var{category} into errors, unless they are
|
||||
explicitly disabled by @option{-Wno-error=@var{category}}.
|
||||
|
||||
@@ -14824,13 +14987,13 @@ Bison. See the file @file{ABOUT-NLS} for more information.
|
||||
I can't build Bison because my C compiler is too old.
|
||||
@end quotation
|
||||
|
||||
Except for GLR parsers (@pxref{Compiler Requirements for GLR}), the C
|
||||
code that Bison generates requires only C89 or later. However, Bison
|
||||
itself requires common C99 features such as declarations after
|
||||
statements. Bison's @code{configure} script attempts to enable C99 (or
|
||||
later) support on compilers that default to pre-C99. If your compiler
|
||||
lacks these C99 features entirely, GCC may well be a better choice; or
|
||||
you can try upgrading to your compiler's latest version.
|
||||
Except for GLR parsers (which require C99), the C code that Bison generates
|
||||
requires only C89 or later. However, Bison itself requires common C99
|
||||
features such as declarations after statements. Bison's @code{configure}
|
||||
script attempts to enable C99 (or later) support on compilers that default
|
||||
to pre-C99. If your compiler lacks these C99 features entirely, GCC may
|
||||
well be a better choice; or you can try upgrading to your compiler's latest
|
||||
version.
|
||||
|
||||
@node Where can I find help?
|
||||
@section Where can I find help?
|
||||
@@ -15271,6 +15434,12 @@ Macro to discard a value from the parser stack and fake a lookahead
|
||||
token. @xref{Action Features}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Macro} YYBISON
|
||||
The version of Bison as an integer, for instance 30704 for version 3.7.4.
|
||||
Defined in @file{yacc.c} only. Before version 3.7.4, @code{YYBISON} was
|
||||
defined to 1.
|
||||
@end deffn
|
||||
|
||||
@deffn {Variable} yychar
|
||||
External integer variable that contains the integer value of the
|
||||
lookahead token. (In a pure parser, it is a local variable within
|
||||
@@ -15491,6 +15660,10 @@ permitted. @xref{Language and Grammar}.
|
||||
A sequence of tokens and/or nonterminals, with one dot, that demonstrates a
|
||||
conflict. The dot marks the place where the conflict occurs.
|
||||
|
||||
@cindex unifying counterexample
|
||||
@cindex counterexample, unifying
|
||||
@cindex nonunifying counterexample
|
||||
@cindex counterexample, nonunifying
|
||||
A @emph{unifying} counterexample is a single string that has two different
|
||||
parses; its existence proves that the grammar is ambiguous. When a unifying
|
||||
counterexample cannot be found in reasonable time, a @emph{nonunifying}
|
||||
@@ -15887,7 +16060,7 @@ London, Department of Computer Science, TR-00-12 (December 2000).
|
||||
@c LocalWords: TokenKind Automake's rtti Wcounterexamples Chinawat PLDI
|
||||
@c LocalWords: Isradisaikul tcite pcite rgbGreen colorGreen rgbYellow Wcex
|
||||
@c LocalWords: colorYellow rgbRed colorRed rgbBlue colorBlue rgbPurple
|
||||
@c LocalWords: colorPurple ifhtml ifnothtml situ rcex
|
||||
@c LocalWords: colorPurple ifhtml ifnothtml situ rcex MERCHANTABILITY Wnone
|
||||
|
||||
@c Local Variables:
|
||||
@c ispell-dictionary: "american"
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
%union
|
||||
{
|
||||
int ival;
|
||||
const char *sval;
|
||||
}
|
||||
|
||||
%token <ival> NUM
|
||||
%nterm <ival> exp
|
||||
%token <sval> STR
|
||||
%nterm <sval> useless
|
||||
|
||||
%left '+' '-'
|
||||
%left '*'
|
||||
|
||||
%%
|
||||
exp:
|
||||
exp '+' exp
|
||||
| exp '-' exp
|
||||
| exp '*' exp
|
||||
| exp '/' exp
|
||||
| NUM
|
||||
;
|
||||
useless: STR;
|
||||
@@ -0,0 +1,13 @@
|
||||
%%
|
||||
stmt:
|
||||
expr
|
||||
| if_stmt
|
||||
;
|
||||
|
||||
if_stmt:
|
||||
"if" expr "then" stmt
|
||||
| "if" expr "then" stmt "else" stmt
|
||||
;
|
||||
|
||||
expr:
|
||||
"identifier"
|
||||
+1
-1
@@ -57,7 +57,7 @@ MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
|
||||
|
||||
# Fix Info's @code in @deftype
|
||||
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html
|
||||
all: $(srcdir)/$(%C%_bison).info.bak
|
||||
all-local: $(srcdir)/$(%C%_bison).info.bak
|
||||
$(srcdir)/$(%C%_bison).info.bak: $(srcdir)/$(%C%_bison).info
|
||||
$(AM_V_GEN) $(PERL) -pi.bak -0777 \
|
||||
-e 's{(^ --.*\n(?: {10}.*\n)*)}' \
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
%%
|
||||
sequence:
|
||||
%empty
|
||||
| maybeword
|
||||
| sequence "word"
|
||||
;
|
||||
maybeword:
|
||||
%empty
|
||||
| "word"
|
||||
;
|
||||
+41
-29
@@ -185,13 +185,13 @@ my $verbose = 1;
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<verbose($level, $message)>
|
||||
=item C<verbose ($level, $message)>
|
||||
|
||||
Report the C<$message> is C<$level> E<lt>= C<$verbose>.
|
||||
|
||||
=cut
|
||||
|
||||
sub verbose($$)
|
||||
sub verbose ($$)
|
||||
{
|
||||
my ($level, $message) = @_;
|
||||
print STDERR $message
|
||||
@@ -201,13 +201,13 @@ sub verbose($$)
|
||||
|
||||
######################################################################
|
||||
|
||||
=item C<directives($bench, @directive)>
|
||||
=item C<directives ($bench, @directive)>
|
||||
|
||||
Format the list of directives for Bison for bench named C<$bench>.
|
||||
|
||||
=cut
|
||||
|
||||
sub directives($@)
|
||||
sub directives ($@)
|
||||
{
|
||||
my ($bench, @directive) = @_;
|
||||
my $res = "/* Directives for bench '$bench'. */\n";
|
||||
@@ -218,6 +218,27 @@ sub directives($@)
|
||||
|
||||
######################################################################
|
||||
|
||||
=item C<is_pure (@directive)>
|
||||
|
||||
Whether api.pure is set.
|
||||
|
||||
=cut
|
||||
|
||||
sub is_pure (@)
|
||||
{
|
||||
my (@directive) = @_;
|
||||
for my $dir (@directive)
|
||||
{
|
||||
if ($dir =~ /\A%define api.pure/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
||||
=item C<generate_grammar_triangular ($base, $max, @directive)>
|
||||
|
||||
Create a large triangular grammar which looks like :
|
||||
@@ -389,18 +410,14 @@ sub generate_grammar_calc ($$@)
|
||||
%define api.value.type union
|
||||
$directives
|
||||
|
||||
%{
|
||||
%code provides {
|
||||
static int power (int base, int exponent);
|
||||
/* yyerror receives the location if:
|
||||
- %location & %pure & %glr
|
||||
- %location & %pure & %yacc & %parse-param. */
|
||||
static void yyerror (const char *s);
|
||||
#if YYPURE
|
||||
static int yylex (YYSTYPE* yylvalp);
|
||||
#else
|
||||
static int yylex (void);
|
||||
#endif
|
||||
%}
|
||||
static int yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]});
|
||||
}
|
||||
|
||||
/* Bison Declarations */
|
||||
%token
|
||||
@@ -467,12 +484,7 @@ yyerror (const char *s)
|
||||
}
|
||||
|
||||
static int
|
||||
#if YYPURE
|
||||
# define yylval (*yylvalp)
|
||||
yylex (YYSTYPE* yylvalp)
|
||||
#else
|
||||
yylex (void)
|
||||
#endif
|
||||
yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]})
|
||||
{
|
||||
int c;
|
||||
|
||||
@@ -498,7 +510,7 @@ yylex (void)
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
int nchars = 0;
|
||||
int n = sscanf (input - 1, "%d%n", &yylval.NUM, &nchars);
|
||||
int n = sscanf (input - 1, "%d%n", &@{[is_pure (@directive) ? "yylvalp->" : "yylval."]}NUM, &nchars);
|
||||
assert (n == 1);
|
||||
input += nchars - 1;
|
||||
return NUM;
|
||||
@@ -506,7 +518,7 @@ yylex (void)
|
||||
|
||||
default:
|
||||
yyerror ("error: invalid character");
|
||||
return yylex ();
|
||||
return yylex (@{[is_pure (@directive) ? "yylvalp" : ""]});
|
||||
}
|
||||
}
|
||||
EOF
|
||||
@@ -592,10 +604,10 @@ $directives
|
||||
// Prototype of the yylex function providing subsequent tokens.
|
||||
static
|
||||
#if USE_TOKEN_CTOR
|
||||
yy::parser::symbol_type yylex();
|
||||
yy::parser::symbol_type yylex ();
|
||||
#else
|
||||
yy::parser::token_type yylex(yy::parser::semantic_type* yylvalp,
|
||||
yy::parser::location_type* yyllocp);
|
||||
yy::parser::token_type yylex (yy::parser::semantic_type *yylvalp,
|
||||
yy::parser::location_type *yyllocp);
|
||||
#endif
|
||||
|
||||
// Conversion to string.
|
||||
@@ -618,8 +630,8 @@ EOF
|
||||
print $out <<'EOF';
|
||||
%token <std::string> TEXT
|
||||
%token <int> NUMBER
|
||||
%printer { std::cerr << "Number: " << $$; } <int>
|
||||
%printer { std::cerr << "Text: " << $$; } <std::string>
|
||||
%printer { yyo << "Number: " << $$; } <int>
|
||||
%printer { yyo << "Text: " << $$; } <std::string>
|
||||
%type <std::string> text result
|
||||
|
||||
%%
|
||||
@@ -641,8 +653,8 @@ EOF
|
||||
%union {int ival; std::string* sval;}
|
||||
%token <sval> TEXT
|
||||
%token <ival> NUMBER
|
||||
%printer { std::cerr << "Number: " << $$; } <ival>
|
||||
%printer { std::cerr << "Text: " << *$$; } <sval>
|
||||
%printer { yyo << "Number: " << $$; } <ival>
|
||||
%printer { yyo << "Text: " << *$$; } <sval>
|
||||
%type <sval> text result
|
||||
|
||||
%%
|
||||
@@ -664,10 +676,10 @@ EOF
|
||||
|
||||
static
|
||||
#if USE_TOKEN_CTOR
|
||||
yy::parser::symbol_type yylex()
|
||||
yy::parser::symbol_type yylex ()
|
||||
#else
|
||||
yy::parser::token_type yylex(yy::parser::semantic_type* yylvalp,
|
||||
yy::parser::location_type* yyllocp)
|
||||
yy::parser::token_type yylex (yy::parser::semantic_type *yylvalp,
|
||||
yy::parser::location_type *yyllocp)
|
||||
#endif
|
||||
{
|
||||
typedef yy::parser::location_type location_type;
|
||||
|
||||
+10
-1
@@ -53,7 +53,9 @@ push-parser model.
|
||||
This example demonstrates best practices when using Bison.
|
||||
- Its hand-written scanner tracks locations.
|
||||
- Its interface is pure.
|
||||
- It uses the `error` token to get error recovery.
|
||||
- It uses %params to pass user information to the parser and scanner.
|
||||
- Its scanner uses the `error` token to signal lexical errors and enter
|
||||
error recovery.
|
||||
- Its interface is "incremental", well suited for interaction: it uses the
|
||||
push-parser API to feed the parser with the incoming tokens.
|
||||
- It features an interactive command line with completion based on the
|
||||
@@ -62,6 +64,13 @@ This example demonstrates best practices when using Bison.
|
||||
messages.
|
||||
- It uses a custom syntax error with location, lookahead correction and
|
||||
token internationalization.
|
||||
- Error messages quote the source with squiggles that underline the error:
|
||||
```
|
||||
> 123 456
|
||||
1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
|
||||
1 | 123 456
|
||||
| ^~~
|
||||
```
|
||||
- It supports debug traces with semantic values.
|
||||
- It uses named references instead of the traditional $1, $2, etc.
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
This example demonstrates best practices when using Bison.
|
||||
- Its hand-written scanner tracks locations.
|
||||
- Its interface is pure.
|
||||
- It uses the `error` token to get error recovery.
|
||||
- It uses %params to pass user information to the parser and scanner.
|
||||
- Its scanner uses the `error` token to signal lexical errors and enter
|
||||
error recovery.
|
||||
- Its interface is "incremental", well suited for interaction: it uses the
|
||||
push-parser API to feed the parser with the incoming tokens.
|
||||
- It features an interactive command line with completion based on the
|
||||
@@ -11,6 +13,13 @@ This example demonstrates best practices when using Bison.
|
||||
messages.
|
||||
- It uses a custom syntax error with location, lookahead correction and
|
||||
token internationalization.
|
||||
- Error messages quote the source with squiggles that underline the error:
|
||||
```
|
||||
> 123 456
|
||||
1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
|
||||
1 | 123 456
|
||||
| ^~~
|
||||
```
|
||||
- It supports debug traces with semantic values.
|
||||
- It uses named references instead of the traditional $1, $2, etc.
|
||||
|
||||
|
||||
@@ -101,14 +101,28 @@ cat >input <<EOF
|
||||
EOF
|
||||
run 0 '> *
|
||||
> ''
|
||||
err: 1.1: syntax error: expected end of file or - or ( or exit or number or function etc., before *'
|
||||
err: 1.1: syntax error: expected end of file or - or ( or exit or number or function etc., before *
|
||||
err: 1 | *
|
||||
err: | ^'
|
||||
|
||||
# Underline long errors.
|
||||
cat >input <<EOF
|
||||
123 123456
|
||||
EOF
|
||||
run 0 '> 123 123456
|
||||
> ''
|
||||
err: 1.5-10: syntax error: expected end of file or + or - or * or / or ^ before number
|
||||
err: 1 | 123 123456
|
||||
err: | ^~~~~~'
|
||||
|
||||
cat >input <<EOF
|
||||
1 + 2 * * 3
|
||||
EOF
|
||||
run 0 '> 1 + 2 * * 3
|
||||
> ''
|
||||
err: 1.9: syntax error: expected - or ( or number or function or variable before *'
|
||||
err: 1.9: syntax error: expected - or ( or number or function or variable before *
|
||||
err: 1 | 1 + 2 * * 3
|
||||
err: | ^'
|
||||
|
||||
cat >input <<EOF
|
||||
1 / 0
|
||||
@@ -132,8 +146,14 @@ run 0 '> ((1 ++ 2) ** 3)
|
||||
1332
|
||||
> ''
|
||||
err: 1.6: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1 | ((1 ++ 2) ** 3)
|
||||
err: | ^
|
||||
err: 2.5: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 2.16: syntax error: expected - or ( or number or function or variable before *'
|
||||
err: 2 | (1 ++ 2) + (3 ** 4)
|
||||
err: | ^
|
||||
err: 2.16: syntax error: expected - or ( or number or function or variable before *
|
||||
err: 2 | (1 ++ 2) + (3 ** 4)
|
||||
err: | ^'
|
||||
|
||||
# The rule "( error )" should work even if there are no tokens between "(" and ")".
|
||||
cat >input <<EOF
|
||||
@@ -142,7 +162,9 @@ EOF
|
||||
run 0 '> ()
|
||||
666
|
||||
> ''
|
||||
err: 1.2: syntax error: expected - or ( or number or function or variable before )'
|
||||
err: 1.2: syntax error: expected - or ( or number or function or variable before )
|
||||
err: 1 | ()
|
||||
err: | ^'
|
||||
|
||||
|
||||
cat >input <<EOF
|
||||
@@ -189,6 +211,8 @@ err: LAC: checking lookahead function: S5
|
||||
err: LAC: checking lookahead variable: S6
|
||||
err: LAC: checking lookahead NEG: Err
|
||||
err: 1.2: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1 | (+_)
|
||||
err: | ^
|
||||
err: LAC: initial context discarded due to error recovery
|
||||
err: Shifting token error (1.2: )
|
||||
err: Entering state 10
|
||||
@@ -227,29 +251,29 @@ err: Next token is token ) (1.4: )
|
||||
err: Shifting token ) (1.4: )
|
||||
err: Entering state 20
|
||||
err: Stack now 0 2 10 20
|
||||
err: Reducing stack by rule 15 (line 151):
|
||||
err: Reducing stack by rule XX (line XXX):
|
||||
err: $1 = token ( (1.1: )
|
||||
err: $2 = token error (1.2-3: )
|
||||
err: $3 = token ) (1.4: )
|
||||
err: -> $$ = nterm exp (1.1-4: 666)
|
||||
err: Entering state 7
|
||||
err: Stack now 0 7
|
||||
err: Entering state 8
|
||||
err: Stack now 0 8
|
||||
err: Return for a new token:
|
||||
err: Reading a token
|
||||
err: Now at end of input.
|
||||
err: LAC: initial context established for end of file
|
||||
err: LAC: checking lookahead end of file: R2 G8 S19
|
||||
err: Reducing stack by rule 2 (line 126):
|
||||
err: LAC: checking lookahead end of file: R2 G7 S14
|
||||
err: Reducing stack by rule XX (line XXX):
|
||||
err: $1 = nterm exp (1.1-4: 666)
|
||||
err: -> $$ = nterm input (1.1-4: )
|
||||
err: Entering state 8
|
||||
err: Stack now 0 8
|
||||
err: Entering state 7
|
||||
err: Stack now 0 7
|
||||
err: Now at end of input.
|
||||
err: Shifting token end of file (1.5: )
|
||||
err: LAC: initial context discarded due to shift
|
||||
err: Entering state 19
|
||||
err: Stack now 0 8 19
|
||||
err: Stack now 0 8 19
|
||||
err: Entering state 14
|
||||
err: Stack now 0 7 14
|
||||
err: Stack now 0 7 14
|
||||
err: Cleanup: popping token end of file (1.5: )
|
||||
err: Cleanup: popping nterm input (1.1-4: )' -p
|
||||
|
||||
@@ -286,7 +310,9 @@ run 0 '> (1+
|
||||
( - atan cos exp ln number sin sqrt
|
||||
> (1+
|
||||
> ''
|
||||
err: 1.4: syntax error: expected - or ( or number or function or variable before end of file'
|
||||
err: 1.4: syntax error: expected - or ( or number or function or variable before end of file
|
||||
err: 1 | (1+
|
||||
err: | ^'
|
||||
|
||||
# Check the completion of a word.
|
||||
sed -e 's/\\t/ /g' >input <<EOF
|
||||
@@ -294,7 +320,9 @@ sed -e 's/\\t/ /g' >input <<EOF
|
||||
EOF
|
||||
run 0 '> (atan ( ''
|
||||
> ''
|
||||
err: 1.9: syntax error: expected - or ( or number or function or variable before end of file'
|
||||
err: 1.9: syntax error: expected - or ( or number or function or variable before end of file
|
||||
err: 1 | (atan ( ''
|
||||
err: | ^'
|
||||
|
||||
# Check the completion at the very beginning.
|
||||
sed -e 's/\\t/ /g' >input <<EOF
|
||||
@@ -313,8 +341,9 @@ sed -e 's/\\t/ /g' >input <<EOF
|
||||
EOF
|
||||
run -n 0 '> 1++ ''
|
||||
> ''
|
||||
err: 1.1: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1.3: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1 | 1++ ''
|
||||
err: | ^
|
||||
'
|
||||
|
||||
# And even when the error was recovered from.
|
||||
@@ -323,8 +352,10 @@ sed -e 's/\\t/ /g' >input <<EOF
|
||||
EOF
|
||||
run -n 0 '> (1++2) + 3 + ''
|
||||
> ''
|
||||
err: 1.1: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1.1: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1.4: syntax error: expected - or ( or number or function or variable before +
|
||||
err: 1 | (1++2) + 3 + ''
|
||||
err: | ^
|
||||
err: 1.15: syntax error: expected - or ( or number or function or variable before end of file
|
||||
err: 1 | (1++2) + 3 + ''
|
||||
err: | ^
|
||||
'
|
||||
|
||||
@@ -65,6 +65,15 @@
|
||||
|
||||
symrec *putsym (char const *name, int sym_type);
|
||||
symrec *getsym (char const *name);
|
||||
|
||||
// Exchanging information with the parser.
|
||||
typedef struct
|
||||
{
|
||||
// Whether to not emit error messages.
|
||||
int silent;
|
||||
// The current input line.
|
||||
const char *line;
|
||||
} user_context;
|
||||
}
|
||||
|
||||
// Emitted in the header file, after the definition of YYSTYPE.
|
||||
@@ -74,9 +83,13 @@
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
# endif
|
||||
int yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc);
|
||||
void yyerror (YYLTYPE *loc, char const *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||
|
||||
yytoken_kind_t
|
||||
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
|
||||
const user_context *uctx);
|
||||
void yyerror (YYLTYPE *loc, const user_context *uctx,
|
||||
char const *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
}
|
||||
|
||||
// Emitted in the implementation file.
|
||||
@@ -116,6 +129,9 @@
|
||||
// Generate the parser description file (calc.output).
|
||||
%verbose
|
||||
|
||||
// User information exchanged with the parser and scanner.
|
||||
%param {const user_context *uctx}
|
||||
|
||||
// Generate YYSTYPE from the types assigned to symbols.
|
||||
%define api.value.type union
|
||||
%token
|
||||
@@ -171,7 +187,7 @@ exp:
|
||||
{
|
||||
if ($r == 0)
|
||||
{
|
||||
yyerror (&@$, "error: division by zero");
|
||||
yyerror (&@$, uctx, "error: division by zero");
|
||||
YYERROR;
|
||||
}
|
||||
else
|
||||
@@ -257,8 +273,9 @@ symbol_count (void)
|
||||
| Scanner. |
|
||||
`----------*/
|
||||
|
||||
int
|
||||
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
|
||||
yytoken_kind_t
|
||||
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
|
||||
const user_context *uctx)
|
||||
{
|
||||
int c;
|
||||
|
||||
@@ -328,7 +345,7 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
|
||||
|
||||
// Stray characters.
|
||||
default:
|
||||
yyerror (yylloc, "syntax error: invalid character: %c", c);
|
||||
yyerror (yylloc, uctx, "syntax error: invalid character: %c", c);
|
||||
return TOK_YYerror;
|
||||
}
|
||||
}
|
||||
@@ -366,8 +383,11 @@ error_format_string (int argc)
|
||||
|
||||
|
||||
int
|
||||
yyreport_syntax_error (const yypcontext_t *ctx)
|
||||
yyreport_syntax_error (const yypcontext_t *ctx, const user_context *uctx)
|
||||
{
|
||||
if (uctx->silent)
|
||||
return 0;
|
||||
|
||||
enum { ARGS_MAX = 6 };
|
||||
yysymbol_kind_t arg[ARGS_MAX];
|
||||
int argsize = yypcontext_expected_tokens (ctx, arg, ARGS_MAX);
|
||||
@@ -378,11 +398,12 @@ yyreport_syntax_error (const yypcontext_t *ctx)
|
||||
argsize = ARGS_MAX;
|
||||
const char *format = error_format_string (1 + argsize + too_many_expected_tokens);
|
||||
|
||||
const YYLTYPE *loc = yypcontext_location (ctx);
|
||||
while (*format)
|
||||
// %@: location.
|
||||
if (format[0] == '%' && format[1] == '@')
|
||||
{
|
||||
YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
|
||||
YY_LOCATION_PRINT (stderr, *loc);
|
||||
format += 2;
|
||||
}
|
||||
// %u: unexpected token.
|
||||
@@ -407,13 +428,25 @@ yyreport_syntax_error (const yypcontext_t *ctx)
|
||||
++format;
|
||||
}
|
||||
fputc ('\n', stderr);
|
||||
|
||||
// Quote the source line.
|
||||
{
|
||||
fprintf (stderr, "%5d | %s\n", loc->first_line, uctx->line);
|
||||
fprintf (stderr, "%5s | %*s", "", loc->first_column, "^");
|
||||
for (int i = loc->last_column - loc->first_column - 1; 0 < i; --i)
|
||||
putc ('~', stderr);
|
||||
putc ('\n', stderr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Called by yyparse on error.
|
||||
void yyerror (YYLTYPE *loc, char const *format, ...)
|
||||
void yyerror (YYLTYPE *loc, const user_context *uctx, char const *format, ...)
|
||||
{
|
||||
if (uctx->silent)
|
||||
return;
|
||||
|
||||
YY_LOCATION_PRINT (stderr, *loc);
|
||||
fputs (": ", stderr);
|
||||
va_list args;
|
||||
@@ -449,11 +482,13 @@ xstrndup (const char *string, size_t n)
|
||||
static int
|
||||
process_line (YYLTYPE *lloc, const char *line)
|
||||
{
|
||||
user_context uctx = {0, line};
|
||||
yypstate *ps = yypstate_new ();
|
||||
int status = 0;
|
||||
do {
|
||||
YYSTYPE lval;
|
||||
status = yypush_parse (ps, yylex (&line, &lval, lloc), &lval, lloc);
|
||||
yytoken_kind_t token = yylex (&line, &lval, lloc, &uctx);
|
||||
status = yypush_parse (ps, token, &lval, lloc, &uctx);
|
||||
} while (status == YYPUSH_MORE);
|
||||
yypstate_delete (ps);
|
||||
lloc->last_line++;
|
||||
@@ -468,18 +503,19 @@ expected_tokens (const char *input,
|
||||
int *tokens, int ntokens)
|
||||
{
|
||||
YYDPRINTF ((stderr, "expected_tokens (\"%s\")", input));
|
||||
user_context uctx = {1, input};
|
||||
|
||||
// Parse the current state of the line.
|
||||
yypstate *ps = yypstate_new ();
|
||||
int status = 0;
|
||||
YYLTYPE lloc = { 1, 1, 1, 1 };
|
||||
do {
|
||||
YYLTYPE lloc = { 1, 1, 1, 1 };
|
||||
YYSTYPE lval;
|
||||
int token = yylex (&input, &lval, &lloc);
|
||||
yytoken_kind_t token = yylex (&input, &lval, &lloc, &uctx);
|
||||
// Don't let the parse know when we reach the end of input.
|
||||
if (!token)
|
||||
if (token == TOK_YYEOF)
|
||||
break;
|
||||
status = yypush_parse (ps, token, &lval, &lloc);
|
||||
status = yypush_parse (ps, token, &lval, &lloc, &uctx);
|
||||
} while (status == YYPUSH_MORE);
|
||||
|
||||
int res = 0;
|
||||
|
||||
@@ -31,6 +31,13 @@ endif FLEX_WORKS
|
||||
|
||||
%D%/parse.c: $(dependencies)
|
||||
|
||||
# Tell Make scan.o depends on parse.h, except that Make sees only
|
||||
# parse.c, not parse.h. We can't use BUILT_SOURCES to this end, since
|
||||
# we use the built bison.
|
||||
%D%/lexcalc$(DASH)scan.o: %D%/parse.c
|
||||
# Likewise, but for Automake before 1.16.
|
||||
%D%/examples_c_lexcalc_lexcalc$(DASH)scan.o: %D%/parse.c
|
||||
|
||||
EXTRA_DIST += %D%/lexcalc.test
|
||||
dist_lexcalc_DATA = %D%/parse.y %D%/scan.l %D%/Makefile %D%/README.md
|
||||
CLEANFILES += %D%/parse.[ch] %D%/scan.c %D%/parse.output
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ EXTRA_DIST += %D%/calc.test
|
||||
|
||||
%D%/calc.d: %D%/calc.y $(dependencies)
|
||||
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||
$(AM_V_at)$(BISON) $(srcdir)/%D%/calc.y -o $@
|
||||
$(AM_V_at)$(BISON) -o $@ $(srcdir)/%D%/calc.y
|
||||
|
||||
%D%/calc: %D%/calc.d
|
||||
$(AM_V_GEN) $(DC) $(DCFLAGS) -of$@ %D%/calc.d
|
||||
|
||||
@@ -27,7 +27,7 @@ EXTRA_DIST += %D%/Calc.test
|
||||
|
||||
%D%/Calc.java: %D%/Calc.y $(dependencies)
|
||||
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||
$(AM_V_at)$(BISON) $(srcdir)/%D%/Calc.y -o $@
|
||||
$(AM_V_at)$(BISON) -o $@ $(srcdir)/%D%/Calc.y
|
||||
|
||||
%D%/Calc.class: %D%/Calc.java
|
||||
$(AM_V_GEN) $(SHELL) $(top_builddir)/javacomp.sh %D%/Calc.java
|
||||
|
||||
@@ -27,7 +27,7 @@ EXTRA_DIST += %D%/Calc.test
|
||||
|
||||
%D%/Calc.java: %D%/Calc.y $(dependencies)
|
||||
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||
$(AM_V_at)$(BISON) $(srcdir)/%D%/Calc.y -o $@
|
||||
$(AM_V_at)$(BISON) -o $@ $(srcdir)/%D%/Calc.y
|
||||
|
||||
%D%/Calc.class: %D%/Calc.java
|
||||
$(AM_V_GEN) $(SHELL) $(top_builddir)/javacomp.sh %D%/Calc.java
|
||||
|
||||
+1
-1
Submodule gnulib updated: 12c89745e3...839ed059f4
+4
-2
@@ -192,8 +192,6 @@
|
||||
/localcharset.h
|
||||
/locale.h
|
||||
/locale.in.h
|
||||
/localtime-buffer.c
|
||||
/localtime-buffer.h
|
||||
/lstat.c
|
||||
/malloc.c
|
||||
/malloca.c
|
||||
@@ -313,6 +311,7 @@
|
||||
/stdlib.h
|
||||
/stdlib.in.h
|
||||
/stpcpy.c
|
||||
/stpncpy.c
|
||||
/strchrnul.c
|
||||
/strchrnul.valgrind
|
||||
/strdup.c
|
||||
@@ -337,8 +336,11 @@
|
||||
/sys_types.in.h
|
||||
/sys_wait.in.h
|
||||
/sysexits.in.h
|
||||
/termios.h
|
||||
/termios.in.h
|
||||
/textstyle.h
|
||||
/textstyle.in.h
|
||||
/thread-optim.h
|
||||
/time.h
|
||||
/time.in.h
|
||||
/timespec.c
|
||||
|
||||
+5
-1
@@ -97,7 +97,6 @@
|
||||
/locale-ja.m4
|
||||
/locale-zh.m4
|
||||
/locale_h.m4
|
||||
/localtime-buffer.m4
|
||||
/lock.m4
|
||||
/longlong.m4
|
||||
/lstat.m4
|
||||
@@ -117,6 +116,7 @@
|
||||
/msvc-inval.m4
|
||||
/msvc-nothrow.m4
|
||||
/multiarch.m4
|
||||
/musl.m4
|
||||
/nls.m4
|
||||
/nocrash.m4
|
||||
/non-recursive-gnulib-prefix-hack.m4
|
||||
@@ -128,6 +128,7 @@
|
||||
/open.m4
|
||||
/pathmax.m4
|
||||
/perror.m4
|
||||
/pid_t.m4
|
||||
/pipe2.m4
|
||||
/po.m4
|
||||
/posix_spawn.m4
|
||||
@@ -175,6 +176,7 @@
|
||||
/stdio_h.m4
|
||||
/stdlib_h.m4
|
||||
/stpcpy.m4
|
||||
/stpncpy.m4
|
||||
/strchrnul.m4
|
||||
/strdup.m4
|
||||
/strerror.m4
|
||||
@@ -183,6 +185,7 @@
|
||||
/strndup.m4
|
||||
/strnlen.m4
|
||||
/strverscmp.m4
|
||||
/sys_ioctl_h.m4
|
||||
/sys_resource_h.m4
|
||||
/sys_socket_h.m4
|
||||
/sys_stat_h.m4
|
||||
@@ -190,6 +193,7 @@
|
||||
/sys_times_h.m4
|
||||
/sys_types_h.m4
|
||||
/sys_wait_h.m4
|
||||
/termios_h.m4
|
||||
/threadlib.m4
|
||||
/time_h.m4
|
||||
/timespec.m4
|
||||
|
||||
@@ -169,10 +169,10 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
|
||||
bitset_copy (tokens, shift_tokens);
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
{
|
||||
bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
|
||||
bitset_and (conflicted_tokens_rule, tokens, reds->lookaheads[i]);
|
||||
bitset_or (conflicted_tokens,
|
||||
conflicted_tokens, conflicted_tokens_rule);
|
||||
bitset_or (tokens, tokens, reds->lookahead_tokens[i]);
|
||||
bitset_or (tokens, tokens, reds->lookaheads[i]);
|
||||
/* Check that rules are sorted on rule number or the next step in
|
||||
AnnotationList__compute_from_inadequacies will misbehave. */
|
||||
aver (i == 0 || reds->rules[i-1] < reds->rules[i]);
|
||||
@@ -401,7 +401,7 @@ AnnotationList__compute_from_inadequacies (
|
||||
struct obstack *annotations_obstackp,
|
||||
InadequacyListNodeCount *inadequacy_list_node_count)
|
||||
{
|
||||
/* Return an empty list if s->lookahead_tokens = NULL. */
|
||||
/* Return an empty list if s->lookaheads = NULL. */
|
||||
if (s->consistent)
|
||||
return;
|
||||
|
||||
@@ -422,7 +422,7 @@ AnnotationList__compute_from_inadequacies (
|
||||
/* Allocate the annotation node. */
|
||||
{
|
||||
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
|
||||
if (bitset_test (s->reductions->lookaheads[rule_i],
|
||||
conflicted_token))
|
||||
++contribution_count;
|
||||
if (bitset_test (shift_tokens, conflicted_token))
|
||||
@@ -445,7 +445,7 @@ AnnotationList__compute_from_inadequacies (
|
||||
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
{
|
||||
rule *the_rule = s->reductions->rules[rule_i];
|
||||
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
|
||||
if (bitset_test (s->reductions->lookaheads[rule_i],
|
||||
conflicted_token))
|
||||
{
|
||||
bitset_set (actions, rule_i);
|
||||
|
||||
+35
-3
@@ -35,6 +35,13 @@
|
||||
#include "getargs.h"
|
||||
#include "quote.h"
|
||||
|
||||
// The URL of the manual page about diagnostics. Use the per-node
|
||||
// manual, to avoid downloading repeatedly the whole manual over the
|
||||
// Internet.
|
||||
static const char *diagnostics_url
|
||||
= "https://www.gnu.org/software/bison/manual/html_node/Diagnostics.html";
|
||||
|
||||
|
||||
err_status complaint_status = status_none;
|
||||
|
||||
bool warnings_are_errors = false;
|
||||
@@ -96,6 +103,20 @@ end_use_class (const char *s, FILE *out)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
begin_hyperlink (FILE *out, const char *ref)
|
||||
{
|
||||
if (out == stderr)
|
||||
styled_ostream_set_hyperlink (errstream, ref, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
end_hyperlink (FILE *out)
|
||||
{
|
||||
if (out == stderr)
|
||||
styled_ostream_set_hyperlink (errstream, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
flush (FILE *out)
|
||||
{
|
||||
@@ -427,9 +448,20 @@ warnings_print_categories (warnings warn_flags, FILE *out)
|
||||
const char* style = severity_style (s);
|
||||
fputs (" [", out);
|
||||
begin_use_class (style, out);
|
||||
fprintf (out, "-W%s%s",
|
||||
s == severity_error ? "error=" : "",
|
||||
argmatch_warning_argument (&w));
|
||||
// E.g., "counterexamples".
|
||||
const char *warning = argmatch_warning_argument (&w);
|
||||
char ref[200];
|
||||
snprintf (ref, sizeof ref,
|
||||
"%s#W%s", diagnostics_url, warning);
|
||||
begin_hyperlink (out, ref);
|
||||
ostream_printf (errstream,
|
||||
"-W%s%s",
|
||||
s == severity_error ? "error=" : "",
|
||||
warning);
|
||||
end_hyperlink (out);
|
||||
// Because we mix stdio with ostream I/O, we need to flush
|
||||
// here for sake of color == debug.
|
||||
flush (out);
|
||||
end_use_class (style, out);
|
||||
fputc (']', out);
|
||||
/* Display only the first match, the second is "-Wall". */
|
||||
|
||||
+29
-25
@@ -250,9 +250,9 @@ flush_shift (state *s, int token)
|
||||
`--------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
flush_reduce (bitset lookahead_tokens, int token)
|
||||
flush_reduce (bitset lookaheads, int token)
|
||||
{
|
||||
bitset_reset (lookahead_tokens, token);
|
||||
bitset_reset (lookaheads, token);
|
||||
}
|
||||
|
||||
|
||||
@@ -275,10 +275,10 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
|
||||
/* Find the rule to reduce by to get precedence of reduction. */
|
||||
rule *redrule = reds->rules[ruleno];
|
||||
int redprec = redrule->prec->prec;
|
||||
bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
|
||||
bitset lookaheads = reds->lookaheads[ruleno];
|
||||
|
||||
for (symbol_number i = 0; i < ntokens; ++i)
|
||||
if (bitset_test (lookahead_tokens, i)
|
||||
if (bitset_test (lookaheads, i)
|
||||
&& bitset_test (lookahead_set, i)
|
||||
&& symbols[i]->content->prec)
|
||||
{
|
||||
@@ -295,7 +295,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
|
||||
{
|
||||
register_precedence (i, redrule->prec->number);
|
||||
log_resolution (redrule, i, shift_resolution);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
flush_reduce (lookaheads, i);
|
||||
}
|
||||
else
|
||||
/* Matching precedence levels.
|
||||
@@ -316,7 +316,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
|
||||
case right_assoc:
|
||||
register_assoc (i, redrule->prec->number);
|
||||
log_resolution (redrule, i, right_resolution);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
flush_reduce (lookaheads, i);
|
||||
break;
|
||||
|
||||
case left_assoc:
|
||||
@@ -329,7 +329,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
|
||||
register_assoc (i, redrule->prec->number);
|
||||
log_resolution (redrule, i, nonassoc_resolution);
|
||||
flush_shift (s, i);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
flush_reduce (lookaheads, i);
|
||||
/* Record an explicit error for this token. */
|
||||
errors[(*nerrs)++] = symbols[i];
|
||||
break;
|
||||
@@ -369,7 +369,7 @@ set_conflicts (state *s, symbol **errors)
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
if (reds->rules[i]->prec
|
||||
&& reds->rules[i]->prec->prec
|
||||
&& !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
|
||||
&& !bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
|
||||
resolve_sr_conflict (s, i, errors, &nerrs);
|
||||
|
||||
if (nerrs)
|
||||
@@ -385,13 +385,13 @@ set_conflicts (state *s, symbol **errors)
|
||||
/* Loop over all rules which require lookahead in this state. Check
|
||||
for conflicts not resolved above.
|
||||
|
||||
reds->lookahead_tokens can be NULL if the LR type is LR(0). */
|
||||
if (reds->lookahead_tokens)
|
||||
reds->lookaheads can be NULL if the LR type is LR(0). */
|
||||
if (reds->lookaheads)
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
{
|
||||
if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
|
||||
if (!bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
|
||||
conflicts[s->number] = true;
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ count_state_sr_conflicts (const state *s)
|
||||
}
|
||||
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);
|
||||
|
||||
bitset_and (lookahead_set, lookahead_set, shift_set);
|
||||
|
||||
@@ -499,7 +499,7 @@ count_state_rr_conflicts (const state *s)
|
||||
{
|
||||
int count = 0;
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
count += bitset_test (reds->lookahead_tokens[j], i);
|
||||
count += bitset_test (reds->lookaheads[j], i);
|
||||
if (2 <= count)
|
||||
res += count-1;
|
||||
}
|
||||
@@ -534,7 +534,7 @@ count_rule_state_sr_conflicts (rule *r, state *s)
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
if (reds->rules[i] == r)
|
||||
{
|
||||
bitset lookaheads = reds->lookahead_tokens[i];
|
||||
bitset lookaheads = reds->lookaheads[i];
|
||||
int j;
|
||||
FOR_EACH_SHIFT (trans, j)
|
||||
res += bitset_test (lookaheads, TRANSITION_SYMBOL (trans, j));
|
||||
@@ -576,8 +576,8 @@ count_rule_state_rr_conflicts (rule *r, state *s)
|
||||
if (reds->rules[j] != r)
|
||||
{
|
||||
bitset_and (lookaheads,
|
||||
reds->lookahead_tokens[i],
|
||||
reds->lookahead_tokens[j]);
|
||||
reds->lookaheads[i],
|
||||
reds->lookaheads[j]);
|
||||
res += bitset_count (lookaheads);
|
||||
}
|
||||
bitset_free (lookaheads);
|
||||
@@ -686,7 +686,8 @@ conflicts_print (void)
|
||||
expected_rr_conflicts = -1;
|
||||
}
|
||||
|
||||
bool has_unexpected_conflicts = false;
|
||||
// The warning flags used to emit a diagnostic, if we did.
|
||||
warnings unexpected_conflicts_warning = Wnone;
|
||||
/* The following two blocks scream for factoring, but i18n support
|
||||
would make it ugly. */
|
||||
{
|
||||
@@ -703,7 +704,8 @@ conflicts_print (void)
|
||||
complain (NULL, complaint,
|
||||
_("shift/reduce conflicts: %d found, %d expected"),
|
||||
total, expected);
|
||||
has_unexpected_conflicts = true;
|
||||
if (total)
|
||||
unexpected_conflicts_warning = complaint;
|
||||
}
|
||||
}
|
||||
else if (total)
|
||||
@@ -713,7 +715,7 @@ conflicts_print (void)
|
||||
"%d shift/reduce conflicts",
|
||||
total),
|
||||
total);
|
||||
has_unexpected_conflicts = true;
|
||||
unexpected_conflicts_warning = Wconflicts_sr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,7 +733,8 @@ conflicts_print (void)
|
||||
complain (NULL, complaint,
|
||||
_("reduce/reduce conflicts: %d found, %d expected"),
|
||||
total, expected);
|
||||
has_unexpected_conflicts = true;
|
||||
if (total)
|
||||
unexpected_conflicts_warning = complaint;
|
||||
}
|
||||
}
|
||||
else if (total)
|
||||
@@ -741,15 +744,16 @@ conflicts_print (void)
|
||||
"%d reduce/reduce conflicts",
|
||||
total),
|
||||
total);
|
||||
has_unexpected_conflicts = true;
|
||||
unexpected_conflicts_warning = Wconflicts_rr;
|
||||
}
|
||||
}
|
||||
|
||||
if (warning_is_enabled (Wcounterexamples))
|
||||
report_counterexamples ();
|
||||
else if (has_unexpected_conflicts)
|
||||
complain (NULL, Wother,
|
||||
_("rerun with option '-Wcounterexamples' to generate conflict counterexamples"));
|
||||
else if (unexpected_conflicts_warning != Wnone)
|
||||
subcomplain (NULL, unexpected_conflicts_warning,
|
||||
_("rerun with option '-Wcounterexamples'"
|
||||
" to generate conflict counterexamples"));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+173
-105
@@ -26,6 +26,7 @@
|
||||
#include <gl_linked_list.h>
|
||||
#include <gl_rbtreehash_list.h>
|
||||
#include <hash.h>
|
||||
#include <mbswidth.h>
|
||||
#include <stdlib.h>
|
||||
#include <textstyle.h>
|
||||
#include <time.h>
|
||||
@@ -76,17 +77,29 @@ typedef struct
|
||||
{
|
||||
derivation *d1;
|
||||
derivation *d2;
|
||||
bool shift_reduce;
|
||||
bool unifying;
|
||||
bool timeout;
|
||||
} counterexample;
|
||||
|
||||
static counterexample *
|
||||
new_counterexample (derivation *d1, derivation *d2,
|
||||
bool shift_reduce,
|
||||
bool u, bool t)
|
||||
{
|
||||
counterexample *res = xmalloc (sizeof (counterexample));
|
||||
res->d1 = d1;
|
||||
res->d2 = d2;
|
||||
counterexample *res = xmalloc (sizeof *res);
|
||||
res->shift_reduce = shift_reduce;
|
||||
if (shift_reduce)
|
||||
{
|
||||
// Display the shift first.
|
||||
res->d1 = d2;
|
||||
res->d2 = d1;
|
||||
}
|
||||
else
|
||||
{
|
||||
res->d1 = d1;
|
||||
res->d2 = d2;
|
||||
}
|
||||
res->unifying = u;
|
||||
res->timeout = t;
|
||||
return res;
|
||||
@@ -101,13 +114,31 @@ free_counterexample (counterexample *cex)
|
||||
}
|
||||
|
||||
static void
|
||||
print_counterexample (counterexample *cex, FILE *out, const char *prefix)
|
||||
counterexample_print (const counterexample *cex, FILE *out, const char *prefix)
|
||||
{
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, cex->unifying ? _("Example") : _("First example"));
|
||||
derivation_print_leaves (cex->d1, out, prefix);
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, _("First derivation"));
|
||||
const bool flat = getenv ("YYFLAT");
|
||||
const char *example1_label
|
||||
= cex->unifying ? _("Example") : _("First example");
|
||||
const char *example2_label
|
||||
= cex->unifying ? _("Example") : _("Second example");
|
||||
const char *deriv1_label
|
||||
= cex->shift_reduce ? _("Shift derivation") : _("First reduce derivation");
|
||||
const char *deriv2_label
|
||||
= cex->shift_reduce ? _("Reduce derivation") : _("Second reduce derivation");
|
||||
const int width =
|
||||
max_int (max_int (mbswidth (example1_label, 0), mbswidth (example2_label, 0)),
|
||||
max_int (mbswidth (deriv1_label, 0), mbswidth (deriv2_label, 0)));
|
||||
if (flat)
|
||||
fprintf (out, " %s%s%*s ", prefix,
|
||||
example1_label, width - mbswidth (example1_label, 0), "");
|
||||
else
|
||||
fprintf (out, " %s%s: ", prefix, example1_label);
|
||||
derivation_print_leaves (cex->d1, out);
|
||||
if (flat)
|
||||
fprintf (out, " %s%s%*s ", prefix,
|
||||
deriv1_label, width - mbswidth (deriv1_label, 0), "");
|
||||
else
|
||||
fprintf (out, " %s%s", prefix, deriv1_label);
|
||||
derivation_print (cex->d1, out, prefix);
|
||||
|
||||
// If we output to the terminal (via stderr) and we have color
|
||||
@@ -115,15 +146,22 @@ print_counterexample (counterexample *cex, FILE *out, const char *prefix)
|
||||
// to see the differences.
|
||||
if (!cex->unifying || is_styled (stderr))
|
||||
{
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, cex->unifying ? _("Example") : _("Second example"));
|
||||
derivation_print_leaves (cex->d2, out, prefix);
|
||||
if (flat)
|
||||
fprintf (out, " %s%s%*s ", prefix,
|
||||
example2_label, width - mbswidth (example2_label, 0), "");
|
||||
else
|
||||
fprintf (out, " %s%s: ", prefix, example2_label);
|
||||
derivation_print_leaves (cex->d2, out);
|
||||
}
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, _("Second derivation"));
|
||||
if (flat)
|
||||
fprintf (out, " %s%s%*s ", prefix,
|
||||
deriv2_label, width - mbswidth (deriv2_label, 0), "");
|
||||
else
|
||||
fprintf (out, " %s%s", prefix, deriv2_label);
|
||||
derivation_print (cex->d2, out, prefix);
|
||||
|
||||
fputc ('\n', out);
|
||||
if (out != stderr)
|
||||
putc ('\n', out);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -144,7 +182,7 @@ typedef struct si_bfs_node
|
||||
static si_bfs_node *
|
||||
si_bfs_new (state_item_number si, si_bfs_node *parent)
|
||||
{
|
||||
si_bfs_node *res = xcalloc (1, sizeof (si_bfs_node));
|
||||
si_bfs_node *res = xcalloc (1, sizeof *res);
|
||||
res->si = si;
|
||||
res->parent = parent;
|
||||
res->reference_count = 1;
|
||||
@@ -175,6 +213,8 @@ si_bfs_free (si_bfs_node *n)
|
||||
}
|
||||
}
|
||||
|
||||
typedef gl_list_t si_bfs_node_list;
|
||||
|
||||
/**
|
||||
* start is a state_item such that conflict_sym is an element of FIRSTS of the
|
||||
* nonterminal after the dot in start. Because of this, we should be able to
|
||||
@@ -188,15 +228,16 @@ expand_to_conflict (state_item_number start, symbol_number conflict_sym)
|
||||
{
|
||||
si_bfs_node *init = si_bfs_new (start, NULL);
|
||||
|
||||
gl_list_t queue = gl_list_create (GL_LINKED_LIST, NULL, NULL,
|
||||
(gl_listelement_dispose_fn) si_bfs_free,
|
||||
true, 1, (const void **) &init);
|
||||
si_bfs_node_list queue
|
||||
= gl_list_create (GL_LINKED_LIST, NULL, NULL,
|
||||
(gl_listelement_dispose_fn) si_bfs_free,
|
||||
true, 1, (const void **) &init);
|
||||
si_bfs_node *node = NULL;
|
||||
// breadth-first search for a path of productions to the conflict symbol
|
||||
while (gl_list_size (queue) > 0)
|
||||
{
|
||||
node = (si_bfs_node *) gl_list_get_at (queue, 0);
|
||||
state_item *silast = state_items + node->si;
|
||||
state_item *silast = &state_items[node->si];
|
||||
symbol_number sym = item_number_as_symbol_number (*silast->item);
|
||||
if (sym == conflict_sym)
|
||||
break;
|
||||
@@ -238,7 +279,7 @@ expand_to_conflict (state_item_number start, symbol_number conflict_sym)
|
||||
|
||||
for (si_bfs_node *n = node; n != NULL; n = n->parent)
|
||||
{
|
||||
state_item *si = state_items + n->si;
|
||||
state_item *si = &state_items[n->si];
|
||||
item_number *pos = si->item;
|
||||
if (SI_PRODUCTION (si))
|
||||
{
|
||||
@@ -274,7 +315,7 @@ expand_to_conflict (state_item_number start, symbol_number conflict_sym)
|
||||
*/
|
||||
static derivation *
|
||||
complete_diverging_example (symbol_number conflict_sym,
|
||||
gl_list_t path, derivation_list derivs)
|
||||
state_item_list path, derivation_list derivs)
|
||||
{
|
||||
// The idea is to transfer each pending symbol on the productions
|
||||
// associated with the given StateItems to the resulting derivation.
|
||||
@@ -395,15 +436,15 @@ complete_diverging_example (symbol_number conflict_sym,
|
||||
/* Iterate backwards through the shifts of the path in the reduce
|
||||
conflict, and find a path of shifts from the shift conflict that
|
||||
goes through the same states. */
|
||||
static gl_list_t
|
||||
nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
static state_item_list
|
||||
nonunifying_shift_path (state_item_list reduce_path, state_item *shift_conflict)
|
||||
{
|
||||
gl_list_node_t tmp = gl_list_add_last (reduce_path, NULL);
|
||||
gl_list_node_t next_node = gl_list_previous_node (reduce_path, tmp);
|
||||
gl_list_node_t node = gl_list_previous_node (reduce_path, next_node);
|
||||
gl_list_remove_node (reduce_path, tmp);
|
||||
state_item *si = shift_conflict;
|
||||
gl_list_t result =
|
||||
state_item_list result =
|
||||
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
|
||||
// FIXME: bool paths_merged;
|
||||
for (; node != NULL; next_node = node,
|
||||
@@ -425,10 +466,10 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
|
||||
// bfs to find a shift to the right state
|
||||
si_bfs_node *init = si_bfs_new (si - state_items, NULL);
|
||||
gl_list_t queue =
|
||||
gl_list_create (GL_LINKED_LIST, NULL, NULL,
|
||||
(gl_listelement_dispose_fn) si_bfs_free,
|
||||
true, 1, (const void **) &init);
|
||||
si_bfs_node_list queue
|
||||
= gl_list_create (GL_LINKED_LIST, NULL, NULL,
|
||||
(gl_listelement_dispose_fn) si_bfs_free,
|
||||
true, 1, (const void **) &init);
|
||||
si_bfs_node *sis = NULL;
|
||||
state_item *prevsi = NULL;
|
||||
while (gl_list_size (queue) > 0)
|
||||
@@ -438,7 +479,7 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
if (sis->si == 0)
|
||||
break;
|
||||
|
||||
state_item *search_si = state_items + sis->si;
|
||||
state_item *search_si = &state_items[sis->si];
|
||||
// if the current state-item is a production item,
|
||||
// its reverse production items get added to the queue.
|
||||
// Otherwise, look for a reverse transition to the target state.
|
||||
@@ -447,7 +488,7 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
state_item_number sin;
|
||||
BITSET_FOR_EACH (biter, rsi, sin, 0)
|
||||
{
|
||||
prevsi = state_items + sin;
|
||||
prevsi = &state_items[sin];
|
||||
if (SI_TRANSITION (search_si))
|
||||
{
|
||||
if (prevsi->state == refsi->state)
|
||||
@@ -465,9 +506,9 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
// prepend path to shift we found
|
||||
if (sis)
|
||||
{
|
||||
gl_list_node_t ln = gl_list_add_first (result, state_items + sis->si);
|
||||
gl_list_node_t ln = gl_list_add_first (result, &state_items[sis->si]);
|
||||
for (si_bfs_node *n = sis->parent; n; n = n->parent)
|
||||
ln = gl_list_add_after (result, ln, state_items + n->si);
|
||||
ln = gl_list_add_after (result, ln, &state_items[n->si]);
|
||||
|
||||
}
|
||||
si = prevsi;
|
||||
@@ -480,7 +521,7 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
for (gl_list_iterator_t it = gl_list_iterator (result);
|
||||
state_item_list_next (&it, &sip);
|
||||
)
|
||||
print_state_item (sip, stderr, "");
|
||||
state_item_print (sip, stderr, "");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -493,17 +534,17 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
|
||||
static counterexample *
|
||||
example_from_path (bool shift_reduce,
|
||||
state_item_number itm2,
|
||||
gl_list_t shortest_path, symbol_number next_sym)
|
||||
state_item_list shortest_path, symbol_number next_sym)
|
||||
{
|
||||
derivation *deriv1 =
|
||||
complete_diverging_example (next_sym, shortest_path, NULL);
|
||||
gl_list_t path_2
|
||||
state_item_list path_2
|
||||
= shift_reduce
|
||||
? nonunifying_shift_path (shortest_path, &state_items [itm2])
|
||||
: shortest_path_from_start (itm2, next_sym);
|
||||
derivation *deriv2 = complete_diverging_example (next_sym, path_2, NULL);
|
||||
gl_list_free (path_2);
|
||||
return new_counterexample (deriv1, deriv2, false, true);
|
||||
return new_counterexample (deriv1, deriv2, shift_reduce, false, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -525,7 +566,7 @@ typedef struct
|
||||
static search_state *
|
||||
initial_search_state (state_item *conflict1, state_item *conflict2)
|
||||
{
|
||||
search_state *res = xmalloc (sizeof (search_state));
|
||||
search_state *res = xmalloc (sizeof *res);
|
||||
res->states[0] = new_parse_state (conflict1);
|
||||
res->states[1] = new_parse_state (conflict2);
|
||||
parse_state_retain (res->states[0]);
|
||||
@@ -537,7 +578,7 @@ initial_search_state (state_item *conflict1, state_item *conflict2)
|
||||
static search_state *
|
||||
new_search_state (parse_state *ps1, parse_state *ps2, int complexity)
|
||||
{
|
||||
search_state *res = xmalloc (sizeof (search_state));
|
||||
search_state *res = xmalloc (sizeof *res);
|
||||
res->states[0] = ps1;
|
||||
res->states[1] = ps2;
|
||||
parse_state_retain (res->states[0]);
|
||||
@@ -549,8 +590,8 @@ new_search_state (parse_state *ps1, parse_state *ps2, int complexity)
|
||||
static search_state *
|
||||
copy_search_state (search_state *parent)
|
||||
{
|
||||
search_state *res = xmalloc (sizeof (search_state));
|
||||
memcpy (res, parent, sizeof (search_state));
|
||||
search_state *res = xmalloc (sizeof *res);
|
||||
*res = *parent;
|
||||
parse_state_retain (res->states[0]);
|
||||
parse_state_retain (res->states[1]);
|
||||
return res;
|
||||
@@ -583,6 +624,8 @@ search_state_print (search_state *ss)
|
||||
putc ('\n', stderr);
|
||||
}
|
||||
|
||||
typedef gl_list_t search_state_list;
|
||||
|
||||
static inline bool
|
||||
search_state_list_next (gl_list_iterator_t *it, search_state **ss)
|
||||
{
|
||||
@@ -614,18 +657,20 @@ ss_set_parse_state (search_state *ss, int idx, parse_state *ps)
|
||||
*/
|
||||
static counterexample *
|
||||
complete_diverging_examples (search_state *ss,
|
||||
symbol_number next_sym)
|
||||
symbol_number next_sym,
|
||||
bool shift_reduce)
|
||||
{
|
||||
derivation *new_derivs[2];
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
gl_list_t sitems;
|
||||
state_item_list sitems;
|
||||
derivation_list derivs;
|
||||
parse_state_lists (ss->states[i], &sitems, &derivs);
|
||||
new_derivs[i] = complete_diverging_example (next_sym, sitems, derivs);
|
||||
gl_list_free (sitems);
|
||||
}
|
||||
return new_counterexample (new_derivs[0], new_derivs[1], false, true);
|
||||
return new_counterexample (new_derivs[0], new_derivs[1],
|
||||
shift_reduce, false, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -635,7 +680,7 @@ complete_diverging_examples (search_state *ss,
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gl_list_t states;
|
||||
search_state_list states;
|
||||
int complexity;
|
||||
} search_state_bundle;
|
||||
|
||||
@@ -664,6 +709,8 @@ ssb_equals (const search_state_bundle *s1, const search_state_bundle *s2)
|
||||
return s1->complexity == s2->complexity;
|
||||
}
|
||||
|
||||
typedef gl_list_t ssb_list;
|
||||
|
||||
static size_t
|
||||
visited_hasher (const search_state *ss, size_t max)
|
||||
{
|
||||
@@ -679,7 +726,7 @@ visited_comparator (const search_state *ss1, const search_state *ss2)
|
||||
}
|
||||
|
||||
/* Priority queue for search states with minimal complexity. */
|
||||
static gl_list_t ssb_queue;
|
||||
static ssb_list ssb_queue;
|
||||
static Hash_table *visited;
|
||||
/* The set of parser states on the shortest lookahead-sensitive path. */
|
||||
static bitset scp_set = NULL;
|
||||
@@ -702,7 +749,7 @@ ssb_append (search_state *ss)
|
||||
parse_state_free_contents_early (ss->states[1]);
|
||||
parse_state_retain (ss->states[0]);
|
||||
parse_state_retain (ss->states[1]);
|
||||
search_state_bundle *ssb = xmalloc (sizeof (search_state_bundle));
|
||||
search_state_bundle *ssb = xmalloc (sizeof *ssb);
|
||||
ssb->complexity = ss->complexity;
|
||||
gl_list_node_t n = gl_list_search (ssb_queue, ssb);
|
||||
if (!n)
|
||||
@@ -756,12 +803,12 @@ reduction_cost (const parse_state *ps)
|
||||
return SHIFT_COST * shifts + PRODUCTION_COST * productions;
|
||||
}
|
||||
|
||||
static gl_list_t
|
||||
static search_state_list
|
||||
reduction_step (search_state *ss, const item_number *conflict_item,
|
||||
int parser_state, int rule_len)
|
||||
{
|
||||
(void) conflict_item; // FIXME: Unused
|
||||
gl_list_t result =
|
||||
search_state_list result =
|
||||
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, 1);
|
||||
|
||||
parse_state *ps = ss->states[parser_state];
|
||||
@@ -897,7 +944,7 @@ search_state_prepend (search_state *ss, symbol_number sym, bitset guide)
|
||||
* the same prefix up to the dot.
|
||||
*/
|
||||
static bool
|
||||
has_common_prefix (const item_number *itm1, const item_number *itm2)
|
||||
have_common_prefix (const item_number *itm1, const item_number *itm2)
|
||||
{
|
||||
int i = 0;
|
||||
for (; !item_number_is_rule_number (itm1[i]); ++i)
|
||||
@@ -988,14 +1035,14 @@ generate_next_states (search_state *ss, state_item *conflict1,
|
||||
// prepended further, reduce.
|
||||
if (ready1 && ready2)
|
||||
{
|
||||
gl_list_t reduced1 = reduction_step (ss, conflict1->item, 0, len1);
|
||||
search_state_list reduced1 = reduction_step (ss, conflict1->item, 0, len1);
|
||||
gl_list_add_last (reduced1, ss);
|
||||
search_state *red1 = NULL;
|
||||
for (gl_list_iterator_t iter = gl_list_iterator (reduced1);
|
||||
search_state_list_next (&iter, &red1);
|
||||
)
|
||||
{
|
||||
gl_list_t reduced2 =
|
||||
search_state_list reduced2 =
|
||||
reduction_step (red1, conflict2->item, 1, len2);
|
||||
search_state *red2 = NULL;
|
||||
for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2);
|
||||
@@ -1011,7 +1058,7 @@ generate_next_states (search_state *ss, state_item *conflict1,
|
||||
}
|
||||
else if (ready1)
|
||||
{
|
||||
gl_list_t reduced1 = reduction_step (ss, conflict1->item, 0, len1);
|
||||
search_state_list reduced1 = reduction_step (ss, conflict1->item, 0, len1);
|
||||
search_state *red1 = NULL;
|
||||
for (gl_list_iterator_t iter = gl_list_iterator (reduced1);
|
||||
search_state_list_next (&iter, &red1);
|
||||
@@ -1021,7 +1068,7 @@ generate_next_states (search_state *ss, state_item *conflict1,
|
||||
}
|
||||
else if (ready2)
|
||||
{
|
||||
gl_list_t reduced2 = reduction_step (ss, conflict2->item, 1, len2);
|
||||
search_state_list reduced2 = reduction_step (ss, conflict2->item, 1, len2);
|
||||
search_state *red2 = NULL;
|
||||
for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2);
|
||||
search_state_list_next (&iter2, &red2);
|
||||
@@ -1055,10 +1102,10 @@ static counterexample *
|
||||
unifying_example (state_item_number itm1,
|
||||
state_item_number itm2,
|
||||
bool shift_reduce,
|
||||
gl_list_t reduce_path, symbol_number next_sym)
|
||||
state_item_list reduce_path, symbol_number next_sym)
|
||||
{
|
||||
state_item *conflict1 = state_items + itm1;
|
||||
state_item *conflict2 = state_items + itm2;
|
||||
state_item *conflict1 = &state_items[itm1];
|
||||
state_item *conflict2 = &state_items[itm2];
|
||||
search_state *initial = initial_search_state (conflict1, conflict2);
|
||||
ssb_queue = gl_list_create_empty (GL_RBTREEHASH_LIST,
|
||||
(gl_listelement_equals_fn) ssb_equals,
|
||||
@@ -1094,7 +1141,7 @@ unifying_example (state_item_number itm1,
|
||||
const state_item *si1src = parse_state_head (ps1);
|
||||
const state_item *si2src = parse_state_head (ps2);
|
||||
if (item_rule (si1src->item)->lhs == item_rule (si2src->item)->lhs
|
||||
&& has_common_prefix (si1src->item, si2src->item))
|
||||
&& have_common_prefix (si1src->item, si2src->item))
|
||||
{
|
||||
// Stage 4: both paths share a prefix
|
||||
derivation *d1 = parse_state_derivation (ps1);
|
||||
@@ -1104,7 +1151,7 @@ unifying_example (state_item_number itm1,
|
||||
{
|
||||
// Once we have two derivations for the same symbol,
|
||||
// we've found a unifying counterexample.
|
||||
cex = new_counterexample (d1, d2, true, false);
|
||||
cex = new_counterexample (d1, d2, shift_reduce, true, false);
|
||||
derivation_retain (d1);
|
||||
derivation_retain (d2);
|
||||
goto cex_search_end;
|
||||
@@ -1142,7 +1189,7 @@ cex_search_end:;
|
||||
// If a search state from Stage 3 is available, use it
|
||||
// to construct a more compact nonunifying counterexample.
|
||||
if (stage3result)
|
||||
cex = complete_diverging_examples (stage3result, next_sym);
|
||||
cex = complete_diverging_examples (stage3result, next_sym, shift_reduce);
|
||||
// Otherwise, construct a nonunifying counterexample that
|
||||
// begins from the start state using the shortest
|
||||
// lookahead-sensitive path to the reduce item.
|
||||
@@ -1190,7 +1237,7 @@ counterexample_report (state_item_number itm1, state_item_number itm2,
|
||||
{
|
||||
// Compute the shortest lookahead-sensitive path and associated sets of
|
||||
// parser states.
|
||||
gl_list_t shortest_path = shortest_path_from_start (itm1, next_sym);
|
||||
state_item_list shortest_path = shortest_path_from_start (itm1, next_sym);
|
||||
bool reduce_prod_reached = false;
|
||||
const rule *reduce_rule = item_rule (state_items[itm1].item);
|
||||
|
||||
@@ -1215,21 +1262,31 @@ counterexample_report (state_item_number itm1, state_item_number itm2,
|
||||
: example_from_path (shift_reduce, itm2, shortest_path, next_sym);
|
||||
|
||||
gl_list_free (shortest_path);
|
||||
print_counterexample (cex, out, prefix);
|
||||
counterexample_print (cex, out, prefix);
|
||||
free_counterexample (cex);
|
||||
}
|
||||
|
||||
|
||||
// ITM1 denotes a shift, ITM2 a reduce.
|
||||
static void
|
||||
counterexample_report_shift_reduce (state_item_number itm1, state_item_number itm2,
|
||||
symbol_number next_sym,
|
||||
FILE *out, const char *prefix)
|
||||
{
|
||||
fputs (prefix, out);
|
||||
fprintf (out, _("Shift/reduce conflict on token %s:\n"), symbols[next_sym]->tag);
|
||||
if (*prefix)
|
||||
if (out == stderr)
|
||||
complain (NULL, Wcounterexamples,
|
||||
_("shift/reduce conflict on token %s"), symbols[next_sym]->tag);
|
||||
else
|
||||
{
|
||||
print_state_item (&state_items[itm1], out, prefix);
|
||||
print_state_item (&state_items[itm2], out, prefix);
|
||||
fputs (prefix, out);
|
||||
fprintf (out, _("shift/reduce conflict on token %s"), symbols[next_sym]->tag);
|
||||
fprintf (out, "%s\n", _(":"));
|
||||
}
|
||||
// In the report, print the items.
|
||||
if (out != stderr || trace_flag & trace_cex)
|
||||
{
|
||||
state_item_print (&state_items[itm1], out, prefix);
|
||||
state_item_print (&state_items[itm2], out, prefix);
|
||||
}
|
||||
counterexample_report (itm1, itm2, next_sym, true, out, prefix);
|
||||
}
|
||||
@@ -1240,32 +1297,49 @@ counterexample_report_reduce_reduce (state_item_number itm1, state_item_number i
|
||||
FILE *out, const char *prefix)
|
||||
{
|
||||
{
|
||||
fputs (prefix, out);
|
||||
fputs (ngettext ("Reduce/reduce conflict on token",
|
||||
"Reduce/reduce conflict on tokens",
|
||||
bitset_count (conflict_syms)), out);
|
||||
struct obstack obstack;
|
||||
obstack_init (&obstack);
|
||||
bitset_iterator biter;
|
||||
state_item_number sym;
|
||||
const char *sep = " ";
|
||||
const char *sep = "";
|
||||
BITSET_FOR_EACH (biter, conflict_syms, sym, 0)
|
||||
{
|
||||
fprintf (out, "%s%s", sep, symbols[sym]->tag);
|
||||
obstack_printf (&obstack, "%s%s", sep, symbols[sym]->tag);
|
||||
sep = ", ";
|
||||
}
|
||||
fputs (_(":\n"), out);
|
||||
char *tokens = obstack_finish0 (&obstack);
|
||||
if (out == stderr)
|
||||
complain (NULL, Wcounterexamples,
|
||||
ngettext ("reduce/reduce conflict on token %s",
|
||||
"reduce/reduce conflict on tokens %s",
|
||||
bitset_count (conflict_syms)),
|
||||
tokens);
|
||||
else
|
||||
{
|
||||
fputs (prefix, out);
|
||||
fprintf (out,
|
||||
ngettext ("reduce/reduce conflict on token %s",
|
||||
"reduce/reduce conflict on tokens %s",
|
||||
bitset_count (conflict_syms)),
|
||||
tokens);
|
||||
fprintf (out, "%s\n", _(":"));
|
||||
}
|
||||
obstack_free (&obstack, NULL);
|
||||
}
|
||||
if (*prefix)
|
||||
// In the report, print the items.
|
||||
if (out != stderr || trace_flag & trace_cex)
|
||||
{
|
||||
print_state_item (&state_items[itm1], out, prefix);
|
||||
print_state_item (&state_items[itm2], out, prefix);
|
||||
state_item_print (&state_items[itm1], out, prefix);
|
||||
state_item_print (&state_items[itm2], out, prefix);
|
||||
}
|
||||
counterexample_report (itm1, itm2, bitset_first (conflict_syms), false, out, prefix);
|
||||
counterexample_report (itm1, itm2, bitset_first (conflict_syms),
|
||||
false, out, prefix);
|
||||
}
|
||||
|
||||
static state_item_number
|
||||
find_state_item_number (const rule *r, state_number sn)
|
||||
{
|
||||
for (int i = state_item_map[sn]; i < state_item_map[sn + 1]; ++i)
|
||||
for (state_item_number i = state_item_map[sn]; i < state_item_map[sn + 1]; ++i)
|
||||
if (!SI_DISABLED (i)
|
||||
&& item_number_as_rule_number (*state_items[i].item) == r->number)
|
||||
return i;
|
||||
@@ -1277,41 +1351,35 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
|
||||
{
|
||||
const state_number sn = s->number;
|
||||
const reductions *reds = s->reductions;
|
||||
bitset lookaheads = bitset_create (ntokens, BITSET_FIXED);
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
{
|
||||
const rule *r1 = reds->rules[i];
|
||||
const state_item_number c1 = find_state_item_number (r1, sn);
|
||||
for (int j = state_item_map[sn]; j < state_item_map[sn + 1]; ++j)
|
||||
if (!SI_DISABLED (j))
|
||||
for (state_item_number c2 = state_item_map[sn]; c2 < state_item_map[sn + 1]; ++c2)
|
||||
if (!SI_DISABLED (c2))
|
||||
{
|
||||
state_item *si = state_items + j;
|
||||
item_number conf = *si->item;
|
||||
item_number conf = *state_items[c2].item;
|
||||
if (item_number_is_symbol_number (conf)
|
||||
&& bitset_test (reds->lookahead_tokens[i], conf))
|
||||
counterexample_report_shift_reduce (c1, j, conf, out, prefix);
|
||||
&& bitset_test (reds->lookaheads[i], conf))
|
||||
counterexample_report_shift_reduce (c1, c2, conf, out, prefix);
|
||||
}
|
||||
for (int j = i+1; j < reds->num; ++j)
|
||||
{
|
||||
bitset conf = bitset_create (ntokens, BITSET_FIXED);
|
||||
bitset_intersection (conf,
|
||||
reds->lookahead_tokens[i],
|
||||
reds->lookahead_tokens[j]);
|
||||
if (!bitset_empty_p (conf))
|
||||
{
|
||||
const rule *r2 = reds->rules[j];
|
||||
for (int k = state_item_map[sn]; k < state_item_map[sn + 1]; ++k)
|
||||
if (!SI_DISABLED (k))
|
||||
{
|
||||
state_item *si = state_items + k;
|
||||
const rule *r = item_rule (si->item);
|
||||
if (r == r2)
|
||||
{
|
||||
counterexample_report_reduce_reduce (c1, k, conf, out, prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bitset_free (conf);
|
||||
const rule *r2 = reds->rules[j];
|
||||
// Conflicts: common lookaheads.
|
||||
bitset_intersection (lookaheads,
|
||||
reds->lookaheads[i],
|
||||
reds->lookaheads[j]);
|
||||
if (!bitset_empty_p (lookaheads))
|
||||
for (state_item_number c2 = state_item_map[sn]; c2 < state_item_map[sn + 1]; ++c2)
|
||||
if (!SI_DISABLED (c2)
|
||||
&& item_rule (state_items[c2].item) == r2)
|
||||
{
|
||||
counterexample_report_reduce_reduce (c1, c2, lookaheads, out, prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bitset_free (lookaheads);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,17 @@
|
||||
#ifndef COUNTEREXAMPLE_H
|
||||
# define COUNTEREXAMPLE_H
|
||||
|
||||
# include "state-item.h"
|
||||
# include "state.h"
|
||||
|
||||
// Init/deinit this module.
|
||||
void counterexample_init (void);
|
||||
void counterexample_free (void);
|
||||
|
||||
void counterexample_report_state (const state *s, FILE *out, const char *prefix);
|
||||
// Print the counterexamples for the conflicts of state S.
|
||||
//
|
||||
// Used both for the warnings on the terminal (OUT = stderr, PREFIX =
|
||||
// ""), and for the reports (OUT != stderr, PREFIX != "").
|
||||
void
|
||||
counterexample_report_state (const state *s, FILE *out, const char *prefix);
|
||||
|
||||
#endif /* COUNTEREXAMPLE_H */
|
||||
|
||||
+271
-46
@@ -20,8 +20,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "derivation.h"
|
||||
#include "glyphs.h"
|
||||
|
||||
#include <c-ctype.h>
|
||||
#include <gl_linked_list.h>
|
||||
#include <mbswidth.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "complain.h"
|
||||
@@ -29,11 +32,15 @@
|
||||
struct derivation
|
||||
{
|
||||
symbol_number sym;
|
||||
gl_list_t children;
|
||||
derivation_list children;
|
||||
int reference_count;
|
||||
// Color assigned for styling. Guarantees that the derivation is
|
||||
// always displayed with the same color, independently of the order
|
||||
// in which the derivations are traversed.
|
||||
int color;
|
||||
};
|
||||
|
||||
static derivation d_dot = { -1, NULL, -1 };
|
||||
static derivation d_dot = { -1, NULL, -1, -1 };
|
||||
|
||||
derivation *
|
||||
derivation_dot (void)
|
||||
@@ -69,11 +76,12 @@ void derivation_list_free (derivation_list dl)
|
||||
derivation *
|
||||
derivation_new (symbol_number sym, derivation_list children)
|
||||
{
|
||||
derivation *deriv = xmalloc (sizeof (derivation));
|
||||
deriv->sym = sym;
|
||||
deriv->children = children;
|
||||
deriv->reference_count = 0;
|
||||
return deriv;
|
||||
derivation *res = xmalloc (sizeof *res);
|
||||
res->sym = sym;
|
||||
res->children = children;
|
||||
res->reference_count = 0;
|
||||
res->color = -1;
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -126,27 +134,236 @@ derivation_size (const derivation *deriv)
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Print DERIV, colored according to COUNTER.
|
||||
Return false if nothing is printed. */
|
||||
|
||||
// Longest distance from root to leaf.
|
||||
static int
|
||||
derivation_depth (const derivation *deriv)
|
||||
{
|
||||
if (deriv->children)
|
||||
{
|
||||
// Children's depth cannot be 0, even if there are no children
|
||||
// (the case of a derivation with an empty RHS).
|
||||
int res = 1;
|
||||
derivation *child;
|
||||
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
|
||||
derivation_list_next (&it, &child);
|
||||
)
|
||||
res = max_int (res, derivation_depth (child));
|
||||
return res + 1;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool
|
||||
derivation_print_impl (const derivation *deriv, FILE *f,
|
||||
bool leaves_only,
|
||||
int *counter, const char *prefix)
|
||||
all_spaces (const char *s)
|
||||
{
|
||||
while (c_isspace (*s))
|
||||
s++;
|
||||
return *s == '\0';
|
||||
}
|
||||
|
||||
// Printing the derivation as trees without trailing spaces is
|
||||
// painful: we cannot simply pad one "column" before moving to the
|
||||
// next:
|
||||
//
|
||||
// exp
|
||||
// ↳ x1 e1 foo1 x1
|
||||
// ↳ x2 ↳ ε ↳ foo2 ↳ x2
|
||||
// ↳ x3 ↳ foo3 ↳ x3
|
||||
// ↳ "X" • ↳ x1 foo4 ↳ "X"
|
||||
// ↳ x2 ↳ "quuux"
|
||||
// ↳ x3
|
||||
// ↳ "X"
|
||||
//
|
||||
// It's hard for a column to know that it's "last" to decide whether
|
||||
// to output the right-padding or not. So when we need to pad on the
|
||||
// right to complete a column, we don't output the spaces, we
|
||||
// accumulate the width of padding in *PADDING.
|
||||
//
|
||||
// Each time we actually print something (non space), we flush that
|
||||
// padding. When we _don't_ print something, its width is added to
|
||||
// the current padding.
|
||||
//
|
||||
// This function implements this.
|
||||
//
|
||||
// When COND is true, put S on OUT, preceded by *PADDING white spaces.
|
||||
// Otherwise add the width to *PADDING. Return the width of S.
|
||||
static int
|
||||
fputs_if (bool cond, FILE *out, int *padding, const char *s)
|
||||
{
|
||||
int res = mbswidth (s, 0);
|
||||
if (cond && !all_spaces (s))
|
||||
{
|
||||
fprintf (out, "%*s%s", *padding, "", s);
|
||||
*padding = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*padding += res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// The width taken to report this derivation recursively down to its
|
||||
// leaves.
|
||||
static int
|
||||
derivation_width (const derivation *deriv)
|
||||
{
|
||||
if (deriv->children)
|
||||
{
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
int self_width = mbswidth (sym->tag, 0);
|
||||
|
||||
// Arrow and space.
|
||||
int children_width = down_arrow_width;
|
||||
if (gl_list_size (deriv->children) == 0)
|
||||
// Empty rhs.
|
||||
children_width += empty_width;
|
||||
else
|
||||
{
|
||||
derivation *child;
|
||||
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
|
||||
derivation_list_next (&it, &child);
|
||||
)
|
||||
children_width
|
||||
+= derivation_separator_width + derivation_width (child);
|
||||
// No separator at the beginning.
|
||||
children_width -= derivation_separator_width;
|
||||
}
|
||||
return max_int (self_width, children_width);
|
||||
}
|
||||
else if (deriv == &d_dot)
|
||||
{
|
||||
return dot_width;
|
||||
}
|
||||
else // leaf.
|
||||
{
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
return mbswidth (sym->tag, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Print DERIV for DEPTH.
|
||||
//
|
||||
// The tree is printed from top to bottom with DEPTH ranging from 0 to
|
||||
// the total depth of the tree. DERIV should only printed when we
|
||||
// reach its depth, i.e., then DEPTH is 0.
|
||||
//
|
||||
// When DEPTH is 1 and we're on a subderivation, then we print the RHS
|
||||
// of the derivation (in DEPTH 0 we printed its LHS).
|
||||
//
|
||||
// Return the "logical printed" width. We might have not have reached
|
||||
// that width, in which case the missing spaces are in *PADDING.
|
||||
static int
|
||||
derivation_print_tree_impl (const derivation *deriv, FILE *out,
|
||||
int depth, int *padding)
|
||||
{
|
||||
const int width = derivation_width (deriv);
|
||||
|
||||
int res = 0;
|
||||
if (deriv->children)
|
||||
{
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
char style[20];
|
||||
snprintf (style, 20, "cex-%d", *counter);
|
||||
snprintf (style, 20, "cex-%d", deriv->color);
|
||||
|
||||
if (depth == 0 || depth == 1)
|
||||
{
|
||||
begin_use_class (style, out);
|
||||
begin_use_class ("cex-step", out);
|
||||
}
|
||||
if (depth == 0)
|
||||
{
|
||||
res += fputs_if (true, out, padding, sym->tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
res += fputs_if (depth == 1, out, padding, down_arrow);
|
||||
if (gl_list_size (deriv->children) == 0)
|
||||
// Empty rhs.
|
||||
res += fputs_if (depth == 1, out, padding, empty);
|
||||
else
|
||||
{
|
||||
bool first = true;
|
||||
derivation *child;
|
||||
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
|
||||
derivation_list_next (&it, &child);
|
||||
)
|
||||
{
|
||||
if (!first)
|
||||
res += fputs_if (depth == 1, out, padding, derivation_separator);
|
||||
res += derivation_print_tree_impl (child, out, depth - 1, padding);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth == 0 || depth == 1)
|
||||
{
|
||||
end_use_class ("cex-step", out);
|
||||
end_use_class (style, out);
|
||||
}
|
||||
*padding += width - res;
|
||||
res = width;
|
||||
}
|
||||
else if (deriv == &d_dot)
|
||||
{
|
||||
if (depth == 0)
|
||||
begin_use_class ("cex-dot", out);
|
||||
res += fputs_if (depth == 0, out, padding, dot);
|
||||
if (depth == 0)
|
||||
end_use_class ("cex-dot", out);
|
||||
}
|
||||
else // leaf.
|
||||
{
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
if (depth == 0)
|
||||
begin_use_class ("cex-leaf", out);
|
||||
res += fputs_if (depth == 0, out, padding, sym->tag);
|
||||
if (depth == 0)
|
||||
end_use_class ("cex-leaf", out);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
derivation_print_tree (const derivation *deriv, FILE *out, const char *prefix)
|
||||
{
|
||||
fputc ('\n', out);
|
||||
for (int depth = 0, max_depth = derivation_depth (deriv);
|
||||
depth < max_depth; ++depth)
|
||||
{
|
||||
int padding = 0;
|
||||
fprintf (out, " %s", prefix);
|
||||
derivation_print_tree_impl (deriv, out, depth, &padding);
|
||||
fputc ('\n', out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Print DERIV, colored according to COUNTER.
|
||||
Return false if nothing is printed. */
|
||||
static bool
|
||||
derivation_print_flat_impl (derivation *deriv, FILE *out,
|
||||
bool leaves_only,
|
||||
int *counter, const char *prefix)
|
||||
{
|
||||
if (deriv->children)
|
||||
{
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
deriv->color = *counter;
|
||||
++*counter;
|
||||
begin_use_class (style, f);
|
||||
char style[20];
|
||||
snprintf (style, 20, "cex-%d", deriv->color);
|
||||
begin_use_class (style, out);
|
||||
|
||||
if (!leaves_only)
|
||||
{
|
||||
fputs (prefix, f);
|
||||
begin_use_class ("cex-step", f);
|
||||
fprintf (f, "%s ::=[ ", sym->tag);
|
||||
end_use_class ("cex-step", f);
|
||||
fputs (prefix, out);
|
||||
begin_use_class ("cex-step", out);
|
||||
fprintf (out, "%s %s [ ", sym->tag, arrow);
|
||||
end_use_class ("cex-step", out);
|
||||
prefix = "";
|
||||
}
|
||||
bool res = false;
|
||||
@@ -155,7 +372,8 @@ derivation_print_impl (const derivation *deriv, FILE *f,
|
||||
derivation_list_next (&it, &child);
|
||||
)
|
||||
{
|
||||
if (derivation_print_impl (child, f, leaves_only, counter, prefix))
|
||||
if (derivation_print_flat_impl (child, out,
|
||||
leaves_only, counter, prefix))
|
||||
{
|
||||
prefix = " ";
|
||||
res = true;
|
||||
@@ -165,49 +383,56 @@ derivation_print_impl (const derivation *deriv, FILE *f,
|
||||
}
|
||||
if (!leaves_only)
|
||||
{
|
||||
begin_use_class ("cex-step", f);
|
||||
begin_use_class ("cex-step", out);
|
||||
if (res)
|
||||
fputs (" ]", f);
|
||||
fputs (" ]", out);
|
||||
else
|
||||
fputs ("]", f);
|
||||
end_use_class ("cex-step", f);
|
||||
fputs ("]", out);
|
||||
end_use_class ("cex-step", out);
|
||||
}
|
||||
end_use_class (style, f);
|
||||
end_use_class (style, out);
|
||||
return res;
|
||||
}
|
||||
else if (deriv == &d_dot)
|
||||
{
|
||||
fputs (prefix, f);
|
||||
begin_use_class ("cex-dot", f);
|
||||
print_dot (f);
|
||||
end_use_class ("cex-dot", f);
|
||||
fputs (prefix, out);
|
||||
begin_use_class ("cex-dot", out);
|
||||
fputs (dot, out);
|
||||
end_use_class ("cex-dot", out);
|
||||
}
|
||||
else // leaf.
|
||||
{
|
||||
fputs (prefix, f);
|
||||
fputs (prefix, out);
|
||||
const symbol *sym = symbols[deriv->sym];
|
||||
begin_use_class ("cex-leaf", f);
|
||||
fprintf (f, "%s", sym->tag);
|
||||
end_use_class ("cex-leaf", f);
|
||||
begin_use_class ("cex-leaf", out);
|
||||
fprintf (out, "%s", sym->tag);
|
||||
end_use_class ("cex-leaf", out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
derivation_print_flat (const derivation *deriv, FILE *out, const char *prefix)
|
||||
{
|
||||
int counter = 0;
|
||||
fputs (prefix, out);
|
||||
derivation_print_flat_impl ((derivation *)deriv, out, false, &counter, "");
|
||||
fputc ('\n', out);
|
||||
}
|
||||
|
||||
void
|
||||
derivation_print_leaves (const derivation *deriv, FILE *out)
|
||||
{
|
||||
int counter = 0;
|
||||
derivation_print_flat_impl ((derivation *)deriv, out, true, &counter, "");
|
||||
fputc ('\n', out);
|
||||
}
|
||||
|
||||
void
|
||||
derivation_print (const derivation *deriv, FILE *out, const char *prefix)
|
||||
{
|
||||
int counter = 0;
|
||||
fputs (prefix, out);
|
||||
derivation_print_impl (deriv, out, false, &counter, "");
|
||||
fputc ('\n', out);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix)
|
||||
{
|
||||
int counter = 0;
|
||||
fputs (prefix, out);
|
||||
derivation_print_impl (deriv, out, true, &counter, "");
|
||||
fputc ('\n', out);
|
||||
if (getenv ("YYFLAT"))
|
||||
derivation_print_flat (deriv, out, prefix);
|
||||
else
|
||||
derivation_print_tree (deriv, out, prefix);
|
||||
}
|
||||
|
||||
+4
-1
@@ -60,12 +60,15 @@ static inline derivation *derivation_new_leaf (symbol_number sym)
|
||||
{
|
||||
return derivation_new (sym, NULL);
|
||||
}
|
||||
|
||||
// Number of symbols.
|
||||
size_t derivation_size (const derivation *deriv);
|
||||
void derivation_print (const derivation *deriv, FILE *out, const char *prefix);
|
||||
void derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix);
|
||||
void derivation_print_leaves (const derivation *deriv, FILE *out);
|
||||
void derivation_free (derivation *deriv);
|
||||
void derivation_retain (derivation *deriv);
|
||||
|
||||
// A derivation denoting the position of the dot.
|
||||
derivation *derivation_dot (void);
|
||||
|
||||
#endif /* DERIVATION_H */
|
||||
|
||||
+9
-1
@@ -112,7 +112,15 @@ static struct obstack obstack_for_string;
|
||||
# define STRING_1GROW(Char) \
|
||||
obstack_1grow (&obstack_for_string, Char)
|
||||
|
||||
# define STRING_FREE() \
|
||||
# ifdef NDEBUG
|
||||
# define STRING_FREE() \
|
||||
obstack_free (&obstack_for_string, last_string)
|
||||
# else
|
||||
# define STRING_FREE() \
|
||||
do { \
|
||||
obstack_free (&obstack_for_string, last_string); \
|
||||
last_string = NULL; \
|
||||
} while (0)
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ static const argmatch_report_arg argmatch_report_args[] =
|
||||
{ "none", report_none },
|
||||
{ "states", report_states },
|
||||
{ "itemsets", report_states | report_itemsets },
|
||||
{ "lookaheads", report_states | report_lookahead_tokens },
|
||||
{ "lookaheads", report_states | report_lookaheads },
|
||||
{ "solved", report_states | report_solved_conflicts },
|
||||
{ "counterexamples", report_cex },
|
||||
{ "cex", report_cex },
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ enum report
|
||||
report_none = 0,
|
||||
report_states = 1 << 0,
|
||||
report_itemsets = 1 << 1,
|
||||
report_lookahead_tokens = 1 << 2,
|
||||
report_lookaheads = 1 << 2,
|
||||
report_solved_conflicts = 1 << 3,
|
||||
report_cex = 1 << 4,
|
||||
report_all = ~0
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* Graphical symbols.
|
||||
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "glyphs.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <attribute.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <mbswidth.h>
|
||||
#include <unicodeio.h>
|
||||
|
||||
|
||||
glyph_buffer_t arrow;
|
||||
int arrow_width;
|
||||
|
||||
glyph_buffer_t down_arrow;
|
||||
int down_arrow_width;
|
||||
|
||||
glyph_buffer_t dot;
|
||||
int dot_width;
|
||||
|
||||
glyph_buffer_t empty;
|
||||
int empty_width;
|
||||
|
||||
const char *derivation_separator = " ";
|
||||
int derivation_separator_width = 1;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
glyph_buffer_t *pbuf;
|
||||
const char *fallback;
|
||||
} callback_arg_t;
|
||||
|
||||
|
||||
static long
|
||||
on_success (const char *buf, size_t buflen, void *callback_arg)
|
||||
{
|
||||
callback_arg_t *arg = (callback_arg_t *) callback_arg;
|
||||
assert (buflen + 1 < sizeof *arg->pbuf);
|
||||
*stpncpy (*arg->pbuf, buf, buflen) = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
static long
|
||||
on_failure (unsigned code MAYBE_UNUSED, const char *msg MAYBE_UNUSED,
|
||||
void *callback_arg)
|
||||
{
|
||||
callback_arg_t *arg = (callback_arg_t *) callback_arg;
|
||||
assert (strlen (arg->fallback) + 1 < sizeof *arg->pbuf);
|
||||
strcpy (*arg->pbuf, arg->fallback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
glyph_set (glyph_buffer_t *glyph, int *width,
|
||||
unsigned code, const char *fallback)
|
||||
{
|
||||
callback_arg_t arg = { glyph, fallback };
|
||||
int res = unicode_to_mb (code, on_success, on_failure, &arg);
|
||||
*width = mbswidth (*glyph, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
glyphs_init (void)
|
||||
{
|
||||
glyph_set (&arrow, &arrow_width, 0x2192, "->");
|
||||
glyph_set (&dot, &dot_width, 0x2022, ".");
|
||||
glyph_set (&down_arrow, &down_arrow_width, 0x21b3, "`->");
|
||||
glyph_set (&empty, &empty_width, 0x03b5, "%empty");
|
||||
|
||||
strncat (down_arrow, " ", sizeof down_arrow - strlen (down_arrow) - 1);
|
||||
down_arrow_width += 1;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* Graphical symbols.
|
||||
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef GLYPHS_H
|
||||
# define GLYPHS_H
|
||||
|
||||
/* Initialize the following variables. */
|
||||
void glyphs_init (void);
|
||||
|
||||
/* In gnulib/lib/unicodeio.h unicode_to_mb uses a buffer of 25 bytes.
|
||||
In down_arrow, we append one space. */
|
||||
typedef char glyph_buffer_t[26];
|
||||
|
||||
/* "→", separates the lhs of a rule from its rhs. */
|
||||
extern glyph_buffer_t arrow;
|
||||
extern int arrow_width;
|
||||
|
||||
/* "•", a point in an item (aka, a dotted rule). */
|
||||
extern glyph_buffer_t dot;
|
||||
extern int dot_width;
|
||||
|
||||
/* "↳ ", below an lhs to announce the rhs. */
|
||||
extern glyph_buffer_t down_arrow;
|
||||
extern int down_arrow_width;
|
||||
|
||||
/* "ε", an empty rhs. */
|
||||
extern glyph_buffer_t empty;
|
||||
extern int empty_width;
|
||||
|
||||
/* " ", separate symbols in the rhs of a derivation. */
|
||||
extern const char *derivation_separator;
|
||||
extern int derivation_separator_width;
|
||||
|
||||
#endif /* GLYPHS_H */
|
||||
+2
-2
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "complain.h"
|
||||
#include "getargs.h"
|
||||
#include "glyphs.h"
|
||||
#include "gram.h"
|
||||
#include "print-xml.h"
|
||||
#include "reader.h"
|
||||
@@ -56,8 +57,7 @@ item_print (item_number *item, rule const *previous_rule, FILE *out)
|
||||
|
||||
for (item_number *sp = r->rhs; sp < item; sp++)
|
||||
fprintf (out, " %s", symbols[*sp]->tag);
|
||||
putc (' ', out);
|
||||
print_dot (out);
|
||||
fprintf (out, " %s", dot);
|
||||
if (0 <= *r->rhs)
|
||||
for (item_number *sp = item; 0 <= *sp; ++sp)
|
||||
fprintf (out, " %s", symbols[*sp]->tag);
|
||||
|
||||
-21
@@ -103,8 +103,6 @@
|
||||
|
||||
# include "system.h"
|
||||
|
||||
# include <unicodeio.h>
|
||||
|
||||
# include "location.h"
|
||||
# include "symtab.h"
|
||||
|
||||
@@ -217,25 +215,6 @@ typedef struct
|
||||
extern rule *rules;
|
||||
extern rule_number nrules;
|
||||
|
||||
/* Fallback in case we can't print "•". */
|
||||
static inline long
|
||||
print_dot_fallback (unsigned int code _GL_UNUSED,
|
||||
const char *msg _GL_UNUSED,
|
||||
void *callback_arg)
|
||||
{
|
||||
FILE *out = (FILE *) callback_arg;
|
||||
putc ('.', out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Print "•", the symbol used to represent a point in an item (aka, a
|
||||
dotted rule). */
|
||||
static inline void
|
||||
print_dot (FILE *out)
|
||||
{
|
||||
unicode_to_mb (0x2022, fwrite_success_callback, print_dot_fallback, out);
|
||||
}
|
||||
|
||||
/* Get the rule associated to this item. ITEM points inside RITEM. */
|
||||
static inline rule const *
|
||||
item_rule (item_number const *item)
|
||||
|
||||
+2
-2
@@ -184,9 +184,9 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
||||
bool firste = true;
|
||||
rule_number ruleno = reds->rules[j]->number;
|
||||
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
for (int i = 0; i < ntokens; i++)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookaheads[j], i))
|
||||
{
|
||||
if (bitset_test (no_reduce_set, i))
|
||||
firstd = print_token (&dout, firstd, symbols[i]->tag);
|
||||
|
||||
+2
-2
@@ -423,7 +423,7 @@ ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
|
||||
check all predecessors' goto follows for the LHS. */
|
||||
if (item_number_is_rule_number (ritem[s->items[item] - 2]))
|
||||
{
|
||||
aver (lhs != accept->content->number);
|
||||
aver (lhs != acceptsymbol->content->number);
|
||||
for (state **predecessor = predecessors[s->number];
|
||||
*predecessor;
|
||||
++predecessor)
|
||||
@@ -1025,7 +1025,7 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows,
|
||||
{
|
||||
rule *this_rule = node->state->reductions->rules[r];
|
||||
bitset lookahead_set =
|
||||
node->state->reductions->lookahead_tokens[r];
|
||||
node->state->reductions->lookaheads[r];
|
||||
if (item_number_is_rule_number (*this_rule->rhs))
|
||||
ielr_compute_goto_follow_set (follow_kernel_items,
|
||||
always_follows, node,
|
||||
|
||||
+24
-27
@@ -256,9 +256,9 @@ lookback_find_state (int lookback_index)
|
||||
state *res = NULL;
|
||||
for (int j = 0; j < nstates; ++j)
|
||||
if (states[j]->reductions
|
||||
&& states[j]->reductions->lookahead_tokens)
|
||||
&& states[j]->reductions->lookaheads)
|
||||
{
|
||||
if (states[j]->reductions->lookahead_tokens - LA > lookback_index)
|
||||
if (states[j]->reductions->lookaheads - LA > lookback_index)
|
||||
/* Went too far. */
|
||||
break;
|
||||
else
|
||||
@@ -280,7 +280,7 @@ lookback_print (FILE *out)
|
||||
{
|
||||
fprintf (out, " %3d = ", i);
|
||||
const state *s = lookback_find_state (i);
|
||||
int rnum = i - (s->reductions->lookahead_tokens - LA);
|
||||
int rnum = i - (s->reductions->lookaheads - LA);
|
||||
const rule *r = s->reductions->rules[rnum];
|
||||
fprintf (out, "(%3d, ", s->number);
|
||||
rule_print (r, NULL, out);
|
||||
@@ -305,7 +305,7 @@ static void
|
||||
add_lookback_edge (state *s, rule const *r, goto_number gotono)
|
||||
{
|
||||
int ri = state_reduction_find (s, r);
|
||||
int idx = (s->reductions->lookahead_tokens - LA) + ri;
|
||||
int idx = (s->reductions->lookaheads - LA) + ri;
|
||||
lookback[idx] = goto_list_new (gotono, lookback[idx]);
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ compute_follows (void)
|
||||
|
||||
|
||||
static void
|
||||
compute_lookahead_tokens (void)
|
||||
compute_lookaheads (void)
|
||||
{
|
||||
if (trace_flag & trace_automaton)
|
||||
lookback_print (stderr);
|
||||
@@ -437,13 +437,12 @@ compute_lookahead_tokens (void)
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------.
|
||||
| Count the number of lookahead tokens required for S |
|
||||
| (N_LOOKAHEAD_TOKENS member). |
|
||||
`----------------------------------------------------*/
|
||||
/*------------------------------------------------------.
|
||||
| Count the number of lookahead tokens required for S. |
|
||||
`------------------------------------------------------*/
|
||||
|
||||
static int
|
||||
state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
|
||||
state_lookaheads_count (state *s, bool default_reduction_only_for_accept)
|
||||
{
|
||||
const reductions *reds = s->reductions;
|
||||
const transitions *trans = s->transitions;
|
||||
@@ -473,9 +472,9 @@ state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------.
|
||||
| Compute LA, NLA, and the lookahead_tokens members. |
|
||||
`----------------------------------------------------*/
|
||||
/*----------------------------------------------.
|
||||
| Compute LA, NLA, and the lookaheads members. |
|
||||
`----------------------------------------------*/
|
||||
|
||||
void
|
||||
initialize_LA (void)
|
||||
@@ -491,25 +490,23 @@ initialize_LA (void)
|
||||
/* Compute the total number of reductions requiring a lookahead. */
|
||||
nLA = 0;
|
||||
for (state_number i = 0; i < nstates; ++i)
|
||||
nLA +=
|
||||
state_lookahead_tokens_count (states[i],
|
||||
default_reduction_only_for_accept);
|
||||
nLA += state_lookaheads_count (states[i],
|
||||
default_reduction_only_for_accept);
|
||||
/* Avoid having to special case 0. */
|
||||
if (!nLA)
|
||||
nLA = 1;
|
||||
|
||||
bitsetv pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
||||
|
||||
/* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
|
||||
/* Initialize the members LOOKAHEADS for each state whose reductions
|
||||
require lookahead tokens. */
|
||||
for (state_number i = 0; i < nstates; ++i)
|
||||
{
|
||||
int count =
|
||||
state_lookahead_tokens_count (states[i],
|
||||
default_reduction_only_for_accept);
|
||||
int count = state_lookaheads_count (states[i],
|
||||
default_reduction_only_for_accept);
|
||||
if (count)
|
||||
{
|
||||
states[i]->reductions->lookahead_tokens = pLA;
|
||||
states[i]->reductions->lookaheads = pLA;
|
||||
pLA += count;
|
||||
}
|
||||
}
|
||||
@@ -521,7 +518,7 @@ initialize_LA (void)
|
||||
`---------------------------------------------*/
|
||||
|
||||
static void
|
||||
lookahead_tokens_print (FILE *out)
|
||||
lookaheads_print (FILE *out)
|
||||
{
|
||||
fputs ("Lookaheads:\n", out);
|
||||
for (state_number i = 0; i < nstates; ++i)
|
||||
@@ -533,11 +530,11 @@ lookahead_tokens_print (FILE *out)
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
{
|
||||
fprintf (out, " rule %d:", reds->rules[j]->number);
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
{
|
||||
bitset_iterator iter;
|
||||
int k;
|
||||
BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0)
|
||||
BITSET_FOR_EACH (iter, reds->lookaheads[j], k, 0)
|
||||
fprintf (out, " %s", symbols[k]->tag);
|
||||
}
|
||||
fputc ('\n', out);
|
||||
@@ -564,10 +561,10 @@ lalr (void)
|
||||
lookback = xcalloc (nLA, sizeof *lookback);
|
||||
build_relations ();
|
||||
compute_follows ();
|
||||
compute_lookahead_tokens ();
|
||||
compute_lookaheads ();
|
||||
|
||||
if (trace_flag & trace_sets)
|
||||
lookahead_tokens_print (stderr);
|
||||
lookaheads_print (stderr);
|
||||
if (trace_flag & trace_automaton)
|
||||
{
|
||||
begin_use_class ("trace0", stderr);
|
||||
@@ -614,6 +611,6 @@ void
|
||||
lalr_free (void)
|
||||
{
|
||||
for (state_number s = 0; s < nstates; ++s)
|
||||
states[s]->reductions->lookahead_tokens = NULL;
|
||||
states[s]->reductions->lookaheads = NULL;
|
||||
bitsetv_free (LA);
|
||||
}
|
||||
|
||||
+4
-1
@@ -53,6 +53,8 @@ src_bison_SOURCES = \
|
||||
src/flex-scanner.h \
|
||||
src/getargs.c \
|
||||
src/getargs.h \
|
||||
src/glyphs.c \
|
||||
src/glyphs.h \
|
||||
src/gram.c \
|
||||
src/gram.h \
|
||||
src/graphviz.c \
|
||||
@@ -101,6 +103,8 @@ src_bison_SOURCES = \
|
||||
src/state.h \
|
||||
src/state-item.c \
|
||||
src/state-item.h \
|
||||
src/strversion.c \
|
||||
src/strversion.h \
|
||||
src/symlist.c \
|
||||
src/symlist.h \
|
||||
src/symtab.c \
|
||||
@@ -141,7 +145,6 @@ src_bison_LDADD = \
|
||||
$(LIB_SETLOCALE_NULL) \
|
||||
$(LIBICONV) \
|
||||
$(LIBINTL) \
|
||||
$(LIBREADLINE) \
|
||||
$(LIBTEXTSTYLE)
|
||||
|
||||
|
||||
|
||||
+3
-13
@@ -40,18 +40,6 @@
|
||||
|
||||
location const empty_loc = EMPTY_LOCATION_INIT;
|
||||
|
||||
static int
|
||||
min_int (int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static int
|
||||
max_int (int a, int b)
|
||||
{
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
/* The terminal width. Not less than 40. */
|
||||
static int
|
||||
columns (void)
|
||||
@@ -167,7 +155,9 @@ int
|
||||
location_print (location loc, FILE *out)
|
||||
{
|
||||
int res = 0;
|
||||
if (trace_flag & trace_locations)
|
||||
if (location_empty (loc))
|
||||
res += fprintf (out, "(empty location)");
|
||||
else if (trace_flag & trace_locations)
|
||||
{
|
||||
res += boundary_print (&loc.start, out);
|
||||
res += fprintf (out, "-");
|
||||
|
||||
+14
-12
@@ -82,8 +82,10 @@ lssi_comparator (lssi *s1, lssi *s2)
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef gl_list_t lssi_list;
|
||||
|
||||
static inline bool
|
||||
append_lssi (lssi *sn, Hash_table *visited, gl_list_t queue)
|
||||
append_lssi (lssi *sn, Hash_table *visited, lssi_list queue)
|
||||
{
|
||||
if (hash_lookup (visited, sn))
|
||||
{
|
||||
@@ -100,7 +102,7 @@ append_lssi (lssi *sn, Hash_table *visited, gl_list_t queue)
|
||||
static void
|
||||
lssi_print (lssi *l)
|
||||
{
|
||||
print_state_item (state_items + l->si, stdout);
|
||||
print_state_item (&state_items[l->si], stdout);
|
||||
if (l->lookahead)
|
||||
{
|
||||
printf ("FOLLOWL = { ");
|
||||
@@ -121,7 +123,7 @@ static bitset
|
||||
eligible_state_items (state_item *target)
|
||||
{
|
||||
bitset result = bitset_create (nstate_items, BITSET_FIXED);
|
||||
gl_list_t queue =
|
||||
state_item_list queue =
|
||||
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
|
||||
(const void **) &target);
|
||||
while (gl_list_size (queue) > 0)
|
||||
@@ -147,7 +149,7 @@ eligible_state_items (state_item *target)
|
||||
* this conflict. If optimized is true, only consider parser states
|
||||
* that can reach the conflict state.
|
||||
*/
|
||||
gl_list_t
|
||||
state_item_list
|
||||
shortest_path_from_start (state_item_number target, symbol_number next_sym)
|
||||
{
|
||||
bitset eligible = eligible_state_items (&state_items[target]);
|
||||
@@ -159,7 +161,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
|
||||
bitset il = bitset_create (nsyms, BITSET_FIXED);
|
||||
bitset_set (il, 0);
|
||||
lssi *init = new_lssi (0, NULL, il, true);
|
||||
gl_list_t queue = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL,
|
||||
lssi_list queue = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL,
|
||||
NULL, true);
|
||||
append_lssi (init, visited, queue);
|
||||
// breadth-first search
|
||||
@@ -175,7 +177,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
state_item *si = state_items + last;
|
||||
state_item *si = &state_items[last];
|
||||
// Transitions don't change follow_L
|
||||
if (si->trans >= 0)
|
||||
{
|
||||
@@ -240,10 +242,10 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
|
||||
fputs ("Cannot find shortest path to conflict state.", stderr);
|
||||
abort ();
|
||||
}
|
||||
gl_list_t res =
|
||||
state_item_list res =
|
||||
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
|
||||
for (lssi *sn = n; sn != NULL; sn = sn->parent)
|
||||
gl_list_add_first (res, state_items + sn->si);
|
||||
gl_list_add_first (res, &state_items[sn->si]);
|
||||
|
||||
hash_free (visited);
|
||||
gl_list_free (queue);
|
||||
@@ -254,7 +256,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
|
||||
gl_list_iterator_t it = gl_list_iterator (res);
|
||||
const void *sip;
|
||||
while (gl_list_iterator_next (&it, &sip, NULL))
|
||||
print_state_item ((state_item *) sip, stdout, "");
|
||||
state_item_print ((state_item *) sip, stdout, "");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -306,10 +308,10 @@ intersect (bitset ts, bitset syms)
|
||||
* Compute a list of state_items that have a production to n with respect
|
||||
* to its lookahead
|
||||
*/
|
||||
gl_list_t
|
||||
state_item_list
|
||||
lssi_reverse_production (const state_item *si, bitset lookahead)
|
||||
{
|
||||
gl_list_t result =
|
||||
state_item_list result =
|
||||
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
|
||||
if (SI_TRANSITION (si))
|
||||
return result;
|
||||
@@ -320,7 +322,7 @@ lssi_reverse_production (const state_item *si, bitset lookahead)
|
||||
state_item_number sin;
|
||||
BITSET_FOR_EACH (biter, si->revs, sin, 0)
|
||||
{
|
||||
state_item *prevsi = state_items + sin;
|
||||
state_item *prevsi = &state_items[sin];
|
||||
if (!production_allowed (prevsi, si))
|
||||
continue;
|
||||
bitset prev_lookahead = prevsi->lookahead;
|
||||
|
||||
+3
-3
@@ -32,8 +32,8 @@
|
||||
* find shortest lookahead-sensitive path of state-items to target such that
|
||||
* next_sym is in the follow_L set of target in that position.
|
||||
*/
|
||||
gl_list_t shortest_path_from_start (state_item_number target,
|
||||
symbol_number next_sym);
|
||||
state_item_list shortest_path_from_start (state_item_number target,
|
||||
symbol_number next_sym);
|
||||
|
||||
/**
|
||||
* Determine if the given terminal is in the given symbol set or can begin
|
||||
@@ -52,6 +52,6 @@ bool intersect (bitset ts, bitset syms);
|
||||
* to this state-item such that the resulting possible lookahead symbols are
|
||||
* as given.
|
||||
*/
|
||||
gl_list_t lssi_reverse_production (const state_item *si, bitset lookahead);
|
||||
state_item_list lssi_reverse_production (const state_item *si, bitset lookahead);
|
||||
|
||||
#endif /* LSSI_H */
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "files.h"
|
||||
#include "fixits.h"
|
||||
#include "getargs.h"
|
||||
#include "glyphs.h"
|
||||
#include "gram.h"
|
||||
#include "ielr.h"
|
||||
#include "lalr.h"
|
||||
@@ -85,6 +86,7 @@ main (int argc, char *argv[])
|
||||
|
||||
atexit (close_stdout);
|
||||
|
||||
glyphs_init ();
|
||||
uniqstrs_new ();
|
||||
muscle_init ();
|
||||
complain_init ();
|
||||
|
||||
@@ -127,9 +127,6 @@ muscle_init (void)
|
||||
|
||||
muscle_table = hash_xinitialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
|
||||
hash_compare_muscles, muscle_entry_free);
|
||||
|
||||
/* Version and input file. */
|
||||
MUSCLE_INSERT_STRING ("version", VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+8
-4
@@ -42,6 +42,7 @@
|
||||
#include "scan-skel.h"
|
||||
#include "symtab.h"
|
||||
#include "tables.h"
|
||||
#include "strversion.h"
|
||||
|
||||
static struct obstack format_obstack;
|
||||
|
||||
@@ -249,7 +250,7 @@ prepare_symbol_names (char const *muscle_name)
|
||||
if (i)
|
||||
obstack_1grow (&format_obstack, ' ');
|
||||
if (translatable)
|
||||
obstack_sgrow (&format_obstack, "]b4_symbol_translate([");
|
||||
obstack_sgrow (&format_obstack, "]b4_symbol_translate""([");
|
||||
obstack_escape (&format_obstack, cp);
|
||||
if (translatable)
|
||||
obstack_sgrow (&format_obstack, "])[");
|
||||
@@ -554,7 +555,7 @@ prepare_symbol_definitions (void)
|
||||
/* Map "orig NUM" to new numbers. See data/README. */
|
||||
for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; ++i)
|
||||
{
|
||||
obstack_printf (&format_obstack, "symbol(orig %d, number)", i);
|
||||
obstack_printf (&format_obstack, "symbol""(orig %d, number)", i);
|
||||
const char *key = obstack_finish0 (&format_obstack);
|
||||
MUSCLE_INSERT_INT (key, nterm_map ? nterm_map[i - ntokens] : i);
|
||||
}
|
||||
@@ -565,12 +566,12 @@ prepare_symbol_definitions (void)
|
||||
const char *key;
|
||||
|
||||
#define SET_KEY(Entry) \
|
||||
obstack_printf (&format_obstack, "symbol(%d, %s)", \
|
||||
obstack_printf (&format_obstack, "symbol""(%d, %s)", \
|
||||
i, Entry); \
|
||||
key = obstack_finish0 (&format_obstack);
|
||||
|
||||
#define SET_KEY2(Entry, Suffix) \
|
||||
obstack_printf (&format_obstack, "symbol(%d, %s_%s)", \
|
||||
obstack_printf (&format_obstack, "symbol""(%d, %s_%s)", \
|
||||
i, Entry, Suffix); \
|
||||
key = obstack_finish0 (&format_obstack);
|
||||
|
||||
@@ -807,6 +808,9 @@ prepare (void)
|
||||
char const *cp = getenv ("BISON_USE_PUSH_FOR_PULL");
|
||||
bool use_push_for_pull_flag = cp && *cp && strtol (cp, 0, 10);
|
||||
|
||||
/* Versions. */
|
||||
MUSCLE_INSERT_STRING ("version_string", VERSION);
|
||||
MUSCLE_INSERT_INT ("version", strversion_to_int (VERSION));
|
||||
MUSCLE_INSERT_INT ("required_version", required_version);
|
||||
|
||||
/* Flags. */
|
||||
|
||||
+38
-70
@@ -1,4 +1,4 @@
|
||||
/* A Bison parser, made by GNU Bison 3.6.90. */
|
||||
/* A Bison parser, made by GNU Bison 3.7.3.7-d831b. */
|
||||
|
||||
/* Bison implementation for Yacc-like parsers in C
|
||||
|
||||
@@ -46,10 +46,10 @@
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
/* Identify Bison output. */
|
||||
#define YYBISON 1
|
||||
#define YYBISON 30703
|
||||
|
||||
/* Bison version. */
|
||||
#define YYBISON_VERSION "3.6.90"
|
||||
#define YYBISON_VERSION "3.7.3.7-d831b"
|
||||
|
||||
/* Skeleton name. */
|
||||
#define YYSKELETON_NAME "yacc.c"
|
||||
@@ -149,7 +149,7 @@ enum yysymbol_kind_t
|
||||
YYSYMBOL_BRACED_CODE = 41, /* "{...}" */
|
||||
YYSYMBOL_BRACED_PREDICATE = 42, /* "%?{...}" */
|
||||
YYSYMBOL_BRACKETED_ID = 43, /* "[identifier]" */
|
||||
YYSYMBOL_CHAR = 44, /* "character literal" */
|
||||
YYSYMBOL_CHAR_LITERAL = 44, /* "character literal" */
|
||||
YYSYMBOL_COLON = 45, /* ":" */
|
||||
YYSYMBOL_EPILOGUE = 46, /* "epilogue" */
|
||||
YYSYMBOL_EQUAL = 47, /* "=" */
|
||||
@@ -162,7 +162,7 @@ enum yysymbol_kind_t
|
||||
YYSYMBOL_TAG = 54, /* "<tag>" */
|
||||
YYSYMBOL_TAG_ANY = 55, /* "<*>" */
|
||||
YYSYMBOL_TAG_NONE = 56, /* "<>" */
|
||||
YYSYMBOL_INT = 57, /* "integer literal" */
|
||||
YYSYMBOL_INT_LITERAL = 57, /* "integer literal" */
|
||||
YYSYMBOL_PERCENT_PARAM = 58, /* "%param" */
|
||||
YYSYMBOL_PERCENT_UNION = 59, /* "%union" */
|
||||
YYSYMBOL_PERCENT_EMPTY = 60, /* "%empty" */
|
||||
@@ -218,8 +218,6 @@ typedef enum yysymbol_kind_t yysymbol_kind_t;
|
||||
#include "system.h"
|
||||
|
||||
#include <c-ctype.h>
|
||||
#include <errno.h>
|
||||
#include <intprops.h>
|
||||
#include <quotearg.h>
|
||||
#include <vasnprintf.h>
|
||||
#include <xmemdup0.h>
|
||||
@@ -233,6 +231,7 @@ typedef enum yysymbol_kind_t yysymbol_kind_t;
|
||||
#include "reader.h"
|
||||
#include "scan-code.h"
|
||||
#include "scan-gram.h"
|
||||
#include "strversion.h"
|
||||
|
||||
/* Pretend to be at least that version, to check features published
|
||||
in that version while developping it. */
|
||||
@@ -639,19 +638,19 @@ union yyalloc
|
||||
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
|
||||
static const yytype_int16 yyrline[] =
|
||||
{
|
||||
0, 312, 312, 321, 322, 326, 327, 333, 337, 342,
|
||||
343, 344, 345, 346, 347, 348, 353, 358, 359, 360,
|
||||
361, 362, 363, 363, 364, 365, 366, 367, 368, 369,
|
||||
370, 371, 375, 376, 385, 386, 390, 401, 405, 409,
|
||||
417, 427, 428, 438, 439, 445, 458, 458, 463, 463,
|
||||
468, 472, 482, 483, 484, 485, 489, 490, 495, 496,
|
||||
500, 501, 505, 506, 507, 520, 529, 533, 537, 545,
|
||||
546, 550, 563, 564, 569, 570, 571, 589, 593, 597,
|
||||
605, 607, 612, 619, 629, 633, 637, 645, 650, 662,
|
||||
663, 669, 670, 671, 678, 678, 686, 687, 688, 693,
|
||||
696, 698, 700, 702, 704, 706, 708, 710, 712, 717,
|
||||
718, 727, 751, 752, 753, 754, 766, 768, 792, 797,
|
||||
798, 803, 811, 812
|
||||
0, 311, 311, 320, 321, 325, 326, 332, 336, 341,
|
||||
342, 343, 344, 345, 346, 347, 352, 357, 358, 359,
|
||||
360, 361, 362, 362, 363, 364, 365, 366, 367, 368,
|
||||
369, 370, 374, 375, 384, 385, 389, 400, 404, 408,
|
||||
416, 426, 427, 437, 438, 444, 457, 457, 462, 462,
|
||||
467, 471, 481, 482, 483, 484, 488, 489, 494, 495,
|
||||
499, 500, 504, 505, 506, 519, 528, 532, 536, 544,
|
||||
545, 549, 562, 563, 568, 569, 570, 588, 592, 596,
|
||||
604, 606, 611, 618, 628, 632, 636, 644, 649, 661,
|
||||
662, 668, 669, 670, 677, 677, 685, 686, 687, 692,
|
||||
695, 697, 699, 701, 703, 705, 707, 709, 711, 716,
|
||||
717, 726, 750, 751, 752, 753, 765, 767, 791, 796,
|
||||
797, 802, 810, 811
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1115,8 +1114,8 @@ tron (yyo);
|
||||
{ fprintf (yyo, "[%s]", ((*yyvaluep).BRACKETED_ID)); }
|
||||
break;
|
||||
|
||||
case YYSYMBOL_CHAR: /* "character literal" */
|
||||
{ fputs (char_name (((*yyvaluep).CHAR)), yyo); }
|
||||
case YYSYMBOL_CHAR_LITERAL: /* "character literal" */
|
||||
{ fputs (char_name (((*yyvaluep).CHAR_LITERAL)), yyo); }
|
||||
break;
|
||||
|
||||
case YYSYMBOL_EPILOGUE: /* "epilogue" */
|
||||
@@ -1139,8 +1138,8 @@ tron (yyo);
|
||||
{ fprintf (yyo, "<%s>", ((*yyvaluep).TAG)); }
|
||||
break;
|
||||
|
||||
case YYSYMBOL_INT: /* "integer literal" */
|
||||
{ fprintf (yyo, "%d", ((*yyvaluep).INT)); }
|
||||
case YYSYMBOL_INT_LITERAL: /* "integer literal" */
|
||||
{ fprintf (yyo, "%d", ((*yyvaluep).INT_LITERAL)); }
|
||||
break;
|
||||
|
||||
case YYSYMBOL_PERCENT_PARAM: /* "%param" */
|
||||
@@ -2087,11 +2086,11 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 12: /* prologue_declaration: "%expect" "integer literal" */
|
||||
{ expected_sr_conflicts = (yyvsp[0].INT); }
|
||||
{ expected_sr_conflicts = (yyvsp[0].INT_LITERAL); }
|
||||
break;
|
||||
|
||||
case 13: /* prologue_declaration: "%expect-rr" "integer literal" */
|
||||
{ expected_rr_conflicts = (yyvsp[0].INT); }
|
||||
{ expected_rr_conflicts = (yyvsp[0].INT_LITERAL); }
|
||||
break;
|
||||
|
||||
case 14: /* prologue_declaration: "%file-prefix" "string" */
|
||||
@@ -2339,13 +2338,13 @@ yyreduce:
|
||||
|
||||
case 67: /* token_decls: "<tag>" token_decl.1 */
|
||||
{
|
||||
(yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG), (yylsp[-1]));
|
||||
(yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG));
|
||||
}
|
||||
break;
|
||||
|
||||
case 68: /* token_decls: token_decls "<tag>" token_decl.1 */
|
||||
{
|
||||
(yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG), (yylsp[-1])));
|
||||
(yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG)));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2396,13 +2395,13 @@ yyreduce:
|
||||
|
||||
case 78: /* token_decls_for_prec: "<tag>" token_decl_for_prec.1 */
|
||||
{
|
||||
(yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG), (yylsp[-1]));
|
||||
(yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG));
|
||||
}
|
||||
break;
|
||||
|
||||
case 79: /* token_decls_for_prec: token_decls_for_prec "<tag>" token_decl_for_prec.1 */
|
||||
{
|
||||
(yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG), (yylsp[-1])));
|
||||
(yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG)));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2431,13 +2430,13 @@ yyreduce:
|
||||
|
||||
case 85: /* symbol_decls: "<tag>" symbol_decl.1 */
|
||||
{
|
||||
(yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG), (yylsp[-1]));
|
||||
(yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG));
|
||||
}
|
||||
break;
|
||||
|
||||
case 86: /* symbol_decls: symbol_decls "<tag>" symbol_decl.1 */
|
||||
{
|
||||
(yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG), (yylsp[-1])));
|
||||
(yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG)));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2506,7 +2505,7 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 105: /* rhs: rhs "%dprec" "integer literal" */
|
||||
{ grammar_current_rule_dprec_set ((yyvsp[0].INT), (yylsp[0])); }
|
||||
{ grammar_current_rule_dprec_set ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
|
||||
break;
|
||||
|
||||
case 106: /* rhs: rhs "%merge" "<tag>" */
|
||||
@@ -2514,11 +2513,11 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 107: /* rhs: rhs "%expect" "integer literal" */
|
||||
{ grammar_current_rule_expect_sr ((yyvsp[0].INT), (yylsp[0])); }
|
||||
{ grammar_current_rule_expect_sr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
|
||||
break;
|
||||
|
||||
case 108: /* rhs: rhs "%expect-rr" "integer literal" */
|
||||
{ grammar_current_rule_expect_rr ((yyvsp[0].INT), (yylsp[0])); }
|
||||
{ grammar_current_rule_expect_rr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
|
||||
break;
|
||||
|
||||
case 109: /* named_ref.opt: %empty */
|
||||
@@ -2566,9 +2565,9 @@ yyreduce:
|
||||
location loc = muscle_percent_define_get_loc (var);
|
||||
subcomplain (&loc, complaint, _("definition of %s"), var);
|
||||
}
|
||||
(yyval.id) = symbol_get (char_name ((yyvsp[0].CHAR)), (yylsp[0]));
|
||||
(yyval.id) = symbol_get (char_name ((yyvsp[0].CHAR_LITERAL)), (yylsp[0]));
|
||||
symbol_class_set ((yyval.id), token_sym, (yylsp[0]), false);
|
||||
symbol_code_set ((yyval.id), (yyvsp[0].CHAR), (yylsp[0]));
|
||||
symbol_code_set ((yyval.id), (yyvsp[0].CHAR_LITERAL), (yylsp[0]));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -3032,41 +3031,11 @@ handle_pure_parser (location const *loc, char const *directive)
|
||||
}
|
||||
|
||||
|
||||
/* Convert VERSION into an int (MAJOR * 100 + MINOR). Return -1 on
|
||||
errors.
|
||||
|
||||
Changes of behavior are only on minor version changes, so "3.0.5"
|
||||
is the same as "3.0": 300. */
|
||||
static int
|
||||
str_to_version (char const *version)
|
||||
{
|
||||
IGNORE_TYPE_LIMITS_BEGIN
|
||||
int res = 0;
|
||||
errno = 0;
|
||||
char *cp = NULL;
|
||||
long major = strtol (version, &cp, 10);
|
||||
if (errno || cp == version || *cp != '.' || major < 0
|
||||
|| INT_MULTIPLY_WRAPV (major, 100, &res))
|
||||
return -1;
|
||||
|
||||
++cp;
|
||||
char *cp1 = NULL;
|
||||
long minor = strtol (cp, &cp1, 10);
|
||||
if (errno || cp1 == cp || (*cp1 != '\0' && *cp1 != '.')
|
||||
|| ! (0 <= minor && minor < 100)
|
||||
|| INT_ADD_WRAPV (minor, res, &res))
|
||||
return -1;
|
||||
|
||||
IGNORE_TYPE_LIMITS_END
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
handle_require (location const *loc, char const *version_quoted)
|
||||
{
|
||||
char *version = unquote (version_quoted);
|
||||
required_version = str_to_version (version);
|
||||
required_version = strversion_to_int (version);
|
||||
if (required_version == -1)
|
||||
{
|
||||
complain (loc, complaint, _("invalid version requirement: %s"),
|
||||
@@ -3147,8 +3116,7 @@ char_name (char c)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
static void
|
||||
current_lhs (symbol *sym, location loc, named_ref *ref)
|
||||
{
|
||||
current_lhs_symbol = sym;
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
/* A Bison parser, made by GNU Bison 3.6.90. */
|
||||
/* A Bison parser, made by GNU Bison 3.7.3.7-d831b. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
@@ -123,7 +123,7 @@ extern int gram_debug;
|
||||
BRACED_CODE = 41, /* "{...}" */
|
||||
BRACED_PREDICATE = 42, /* "%?{...}" */
|
||||
BRACKETED_ID = 43, /* "[identifier]" */
|
||||
CHAR = 44, /* "character literal" */
|
||||
CHAR_LITERAL = 44, /* "character literal" */
|
||||
COLON = 45, /* ":" */
|
||||
EPILOGUE = 46, /* "epilogue" */
|
||||
EQUAL = 47, /* "=" */
|
||||
@@ -136,7 +136,7 @@ extern int gram_debug;
|
||||
TAG = 54, /* "<tag>" */
|
||||
TAG_ANY = 55, /* "<*>" */
|
||||
TAG_NONE = 56, /* "<>" */
|
||||
INT = 57, /* "integer literal" */
|
||||
INT_LITERAL = 57, /* "integer literal" */
|
||||
PERCENT_PARAM = 58, /* "%param" */
|
||||
PERCENT_UNION = 59, /* "%union" */
|
||||
PERCENT_EMPTY = 60 /* "%empty" */
|
||||
@@ -156,7 +156,7 @@ union GRAM_STYPE
|
||||
char* EPILOGUE; /* "epilogue" */
|
||||
char* PROLOGUE; /* "%{...%}" */
|
||||
code_props_type code_props_type; /* code_props_type */
|
||||
int INT; /* "integer literal" */
|
||||
int INT_LITERAL; /* "integer literal" */
|
||||
int yykind_82; /* int.opt */
|
||||
named_ref* yykind_95; /* named_ref.opt */
|
||||
param_type PERCENT_PARAM; /* "%param" */
|
||||
@@ -188,7 +188,7 @@ union GRAM_STYPE
|
||||
uniqstr yykind_74; /* tag.opt */
|
||||
uniqstr tag; /* tag */
|
||||
uniqstr variable; /* variable */
|
||||
unsigned char CHAR; /* "character literal" */
|
||||
unsigned char CHAR_LITERAL; /* "character literal" */
|
||||
value_type value; /* value */
|
||||
|
||||
|
||||
|
||||
+19
-51
@@ -42,8 +42,6 @@
|
||||
#include "system.h"
|
||||
|
||||
#include <c-ctype.h>
|
||||
#include <errno.h>
|
||||
#include <intprops.h>
|
||||
#include <quotearg.h>
|
||||
#include <vasnprintf.h>
|
||||
#include <xmemdup0.h>
|
||||
@@ -57,6 +55,7 @@
|
||||
#include "reader.h"
|
||||
#include "scan-code.h"
|
||||
#include "scan-gram.h"
|
||||
#include "strversion.h"
|
||||
|
||||
/* Pretend to be at least that version, to check features published
|
||||
in that version while developping it. */
|
||||
@@ -214,7 +213,7 @@
|
||||
BRACED_CODE "{...}"
|
||||
BRACED_PREDICATE "%?{...}"
|
||||
BRACKETED_ID _("[identifier]")
|
||||
CHAR _("character literal")
|
||||
CHAR_LITERAL _("character literal")
|
||||
COLON ":"
|
||||
EPILOGUE _("epilogue")
|
||||
EQUAL "="
|
||||
@@ -232,7 +231,7 @@
|
||||
%code pre-printer {tron (yyo);}
|
||||
%code post-printer {troff (yyo);}
|
||||
|
||||
%type <unsigned char> CHAR
|
||||
%type <unsigned char> CHAR_LITERAL
|
||||
%printer { fputs (char_name ($$), yyo); } <unsigned char>
|
||||
|
||||
%type <char*> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING TSTRING
|
||||
@@ -249,7 +248,7 @@
|
||||
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
||||
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
||||
|
||||
%token <int> INT _("integer literal")
|
||||
%token <int> INT_LITERAL _("integer literal")
|
||||
%printer { fprintf (yyo, "%d", $$); } <int>
|
||||
|
||||
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
|
||||
@@ -342,8 +341,8 @@ prologue_declaration:
|
||||
| "%defines" { defines_flag = true; }
|
||||
| "%defines" STRING { handle_defines ($2); }
|
||||
| "%error-verbose" { handle_error_verbose (&@$, $1); }
|
||||
| "%expect" INT { expected_sr_conflicts = $2; }
|
||||
| "%expect-rr" INT { expected_rr_conflicts = $2; }
|
||||
| "%expect" INT_LITERAL { expected_sr_conflicts = $2; }
|
||||
| "%expect-rr" INT_LITERAL { expected_rr_conflicts = $2; }
|
||||
| "%file-prefix" STRING { handle_file_prefix (&@$, &@1, $1, $2); }
|
||||
| "%glr-parser"
|
||||
{
|
||||
@@ -532,11 +531,11 @@ token_decls:
|
||||
}
|
||||
| TAG token_decl.1[syms]
|
||||
{
|
||||
$$ = symbol_list_type_set ($syms, $TAG, @TAG);
|
||||
$$ = symbol_list_type_set ($syms, $TAG);
|
||||
}
|
||||
| token_decls TAG token_decl.1[syms]
|
||||
{
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG, @TAG));
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -561,7 +560,7 @@ token_decl:
|
||||
%type <int> int.opt;
|
||||
int.opt:
|
||||
%empty { $$ = -1; }
|
||||
| INT
|
||||
| INT_LITERAL
|
||||
;
|
||||
|
||||
%type <symbol*> alias;
|
||||
@@ -592,11 +591,11 @@ token_decls_for_prec:
|
||||
}
|
||||
| TAG token_decl_for_prec.1[syms]
|
||||
{
|
||||
$$ = symbol_list_type_set ($syms, $TAG, @TAG);
|
||||
$$ = symbol_list_type_set ($syms, $TAG);
|
||||
}
|
||||
| token_decls_for_prec TAG token_decl_for_prec.1[syms]
|
||||
{
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG, @TAG));
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -632,11 +631,11 @@ symbol_decls:
|
||||
}
|
||||
| TAG symbol_decl.1[syms]
|
||||
{
|
||||
$$ = symbol_list_type_set ($syms, $TAG, @TAG);
|
||||
$$ = symbol_list_type_set ($syms, $TAG);
|
||||
}
|
||||
| symbol_decls TAG symbol_decl.1[syms]
|
||||
{
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG, @TAG));
|
||||
$$ = symbol_list_append ($1, symbol_list_type_set ($syms, $TAG));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -703,13 +702,13 @@ rhs:
|
||||
{ grammar_current_rule_empty_set (@2); }
|
||||
| rhs "%prec" symbol
|
||||
{ grammar_current_rule_prec_set ($3, @3); }
|
||||
| rhs "%dprec" INT
|
||||
| rhs "%dprec" INT_LITERAL
|
||||
{ grammar_current_rule_dprec_set ($3, @3); }
|
||||
| rhs "%merge" TAG
|
||||
{ grammar_current_rule_merge_set ($3, @3); }
|
||||
| rhs "%expect" INT
|
||||
| rhs "%expect" INT_LITERAL
|
||||
{ grammar_current_rule_expect_sr ($3, @3); }
|
||||
| rhs "%expect-rr" INT
|
||||
| rhs "%expect-rr" INT_LITERAL
|
||||
{ grammar_current_rule_expect_rr ($3, @3); }
|
||||
;
|
||||
|
||||
@@ -765,7 +764,7 @@ value:
|
||||
id:
|
||||
ID
|
||||
{ $$ = symbol_from_uniqstr ($1, @1); }
|
||||
| CHAR
|
||||
| CHAR_LITERAL
|
||||
{
|
||||
const char *var = "api.token.raw";
|
||||
if (current_class == nterm_sym)
|
||||
@@ -1043,41 +1042,11 @@ handle_pure_parser (location const *loc, char const *directive)
|
||||
}
|
||||
|
||||
|
||||
/* Convert VERSION into an int (MAJOR * 100 + MINOR). Return -1 on
|
||||
errors.
|
||||
|
||||
Changes of behavior are only on minor version changes, so "3.0.5"
|
||||
is the same as "3.0": 300. */
|
||||
static int
|
||||
str_to_version (char const *version)
|
||||
{
|
||||
IGNORE_TYPE_LIMITS_BEGIN
|
||||
int res = 0;
|
||||
errno = 0;
|
||||
char *cp = NULL;
|
||||
long major = strtol (version, &cp, 10);
|
||||
if (errno || cp == version || *cp != '.' || major < 0
|
||||
|| INT_MULTIPLY_WRAPV (major, 100, &res))
|
||||
return -1;
|
||||
|
||||
++cp;
|
||||
char *cp1 = NULL;
|
||||
long minor = strtol (cp, &cp1, 10);
|
||||
if (errno || cp1 == cp || (*cp1 != '\0' && *cp1 != '.')
|
||||
|| ! (0 <= minor && minor < 100)
|
||||
|| INT_ADD_WRAPV (minor, res, &res))
|
||||
return -1;
|
||||
|
||||
IGNORE_TYPE_LIMITS_END
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
handle_require (location const *loc, char const *version_quoted)
|
||||
{
|
||||
char *version = unquote (version_quoted);
|
||||
required_version = str_to_version (version);
|
||||
required_version = strversion_to_int (version);
|
||||
if (required_version == -1)
|
||||
{
|
||||
complain (loc, complaint, _("invalid version requirement: %s"),
|
||||
@@ -1158,8 +1127,7 @@ char_name (char c)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
static void
|
||||
current_lhs (symbol *sym, location loc, named_ref *ref)
|
||||
{
|
||||
current_lhs_symbol = sym;
|
||||
|
||||
+47
-53
@@ -28,19 +28,19 @@
|
||||
#include "lssi.h"
|
||||
#include "nullable.h"
|
||||
|
||||
typedef struct parse_state
|
||||
struct parse_state
|
||||
{
|
||||
// path of state-items the parser has traversed
|
||||
// Path of state-items the parser has traversed.
|
||||
struct si_chunk
|
||||
{
|
||||
// elements newly added in this chunk
|
||||
gl_list_t contents;
|
||||
// properties of the linked list this chunk represents
|
||||
// Elements newly added in this chunk.
|
||||
state_item_list contents;
|
||||
// Properties of the linked list this chunk represents.
|
||||
const state_item *head_elt;
|
||||
const state_item *tail_elt;
|
||||
size_t total_size;
|
||||
} state_items;
|
||||
// list of derivations of the symbols
|
||||
// List of derivations of the symbols.
|
||||
struct deriv_chunk
|
||||
{
|
||||
derivation_list contents;
|
||||
@@ -50,18 +50,15 @@ typedef struct parse_state
|
||||
} derivs;
|
||||
struct parse_state *parent;
|
||||
int reference_count;
|
||||
// incremented during productions,
|
||||
// decremented during reductions
|
||||
// Incremented during productions, decremented during reductions.
|
||||
int depth;
|
||||
// whether the contents of the chunks should be
|
||||
// prepended or appended to the list the chunks
|
||||
// represent
|
||||
// Whether the contents of the chunks should be prepended or
|
||||
// appended to the list the chunks represent.
|
||||
bool prepend;
|
||||
// causes chunk contents to be freed when the
|
||||
// reference count is one. Used when only the chunk metadata
|
||||
// will be needed.
|
||||
// Causes chunk contents to be freed when the reference count is
|
||||
// one. Used when only the chunk metadata will be needed.
|
||||
bool free_contents_early;
|
||||
} parse_state;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
@@ -135,7 +132,7 @@ static parse_state *
|
||||
copy_parse_state (bool prepend, parse_state *parent)
|
||||
{
|
||||
parse_state *res = xmalloc (sizeof *res);
|
||||
memcpy (res, parent, sizeof *res);
|
||||
*res = *parent;
|
||||
res->state_items.contents
|
||||
= gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
|
||||
res->derivs.contents = derivation_list_new ();
|
||||
@@ -252,7 +249,7 @@ parse_state_completed_steps (const parse_state *ps, int *shifts, int *production
|
||||
while (root_ps->parent)
|
||||
root_ps = root_ps->parent;
|
||||
|
||||
gl_list_t sis = root_ps->state_items.contents;
|
||||
state_item_list sis = root_ps->state_items.contents;
|
||||
int count = 0;
|
||||
|
||||
state_item *last = NULL;
|
||||
@@ -337,19 +334,17 @@ parser_pop (parse_state *ps, int deriv_index,
|
||||
for (int i = 0; i < 4; ++i)
|
||||
chunks[i] = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
|
||||
for (parse_state *pn = ps; pn != NULL; pn = pn->parent)
|
||||
{
|
||||
if (pn->prepend)
|
||||
{
|
||||
gl_list_add_last (chunks[0], pn->state_items.contents);
|
||||
gl_list_add_last (chunks[2], pn->derivs.contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_list_add_first (chunks[1], pn->state_items.contents);
|
||||
gl_list_add_first (chunks[3], pn->derivs.contents);
|
||||
}
|
||||
}
|
||||
gl_list_t popped_derivs = derivation_list_new ();
|
||||
if (pn->prepend)
|
||||
{
|
||||
gl_list_add_last (chunks[0], pn->state_items.contents);
|
||||
gl_list_add_last (chunks[2], pn->derivs.contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_list_add_first (chunks[1], pn->state_items.contents);
|
||||
gl_list_add_first (chunks[3], pn->derivs.contents);
|
||||
}
|
||||
derivation_list popped_derivs = derivation_list_new ();
|
||||
gl_list_t ret_chunks[4] = { ret->state_items.contents, NULL,
|
||||
ret->derivs.contents, popped_derivs
|
||||
};
|
||||
@@ -390,7 +385,7 @@ parser_pop (parse_state *ps, int deriv_index,
|
||||
}
|
||||
|
||||
void
|
||||
parse_state_lists (parse_state *ps, gl_list_t *sitems,
|
||||
parse_state_lists (parse_state *ps, state_item_list *sitems,
|
||||
derivation_list *derivs)
|
||||
{
|
||||
parse_state *temp = empty_parse_state ();
|
||||
@@ -418,12 +413,12 @@ nullable_closure (parse_state *ps, state_item *si, parse_state_list state_list)
|
||||
for (state_item_number sin = si->trans; sin != -1;
|
||||
prev_sin = sin, sin = state_items[sin].trans)
|
||||
{
|
||||
state_item *psi = state_items + prev_sin;
|
||||
state_item *psi = &state_items[prev_sin];
|
||||
symbol_number sp = item_number_as_symbol_number (*psi->item);
|
||||
if (ISTOKEN (sp) || !nullable[sp - ntokens])
|
||||
break;
|
||||
|
||||
state_item *nsi = state_items + sin;
|
||||
state_item *nsi = &state_items[sin];
|
||||
current_ps = copy_parse_state (false, current_ps);
|
||||
ps_si_append (current_ps, nsi);
|
||||
ps_derivs_append (current_ps, derivation_new (sp, derivation_list_new ()));
|
||||
@@ -431,26 +426,25 @@ nullable_closure (parse_state *ps, state_item *si, parse_state_list state_list)
|
||||
}
|
||||
}
|
||||
|
||||
gl_list_t
|
||||
parse_state_list
|
||||
simulate_transition (parse_state *ps)
|
||||
{
|
||||
const state_item *si = ps->state_items.tail_elt;
|
||||
symbol_number sym = item_number_as_symbol_number (*si->item);
|
||||
// Transition on the same next symbol, taking nullable
|
||||
// symbols into account.
|
||||
gl_list_t result = parse_state_list_new ();
|
||||
parse_state_list result = parse_state_list_new ();
|
||||
state_item_number si_next = si->trans;
|
||||
// check for disabled transition, shouldn't happen
|
||||
// as any state_items that lead to these should be
|
||||
// disabled.
|
||||
// Check for disabled transition, shouldn't happen as any
|
||||
// state_items that lead to these should be disabled.
|
||||
if (si_next < 0)
|
||||
return result;
|
||||
parse_state *next_ps = copy_parse_state (false, ps);
|
||||
ps_si_append (next_ps, state_items + si_next);
|
||||
ps_si_append (next_ps, &state_items[si_next]);
|
||||
ps_derivs_append (next_ps, derivation_new_leaf (sym));
|
||||
parse_state_list_append (result, next_ps);
|
||||
|
||||
nullable_closure (next_ps, state_items + si_next, result);
|
||||
nullable_closure (next_ps, &state_items[si_next], result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -473,10 +467,10 @@ compatible (symbol_number sym1, symbol_number sym2)
|
||||
return false;
|
||||
}
|
||||
|
||||
gl_list_t
|
||||
parse_state_list
|
||||
simulate_production (parse_state *ps, symbol_number compat_sym)
|
||||
{
|
||||
gl_list_t result = parse_state_list_new ();
|
||||
parse_state_list result = parse_state_list_new ();
|
||||
const state_item *si = parse_state_tail (ps);
|
||||
if (si->prods)
|
||||
{
|
||||
@@ -486,7 +480,7 @@ simulate_production (parse_state *ps, symbol_number compat_sym)
|
||||
{
|
||||
// Take production step only if lhs is not nullable and
|
||||
// if first rhs symbol is compatible with compat_sym
|
||||
state_item *next = state_items + sin;
|
||||
state_item *next = &state_items[sin];
|
||||
item_number *itm1 = next->item;
|
||||
if (!compatible (*itm1, compat_sym) || !production_allowed (si, next))
|
||||
continue;
|
||||
@@ -504,10 +498,10 @@ simulate_production (parse_state *ps, symbol_number compat_sym)
|
||||
// simulates a reduction on the given parse state, conflict_item is the
|
||||
// item associated with ps's conflict. symbol_set is a lookahead set this
|
||||
// reduction must be compatible with
|
||||
gl_list_t
|
||||
parse_state_list
|
||||
simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
{
|
||||
gl_list_t result = parse_state_list_new ();
|
||||
parse_state_list result = parse_state_list_new ();
|
||||
|
||||
int s_size = ps->state_items.total_size;
|
||||
int d_size = ps->derivs.total_size;
|
||||
@@ -529,7 +523,7 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
if (s_size != rule_len + 1)
|
||||
{
|
||||
state_item *tail = (state_item *) new_root->state_items.tail_elt;
|
||||
ps_si_append (new_root, state_items + tail->trans);
|
||||
ps_si_append (new_root, &state_items[tail->trans]);
|
||||
parse_state_list_append (result, new_root);
|
||||
}
|
||||
else
|
||||
@@ -537,7 +531,7 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
// The head state_item is a production item, so we need to prepend
|
||||
// with possible source state-items.
|
||||
const state_item *head = ps->state_items.head_elt;
|
||||
gl_list_t prev = lssi_reverse_production (head, symbol_set);
|
||||
state_item_list prev = lssi_reverse_production (head, symbol_set);
|
||||
// TODO: better understand what causes this case.
|
||||
if (gl_list_size (prev) == 0)
|
||||
{
|
||||
@@ -560,7 +554,7 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
copy = copy_parse_state (false, copy);
|
||||
struct si_chunk *sis = ©->state_items;
|
||||
const state_item *tail = sis->tail_elt;
|
||||
ps_si_append (copy, state_items + tail->trans);
|
||||
ps_si_append (copy, &state_items[tail->trans]);
|
||||
parse_state_list_append (result, copy);
|
||||
nullable_closure (copy, (state_item *) sis->tail_elt, result);
|
||||
}
|
||||
@@ -570,10 +564,10 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
return result;
|
||||
}
|
||||
|
||||
gl_list_t
|
||||
parse_state_list
|
||||
parser_prepend (parse_state *ps)
|
||||
{
|
||||
gl_list_t res = parse_state_list_new ();
|
||||
parse_state_list res = parse_state_list_new ();
|
||||
const state_item *head = ps->state_items.head_elt;
|
||||
symbol_number prepend_sym =
|
||||
item_number_as_symbol_number (*(head->item - 1));
|
||||
@@ -582,7 +576,7 @@ parser_prepend (parse_state *ps)
|
||||
BITSET_FOR_EACH (biter, head->revs, sin, 0)
|
||||
{
|
||||
parse_state *copy = copy_parse_state (true, ps);
|
||||
ps_si_prepend (copy, state_items + sin);
|
||||
ps_si_prepend (copy, &state_items[sin]);
|
||||
if (SI_TRANSITION (head))
|
||||
ps_derivs_prepend (copy, derivation_new_leaf (prepend_sym));
|
||||
parse_state_list_append (res, copy);
|
||||
@@ -596,8 +590,8 @@ print_parse_state (parse_state *ps)
|
||||
FILE *out = stderr;
|
||||
fprintf (out, "(size %zu depth %d rc %d)\n",
|
||||
ps->state_items.total_size, ps->depth, ps->reference_count);
|
||||
print_state_item (ps->state_items.head_elt, out, "");
|
||||
print_state_item (ps->state_items.tail_elt, out, "");
|
||||
state_item_print (ps->state_items.head_elt, out, "");
|
||||
state_item_print (ps->state_items.tail_elt, out, "");
|
||||
if (ps->derivs.total_size > 0)
|
||||
derivation_print (ps->derivs.head_elt, out, "");
|
||||
putc ('\n', out);
|
||||
|
||||
@@ -113,7 +113,7 @@ int parse_state_length (const parse_state *ps);
|
||||
int parse_state_depth (const parse_state *ps);
|
||||
|
||||
/* returns the linked lists that the parse state is supposed to represent */
|
||||
void parse_state_lists (parse_state *ps, gl_list_t *state_items,
|
||||
void parse_state_lists (parse_state *ps, state_item_list *state_items,
|
||||
derivation_list *derivs);
|
||||
|
||||
/* various functions that return a list of states based off of
|
||||
|
||||
+3
-3
@@ -96,7 +96,7 @@ print_core (struct obstack *oout, state *s)
|
||||
obstack_sgrow (oout, " %empty");
|
||||
|
||||
/* Experimental feature: display the lookahead tokens. */
|
||||
if (report_flag & report_lookahead_tokens
|
||||
if (report_flag & report_lookaheads
|
||||
&& item_number_is_rule_number (*sp1))
|
||||
{
|
||||
/* Find the reduction we are handling. */
|
||||
@@ -104,13 +104,13 @@ print_core (struct obstack *oout, state *s)
|
||||
int redno = state_reduction_find (s, r);
|
||||
|
||||
/* Print them if there are. */
|
||||
if (reds->lookahead_tokens && redno != -1)
|
||||
if (reds->lookaheads && redno != -1)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
char const *sep = "";
|
||||
obstack_sgrow (oout, " [");
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookaheads[redno], k, 0)
|
||||
{
|
||||
obstack_sgrow (oout, sep);
|
||||
obstack_backslash (oout, symbols[k]->tag);
|
||||
|
||||
+29
-22
@@ -86,12 +86,12 @@ print_core (FILE *out, int level, state *s)
|
||||
reductions *reds = s->reductions;
|
||||
int red = state_reduction_find (s, r);
|
||||
/* Print item with lookaheads if there are. */
|
||||
if (reds->lookahead_tokens && red != -1)
|
||||
if (reds->lookaheads && red != -1)
|
||||
{
|
||||
xml_printf (out, level + 1,
|
||||
"<item rule-number=\"%d\" dot=\"%d\">",
|
||||
r->number, sp1 - sp);
|
||||
state_rule_lookahead_tokens_print_xml (s, r,
|
||||
state_rule_lookaheads_print_xml (s, r,
|
||||
out, level + 2);
|
||||
xml_puts (out, level + 1, "</item>");
|
||||
printed = true;
|
||||
@@ -202,26 +202,26 @@ print_errs (FILE *out, int level, state *s)
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`-------------------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOKAHEAD (which can be 'default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
print_reduction (FILE *out, int level, char const *lookahead_token,
|
||||
print_reduction (FILE *out, int level, char const *lookahead,
|
||||
rule *r, bool enabled)
|
||||
{
|
||||
if (r->number)
|
||||
xml_printf (out, level,
|
||||
"<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
|
||||
xml_escape (lookahead_token),
|
||||
xml_escape (lookahead),
|
||||
r->number,
|
||||
enabled ? "true" : "false");
|
||||
else
|
||||
xml_printf (out, level,
|
||||
"<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
|
||||
xml_escape (lookahead_token),
|
||||
xml_escape (lookahead),
|
||||
enabled ? "true" : "false");
|
||||
}
|
||||
|
||||
@@ -258,13 +258,13 @@ print_reductions (FILE *out, int level, state *s)
|
||||
if (default_reduction)
|
||||
report = true;
|
||||
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookaheads[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -289,14 +289,14 @@ print_reductions (FILE *out, int level, state *s)
|
||||
xml_puts (out, level, "<reductions>");
|
||||
|
||||
/* Report lookahead tokens (or $default) and reductions. */
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool defaulted = false;
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookaheads[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -382,14 +382,17 @@ print_grammar (FILE *out, int level)
|
||||
for (int i = 0; i < max_code + 1; i++)
|
||||
if (token_translations[i] != undeftoken->content->number)
|
||||
{
|
||||
char const *tag = symbols[token_translations[i]]->tag;
|
||||
int precedence = symbols[token_translations[i]]->content->prec;
|
||||
assoc associativity = symbols[token_translations[i]]->content->assoc;
|
||||
symbol const *sym = symbols[token_translations[i]];
|
||||
char const *tag = sym->tag;
|
||||
char const *type = sym->content->type_name;
|
||||
int precedence = sym->content->prec;
|
||||
assoc associativity = sym->content->assoc;
|
||||
xml_indent (out, level + 2);
|
||||
fprintf (out,
|
||||
"<terminal symbol-number=\"%d\" token-number=\"%d\""
|
||||
" name=\"%s\" usefulness=\"%s\"",
|
||||
token_translations[i], i, xml_escape (tag),
|
||||
" name=\"%s\" type=\"%s\" usefulness=\"%s\"",
|
||||
token_translations[i], i, xml_escape_n (0, tag),
|
||||
type ? xml_escape_n (1, type) : "",
|
||||
reduce_token_unused_in_grammar (token_translations[i])
|
||||
? "unused-in-grammar" : "useful");
|
||||
if (precedence)
|
||||
@@ -404,12 +407,16 @@ print_grammar (FILE *out, int level)
|
||||
xml_puts (out, level + 1, "<nonterminals>");
|
||||
for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; i++)
|
||||
{
|
||||
char const *tag = symbols[i]->tag;
|
||||
symbol const *sym = symbols[i];
|
||||
char const *tag = sym->tag;
|
||||
char const *type = sym->content->type_name;
|
||||
xml_printf (out, level + 2,
|
||||
"<nonterminal symbol-number=\"%d\" name=\"%s\""
|
||||
" type=\"%s\""
|
||||
" usefulness=\"%s\"/>",
|
||||
i, xml_escape (tag),
|
||||
reduce_nonterminal_useless_in_grammar (symbols[i]->content)
|
||||
i, xml_escape_n (0, tag),
|
||||
type ? xml_escape_n (1, type) : "",
|
||||
reduce_nonterminal_useless_in_grammar (sym->content)
|
||||
? "useless-in-grammar" : "useful");
|
||||
}
|
||||
xml_puts (out, level + 1, "</nonterminals>");
|
||||
|
||||
+22
-21
@@ -90,9 +90,9 @@ print_core (FILE *out, const state *s)
|
||||
previous_rule = r;
|
||||
|
||||
/* Display the lookahead tokens? */
|
||||
if (report_flag & report_lookahead_tokens
|
||||
if (report_flag & report_lookaheads
|
||||
&& item_number_is_rule_number (*sp1))
|
||||
state_rule_lookahead_tokens_print (s, r, out);
|
||||
state_rule_lookaheads_print (s, r, out);
|
||||
fputc ('\n', out);
|
||||
}
|
||||
}
|
||||
@@ -180,19 +180,19 @@ print_errs (FILE *out, const state *s)
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`-------------------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOKAHEAD (which can be 'default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
print_reduction (FILE *out, size_t width,
|
||||
const char *lookahead_token,
|
||||
const char *lookahead,
|
||||
rule *r, bool enabled)
|
||||
{
|
||||
fprintf (out, " %s", lookahead_token);
|
||||
for (int j = width - mbswidth (lookahead_token, 0); j > 0; --j)
|
||||
fprintf (out, " %s", lookahead);
|
||||
for (int j = width - mbswidth (lookahead, 0); j > 0; --j)
|
||||
fputc (' ', out);
|
||||
if (!enabled)
|
||||
fputc ('[', out);
|
||||
@@ -239,13 +239,13 @@ print_reductions (FILE *out, const state *s)
|
||||
if (default_reduction)
|
||||
width = mbswidth (_("$default"), 0);
|
||||
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
for (int i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookaheads[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -268,7 +268,7 @@ print_reductions (FILE *out, const state *s)
|
||||
bool default_reduction_only = true;
|
||||
|
||||
/* Report lookahead tokens (or $default) and reductions. */
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
for (int i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool defaulted = false;
|
||||
@@ -277,7 +277,7 @@ print_reductions (FILE *out, const state *s)
|
||||
default_reduction_only = false;
|
||||
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookaheads[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -377,11 +377,11 @@ print_terminal_symbols (FILE *out)
|
||||
for (int i = 0; i < max_code + 1; ++i)
|
||||
if (token_translations[i] != undeftoken->content->number)
|
||||
{
|
||||
const char *tag = symbols[token_translations[i]]->tag;
|
||||
const symbol *sym = symbols[token_translations[i]];
|
||||
const char *tag = sym->tag;
|
||||
fprintf (out, "%4s%s", "", tag);
|
||||
if (symbols[token_translations[i]]->content->type_name)
|
||||
fprintf (out, " <%s>",
|
||||
symbols[token_translations[i]]->content->type_name);
|
||||
if (sym->content->type_name)
|
||||
fprintf (out, " <%s>", sym->content->type_name);
|
||||
fprintf (out, " (%d)", i);
|
||||
|
||||
for (rule_number r = 0; r < nrules; r++)
|
||||
@@ -403,7 +403,8 @@ print_nonterminal_symbols (FILE *out)
|
||||
fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
|
||||
for (symbol_number i = ntokens; i < nsyms; i++)
|
||||
{
|
||||
const char *tag = symbols[i]->tag;
|
||||
const symbol *sym = symbols[i];
|
||||
const char *tag = sym->tag;
|
||||
bool on_left = false;
|
||||
bool on_right = false;
|
||||
|
||||
@@ -418,9 +419,9 @@ print_nonterminal_symbols (FILE *out)
|
||||
|
||||
int column = 4 + mbswidth (tag, 0);
|
||||
fprintf (out, "%4s%s", "", tag);
|
||||
if (symbols[i]->content->type_name)
|
||||
if (sym->content->type_name)
|
||||
column += fprintf (out, " <%s>",
|
||||
symbols[i]->content->type_name);
|
||||
sym->content->type_name);
|
||||
fprintf (out, " (%d)\n", i);
|
||||
|
||||
if (on_left)
|
||||
|
||||
+8
-5
@@ -406,8 +406,8 @@ grammar_midrule_action (void)
|
||||
action. Create the MIDRULE. */
|
||||
location dummy_loc = current_rule->action_props.location;
|
||||
symbol *dummy = dummy_symbol_get (dummy_loc);
|
||||
symbol_type_set(dummy,
|
||||
current_rule->action_props.type, current_rule->action_props.location);
|
||||
symbol_type_set (dummy,
|
||||
current_rule->action_props.type, current_rule->action_props.location);
|
||||
symbol_list *midrule = symbol_list_sym_new (dummy, dummy_loc);
|
||||
|
||||
/* Remember named_ref of previous action. */
|
||||
@@ -804,7 +804,7 @@ check_and_convert_grammar (void)
|
||||
|
||||
$accept: %start $end. */
|
||||
{
|
||||
symbol_list *p = symbol_list_sym_new (accept, empty_loc);
|
||||
symbol_list *p = symbol_list_sym_new (acceptsymbol, empty_loc);
|
||||
p->rhs_loc = grammar->rhs_loc;
|
||||
p->next = symbol_list_sym_new (startsymbol, empty_loc);
|
||||
p->next->next = symbol_list_sym_new (eoftoken, empty_loc);
|
||||
@@ -815,8 +815,11 @@ check_and_convert_grammar (void)
|
||||
grammar = p;
|
||||
}
|
||||
|
||||
aver (nsyms <= SYMBOL_NUMBER_MAXIMUM);
|
||||
aver (nsyms == ntokens + nnterms);
|
||||
if (SYMBOL_NUMBER_MAXIMUM - nnterms < ntokens)
|
||||
complain (NULL, fatal, "too many symbols in input grammar (limit is %d)",
|
||||
SYMBOL_NUMBER_MAXIMUM);
|
||||
|
||||
nsyms = ntokens + nnterms;
|
||||
|
||||
/* Assign the symbols their symbol numbers. */
|
||||
symbols_pack ();
|
||||
|
||||
+4
-4
@@ -160,9 +160,9 @@ inaccessable_symbols (void)
|
||||
bitset Pp = bitset_create (nrules, BITSET_FIXED);
|
||||
|
||||
/* If the start symbol isn't useful, then nothing will be useful. */
|
||||
if (bitset_test (N, accept->content->number - ntokens))
|
||||
if (bitset_test (N, acceptsymbol->content->number - ntokens))
|
||||
{
|
||||
bitset_set (V, accept->content->number);
|
||||
bitset_set (V, acceptsymbol->content->number);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -301,7 +301,7 @@ nonterminals_reduce (void)
|
||||
for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp)
|
||||
if (ISVAR (*rhsp))
|
||||
*rhsp = symbol_number_as_item_number (nterm_map[*rhsp - ntokens]);
|
||||
accept->content->number = nterm_map[accept->content->number - ntokens];
|
||||
acceptsymbol->content->number = nterm_map[acceptsymbol->content->number - ntokens];
|
||||
}
|
||||
|
||||
nsyms -= nuseless_nonterminals;
|
||||
@@ -381,7 +381,7 @@ reduce_grammar (void)
|
||||
{
|
||||
reduce_print ();
|
||||
|
||||
if (!bitset_test (N, accept->content->number - ntokens))
|
||||
if (!bitset_test (N, acceptsymbol->content->number - ntokens))
|
||||
complain (&startsymbol_loc, fatal,
|
||||
_("start symbol %s does not derive any sentence"),
|
||||
startsymbol->tag);
|
||||
|
||||
+21
-12
@@ -322,8 +322,8 @@ eqopt ({sp}=)?
|
||||
BEGIN SC_AFTER_IDENTIFIER;
|
||||
}
|
||||
|
||||
{int} RETURN_VALUE (INT, scan_integer (yytext, 10, *loc));
|
||||
{xint} RETURN_VALUE (INT, scan_integer (yytext, 16, *loc));
|
||||
{int} RETURN_VALUE (INT_LITERAL, scan_integer (yytext, 10, *loc));
|
||||
{xint} RETURN_VALUE (INT_LITERAL, scan_integer (yytext, 16, *loc));
|
||||
|
||||
/* Identifiers may not start with a digit. Yet, don't silently
|
||||
accept "1FOO" as "1 FOO". */
|
||||
@@ -403,6 +403,7 @@ eqopt ({sp}=)?
|
||||
{
|
||||
\0 {
|
||||
complain (loc, complaint, _("invalid null character"));
|
||||
STRING_FINISH ();
|
||||
STRING_FREE ();
|
||||
return GRAM_error;
|
||||
}
|
||||
@@ -566,6 +567,8 @@ eqopt ({sp}=)?
|
||||
_("POSIX Yacc does not support string literals"));
|
||||
RETURN_VALUE (STRING, last_string);
|
||||
}
|
||||
<<EOF>> unexpected_eof (token_start, "\"");
|
||||
"\n" unexpected_newline (token_start, "\"");
|
||||
}
|
||||
|
||||
<SC_ESCAPED_TSTRING>
|
||||
@@ -579,13 +582,10 @@ eqopt ({sp}=)?
|
||||
_("POSIX Yacc does not support string literals"));
|
||||
RETURN_VALUE (TSTRING, last_string);
|
||||
}
|
||||
<<EOF>> unexpected_eof (token_start, "\")");
|
||||
"\n" unexpected_newline (token_start, "\")");
|
||||
}
|
||||
|
||||
<SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
|
||||
{
|
||||
<<EOF>> unexpected_eof (token_start, "\"");
|
||||
"\n" unexpected_newline (token_start, "\"");
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------.
|
||||
@@ -599,7 +599,6 @@ eqopt ({sp}=)?
|
||||
STRING_FINISH ();
|
||||
BEGIN INITIAL;
|
||||
loc->start = token_start;
|
||||
val->CHAR = last_string[0];
|
||||
|
||||
if (last_string[0] == '\0')
|
||||
{
|
||||
@@ -615,8 +614,9 @@ eqopt ({sp}=)?
|
||||
}
|
||||
else
|
||||
{
|
||||
val->CHAR_LITERAL = last_string[0];
|
||||
STRING_FREE ();
|
||||
return CHAR;
|
||||
return CHAR_LITERAL;
|
||||
}
|
||||
}
|
||||
{eol} unexpected_newline (token_start, "'");
|
||||
@@ -691,6 +691,15 @@ eqopt ({sp}=)?
|
||||
p);
|
||||
STRING_1GROW ('?');
|
||||
}
|
||||
|
||||
"\\" {
|
||||
// None of the other rules matched: the last character of this
|
||||
// file is "\". But Flex does not support "\\<<EOF>>".
|
||||
unexpected_eof (token_start,
|
||||
YY_START == SC_ESCAPED_CHARACTER ? "?'"
|
||||
: YY_START == SC_ESCAPED_STRING ? "?\""
|
||||
: "?\")");
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------.
|
||||
@@ -933,9 +942,9 @@ convert_ucn_to_byte (char const *ucn)
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------.
|
||||
| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
|
||||
`---------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------.
|
||||
| Handle '#line INT_LITERAL( "FILE")?\n'. ARGS has already skipped '#line '. |
|
||||
`----------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
handle_syncline (char *args, location loc)
|
||||
|
||||
+33
-35
@@ -144,13 +144,13 @@ init_state_items (void)
|
||||
for (int j = 0; j < s->nitems; ++j)
|
||||
{
|
||||
state_item_set (sidx, s, s->items[j]);
|
||||
state_item *si = state_items + sidx;
|
||||
state_item *si = &state_items[sidx];
|
||||
const rule *r = item_rule (si->item);
|
||||
if (rule_search_idx < red->num && red->rules[rule_search_idx] < r)
|
||||
++rule_search_idx;
|
||||
if (rule_search_idx < red->num && r == red->rules[rule_search_idx])
|
||||
{
|
||||
bitsetv lookahead = red->lookahead_tokens;
|
||||
bitsetv lookahead = red->lookaheads;
|
||||
if (lookahead)
|
||||
si->lookahead = lookahead[rule_search_idx];
|
||||
}
|
||||
@@ -163,7 +163,7 @@ init_state_items (void)
|
||||
state_item_set (sidx, s, off);
|
||||
if (item_number_is_rule_number (ritem[off]))
|
||||
{
|
||||
bitsetv lookahead = red->lookahead_tokens;
|
||||
bitsetv lookahead = red->lookaheads;
|
||||
if (lookahead)
|
||||
state_items[sidx].lookahead = lookahead[rule_search_idx];
|
||||
++rule_search_idx;
|
||||
@@ -211,7 +211,7 @@ init_trans (void)
|
||||
for (int j = 0; j < t->num; ++j)
|
||||
if (!TRANSITION_IS_DISABLED (t, j))
|
||||
hash_xinsert (transition_set, t->states[j]);
|
||||
for (int j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
for (state_item_number j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
{
|
||||
item_number *item = state_items[j].item;
|
||||
if (item_number_is_rule_number (*item))
|
||||
@@ -222,16 +222,14 @@ init_trans (void)
|
||||
// find the item in the destination state that corresponds
|
||||
// to the transition of item
|
||||
for (int k = 0; k < dst->nitems; ++k)
|
||||
{
|
||||
if (item + 1 == ritem + dst->items[k])
|
||||
{
|
||||
state_item_number dstSI =
|
||||
state_item_index_lookup (dst->number, k);
|
||||
if (item + 1 == ritem + dst->items[k])
|
||||
{
|
||||
state_item_number dstSI =
|
||||
state_item_index_lookup (dst->number, k);
|
||||
|
||||
state_items[j].trans = dstSI;
|
||||
bitset_set (state_items[dstSI].revs, j);
|
||||
break;
|
||||
}
|
||||
state_items[j].trans = dstSI;
|
||||
bitset_set (state_items[dstSI].revs, j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
hash_free (transition_set);
|
||||
@@ -250,10 +248,10 @@ init_prods (void)
|
||||
|
||||
// Add the nitems of state to skip to the production portion
|
||||
// of that state's state_items
|
||||
for (int j = state_item_map[i] + s->nitems;
|
||||
for (state_item_number j = state_item_map[i] + s->nitems;
|
||||
j < state_item_map[i + 1]; ++j)
|
||||
{
|
||||
state_item *src = state_items + j;
|
||||
state_item *src = &state_items[j];
|
||||
item_number *item = src->item;
|
||||
symbol_number lhs = item_rule (item)->lhs->number;
|
||||
bitset itms = hash_pair_lookup (closure_map, lhs);
|
||||
@@ -266,9 +264,9 @@ init_prods (void)
|
||||
}
|
||||
// For each item with a dot followed by a nonterminal,
|
||||
// try to create a production edge.
|
||||
for (int j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
for (state_item_number j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
{
|
||||
state_item *src = state_items + j;
|
||||
state_item *src = &state_items[j];
|
||||
item_number item = *(src->item);
|
||||
// Skip reduce items and items with terminals after the dot
|
||||
if (item_number_is_rule_number (item) || ISTOKEN (item))
|
||||
@@ -301,12 +299,12 @@ gen_lookaheads (void)
|
||||
{
|
||||
for (state_item_number i = 0; i < nstate_items; ++i)
|
||||
{
|
||||
state_item *si = state_items + i;
|
||||
state_item *si = &state_items[i];
|
||||
if (item_number_is_symbol_number (*(si->item)) || !si->lookahead)
|
||||
continue;
|
||||
|
||||
bitset lookahead = si->lookahead;
|
||||
gl_list_t queue =
|
||||
state_item_list queue =
|
||||
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
|
||||
(const void **) &si);
|
||||
|
||||
@@ -339,7 +337,7 @@ init_firsts (void)
|
||||
firsts = bitsetv_create (nnterms, nsyms, BITSET_FIXED);
|
||||
for (rule_number i = 0; i < nrules; ++i)
|
||||
{
|
||||
rule *r = rules + i;
|
||||
rule *r = &rules[i];
|
||||
item_number *n = r->rhs;
|
||||
// Iterate through nullable nonterminals to try to find a terminal.
|
||||
while (item_number_is_symbol_number (*n) && ISVAR (*n)
|
||||
@@ -357,7 +355,7 @@ init_firsts (void)
|
||||
change = false;
|
||||
for (rule_number i = 0; i < nrules; ++i)
|
||||
{
|
||||
rule *r = rules + i;
|
||||
rule *r = &rules[i];
|
||||
symbol_number lhs = r->lhs->number;
|
||||
bitset f_lhs = FIRSTS (lhs);
|
||||
for (item_number *n = r->rhs;
|
||||
@@ -392,7 +390,7 @@ disable_state_item (state_item *si)
|
||||
static void
|
||||
prune_forward (const state_item *si)
|
||||
{
|
||||
gl_list_t queue =
|
||||
state_item_list queue =
|
||||
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
|
||||
(const void **) &si);
|
||||
|
||||
@@ -401,7 +399,7 @@ prune_forward (const state_item *si)
|
||||
state_item *dsi = (state_item *) gl_list_get_at (queue, 0);
|
||||
gl_list_remove_at (queue, 0);
|
||||
if (dsi->trans >= 0)
|
||||
gl_list_add_last (queue, state_items + dsi->trans);
|
||||
gl_list_add_last (queue, &state_items[dsi->trans]);
|
||||
|
||||
if (dsi->prods)
|
||||
{
|
||||
@@ -409,7 +407,7 @@ prune_forward (const state_item *si)
|
||||
state_item_number sin;
|
||||
BITSET_FOR_EACH (biter, dsi->prods, sin, 0)
|
||||
{
|
||||
const state_item *prod = state_items + sin;
|
||||
const state_item *prod = &state_items[sin];
|
||||
bitset_reset (prod->revs, dsi - state_items);
|
||||
if (bitset_empty_p (prod->revs))
|
||||
gl_list_add_last (queue, prod);
|
||||
@@ -427,7 +425,7 @@ prune_forward (const state_item *si)
|
||||
static void
|
||||
prune_backward (const state_item *si)
|
||||
{
|
||||
gl_list_t queue =
|
||||
state_item_list queue =
|
||||
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
|
||||
(const void **) &si);
|
||||
|
||||
@@ -441,7 +439,7 @@ prune_backward (const state_item *si)
|
||||
{
|
||||
if (SI_DISABLED (sin))
|
||||
continue;
|
||||
state_item *rev = state_items + sin;
|
||||
state_item *rev = &state_items[sin];
|
||||
if (rev->prods)
|
||||
{
|
||||
bitset_reset (rev->prods, dsi - state_items);
|
||||
@@ -466,7 +464,7 @@ prune_disabled_paths (void)
|
||||
{
|
||||
for (int i = nstate_items - 1; i >= 0; --i)
|
||||
{
|
||||
state_item *si = state_items + i;
|
||||
state_item *si = &state_items[i];
|
||||
if (si->trans == -1 && item_number_is_symbol_number (*si->item))
|
||||
{
|
||||
prune_forward (si);
|
||||
@@ -477,7 +475,7 @@ prune_disabled_paths (void)
|
||||
}
|
||||
|
||||
void
|
||||
print_state_item (const state_item *si, FILE *out, const char *prefix)
|
||||
state_item_print (const state_item *si, FILE *out, const char *prefix)
|
||||
{
|
||||
fputs (prefix, out);
|
||||
item_print (si->item, NULL, out);
|
||||
@@ -494,9 +492,9 @@ state_items_report (void)
|
||||
for (state_number i = 0; i < nstates; ++i)
|
||||
{
|
||||
printf ("State %d:\n", i);
|
||||
for (int j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
for (state_item_number j = state_item_map[i]; j < state_item_map[i + 1]; ++j)
|
||||
{
|
||||
state_item *si = state_items + j;
|
||||
state_item *si = &state_items[j];
|
||||
item_print (si->item, NULL, stdout);
|
||||
if (SI_DISABLED (j))
|
||||
{
|
||||
@@ -508,7 +506,7 @@ state_items_report (void)
|
||||
if (si->trans >= 0)
|
||||
{
|
||||
fputs (" -> ", stdout);
|
||||
print_state_item (state_items + si->trans, stdout, "");
|
||||
state_item_print (&state_items[si->trans], stdout, "");
|
||||
}
|
||||
|
||||
bitset sets[2] = { si->prods, si->revs };
|
||||
@@ -523,7 +521,7 @@ state_items_report (void)
|
||||
BITSET_FOR_EACH (biter, b, sin, 0)
|
||||
{
|
||||
fputs (txt[seti], stdout);
|
||||
print_state_item (state_items + sin, stdout, "");
|
||||
state_item_print (&state_items[sin], stdout, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,10 +560,10 @@ state_items_init (void)
|
||||
void
|
||||
state_items_free (void)
|
||||
{
|
||||
for (int i = 0; i < nstate_items; ++i)
|
||||
for (state_item_number i = 0; i < nstate_items; ++i)
|
||||
if (!SI_DISABLED (i))
|
||||
{
|
||||
state_item *si = state_items + i;
|
||||
state_item *si = &state_items[i];
|
||||
if (si->prods)
|
||||
bitset_free (si->prods);
|
||||
bitset_free (si->revs);
|
||||
@@ -594,5 +592,5 @@ production_allowed (const state_item *si, const state_item *next)
|
||||
if (prec1 == prec2 && s1->assoc == left_assoc)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
+14
-9
@@ -28,16 +28,16 @@
|
||||
# include "state.h"
|
||||
|
||||
/* Initializes a graph connecting (state, production item) pairs to
|
||||
pairs they can make a transition or production step to. This graph
|
||||
pairs they can make a transition or production step to. This graph
|
||||
is used to search for paths that represent counterexamples of some
|
||||
conflict.
|
||||
|
||||
state_items is an array of state state-item pairs ordered by state.
|
||||
state_item_map maps state numbers to the first item which
|
||||
corresponds to it in the array. A state's portion in state_items
|
||||
begins with its items in the same order as it was in the
|
||||
state. This is then followed by productions from the closure of the
|
||||
state in order by rule.
|
||||
corresponds to it in the array. A state's portion in state_items
|
||||
begins with its items in the same order as it was in the state.
|
||||
This is then followed by productions from the closure of the state
|
||||
in order by rule.
|
||||
|
||||
There are two type of edges in this graph transitions and
|
||||
productions. Transitions are the same as transitions from the
|
||||
@@ -53,9 +53,9 @@
|
||||
production edges, and all others will have reverse transition
|
||||
edges. */
|
||||
|
||||
# define SI_DISABLED(sin) (state_items[sin].trans == -2)
|
||||
# define SI_PRODUCTION(si) ((si) == state_items || *((si)->item - 1) < 0)
|
||||
# define SI_TRANSITION(si) ((si) != state_items && *((si)->item - 1) >= 0)
|
||||
# define SI_DISABLED(Sin) (state_items[Sin].trans == -2)
|
||||
# define SI_PRODUCTION(Si) ((Si) == state_items || *((Si)->item - 1) < 0)
|
||||
# define SI_TRANSITION(Si) ((Si) != state_items && *((Si)->item - 1) >= 0)
|
||||
|
||||
typedef int state_item_number;
|
||||
|
||||
@@ -69,6 +69,9 @@ typedef struct
|
||||
bitset lookahead;
|
||||
} state_item;
|
||||
|
||||
// A path of state-items.
|
||||
typedef gl_list_t state_item_list;
|
||||
|
||||
extern bitsetv firsts;
|
||||
# define FIRSTS(sym) firsts[(sym) - ntokens]
|
||||
|
||||
@@ -87,11 +90,13 @@ state_item_index_lookup (state_number s, state_item_number off)
|
||||
}
|
||||
|
||||
void state_items_init (void);
|
||||
void print_state_item (const state_item *si, FILE *out, const char *prefix);
|
||||
void state_items_free (void);
|
||||
|
||||
void state_item_print (const state_item *si, FILE *out, const char *prefix);
|
||||
|
||||
bool production_allowed (const state_item *si, const state_item *next);
|
||||
|
||||
// Iterating on a state_item_list.
|
||||
static inline bool
|
||||
state_item_list_next (gl_list_iterator_t *it, state_item **si)
|
||||
{
|
||||
|
||||
+7
-7
@@ -101,7 +101,7 @@ reductions_new (int num, rule **reds)
|
||||
size_t rules_size = num * sizeof *reds;
|
||||
reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
|
||||
res->num = num;
|
||||
res->lookahead_tokens = NULL;
|
||||
res->lookaheads = NULL;
|
||||
memcpy (res->rules, reds, rules_size);
|
||||
return res;
|
||||
}
|
||||
@@ -260,20 +260,20 @@ state_errs_set (state *s, int num, symbol **tokens)
|
||||
`--------------------------------------------------*/
|
||||
|
||||
void
|
||||
state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out)
|
||||
state_rule_lookaheads_print (state const *s, rule const *r, FILE *out)
|
||||
{
|
||||
/* Find the reduction we are handling. */
|
||||
reductions *reds = s->reductions;
|
||||
int red = state_reduction_find (s, r);
|
||||
|
||||
/* Print them if there are. */
|
||||
if (reds->lookahead_tokens && red != -1)
|
||||
if (reds->lookaheads && red != -1)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
char const *sep = "";
|
||||
fprintf (out, " [");
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookaheads[red], k, 0)
|
||||
{
|
||||
fprintf (out, "%s%s", sep, symbols[k]->tag);
|
||||
sep = ", ";
|
||||
@@ -283,7 +283,7 @@ state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out)
|
||||
}
|
||||
|
||||
void
|
||||
state_rule_lookahead_tokens_print_xml (state const *s, rule const *r,
|
||||
state_rule_lookaheads_print_xml (state const *s, rule const *r,
|
||||
FILE *out, int level)
|
||||
{
|
||||
/* Find the reduction we are handling. */
|
||||
@@ -291,12 +291,12 @@ state_rule_lookahead_tokens_print_xml (state const *s, rule const *r,
|
||||
int red = state_reduction_find (s, r);
|
||||
|
||||
/* Print them if there are. */
|
||||
if (reds->lookahead_tokens && red != -1)
|
||||
if (reds->lookaheads && red != -1)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
xml_puts (out, level, "<lookaheads>");
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookaheads[red], k, 0)
|
||||
{
|
||||
xml_printf (out, level + 1, "<symbol>%s</symbol>",
|
||||
xml_escape (symbols[k]->tag));
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@
|
||||
|
||||
Each reductions structure describes the possible reductions at the
|
||||
state whose number is in the number field. rules is an array of
|
||||
num rules. lookahead_tokens is an array of bitsets, one per rule.
|
||||
num rules. lookaheads is an array of bitsets, one per rule.
|
||||
|
||||
Conflict resolution can decide that certain tokens in certain
|
||||
states should explicitly be errors (for implementing %nonassoc).
|
||||
@@ -187,7 +187,7 @@ errs *errs_new (int num, symbol **tokens);
|
||||
typedef struct
|
||||
{
|
||||
int num;
|
||||
bitset *lookahead_tokens;
|
||||
bitset *lookaheads;
|
||||
/* Sorted ascendingly on rule number. */
|
||||
rule *rules[1];
|
||||
} reductions;
|
||||
@@ -254,9 +254,9 @@ void state_errs_set (state *s, int num, symbol **errors);
|
||||
|
||||
/* Print on OUT all the lookahead tokens such that this STATE wants to
|
||||
reduce R. */
|
||||
void state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out);
|
||||
void state_rule_lookahead_tokens_print_xml (state const *s, rule const *r,
|
||||
FILE *out, int level);
|
||||
void state_rule_lookaheads_print (state const *s, rule const *r, FILE *out);
|
||||
void state_rule_lookaheads_print_xml (state const *s, rule const *r,
|
||||
FILE *out, int level);
|
||||
|
||||
/* Create/destroy the states hash table. */
|
||||
void state_hash_new (void);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* Convert version string to int.
|
||||
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
#include "system.h"
|
||||
|
||||
#include "strversion.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <intprops.h>
|
||||
|
||||
int
|
||||
strversion_to_int (char const *version)
|
||||
{
|
||||
IGNORE_TYPE_LIMITS_BEGIN
|
||||
int res = 0;
|
||||
errno = 0;
|
||||
char *cp = NULL;
|
||||
|
||||
{
|
||||
long major = strtol (version, &cp, 10);
|
||||
if (errno || cp == version || *cp != '.' || major < 0
|
||||
|| INT_MULTIPLY_WRAPV (major, 10000, &res))
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
++cp;
|
||||
char *prev = cp;
|
||||
long minor = strtol (cp, &cp, 10);
|
||||
if (errno || cp == prev || (*cp != '\0' && *cp != '.')
|
||||
|| ! (0 <= minor && minor < 100)
|
||||
|| INT_MULTIPLY_WRAPV (minor, 100, &minor)
|
||||
|| INT_ADD_WRAPV (minor, res, &res))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*cp == '.')
|
||||
{
|
||||
++cp;
|
||||
char *prev = cp;
|
||||
long micro = strtol (cp, &cp, 10);
|
||||
if (errno || cp == prev || (*cp != '\0' && *cp != '.')
|
||||
|| ! (0 <= micro && micro < 100)
|
||||
|| INT_ADD_WRAPV (micro, res, &res))
|
||||
return -1;
|
||||
}
|
||||
|
||||
IGNORE_TYPE_LIMITS_END
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* Convert version string to int.
|
||||
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef STRVERSION_H_
|
||||
# define STRVERSION_H_
|
||||
|
||||
/* Convert VERSION into an int (MAJOR * 10000 + MINOR * 100 + MICRO).
|
||||
E.g., "3.7.4" => 30704, "3.8" => 30800.
|
||||
Return -1 on errors. */
|
||||
int strversion_to_int (char const *version);
|
||||
|
||||
#endif
|
||||
+2
-2
@@ -83,10 +83,10 @@ symbol_list_type_new (uniqstr type_name, location loc)
|
||||
|
||||
|
||||
symbol_list *
|
||||
symbol_list_type_set (symbol_list *syms, uniqstr type_name, location loc)
|
||||
symbol_list_type_set (symbol_list *syms, uniqstr type_name)
|
||||
{
|
||||
for (symbol_list *l = syms; l; l = l->next)
|
||||
symbol_type_set (l->content.sym, type_name, loc);
|
||||
symbol_type_set (l->content.sym, type_name, l->sym_loc);
|
||||
return syms;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -110,8 +110,7 @@ symbol_list *symbol_list_type_new (uniqstr type_name, location loc);
|
||||
|
||||
/** Assign the type \c type_name to all the members of \c syms.
|
||||
** \returns \c syms */
|
||||
symbol_list *symbol_list_type_set (symbol_list *syms,
|
||||
uniqstr type_name, location loc);
|
||||
symbol_list *symbol_list_type_set (symbol_list *syms, uniqstr type_name);
|
||||
|
||||
/** Print this list.
|
||||
|
||||
|
||||
+33
-36
@@ -59,7 +59,7 @@ static semantic_type **semantic_types_sorted = NULL;
|
||||
symbol *errtoken = NULL;
|
||||
symbol *undeftoken = NULL;
|
||||
symbol *eoftoken = NULL;
|
||||
symbol *accept = NULL;
|
||||
symbol *acceptsymbol = NULL;
|
||||
symbol *startsymbol = NULL;
|
||||
location startsymbol_loc;
|
||||
|
||||
@@ -137,11 +137,6 @@ symbol_new (uniqstr tag, location loc)
|
||||
res->alias = NULL;
|
||||
res->content = sym_content_new (res);
|
||||
res->is_alias = false;
|
||||
|
||||
if (nsyms == SYMBOL_NUMBER_MAXIMUM)
|
||||
complain (NULL, fatal, _("too many symbols in input grammar (limit is %d)"),
|
||||
SYMBOL_NUMBER_MAXIMUM);
|
||||
nsyms++;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -182,11 +177,11 @@ symbol_free (void *ptr)
|
||||
*/
|
||||
|
||||
static void
|
||||
symbols_sort (symbol **first, symbol **second)
|
||||
symbols_sort (const symbol **first, const symbol **second)
|
||||
{
|
||||
if (0 < location_cmp ((*first)->location, (*second)->location))
|
||||
{
|
||||
symbol* tmp = *first;
|
||||
const symbol* tmp = *first;
|
||||
*first = *second;
|
||||
*second = tmp;
|
||||
}
|
||||
@@ -243,7 +238,11 @@ semantic_type_new (uniqstr tag, const location *loc)
|
||||
| Print a symbol. |
|
||||
`-----------------*/
|
||||
|
||||
#define SYMBOL_ATTR_PRINT(Attr) \
|
||||
#define SYMBOL_INT_ATTR_PRINT(Attr) \
|
||||
if (s->content) \
|
||||
fprintf (f, " %s = %d", #Attr, s->content->Attr)
|
||||
|
||||
#define SYMBOL_STR_ATTR_PRINT(Attr) \
|
||||
if (s->content && s->content->Attr) \
|
||||
fprintf (f, " %s { %s }", #Attr, s->content->Attr)
|
||||
|
||||
@@ -264,7 +263,11 @@ symbol_print (symbol const *s, FILE *f)
|
||||
: c == nterm_sym ? "nterm"
|
||||
: NULL, /* abort. */
|
||||
s->tag);
|
||||
SYMBOL_ATTR_PRINT (type_name);
|
||||
putc (' ', f);
|
||||
location_print (s->location, f);
|
||||
SYMBOL_INT_ATTR_PRINT (code);
|
||||
SYMBOL_INT_ATTR_PRINT (number);
|
||||
SYMBOL_STR_ATTR_PRINT (type_name);
|
||||
SYMBOL_CODE_PRINT (destructor);
|
||||
SYMBOL_CODE_PRINT (printer);
|
||||
}
|
||||
@@ -371,7 +374,7 @@ symbol_from_uniqstr_fuzzy (const uniqstr key)
|
||||
}
|
||||
|
||||
static void
|
||||
complain_symbol_undeclared (symbol *sym)
|
||||
complain_symbol_undeclared (const symbol *sym)
|
||||
{
|
||||
assert (sym->content->status != declared);
|
||||
const symbol *best = symbol_from_uniqstr_fuzzy (sym->tag);
|
||||
@@ -398,7 +401,10 @@ void
|
||||
symbol_location_as_lhs_set (symbol *sym, location loc)
|
||||
{
|
||||
if (!sym->location_of_lhs)
|
||||
sym->location = loc;
|
||||
{
|
||||
sym->location = loc;
|
||||
sym->location_of_lhs = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -548,10 +554,6 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
if (class == token_sym && s->class == pct_type_sym)
|
||||
complain_pct_type_on_token (&sym->location);
|
||||
|
||||
if (class == nterm_sym && s->class != nterm_sym)
|
||||
s->number = nnterms++;
|
||||
else if (class == token_sym && s->number == NUMBER_UNDEFINED)
|
||||
s->number = ntokens++;
|
||||
s->class = class;
|
||||
|
||||
if (declaring)
|
||||
@@ -573,9 +575,9 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------.
|
||||
| Set the USER_TOKEN_NUMBER associated with SYM. |
|
||||
`------------------------------------------------*/
|
||||
/*----------------------------.
|
||||
| Set the token code of SYM. |
|
||||
`----------------------------*/
|
||||
|
||||
void
|
||||
symbol_code_set (symbol *sym, int code, location loc)
|
||||
@@ -598,10 +600,6 @@ symbol_code_set (symbol *sym, int code, location loc)
|
||||
if (code == 0 && !eoftoken)
|
||||
{
|
||||
eoftoken = sym->content->symbol;
|
||||
/* It is always mapped to 0, so it was already counted in
|
||||
NTOKENS. */
|
||||
if (eoftoken->content->number != NUMBER_UNDEFINED)
|
||||
--ntokens;
|
||||
eoftoken->content->number = 0;
|
||||
}
|
||||
}
|
||||
@@ -621,9 +619,11 @@ symbol_check_defined (symbol *sym)
|
||||
{
|
||||
complain_symbol_undeclared (sym);
|
||||
s->class = nterm_sym;
|
||||
s->number = nnterms++;
|
||||
}
|
||||
|
||||
if (s->number == NUMBER_UNDEFINED)
|
||||
s->number = s->class == token_sym ? ntokens++ : nnterms++;
|
||||
|
||||
if (s->class == token_sym
|
||||
&& sym->tag[0] == '"'
|
||||
&& !sym->is_alias)
|
||||
@@ -742,7 +742,7 @@ symbol_pack (symbol *sym)
|
||||
}
|
||||
|
||||
static void
|
||||
complain_code_redeclared (int num, symbol *first, symbol *second)
|
||||
complain_code_redeclared (int num, const symbol *first, const symbol *second)
|
||||
{
|
||||
symbols_sort (&first, &second);
|
||||
complain (&second->location, complaint,
|
||||
@@ -758,13 +758,11 @@ complain_code_redeclared (int num, symbol *first, symbol *second)
|
||||
`-------------------------------------------------*/
|
||||
|
||||
static void
|
||||
symbol_translation (symbol *sym)
|
||||
symbol_translation (const symbol *sym)
|
||||
{
|
||||
/* Nonterminal? */
|
||||
if (sym->content->class == token_sym
|
||||
&& !sym->is_alias)
|
||||
if (sym->content->class == token_sym && !sym->is_alias)
|
||||
{
|
||||
/* A token which translation has already been set?*/
|
||||
/* A token whose translation has already been set? */
|
||||
if (token_translations[sym->content->code]
|
||||
!= undeftoken->content->number)
|
||||
complain_code_redeclared
|
||||
@@ -849,10 +847,10 @@ symbols_new (void)
|
||||
hash_symbol_comparator,
|
||||
symbol_free);
|
||||
|
||||
/* Construct the accept symbol. */
|
||||
accept = symbol_get ("$accept", empty_loc);
|
||||
accept->content->class = nterm_sym;
|
||||
accept->content->number = nnterms++;
|
||||
/* Construct the acceptsymbol symbol. */
|
||||
acceptsymbol = symbol_get ("$accept", empty_loc);
|
||||
acceptsymbol->content->class = nterm_sym;
|
||||
acceptsymbol->content->number = nnterms++;
|
||||
|
||||
/* Construct the YYerror/"error" token */
|
||||
errtoken = symbol_get ("YYerror", empty_loc);
|
||||
@@ -969,7 +967,6 @@ dummy_symbol_get (location loc)
|
||||
assure (len < sizeof buf);
|
||||
symbol *sym = symbol_get (buf, loc);
|
||||
sym->content->class = nterm_sym;
|
||||
sym->content->number = nnterms++;
|
||||
return sym;
|
||||
}
|
||||
|
||||
@@ -1002,7 +999,7 @@ symbol_cmp (void const *a, void const *b)
|
||||
}
|
||||
|
||||
/* Store in *SORTED an array of pointers to the symbols contained in
|
||||
TABLE, sorted (alphabetically) by tag. */
|
||||
TABLE, sorted by order of appearance (i.e., by location). */
|
||||
|
||||
static void
|
||||
table_sort (struct hash_table *table, symbol ***sorted)
|
||||
|
||||
+2
-2
@@ -227,7 +227,7 @@ void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
|
||||
void symbol_class_set (symbol *sym, symbol_class class, location loc,
|
||||
bool declaring);
|
||||
|
||||
/** Set the \c code associated with \c sym. */
|
||||
/** Set the token \c code of \c sym, specified by the user at \c loc. */
|
||||
void symbol_code_set (symbol *sym, int code, location loc);
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ extern symbol *eoftoken;
|
||||
/** The genuine start symbol.
|
||||
|
||||
$accept: start-symbol $end */
|
||||
extern symbol *accept;
|
||||
extern symbol *acceptsymbol;
|
||||
|
||||
/** The user start symbol. */
|
||||
extern symbol *startsymbol;
|
||||
|
||||
@@ -131,6 +131,22 @@ typedef size_t uintptr_t;
|
||||
# include <stdbool.h>
|
||||
|
||||
|
||||
/*-----------.
|
||||
| Integers. |
|
||||
`-----------*/
|
||||
|
||||
static inline int
|
||||
min_int (int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static inline int
|
||||
max_int (int a, int b)
|
||||
{
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
|
||||
/*-------------.
|
||||
| Assertions. |
|
||||
|
||||
+4
-4
@@ -200,7 +200,7 @@ conflict_row (state *s)
|
||||
/* Find all reductions for token J, and record all that do not
|
||||
match ACTROW[J]. */
|
||||
for (int i = 0; i < reds->num; i += 1)
|
||||
if (bitset_test (reds->lookahead_tokens[i], j)
|
||||
if (bitset_test (reds->lookaheads[i], j)
|
||||
&& (actrow[j]
|
||||
!= rule_number_as_item_number (reds->rules[i]->number)))
|
||||
{
|
||||
@@ -247,7 +247,7 @@ action_row (state *s)
|
||||
|
||||
reductions *reds = s->reductions;
|
||||
bool conflicted = false;
|
||||
if (reds->lookahead_tokens)
|
||||
if (reds->lookaheads)
|
||||
/* loop over all the rules available here which require
|
||||
lookahead (in reverse order to give precedence to the first
|
||||
rule) */
|
||||
@@ -257,7 +257,7 @@ action_row (state *s)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int j;
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookaheads[i], j, 0)
|
||||
{
|
||||
/* and record this rule as the rule to use if that
|
||||
token follows. */
|
||||
@@ -308,7 +308,7 @@ action_row (state *s)
|
||||
}
|
||||
|
||||
/* Turn off default reductions where requested by the user. See
|
||||
state_lookahead_tokens_count in lalr.c to understand when states are
|
||||
state_lookaheads_count in lalr.c to understand when states are
|
||||
labeled as consistent. */
|
||||
{
|
||||
char *default_reductions =
|
||||
|
||||
@@ -915,6 +915,12 @@ AT_BISON_OPTION_PUSHDEFS([$1])
|
||||
|
||||
AT_DATA_CALC_Y([$1])
|
||||
AT_FULL_COMPILE(AT_JAVA_IF([[Calc]], [[calc]]), AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
|
||||
|
||||
AT_YACC_IF(
|
||||
[# No direct calls to malloc/free.
|
||||
AT_CHECK([[$EGREP '(malloc|free) *\(' calc.[ch] | $EGREP -v 'INFRINGES ON USER NAME SPACE']],
|
||||
[1])])
|
||||
|
||||
AT_PUSH_IF([AT_JAVA_IF(
|
||||
[# Verify that this is a push parser.
|
||||
AT_CHECK_JAVA_GREP([[Calc.java]],
|
||||
|
||||
+92
-44
@@ -726,7 +726,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
|
||||
[[0]], [[]],
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([[input]])
|
||||
AT_PARSER_CHECK([[input]], [[1]], [[]],
|
||||
@@ -737,7 +737,7 @@ AT_PARSER_CHECK([[input]], [[1]], [[]],
|
||||
AT_BISON_CHECK([[-Dlr.type=canonical-lr -Dparse.lac=full \
|
||||
-o input.c input.y]], [[0]], [[]],
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([[input]])
|
||||
AT_PARSER_CHECK([[input]], [[1]], [[]],
|
||||
@@ -748,7 +748,7 @@ AT_PARSER_CHECK([[input]], [[1]], [[]],
|
||||
AT_BISON_CHECK([[-Dlr.type=ielr -Dparse.lac=full -o input.c input.y]],
|
||||
[[0]], [[]],
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([[input]])
|
||||
AT_PARSER_CHECK([[input]], [[1]], [[]],
|
||||
@@ -773,7 +773,7 @@ exp: exp OP exp | NUM;
|
||||
|
||||
AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
|
||||
# Check the contents of the report.
|
||||
@@ -861,12 +861,18 @@ State 5
|
||||
OP [reduce using rule 1 (exp)]
|
||||
$default reduce using rule 1 (exp)
|
||||
|
||||
Shift/reduce conflict on token OP:
|
||||
shift/reduce conflict on token OP:
|
||||
1 exp: exp OP exp .
|
||||
1 exp: exp . OP exp
|
||||
Example exp OP exp . OP exp
|
||||
First derivation exp ::=[ exp ::=[ exp OP exp . ] OP exp ]
|
||||
Second derivation exp ::=[ exp OP exp ::=[ exp . OP exp ] ]
|
||||
Example: exp OP exp . OP exp
|
||||
Shift derivation
|
||||
exp
|
||||
`-> exp OP exp
|
||||
`-> exp . OP exp
|
||||
Reduce derivation
|
||||
exp
|
||||
`-> exp OP exp
|
||||
`-> exp OP exp .
|
||||
|
||||
]])
|
||||
|
||||
@@ -1026,7 +1032,7 @@ cond:
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], 0, [],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:12.3-18: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -1119,7 +1125,7 @@ m4_popdef([AT_TEST])
|
||||
# else.
|
||||
|
||||
AT_SETUP([Defaulted Conflicted Reduction])
|
||||
AT_KEYWORDS([report])
|
||||
AT_KEYWORDS([cex report])
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[%%
|
||||
@@ -1131,7 +1137,7 @@ id : '0';
|
||||
|
||||
AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
|
||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:4.6-8: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -1203,12 +1209,18 @@ State 1
|
||||
$end [reduce using rule 4 (id)]
|
||||
$default reduce using rule 3 (num)
|
||||
|
||||
Reduce/reduce conflict on token $end:
|
||||
reduce/reduce conflict on token $end:
|
||||
3 num: '0' .
|
||||
4 id: '0' .
|
||||
Example '0' .
|
||||
First derivation exp ::=[ num ::=[ '0' . ] ]
|
||||
Second derivation exp ::=[ id ::=[ '0' . ] ]
|
||||
Example: '0' .
|
||||
First reduce derivation
|
||||
exp
|
||||
`-> num
|
||||
`-> '0' .
|
||||
Second reduce derivation
|
||||
exp
|
||||
`-> id
|
||||
`-> '0' .
|
||||
|
||||
|
||||
|
||||
@@ -1260,7 +1272,7 @@ exp: exp OP exp | NUM;
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], 1, [],
|
||||
[[input.y: error: shift/reduce conflicts: 1 found, 0 expected
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -1297,7 +1309,7 @@ exp: exp OP exp | NUM;
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], 1, [],
|
||||
[[input.y: error: shift/reduce conflicts: 1 found, 2 expected
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -1317,7 +1329,7 @@ a: 'a';
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], 1, [],
|
||||
[[input.y: error: reduce/reduce conflicts: 1 found, 0 expected
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -1518,7 +1530,7 @@ e: e '+' e
|
||||
|
||||
AT_BISON_CHECK([-Wall -o input.c input.y], 0, [],
|
||||
[[input.y: warning: 4 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:1.1-5: warning: useless precedence and associativity for '+' [-Wprecedence]
|
||||
input.y:2.1-5: warning: useless precedence and associativity for '*' [-Wprecedence]
|
||||
]])
|
||||
@@ -1579,6 +1591,8 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([[Unreachable States After Conflict Resolution]])
|
||||
|
||||
AT_KEYWORDS([cex report])
|
||||
|
||||
# If conflict resolution makes states unreachable, remove those states, report
|
||||
# rules that are then unused, and don't report conflicts in those states. Test
|
||||
# what happens when a nonterminal becomes useless as a result of state removal
|
||||
@@ -1624,7 +1638,7 @@ reported_conflicts:
|
||||
AT_BISON_CHECK([[--report=all input.y]], 0, [],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:12.5-20: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:20.5-20: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:21.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
@@ -1750,21 +1764,33 @@ State 4
|
||||
|
||||
reported_conflicts go to state 6
|
||||
|
||||
Shift/reduce conflict on token 'a':
|
||||
shift/reduce conflict on token 'a':
|
||||
10 reported_conflicts: . %empty
|
||||
8 reported_conflicts: . 'a'
|
||||
First example resolved_conflict . 'a'
|
||||
First derivation start ::=[ resolved_conflict reported_conflicts ::=[ . ] 'a' ]
|
||||
Second example resolved_conflict . 'a' 'a'
|
||||
Second derivation start ::=[ resolved_conflict reported_conflicts ::=[ . 'a' ] 'a' ]
|
||||
First example: resolved_conflict . 'a' 'a'
|
||||
Shift derivation
|
||||
start
|
||||
`-> resolved_conflict reported_conflicts 'a'
|
||||
`-> . 'a'
|
||||
Second example: resolved_conflict . 'a'
|
||||
Reduce derivation
|
||||
start
|
||||
`-> resolved_conflict reported_conflicts 'a'
|
||||
`-> .
|
||||
|
||||
Shift/reduce conflict on token 'a':
|
||||
shift/reduce conflict on token 'a':
|
||||
10 reported_conflicts: . %empty
|
||||
9 reported_conflicts: . 'a'
|
||||
First example resolved_conflict . 'a'
|
||||
First derivation start ::=[ resolved_conflict reported_conflicts ::=[ . ] 'a' ]
|
||||
Second example resolved_conflict . 'a' 'a'
|
||||
Second derivation start ::=[ resolved_conflict reported_conflicts ::=[ . 'a' ] 'a' ]
|
||||
First example: resolved_conflict . 'a' 'a'
|
||||
Shift derivation
|
||||
start
|
||||
`-> resolved_conflict reported_conflicts 'a'
|
||||
`-> . 'a'
|
||||
Second example: resolved_conflict . 'a'
|
||||
Reduce derivation
|
||||
start
|
||||
`-> resolved_conflict reported_conflicts 'a'
|
||||
`-> .
|
||||
|
||||
|
||||
|
||||
@@ -1777,12 +1803,16 @@ State 5
|
||||
'a' [reduce using rule 9 (reported_conflicts)]
|
||||
$default reduce using rule 8 (reported_conflicts)
|
||||
|
||||
Reduce/reduce conflict on token 'a':
|
||||
reduce/reduce conflict on token 'a':
|
||||
8 reported_conflicts: 'a' .
|
||||
9 reported_conflicts: 'a' .
|
||||
Example 'a' .
|
||||
First derivation reported_conflicts ::=[ 'a' . ]
|
||||
Second derivation reported_conflicts ::=[ 'a' . ]
|
||||
Example: 'a' .
|
||||
First reduce derivation
|
||||
reported_conflicts
|
||||
`-> 'a' .
|
||||
Second reduce derivation
|
||||
reported_conflicts
|
||||
`-> 'a' .
|
||||
|
||||
|
||||
|
||||
@@ -1808,7 +1838,7 @@ AT_CHECK([[cat input.y >> input-keep.y]])
|
||||
AT_BISON_CHECK([[input-keep.y]], 0, [],
|
||||
[[input-keep.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input-keep.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
input-keep.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input-keep.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input-keep.y:22.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input-keep.y:26.16: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input-keep.y:32.5-7: warning: rule useless in parser due to conflicts [-Wother]
|
||||
@@ -1904,6 +1934,8 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
|
||||
|
||||
AT_KEYWORDS([cex report])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%nonassoc 'a' 'b' 'c'
|
||||
%%
|
||||
@@ -1961,12 +1993,18 @@ AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
|
||||
Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
|
||||
Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
|
||||
|
||||
Reduce/reduce conflict on token 'c':
|
||||
reduce/reduce conflict on token 'c':
|
||||
12 empty_c2: . %empty
|
||||
13 empty_c3: . %empty
|
||||
Example . 'c'
|
||||
First derivation start ::=[ empty_c2 ::=[ . ] 'c' ]
|
||||
Second derivation start ::=[ empty_c3 ::=[ . ] 'c' ]
|
||||
Example: . 'c'
|
||||
First reduce derivation
|
||||
start
|
||||
`-> empty_c2 'c'
|
||||
`-> .
|
||||
Second reduce derivation
|
||||
start
|
||||
`-> empty_c3 'c'
|
||||
`-> .
|
||||
|
||||
|
||||
|
||||
@@ -2000,7 +2038,7 @@ exp: 'a' | 'a';
|
||||
AT_BISON_CHECK([[2.y]], [[0]], [],
|
||||
[[2.y: warning: %expect-rr applies only to GLR parsers [-Wother]
|
||||
2.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
2.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
2.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
2.y:3.12-14: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -2037,15 +2075,14 @@ B: ;
|
||||
AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
|
||||
[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
sr-rr.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
|
||||
[[sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
sr-rr.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
|
||||
[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
]])
|
||||
|
||||
[
|
||||
@@ -2102,19 +2139,30 @@ for gram in sr-rr sr rr; do
|
||||
]AT_BISON_CHECK([[-Werror $file]])[
|
||||
else
|
||||
{
|
||||
issue_note=false
|
||||
if test -z "$sr_exp_i" && test "$sr_count" -ne 0; then
|
||||
echo "warning: $sr_count shift/reduce conflicts"
|
||||
issue_note=true
|
||||
elif test "$sr_exp_i" -ne "$sr_count"; then
|
||||
echo "error: shift/reduce conflicts: $sr_count found, $sr_exp_i expected"
|
||||
if test "$sr_count" -ne 0; then
|
||||
issue_note=true
|
||||
fi
|
||||
fi
|
||||
if test -z "$rr_exp_i" && test "$rr_count" -ne 0; then
|
||||
echo "warning: $rr_count reduce/reduce conflicts"
|
||||
issue_note=true
|
||||
elif test "$rr_exp_i" -ne "$rr_count"; then
|
||||
echo "error: reduce/reduce conflicts: $rr_count found, $rr_exp_i expected"
|
||||
if test "$rr_count" -ne 0; then
|
||||
issue_note=true
|
||||
fi
|
||||
fi
|
||||
if $issue_note; then
|
||||
echo "note: rerun with option '-Wcounterexamples' to generate conflict counterexamples"
|
||||
fi
|
||||
} | sed -e "s/^/$file: /" > experr
|
||||
]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
|
||||
echo "$file: error: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Werror=other]" >> experr
|
||||
]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[
|
||||
fi
|
||||
done
|
||||
|
||||
+559
-183
@@ -17,13 +17,23 @@
|
||||
|
||||
AT_BANNER([[Counterexamples.]])
|
||||
|
||||
# AT_BISON_CHECK_CEX(TREE, FLAT)
|
||||
# ------------------------------
|
||||
m4_define([AT_BISON_CHECK_CEX],
|
||||
[AT_DATA([experr], [$4])
|
||||
sed -e ['s/time limit exceeded: [0-9][.0-9]*/time limit exceeded: XXX/g'] \
|
||||
experr >expout
|
||||
AT_BISON_CHECK([-Wcounterexamples $1], [$2], [$3], [stderr])
|
||||
[AT_KEYWORDS([cex])
|
||||
|
||||
AT_BISON_CHECK([-Wcounterexamples input.y], [0], [], [stderr])
|
||||
# FIXME: Avoid trailing white spaces.
|
||||
AT_CHECK([[sed -e 's/time limit exceeded: [0-9][.0-9]*/time limit exceeded: XXX/g;s/ *$//;' stderr]],
|
||||
[], [$1])
|
||||
|
||||
m4_pushdef([AT_SET_ENV_IF],
|
||||
[[YYFLAT=1; export YYFLAT;]]m4_defn([AT_SET_ENV_IF]))
|
||||
AT_BISON_CHECK([-Wcounterexamples input.y], [0], [], [stderr])
|
||||
AT_CHECK([[sed -e 's/time limit exceeded: [0-9][.0-9]*/time limit exceeded: XXX/g' stderr]],
|
||||
[], [expout])
|
||||
[], [$2])
|
||||
m4_popdef([AT_SET_ENV_IF])
|
||||
|
||||
])
|
||||
|
||||
## --------------------- ##
|
||||
@@ -31,7 +41,6 @@ AT_CHECK([[sed -e 's/time limit exceeded: [0-9][.0-9]*/time limit exceeded: XXX/
|
||||
## --------------------- ##
|
||||
|
||||
AT_SETUP([Unifying S/R])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B C
|
||||
@@ -43,13 +52,25 @@ x: B | B C;
|
||||
y: A | A B;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token B:
|
||||
Example A . B C
|
||||
First derivation s ::=[ a ::=[ A . ] x ::=[ B C ] ]
|
||||
Second derivation s ::=[ y ::=[ A . B ] c ::=[ C ] ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: A . B C
|
||||
Shift derivation
|
||||
s
|
||||
`-> y c
|
||||
`-> A . B `-> C
|
||||
Reduce derivation
|
||||
s
|
||||
`-> a x
|
||||
`-> A . `-> B C
|
||||
input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example A . B C
|
||||
Shift derivation s -> [ y -> [ A . B ] c -> [ C ] ]
|
||||
Reduce derivation s -> [ a -> [ A . ] x -> [ B C ] ]
|
||||
input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -60,7 +81,6 @@ AT_CLEANUP
|
||||
## ------------------- ##
|
||||
|
||||
AT_SETUP([Deep Unifying S/R])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B C
|
||||
@@ -72,18 +92,46 @@ a: A | A a;
|
||||
bc: B bc C | B C;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token B:
|
||||
Example A . B C
|
||||
First derivation s ::=[ a ::=[ A . ] bc ::=[ B C ] ]
|
||||
Second derivation s ::=[ ac ::=[ A ac ::=[ b ::=[ . B ] ] C ] ]
|
||||
|
||||
Shift/reduce conflict on token B:
|
||||
Example A A . B B C C
|
||||
First derivation s ::=[ a ::=[ A a ::=[ A . ] ] bc ::=[ B bc ::=[ B C ] C ] ]
|
||||
Second derivation s ::=[ ac ::=[ A ac ::=[ A ac ::=[ b ::=[ . b ::=[ B B ] ] ] C ] C ] ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: A . B C
|
||||
Shift derivation
|
||||
s
|
||||
`-> ac
|
||||
`-> A ac C
|
||||
`-> b
|
||||
`-> . B
|
||||
Reduce derivation
|
||||
s
|
||||
`-> a bc
|
||||
`-> A . `-> B C
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: A A . B B C C
|
||||
Shift derivation
|
||||
s
|
||||
`-> ac
|
||||
`-> A ac C
|
||||
`-> A ac C
|
||||
`-> b
|
||||
`-> . b
|
||||
`-> B B
|
||||
Reduce derivation
|
||||
s
|
||||
`-> a bc
|
||||
`-> A a `-> B bc C
|
||||
`-> A . `-> B C
|
||||
input.y:6.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example A . B C
|
||||
Shift derivation s -> [ ac -> [ A ac -> [ b -> [ . B ] ] C ] ]
|
||||
Reduce derivation s -> [ a -> [ A . ] bc -> [ B C ] ]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example A A . B B C C
|
||||
Shift derivation s -> [ ac -> [ A ac -> [ A ac -> [ b -> [ . b -> [ B B ] ] ] C ] C ] ]
|
||||
Reduce derivation s -> [ a -> [ A a -> [ A . ] ] bc -> [ B bc -> [ B C ] C ] ]
|
||||
input.y:6.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -94,7 +142,6 @@ AT_CLEANUP
|
||||
## ------------------------------------ ##
|
||||
|
||||
AT_SETUP([S/R Conflict with Nullable Symbols])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B X Y
|
||||
@@ -107,19 +154,47 @@ y: %empty | Y y;
|
||||
xby: B | X xby Y;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token B:
|
||||
Example A . B
|
||||
First derivation s ::=[ ax ::=[ A x ::=[ . ] ] by ::=[ B y ::=[ ] ] ]
|
||||
Second derivation s ::=[ A xby ::=[ . B ] ]
|
||||
|
||||
Shift/reduce conflict on token 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
|
||||
Second derivation $accept ::=[ s ::=[ A xby ::=[ X xby ::=[ . B ] Y ] ] $end ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: A . B
|
||||
Shift derivation
|
||||
s
|
||||
`-> A xby
|
||||
`-> . B
|
||||
Reduce derivation
|
||||
s
|
||||
`-> ax by
|
||||
`-> A x `-> B y
|
||||
`-> . `-> %empty
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
First example: A X . B Y $end
|
||||
Shift derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> A xby
|
||||
`-> X xby Y
|
||||
`-> . B
|
||||
Second example: A X . B y $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> ax by
|
||||
`-> A x `-> B y
|
||||
`-> X x
|
||||
`-> .
|
||||
input.y:5.4-9: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example A . B
|
||||
Shift derivation s -> [ A xby -> [ . B ] ]
|
||||
Reduce derivation s -> [ ax -> [ A x -> [ . ] ] by -> [ B y -> [ ] ] ]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
First example A X . B Y $end
|
||||
Shift derivation $accept -> [ s -> [ A xby -> [ X xby -> [ . B ] Y ] ] $end ]
|
||||
Second example A X . B y $end
|
||||
Reduce derivation $accept -> [ s -> [ ax -> [ A x -> [ X x -> [ . ] ] ] by -> [ B y ] ] $end ]
|
||||
input.y:5.4-9: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -130,7 +205,6 @@ AT_CLEANUP
|
||||
## ---------------------------- ##
|
||||
|
||||
AT_SETUP([Non-unifying Ambiguous S/R])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B C D E
|
||||
@@ -143,14 +217,31 @@ cd: C D;
|
||||
bc: B C;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token C:
|
||||
First example B . C D $end
|
||||
First derivation $accept ::=[ g ::=[ x ::=[ b ::=[ B . ] cd ::=[ C D ] ] ] $end ]
|
||||
Second example B . C $end
|
||||
Second derivation $accept ::=[ g ::=[ x ::=[ bc ::=[ B . C ] ] ] $end ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token C [-Wcounterexamples]
|
||||
First example: B . C $end
|
||||
Shift derivation
|
||||
$accept
|
||||
`-> g $end
|
||||
`-> x
|
||||
`-> bc
|
||||
`-> B . C
|
||||
Second example: B . C D $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> g $end
|
||||
`-> x
|
||||
`-> b cd
|
||||
`-> B . `-> C D
|
||||
input.y:6.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token C [-Wcounterexamples]
|
||||
First example B . C $end
|
||||
Shift derivation $accept -> [ g -> [ x -> [ bc -> [ B . C ] ] ] $end ]
|
||||
Second example B . C D $end
|
||||
Reduce derivation $accept -> [ g -> [ x -> [ b -> [ B . ] cd -> [ C D ] ] ] $end ]
|
||||
input.y:6.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -161,7 +252,6 @@ AT_CLEANUP
|
||||
## ------------------------------ ##
|
||||
|
||||
AT_SETUP([Non-unifying Unambiguous S/R])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B
|
||||
@@ -172,14 +262,31 @@ x: A;
|
||||
y: A A B;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token A:
|
||||
First example A . A $end
|
||||
First derivation $accept ::=[ s ::=[ s ::=[ t ::=[ x ::=[ A . ] ] ] t ::=[ x ::=[ A ] ] ] $end ]
|
||||
Second example A . A B $end
|
||||
Second derivation $accept ::=[ s ::=[ t ::=[ y ::=[ A . A B ] ] ] $end ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
First example: A . A B $end
|
||||
Shift derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> t
|
||||
`-> y
|
||||
`-> A . A B
|
||||
Second example: A . A $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> s t
|
||||
`-> t `-> x
|
||||
`-> x `-> A
|
||||
`-> A .
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
First example A . A B $end
|
||||
Shift derivation $accept -> [ s -> [ t -> [ y -> [ A . A B ] ] ] $end ]
|
||||
Second example A . A $end
|
||||
Reduce derivation $accept -> [ s -> [ s -> [ t -> [ x -> [ A . ] ] ] t -> [ x -> [ A ] ] ] $end ]
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
@@ -189,7 +296,6 @@ AT_CLEANUP
|
||||
## ----------------------- ##
|
||||
|
||||
AT_SETUP([S/R after first token])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B X Y
|
||||
@@ -205,19 +311,45 @@ xy: X Y;
|
||||
y: Y;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token 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 on token X:
|
||||
First example X . X xy
|
||||
First derivation a ::=[ x ::=[ X . ] t ::=[ X xy ] ]
|
||||
Second example A X . X
|
||||
Second derivation a ::=[ t ::=[ A xx ::=[ X . X ] ] ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
Example: b . A X X Y
|
||||
Shift derivation
|
||||
a
|
||||
`-> s
|
||||
`-> b . xx y
|
||||
`-> A X X `-> Y
|
||||
Reduce derivation
|
||||
a
|
||||
`-> r t
|
||||
`-> b . `-> A x xy
|
||||
`-> X `-> X Y
|
||||
input.y: warning: shift/reduce conflict on token X [-Wcounterexamples]
|
||||
First example: A X . X
|
||||
Shift derivation
|
||||
a
|
||||
`-> t
|
||||
`-> A xx
|
||||
`-> X . X
|
||||
Second example: X . X xy
|
||||
Reduce derivation
|
||||
a
|
||||
`-> x t
|
||||
`-> X . `-> X xy
|
||||
input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:8.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
Example b . A X X Y
|
||||
Shift derivation a -> [ s -> [ b . xx -> [ A X X ] y -> [ Y ] ] ]
|
||||
Reduce derivation a -> [ r -> [ b . ] t -> [ A x -> [ X ] xy -> [ X Y ] ] ]
|
||||
input.y: warning: shift/reduce conflict on token X [-Wcounterexamples]
|
||||
First example A X . X
|
||||
Shift derivation a -> [ t -> [ A xx -> [ X . X ] ] ]
|
||||
Second example X . X xy
|
||||
Reduce derivation a -> [ x -> [ X . ] t -> [ X xy ] ]
|
||||
input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:8.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
@@ -229,7 +361,6 @@ AT_CLEANUP
|
||||
## ----------------------------- ##
|
||||
|
||||
AT_SETUP([Unifying R/R counterexample])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A
|
||||
@@ -238,13 +369,24 @@ a : A b ;
|
||||
b : A | b;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
Reduce/reduce conflict on token $end:
|
||||
Example A b .
|
||||
First derivation a ::=[ A b . ]
|
||||
Second derivation a ::=[ A b ::=[ b . ] ]
|
||||
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example: A b .
|
||||
First reduce derivation
|
||||
a
|
||||
`-> A b .
|
||||
Second reduce derivation
|
||||
a
|
||||
`-> A b
|
||||
`-> b .
|
||||
input.y:4.9: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example A b .
|
||||
First reduce derivation a -> [ A b . ]
|
||||
Second reduce derivation a -> [ A b -> [ b . ] ]
|
||||
input.y:4.9: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -255,7 +397,6 @@ AT_CLEANUP
|
||||
## --------------------------------- ##
|
||||
|
||||
AT_SETUP([Non-unifying R/R LR(1) conflict])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B C D
|
||||
@@ -265,14 +406,29 @@ a: D;
|
||||
b: D;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
Reduce/reduce conflict on tokens A, C:
|
||||
First example D . A $end
|
||||
First derivation $accept ::=[ s ::=[ a ::=[ D . ] A ] $end ]
|
||||
Second example B D . A $end
|
||||
Second derivation $accept ::=[ s ::=[ B b ::=[ D . ] A ] $end ]
|
||||
|
||||
input.y: warning: reduce/reduce conflict on tokens A, C [-Wcounterexamples]
|
||||
First example: D . A $end
|
||||
First reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> a A
|
||||
`-> D .
|
||||
Second example: B D . A $end
|
||||
Second reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> B b A
|
||||
`-> D .
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
input.y: warning: reduce/reduce conflict on tokens A, C [-Wcounterexamples]
|
||||
First example D . A $end
|
||||
First reduce derivation $accept -> [ s -> [ a -> [ D . ] A ] $end ]
|
||||
Second example B D . A $end
|
||||
Second reduce derivation $accept -> [ s -> [ B b -> [ D . ] A ] $end ]
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -283,7 +439,6 @@ AT_CLEANUP
|
||||
## --------------------------------- ##
|
||||
|
||||
AT_SETUP([Non-unifying R/R LR(2) conflict])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token H J K X
|
||||
@@ -293,15 +448,31 @@ a: H i;
|
||||
i: X | i J K;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token J:
|
||||
input.y: warning: shift/reduce conflict on token J [-Wcounterexamples]
|
||||
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
|
||||
Second derivation $accept ::=[ a ::=[ H i ::=[ i . J K ] ] $end ]
|
||||
|
||||
First example: H i . J K $end
|
||||
Shift derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> H i
|
||||
`-> i . J K
|
||||
Second example: H i . J $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> a J
|
||||
`-> H i .
|
||||
input.y:4.4-6: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token J [-Wcounterexamples]
|
||||
time limit exceeded: XXX
|
||||
First example H i . J K $end
|
||||
Shift derivation $accept -> [ a -> [ H i -> [ i . J K ] ] $end ]
|
||||
Second example H i . J $end
|
||||
Reduce derivation $accept -> [ s -> [ a -> [ H i . ] J ] $end ]
|
||||
input.y:4.4-6: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -315,7 +486,6 @@ AT_CLEANUP
|
||||
# graph search
|
||||
|
||||
AT_SETUP([Cex Search Prepend])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token N A B C D
|
||||
@@ -326,18 +496,45 @@ a: A;
|
||||
b: A B C | A B D;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token B:
|
||||
Example N A . B C
|
||||
First derivation s ::=[ n ::=[ N a ::=[ A . ] B ] C ]
|
||||
Second derivation s ::=[ n ::=[ N b ::=[ A . B C ] ] ]
|
||||
|
||||
Shift/reduce conflict on token B:
|
||||
Example N N A . B D C
|
||||
First derivation s ::=[ n ::=[ N n ::=[ N a ::=[ A . ] B ] D ] C ]
|
||||
Second derivation s ::=[ n ::=[ N n ::=[ N b ::=[ A . B D ] ] C ] ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: N A . B C
|
||||
Shift derivation
|
||||
s
|
||||
`-> n
|
||||
`-> N b
|
||||
`-> A . B C
|
||||
Reduce derivation
|
||||
s
|
||||
`-> n C
|
||||
`-> N a B
|
||||
`-> A .
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example: N N A . B D C
|
||||
Shift derivation
|
||||
s
|
||||
`-> n
|
||||
`-> N n C
|
||||
`-> N b
|
||||
`-> A . B D
|
||||
Reduce derivation
|
||||
s
|
||||
`-> n C
|
||||
`-> N n D
|
||||
`-> N a B
|
||||
`-> A .
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example N A . B C
|
||||
Shift derivation s -> [ n -> [ N b -> [ A . B C ] ] ]
|
||||
Reduce derivation s -> [ n -> [ N a -> [ A . ] B ] C ]
|
||||
input.y: warning: shift/reduce conflict on token B [-Wcounterexamples]
|
||||
Example N N A . B D C
|
||||
Shift derivation s -> [ n -> [ N n -> [ N b -> [ A . B D ] ] C ] ]
|
||||
Reduce derivation s -> [ n -> [ N n -> [ N a -> [ A . ] B ] D ] C ]
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -351,7 +548,6 @@ AT_CLEANUP
|
||||
# precedence/associativity directives work.
|
||||
|
||||
AT_SETUP([R/R cex with prec])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%left b
|
||||
@@ -363,18 +559,46 @@ B : A b A;
|
||||
C : A c A;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 4 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
Reduce/reduce conflict on tokens b, c:
|
||||
Example B . b c
|
||||
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 on tokens b, c:
|
||||
Example C . c b
|
||||
First derivation S ::=[ C ::=[ A ::=[ C . ] c A ::=[ ] ] B ::=[ A ::=[ ] b A ::=[ ] ] ]
|
||||
Second derivation S ::=[ C B ::=[ A ::=[ C ::=[ A ::=[ . ] c A ::=[ ] ] ] b A ::=[ ] ] ]
|
||||
|
||||
input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples]
|
||||
Example: B . b c
|
||||
First reduce derivation
|
||||
S
|
||||
`-> B C
|
||||
`-> A b A `-> A c A
|
||||
`-> B . `-> %empty `-> %empty `-> %empty
|
||||
Second reduce derivation
|
||||
S
|
||||
`-> B C
|
||||
`-> A c A
|
||||
`-> B `-> %empty
|
||||
`-> A b A
|
||||
`-> . `-> %empty
|
||||
input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples]
|
||||
Example: C . c b
|
||||
First reduce derivation
|
||||
S
|
||||
`-> C B
|
||||
`-> A c A `-> A b A
|
||||
`-> C . `-> %empty `-> %empty `-> %empty
|
||||
Second reduce derivation
|
||||
S
|
||||
`-> C B
|
||||
`-> A b A
|
||||
`-> C `-> %empty
|
||||
`-> A c A
|
||||
`-> . `-> %empty
|
||||
]],
|
||||
[[input.y: warning: 4 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples]
|
||||
Example B . b c
|
||||
First reduce derivation S -> [ B -> [ A -> [ B . ] b A -> [ ] ] C -> [ A -> [ ] c A -> [ ] ] ]
|
||||
Second reduce derivation S -> [ B C -> [ A -> [ B -> [ A -> [ . ] b A -> [ ] ] ] c A -> [ ] ] ]
|
||||
input.y: warning: reduce/reduce conflict on tokens b, c [-Wcounterexamples]
|
||||
Example C . c b
|
||||
First reduce derivation S -> [ C -> [ A -> [ C . ] c A -> [ ] ] B -> [ A -> [ ] b A -> [ ] ] ]
|
||||
Second reduce derivation S -> [ C B -> [ A -> [ C -> [ A -> [ . ] c A -> [ ] ] ] b A -> [ ] ] ]
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
@@ -384,7 +608,6 @@ AT_CLEANUP
|
||||
## ------------------- ##
|
||||
|
||||
AT_SETUP([Null nonterminals])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A
|
||||
@@ -395,58 +618,172 @@ c : ;
|
||||
d : a | c A | d;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: 6 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
Reduce/reduce conflict on token 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 on token A:
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
First example: . c A A $end
|
||||
First reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> . `-> c A A
|
||||
Second example: . c A A $end
|
||||
Second reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> c d
|
||||
`-> . `-> c A A
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
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 on token A:
|
||||
First example: b . c A A $end
|
||||
First reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> a
|
||||
`-> b d
|
||||
`-> . `-> c A A
|
||||
Second example: b . A $end
|
||||
Second reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> c A
|
||||
`-> .
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
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 on token A:
|
||||
First example: c . c A A $end
|
||||
First reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> c d
|
||||
`-> a
|
||||
`-> b d
|
||||
`-> . `-> c A A
|
||||
Second example: c . A $end
|
||||
Second reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> c d
|
||||
`-> c A
|
||||
`-> .
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
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 on token 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 on token 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 on token $end:
|
||||
Example b d .
|
||||
First derivation a ::=[ b d . ]
|
||||
Second derivation a ::=[ b d ::=[ d . ] ]
|
||||
|
||||
Reduce/reduce conflict on token $end:
|
||||
Example c d .
|
||||
First derivation a ::=[ c d . ]
|
||||
Second derivation a ::=[ c d ::=[ d . ] ]
|
||||
|
||||
First example: b c . A
|
||||
Shift derivation
|
||||
a
|
||||
`-> b d
|
||||
`-> c . A
|
||||
Second example: b c . c A A $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> a
|
||||
`-> c d
|
||||
`-> a
|
||||
`-> b d
|
||||
`-> . `-> c A A
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
First example: b c . c A A $end
|
||||
First reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> a
|
||||
`-> c d
|
||||
`-> a
|
||||
`-> b d
|
||||
`-> . `-> c A A
|
||||
Second example: b c . A $end
|
||||
Second reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> a
|
||||
`-> c d
|
||||
`-> c A
|
||||
`-> .
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
First example: b c . A
|
||||
Shift derivation
|
||||
a
|
||||
`-> b d
|
||||
`-> c . A
|
||||
Second example: b c . A $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> a $end
|
||||
`-> b d
|
||||
`-> a
|
||||
`-> c d
|
||||
`-> c A
|
||||
`-> .
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example: b d .
|
||||
First reduce derivation
|
||||
a
|
||||
`-> b d .
|
||||
Second reduce derivation
|
||||
a
|
||||
`-> b d
|
||||
`-> d .
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example: c d .
|
||||
First reduce derivation
|
||||
a
|
||||
`-> c d .
|
||||
Second reduce derivation
|
||||
a
|
||||
`-> c d
|
||||
`-> d .
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:6.15: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: 6 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
First example . c A A $end
|
||||
First reduce derivation $accept -> [ a -> [ b -> [ . ] d -> [ c A A ] ] $end ]
|
||||
Second example . c A A $end
|
||||
Second reduce derivation $accept -> [ a -> [ c -> [ . ] d -> [ c A A ] ] $end ]
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
time limit exceeded: XXX
|
||||
First example b . c A A $end
|
||||
First reduce derivation $accept -> [ a -> [ b d -> [ a -> [ b -> [ . ] d -> [ c A A ] ] ] ] $end ]
|
||||
Second example b . A $end
|
||||
Second reduce derivation $accept -> [ a -> [ b d -> [ c -> [ . ] A ] ] $end ]
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
time limit exceeded: XXX
|
||||
First example c . c A A $end
|
||||
First reduce derivation $accept -> [ a -> [ c d -> [ a -> [ b -> [ . ] d -> [ c A A ] ] ] ] $end ]
|
||||
Second example c . A $end
|
||||
Second reduce derivation $accept -> [ a -> [ c d -> [ c -> [ . ] A ] ] $end ]
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
time limit exceeded: XXX
|
||||
First example b c . A
|
||||
Shift derivation a -> [ b d -> [ c . A ] ]
|
||||
Second example b c . c A A $end
|
||||
Reduce derivation $accept -> [ a -> [ b d -> [ a -> [ c d -> [ a -> [ b -> [ . ] d -> [ c A A ] ] ] ] ] ] $end ]
|
||||
input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples]
|
||||
First example b c . c A A $end
|
||||
First reduce derivation $accept -> [ a -> [ b d -> [ a -> [ c d -> [ a -> [ b -> [ . ] d -> [ c A A ] ] ] ] ] ] $end ]
|
||||
Second example b c . A $end
|
||||
Second reduce derivation $accept -> [ a -> [ b d -> [ a -> [ c d -> [ c -> [ . ] A ] ] ] ] $end ]
|
||||
input.y: warning: shift/reduce conflict on token A [-Wcounterexamples]
|
||||
First example b c . A
|
||||
Shift derivation a -> [ b d -> [ c . A ] ]
|
||||
Second example b c . A $end
|
||||
Reduce derivation $accept -> [ a -> [ b d -> [ a -> [ c d -> [ c -> [ . ] A ] ] ] ] $end ]
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example b d .
|
||||
First reduce derivation a -> [ b d . ]
|
||||
Second reduce derivation a -> [ b d -> [ d . ] ]
|
||||
input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
|
||||
Example c d .
|
||||
First reduce derivation a -> [ c d . ]
|
||||
Second reduce derivation a -> [ c d -> [ d . ] ]
|
||||
input.y:5.4: warning: rule useless in parser due to conflicts [-Wother]
|
||||
input.y:6.15: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
@@ -458,7 +795,6 @@ AT_CLEANUP
|
||||
## --------------------------- ##
|
||||
|
||||
AT_SETUP([Non-unifying Prefix Share])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
# Tests for a counterexample which should start its derivation
|
||||
# at a shared symbol rather than the start symbol.
|
||||
@@ -471,13 +807,26 @@ a: H i J J
|
||||
i: %empty | i J;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token 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 ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token J [-Wcounterexamples]
|
||||
Example: H i J . J J
|
||||
Shift derivation
|
||||
s
|
||||
`-> a J
|
||||
`-> H i J . J
|
||||
Reduce derivation
|
||||
s
|
||||
`-> a
|
||||
`-> H i J J
|
||||
`-> i J .
|
||||
input.y:5.13-15: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token J [-Wcounterexamples]
|
||||
Example H i J . J J
|
||||
Shift derivation s -> [ a -> [ H i J . J ] J ]
|
||||
Reduce derivation s -> [ a -> [ H i -> [ i J . ] J J ] ]
|
||||
input.y:5.13-15: warning: rule useless in parser due to conflicts [-Wother]
|
||||
]])
|
||||
|
||||
@@ -491,7 +840,6 @@ AT_CLEANUP
|
||||
# are derived correctly.
|
||||
|
||||
AT_SETUP([Deep Null Unifying])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A D
|
||||
@@ -503,13 +851,26 @@ c: %empty
|
||||
d: D;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token D:
|
||||
Example A a . D
|
||||
First derivation s ::=[ A a a ::=[ b ::=[ c ::=[ . ] ] ] d ::=[ D ] ]
|
||||
Second derivation s ::=[ A a d ::=[ . D ] ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token D [-Wcounterexamples]
|
||||
Example: A a . D
|
||||
Shift derivation
|
||||
s
|
||||
`-> A a d
|
||||
`-> . D
|
||||
Reduce derivation
|
||||
s
|
||||
`-> A a a d
|
||||
`-> b `-> D
|
||||
`-> c
|
||||
`-> .
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token D [-Wcounterexamples]
|
||||
Example A a . D
|
||||
Shift derivation s -> [ A a d -> [ . D ] ]
|
||||
Reduce derivation s -> [ A a a -> [ b -> [ c -> [ . ] ] ] d -> [ D ] ]
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
@@ -521,7 +882,6 @@ AT_CLEANUP
|
||||
# Tests that expand_to_conflict works with nullable sybols
|
||||
|
||||
AT_SETUP([Deep Null Non-unifying])
|
||||
AT_KEYWORDS([cex])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A D E
|
||||
@@ -533,14 +893,30 @@ c: %empty
|
||||
d: D;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK_CEX([input.y], [], [],
|
||||
AT_BISON_CHECK_CEX(
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
Shift/reduce conflict on token 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
|
||||
Second derivation $accept ::=[ s ::=[ A a d ::=[ . D ] ] $end ]
|
||||
|
||||
input.y: warning: shift/reduce conflict on token D [-Wcounterexamples]
|
||||
First example: A a . D $end
|
||||
Shift derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> A a d
|
||||
`-> . D
|
||||
Second example: A a . D E $end
|
||||
Reduce derivation
|
||||
$accept
|
||||
`-> s $end
|
||||
`-> A a a d E
|
||||
`-> b `-> D
|
||||
`-> c
|
||||
`-> .
|
||||
]],
|
||||
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
input.y: warning: shift/reduce conflict on token D [-Wcounterexamples]
|
||||
First example A a . D $end
|
||||
Shift derivation $accept -> [ s -> [ A a d -> [ . D ] ] $end ]
|
||||
Second example A a . D E $end
|
||||
Reduce derivation $accept -> [ s -> [ A a a -> [ b -> [ c -> [ . ] ] ] d -> [ D ] E ] $end ]
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
+105
-26
@@ -28,6 +28,8 @@ m4_pushdef([AT_TEST],
|
||||
AT_SETUP([$1])
|
||||
AT_KEYWORDS([diagnostics])
|
||||
|
||||
m4_if(m4_index([$1], [Counterexample]), [-1], [], [AT_KEYWORDS([cex])])
|
||||
|
||||
# We need UTF-8 support for correct screen-width computation of UTF-8
|
||||
# characters. Skip the test if not available.
|
||||
locale=`locale -a | $EGREP '^en_US\.(UTF-8|utf8)$' | sed 1q`
|
||||
@@ -49,7 +51,7 @@ if $EGREP ['\^M|\\[0-9][0-9][0-9]'] input.y experr >/dev/null; then
|
||||
AT_PERL_REQUIRE([-pi -e 's{\^M}{\r}g;s{\\(\d{3}|.)}{$v = $[]1; $v =~ /\A\d+\z/ ? chr($v) : $v}ge' input.y experr])
|
||||
fi
|
||||
|
||||
AT_CHECK([LC_ALL="$locale" $5 bison -fcaret --color=debug -Wall,cex input.y], [$3], [], [experr])
|
||||
AT_CHECK(AT_SET_ENV [LC_ALL="$locale" $5 bison -fcaret --color=debug -Wall,cex input.y], [$3], [], [experr])
|
||||
|
||||
# When no style, same messages, but without style.
|
||||
# Except for the second display of the counterexample,
|
||||
@@ -66,7 +68,7 @@ AT_PERL_REQUIRE([-pi -e '
|
||||
# Cannot use AT_BISON_CHECK easily as we need to change the
|
||||
# environment.
|
||||
# FIXME: Enhance AT_BISON_CHECK.
|
||||
AT_CHECK([LC_ALL="$locale" $5 bison -fcaret -Wall,cex input.y], [$3], [], [experr])
|
||||
AT_CHECK(AT_SET_ENV [LC_ALL="$locale" $5 bison -fcaret -Wall,cex input.y], [$3], [], [experr])
|
||||
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -533,34 +535,111 @@ exp
|
||||
]],
|
||||
[1],
|
||||
[[input.y: <error>error:</error> shift/reduce conflicts: 4 found, 0 expected
|
||||
Shift/reduce conflict on token "+":
|
||||
Example <cex-0><cex-1><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
First derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-1><cex-step>exp ::=[ </cex-step><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot><cex-step> ]</cex-step></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-0>
|
||||
Example <cex-0><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Second derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf><cex-1> <cex-step>exp ::=[ </cex-step><cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-1><cex-step> ]</cex-step></cex-0>
|
||||
|
||||
Shift/reduce conflict on token "else":
|
||||
Example <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
First derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot><cex-step> ]</cex-step></cex-1> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-0>
|
||||
Example <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Second derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-1><cex-step> ]</cex-step></cex-0>
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
Example <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
First derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-1><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot><cex-step> ]</cex-step></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-0>
|
||||
Example <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Second derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-step>exp ::=[ </cex-step><cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-1><cex-step> ]</cex-step></cex-0>
|
||||
|
||||
Shift/reduce conflict on token "+":
|
||||
Example <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
First derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-1><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot><cex-step> ]</cex-step></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-0>
|
||||
Example <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Second derivation <cex-0><cex-step>exp ::=[ </cex-step><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf><cex-1> <cex-step>exp ::=[ </cex-step><cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf><cex-step> ]</cex-step></cex-1><cex-step> ]</cex-step></cex-0>
|
||||
|
||||
input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
|
||||
Example: <cex-0><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Shift derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-leaf>exp</cex-leaf><cex-leaf> "+"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
|
||||
Example: <cex-0><cex-1><cex-leaf>exp</cex-leaf> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
Reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>exp</cex-leaf><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
|
||||
input.y: <warning>warning:</warning> shift/reduce conflict on token "else" [<warning>-Wcounterexamples</warning>]
|
||||
Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Shift derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
|
||||
Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
Reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
|
||||
input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
|
||||
Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Shift derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
|
||||
Example: <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
Reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
|
||||
input.y: <warning>warning:</warning> shift/reduce conflict on token "+" [<warning>-Wcounterexamples</warning>]
|
||||
Example: <cex-0><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf><cex-1> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-1></cex-0>
|
||||
Shift derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "else"</cex-leaf><cex-1><cex-step> exp</cex-step></cex-1></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>exp</cex-leaf><cex-dot> •</cex-dot><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-1>
|
||||
Example: <cex-0><cex-1><cex-leaf>"if"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"then"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-leaf>"else"</cex-leaf> <cex-leaf>exp</cex-leaf> <cex-dot>•</cex-dot></cex-1> <cex-leaf>"+"</cex-leaf> <cex-leaf>exp</cex-leaf></cex-0>
|
||||
Reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-1><cex-step>exp</cex-step></cex-1><cex-leaf> "+"</cex-leaf><cex-leaf> exp</cex-leaf></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-leaf>"if"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "then"</cex-leaf><cex-leaf> exp</cex-leaf><cex-leaf> "else"</cex-leaf><cex-leaf> exp</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-1>
|
||||
]])
|
||||
|
||||
|
||||
AT_TEST([[Deep Counterexamples]],
|
||||
[[%expect 0
|
||||
%%
|
||||
exp: x1 e1 foo1 x1 | y1 e2 bar1 y1
|
||||
foo1: foo2
|
||||
foo2: foo3
|
||||
foo3: x1 foo4
|
||||
foo4: "quuux"
|
||||
|
||||
bar1: bar2
|
||||
bar2: bar3
|
||||
bar3: y1 bar4
|
||||
bar4: "quuux"
|
||||
|
||||
x1: x2
|
||||
x2: x3
|
||||
x3: "X"
|
||||
|
||||
y1: y2
|
||||
y2: y3
|
||||
y3: "X"
|
||||
|
||||
e1:
|
||||
e2:
|
||||
]],
|
||||
[1],
|
||||
[[input.y:30.4: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
||||
30 | e1:
|
||||
| <warning>^</warning>
|
||||
| <fixit-insert>%empty</fixit-insert>
|
||||
input.y:31.4: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
||||
31 | e2:
|
||||
| <warning>^</warning>
|
||||
| <fixit-insert>%empty</fixit-insert>
|
||||
input.y: <error>error:</error> reduce/reduce conflicts: 1 found, 0 expected
|
||||
input.y: <warning>warning:</warning> reduce/reduce conflict on token "X" [<warning>-Wcounterexamples</warning>]
|
||||
Example: <cex-0><cex-1><cex-2><cex-3><cex-leaf>"X"</cex-leaf> <cex-dot>•</cex-dot></cex-3></cex-2></cex-1><cex-4></cex-4><cex-5><cex-6><cex-7><cex-8><cex-9><cex-10> <cex-leaf>"X"</cex-leaf></cex-10></cex-9></cex-8><cex-11> <cex-leaf>"quuux"</cex-leaf></cex-11></cex-7></cex-6></cex-5><cex-12><cex-13><cex-14> <cex-leaf>"X"</cex-leaf></cex-14></cex-13></cex-12></cex-0>
|
||||
First reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-1><cex-step>x1</cex-step></cex-1><cex-4><cex-step> e1</cex-step></cex-4><cex-5><cex-step> foo1</cex-step></cex-5><cex-12><cex-step> x1</cex-step></cex-12></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-2><cex-step>x2</cex-step></cex-2></cex-step></cex-1><cex-4><cex-step> ↳ ε</cex-step></cex-4><cex-5><cex-step> ↳ <cex-6><cex-step>foo2</cex-step></cex-6></cex-step></cex-5><cex-12><cex-step> ↳ <cex-13><cex-step>x2</cex-step></cex-13></cex-step></cex-12>
|
||||
<cex-2><cex-step> ↳ <cex-3><cex-step>x3</cex-step></cex-3></cex-step></cex-2><cex-6><cex-step> ↳ <cex-7><cex-step>foo3</cex-step></cex-7></cex-step></cex-6><cex-13><cex-step> ↳ <cex-14><cex-step>x3</cex-step></cex-14></cex-step></cex-13>
|
||||
<cex-3><cex-step> ↳ <cex-leaf>"X"</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-3><cex-7><cex-step> ↳ <cex-8><cex-step>x1</cex-step></cex-8><cex-11><cex-step> foo4</cex-step></cex-11></cex-step></cex-7><cex-14><cex-step> ↳ <cex-leaf>"X"</cex-leaf></cex-step></cex-14>
|
||||
<cex-8><cex-step> ↳ <cex-9><cex-step>x2</cex-step></cex-9></cex-step></cex-8><cex-11><cex-step> ↳ <cex-leaf>"quuux"</cex-leaf></cex-step></cex-11>
|
||||
<cex-9><cex-step> ↳ <cex-10><cex-step>x3</cex-step></cex-10></cex-step></cex-9>
|
||||
<cex-10><cex-step> ↳ <cex-leaf>"X"</cex-leaf></cex-step></cex-10>
|
||||
Example: <cex-0><cex-1><cex-2><cex-3><cex-leaf>"X"</cex-leaf> <cex-dot>•</cex-dot></cex-3></cex-2></cex-1><cex-4></cex-4><cex-5><cex-6><cex-7><cex-8><cex-9><cex-10> <cex-leaf>"X"</cex-leaf></cex-10></cex-9></cex-8><cex-11> <cex-leaf>"quuux"</cex-leaf></cex-11></cex-7></cex-6></cex-5><cex-12><cex-13><cex-14> <cex-leaf>"X"</cex-leaf></cex-14></cex-13></cex-12></cex-0>
|
||||
Second reduce derivation
|
||||
<cex-0><cex-step>exp</cex-step></cex-0>
|
||||
<cex-0><cex-step>↳ <cex-1><cex-step>y1</cex-step></cex-1><cex-4><cex-step> e2</cex-step></cex-4><cex-5><cex-step> bar1</cex-step></cex-5><cex-12><cex-step> y1</cex-step></cex-12></cex-step></cex-0>
|
||||
<cex-1><cex-step> ↳ <cex-2><cex-step>y2</cex-step></cex-2></cex-step></cex-1><cex-4><cex-step> ↳ ε</cex-step></cex-4><cex-5><cex-step> ↳ <cex-6><cex-step>bar2</cex-step></cex-6></cex-step></cex-5><cex-12><cex-step> ↳ <cex-13><cex-step>y2</cex-step></cex-13></cex-step></cex-12>
|
||||
<cex-2><cex-step> ↳ <cex-3><cex-step>y3</cex-step></cex-3></cex-step></cex-2><cex-6><cex-step> ↳ <cex-7><cex-step>bar3</cex-step></cex-7></cex-step></cex-6><cex-13><cex-step> ↳ <cex-14><cex-step>y3</cex-step></cex-14></cex-step></cex-13>
|
||||
<cex-3><cex-step> ↳ <cex-leaf>"X"</cex-leaf><cex-dot> •</cex-dot></cex-step></cex-3><cex-7><cex-step> ↳ <cex-8><cex-step>y1</cex-step></cex-8><cex-11><cex-step> bar4</cex-step></cex-11></cex-step></cex-7><cex-14><cex-step> ↳ <cex-leaf>"X"</cex-leaf></cex-step></cex-14>
|
||||
<cex-8><cex-step> ↳ <cex-9><cex-step>y2</cex-step></cex-9></cex-step></cex-8><cex-11><cex-step> ↳ <cex-leaf>"quuux"</cex-leaf></cex-step></cex-11>
|
||||
<cex-9><cex-step> ↳ <cex-10><cex-step>y3</cex-step></cex-10></cex-step></cex-9>
|
||||
<cex-10><cex-step> ↳ <cex-leaf>"X"</cex-leaf></cex-step></cex-10>
|
||||
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
|
||||
]])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
|
||||
+2
-2
@@ -434,7 +434,7 @@ input.y:323.10: warning: empty rule without %empty [-Wempty-rule]
|
||||
]AT_COND_CASE([[canonical LR]],
|
||||
[[input.y: warning: 265 shift/reduce conflicts [-Wconflicts-sr]]],
|
||||
[[input.y: warning: 65 shift/reduce conflicts [-Wconflicts-sr]]])[
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:39.1-5: warning: useless associativity for FUNC_CALL, use %precedence [-Wprecedence]
|
||||
input.y:44.1-5: warning: useless associativity for YNUMBER, use %precedence [-Wprecedence]
|
||||
input.y:44.1-5: warning: useless associativity for YSTRING, use %precedence [-Wprecedence]
|
||||
@@ -1419,7 +1419,7 @@ input.y:591.18: warning: empty rule without %empty [-Wempty-rule]
|
||||
input.y: warning: 144 reduce/reduce conflicts [-Wconflicts-rr]]],
|
||||
[[input.y: warning: 78 shift/reduce conflicts [-Wconflicts-sr]
|
||||
input.y: warning: 10 reduce/reduce conflicts [-Wconflicts-rr]]])[
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
input.y:72.1-5: warning: useless associativity for HQUA, use %precedence [-Wprecedence]
|
||||
input.y:53.1-6: warning: useless associativity for HASSIGN, use %precedence [-Wprecedence]
|
||||
input.y:54.1-5: warning: useless associativity for HORELSE, use %precedence [-Wprecedence]
|
||||
|
||||
+17
-17
@@ -89,7 +89,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr1.c -rall glr-regr1.y]], 0, [],
|
||||
[[glr-regr1.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
glr-regr1.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr1.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr1])
|
||||
AT_PARSER_CHECK([[glr-regr1 BPBPB]], 0,
|
||||
@@ -214,7 +214,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr2a.c -rall glr-regr2a.y]], 0, [],
|
||||
[[glr-regr2a.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
|
||||
glr-regr2a.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr2a.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr2a])
|
||||
|
||||
@@ -350,7 +350,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: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr3.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr3.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr3])
|
||||
|
||||
@@ -447,7 +447,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr4.c -rall glr-regr4.y]], 0, [],
|
||||
[[glr-regr4.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr4.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr4.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr4])
|
||||
|
||||
@@ -505,7 +505,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr5.c -rall glr-regr5.y]], 0, [],
|
||||
[[glr-regr5.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr5.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr5.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr5])
|
||||
|
||||
@@ -555,7 +555,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr6.c -rall glr-regr6.y]], 0, [],
|
||||
[[glr-regr6.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr6.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr6.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr6])
|
||||
|
||||
@@ -646,7 +646,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr7.c -rall glr-regr7.y]], 0, [],
|
||||
[[glr-regr7.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr7.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr7.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr7])
|
||||
|
||||
@@ -737,7 +737,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr8.c -rall glr-regr8.y]], 0, [],
|
||||
[[glr-regr8.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr8.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr8.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr8])
|
||||
|
||||
@@ -819,7 +819,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr9.c -rall glr-regr9.y]], 0, [],
|
||||
[[glr-regr9.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr9.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr9.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr9])
|
||||
|
||||
@@ -877,7 +877,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr10.c -rall glr-regr10.y]], 0, [],
|
||||
[[glr-regr10.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr10.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr10.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr10])
|
||||
|
||||
@@ -937,7 +937,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr11.c -rall glr-regr11.y]], 0, [],
|
||||
[[glr-regr11.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr11.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr11.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr11])
|
||||
|
||||
@@ -1060,7 +1060,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
AT_BISON_CHECK([[-o glr-regr12.c -rall glr-regr12.y]], 0, [],
|
||||
[[glr-regr12.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
|
||||
glr-regr12.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr12.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr12.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr12])
|
||||
|
||||
@@ -1392,7 +1392,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr14.c -rall glr-regr14.y]], 0, [],
|
||||
[[glr-regr14.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr14.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr14.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr14])
|
||||
|
||||
@@ -1487,7 +1487,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr15.c -rall glr-regr15.y]], 0, [],
|
||||
[[glr-regr15.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr15.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr15.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr15])
|
||||
|
||||
@@ -1549,7 +1549,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr16.c -rall glr-regr16.y]], 0, [],
|
||||
[[glr-regr16.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
glr-regr16.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr16.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr16])
|
||||
|
||||
@@ -1625,7 +1625,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr17.c -rall glr-regr17.y]], 0, [],
|
||||
[[glr-regr17.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
|
||||
glr-regr17.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
glr-regr17.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([glr-regr17])
|
||||
|
||||
@@ -1719,7 +1719,7 @@ d: /* nada. */;
|
||||
|
||||
AT_BISON_CHECK([[-o input.c input.y]], 0, [],
|
||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
|
||||
|
||||
+27
-9
@@ -204,17 +204,20 @@ AT_SETUP([Several parsers])
|
||||
# Generate and compile to *.o. Make sure there is no (allowed) YY*
|
||||
# nor yy* identifiers in the header after applying api.prefix. Check
|
||||
# that headers can be compiled by a C++ compiler.
|
||||
#
|
||||
# They should all use parse.assert to make sure that we don't even
|
||||
# conflict of YY_ASSERT.
|
||||
m4_pushdef([AT_TEST],
|
||||
[AT_BISON_OPTION_PUSHDEFS([%define api.prefix {$1_} $2])
|
||||
[AT_BISON_OPTION_PUSHDEFS([%define api.prefix {$1_} %define parse.assert $2])
|
||||
AT_DATA_GRAMMAR([$1.y],
|
||||
[[%define api.prefix {$1_}
|
||||
%define parse.assert
|
||||
$2
|
||||
%define parse.error verbose
|
||||
%union
|
||||
{
|
||||
int integer;
|
||||
}
|
||||
%{
|
||||
]AT_VARIANT_IF([],
|
||||
[%union {int integer;}])[
|
||||
|
||||
%code {
|
||||
#include <stdio.h> /* printf. */
|
||||
]AT_PUSH_IF([[
|
||||
#if defined __GNUC__ && (7 == __GNUC__ || 9 == __GNUC__)
|
||||
@@ -223,8 +226,10 @@ $2
|
||||
]])[
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
%}
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
exp:
|
||||
'x' '1' { printf ("x1\n"); }
|
||||
| 'x' '2' { printf ("x2\n"); }
|
||||
@@ -235,9 +240,12 @@ exp:
|
||||
| 'x' '7' { printf ("x7\n"); }
|
||||
| 'x' '8' { printf ("x8\n"); }
|
||||
| 'x' '9' { printf ("x9\n"); }
|
||||
| 'x' 'a' { printf ("xa\n"); }
|
||||
| 'x' 'b' { printf ("xb\n"); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(["$1"])[
|
||||
]])
|
||||
@@ -270,6 +278,8 @@ extern "C"
|
||||
#endif
|
||||
#include "x5.hh"
|
||||
#include "x9.hh"
|
||||
#include "xa.hh"
|
||||
#include "xb.hh"
|
||||
|
||||
#define RUN(S) \
|
||||
do { \
|
||||
@@ -292,6 +302,10 @@ main (void)
|
||||
RUN(x8_parse());
|
||||
x9_::parser p9;
|
||||
RUN(p9.parse());
|
||||
xa_::parser pa;
|
||||
RUN(pa.parse());
|
||||
xb_::parser pb;
|
||||
RUN(pb.parse());
|
||||
return 0;
|
||||
}
|
||||
]])# main.cc
|
||||
@@ -304,7 +318,9 @@ AT_TEST([x5], [%locations %debug %language "c++"])
|
||||
AT_TEST([x6], [%define api.pure])
|
||||
AT_TEST([x7], [%define api.push-pull both])
|
||||
AT_TEST([x8], [%define api.pure %define api.push-pull both])
|
||||
AT_TEST([x9], [%locations %code requires {#include "location.hh"} %define api.location.type {x5_::location} %debug %language "c++"])
|
||||
AT_TEST([x9], [%locations %code requires {#include "location.hh"} %define api.location.type {::x5_::location} %debug %language "c++"])
|
||||
AT_TEST([xa], [%locations %code requires {#include "location.hh"} %define api.location.type {::x5_::location} %language "c++" %define api.value.type variant])
|
||||
AT_TEST([xb], [%locations %define api.location.file none %language "c++" %define api.value.type variant])
|
||||
#AT_TEST([x5], [%locations %language "c++" %glr-parser])
|
||||
|
||||
# Check that api.prefix works properly:
|
||||
@@ -340,6 +356,8 @@ AT_PERL_CHECK([[-n -0777 -e '
|
||||
|YY_NULLPTR
|
||||
|YY_RVREF
|
||||
|YY_\w+_INCLUDED
|
||||
|FILE\ \*yyo # Function argument.
|
||||
|const\ yylocp # Function argument.
|
||||
)\b}{}gx;
|
||||
while (/^(.*YY.*)$/gm)
|
||||
{
|
||||
@@ -357,7 +375,7 @@ AT_PERL_CHECK([[-n -0777 -e '
|
||||
# Do this late, so that other checks have been performed.
|
||||
AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
|
||||
|
||||
AT_COMPILE_CXX([parser], [[x[1-9].o -DCC_IS_CXX=$CC_IS_CXX main.cc]])
|
||||
AT_COMPILE_CXX([parser], [[x[1-9a-b].o -DCC_IS_CXX=$CC_IS_CXX main.cc]])
|
||||
AT_PARSER_CHECK([parser], [0], [[expout]])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
+166
-20
@@ -1,4 +1,4 @@
|
||||
# Checking the Bison scanner. -*- Autotest -*-
|
||||
# Checking the Bison reader. -*- Autotest -*-
|
||||
|
||||
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
|
||||
|
||||
@@ -78,10 +78,13 @@ AT_CLEANUP
|
||||
## Invalid inputs. ##
|
||||
## ---------------- ##
|
||||
|
||||
# The truly bad guys no human would write, but easily uncovered by
|
||||
# fuzzers.
|
||||
AT_SETUP([Invalid inputs])
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[\000\001\002\377?
|
||||
"\000"
|
||||
%%
|
||||
?
|
||||
default: 'a' }
|
||||
@@ -92,21 +95,50 @@ default: 'a' }
|
||||
]])
|
||||
AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y]])
|
||||
|
||||
AT_BISON_CHECK([input.y], [1], [],
|
||||
AT_BISON_CHECK([-fcaret input.y], [1], [], [stderr])
|
||||
|
||||
# Autotest's diffing, when there are NUL bytes, just reports "binary
|
||||
# files differ". So don't leave NUL bytes.
|
||||
AT_PERL_CHECK([[-p -e 's{([\0\377])}{sprintf "\\x%02x", ord($1)}ge' stderr]], [],
|
||||
[[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
|
||||
input.y:3.1: error: invalid character: '?'
|
||||
input.y:4.14: error: invalid character: '}'
|
||||
input.y:5.1: error: invalid character: '%'
|
||||
input.y:5.2: error: invalid character: '&'
|
||||
input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
|
||||
input.y:7.1: error: invalid character: '%'
|
||||
input.y:7.2: error: invalid character: '-'
|
||||
input.y:8.1-9.0: error: missing '%}' at end of file
|
||||
1 | \x00\xff?
|
||||
| ^~
|
||||
input.y:2.2: error: invalid null character
|
||||
2 | "\x00"
|
||||
| ^
|
||||
input.y:4.1: error: invalid character: '?'
|
||||
4 | ?
|
||||
| ^
|
||||
input.y:5.14: error: invalid character: '}'
|
||||
5 | default: 'a' }
|
||||
| ^
|
||||
input.y:6.1: error: invalid character: '%'
|
||||
6 | %&
|
||||
| ^
|
||||
input.y:6.2: error: invalid character: '&'
|
||||
6 | %&
|
||||
| ^
|
||||
input.y:7.1-17: error: invalid directive: '%a-does-not-exist'
|
||||
7 | %a-does-not-exist
|
||||
| ^~~~~~~~~~~~~~~~~
|
||||
input.y:8.1: error: invalid character: '%'
|
||||
8 | %-
|
||||
| ^
|
||||
input.y:8.2: error: invalid character: '-'
|
||||
8 | %-
|
||||
| ^
|
||||
input.y:9.1-10.0: error: missing '%}' at end of file
|
||||
9 | %{
|
||||
| ^~
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------ ##
|
||||
## Invalid inputs with {}. ##
|
||||
## ------------------------ ##
|
||||
|
||||
AT_SETUP([Invalid inputs with {}])
|
||||
|
||||
# We used to SEGV here. See
|
||||
@@ -788,6 +820,33 @@ input.y:3.8-10: note: previous declaration
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ---------------- ##
|
||||
## EOF redeclared. ##
|
||||
## ---------------- ##
|
||||
|
||||
AT_SETUP([EOF redeclared])
|
||||
|
||||
# We used to crash when redefining a token after having defined EOF.
|
||||
# See https://lists.gnu.org/r/bug-bison/2020-08/msg00008.html.
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token FOO BAR FOO 0
|
||||
%%
|
||||
input: %empty
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret input.y], [0], [],
|
||||
[[input.y:1.16-18: warning: symbol FOO redeclared [-Wother]
|
||||
1 | %token FOO BAR FOO 0
|
||||
| ^~~
|
||||
input.y:1.8-10: note: previous declaration
|
||||
1 | %token FOO BAR FOO 0
|
||||
| ^~~
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## --------------------------- ##
|
||||
## Symbol class redefinition. ##
|
||||
## --------------------------- ##
|
||||
@@ -1224,12 +1283,12 @@ AT_TEST([[%token foo "foo"
|
||||
%%
|
||||
exp: foo;
|
||||
]],
|
||||
[[input.y:3.7-11: error: %type redeclaration for foo
|
||||
[[input.y:3.13-15: error: %type redeclaration for foo
|
||||
3 | %type <baz> foo
|
||||
| ^~~~~
|
||||
input.y:2.7-11: note: previous declaration
|
||||
| ^~~
|
||||
input.y:2.13-17: note: previous declaration
|
||||
2 | %type <bar> "foo"
|
||||
| ^~~~~
|
||||
| ^~~~~
|
||||
]])
|
||||
|
||||
AT_TEST([[%token foo "foo"
|
||||
@@ -1336,11 +1395,6 @@ AT_CLEANUP
|
||||
AT_SETUP([Torturing the Scanner])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS
|
||||
AT_DATA([input.y], [])
|
||||
AT_BISON_CHECK([input.y], [1], [],
|
||||
[[input.y:1.1: error: unexpected end of file
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA([input.y],
|
||||
[{}
|
||||
@@ -2447,6 +2501,99 @@ input.y:5.19: error: invalid character after \-escape: \001
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------ ##
|
||||
## Unexpected end of file. ##
|
||||
## ------------------------ ##
|
||||
|
||||
AT_SETUP([[Unexpected end of file]])
|
||||
|
||||
|
||||
AT_DATA([input.y], [])
|
||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||
[[input.y:1.1: error: unexpected end of file
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([char.y],
|
||||
[[%token FOO ']])
|
||||
|
||||
AT_BISON_CHECK([-fcaret char.y], [1], [],
|
||||
[[char.y:1.12: error: missing "'" at end of file
|
||||
1 | %token FOO '
|
||||
| ^
|
||||
char.y:1.12: error: empty character literal
|
||||
1 | %token FOO '
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-char.y],
|
||||
[[%token FOO '\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-char.y], [1], [],
|
||||
[[escape-in-char.y:1.12-13: error: missing '?\'' at end of file
|
||||
1 | %token FOO '\
|
||||
| ^~
|
||||
escape-in-char.y:1.14: error: unexpected end of file
|
||||
1 | %token FOO '\
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([string.y],
|
||||
[[%token FOO "]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret string.y], [1], [],
|
||||
[[string.y:1.12: error: missing '"' at end of file
|
||||
1 | %token FOO "
|
||||
| ^
|
||||
string.y:1.13: error: unexpected end of file
|
||||
1 | %token FOO "
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-string.y],
|
||||
[[%token FOO "\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-string.y], [1], [],
|
||||
[[escape-in-string.y:1.12-13: error: missing '?"' at end of file
|
||||
1 | %token FOO "\
|
||||
| ^~
|
||||
escape-in-string.y:1.14: error: unexpected end of file
|
||||
1 | %token FOO "\
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([tstring.y],
|
||||
[[%token FOO _("]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret tstring.y], [1], [],
|
||||
[[tstring.y:1.12-14: error: missing '")' at end of file
|
||||
1 | %token FOO _("
|
||||
| ^~~
|
||||
tstring.y:1.15: error: unexpected end of file
|
||||
1 | %token FOO _("
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-tstring.y],
|
||||
[[%token FOO _("\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-tstring.y], [1], [],
|
||||
[[escape-in-tstring.y:1.12-15: error: missing '?")' at end of file
|
||||
1 | %token FOO _("\
|
||||
| ^~~~
|
||||
escape-in-tstring.y:1.16: error: unexpected end of file
|
||||
1 | %token FOO _("\
|
||||
| ^
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## LAC: Errors for %define. ##
|
||||
## ------------------------- ##
|
||||
@@ -2887,7 +3034,6 @@ input.y:13.1-14: note: previous definition
|
||||
input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
|
||||
input.y:13.16-29: note: previous definition
|
||||
input.y: error: reduce/reduce conflicts: 0 found, 42 expected
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||
]])
|
||||
|
||||
|
||||
+10
-4
@@ -351,7 +351,7 @@ AT_TOKEN_CTOR_IF(
|
||||
[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
|
||||
m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
|
||||
m4_pushdef([AT_YYLEX_FORMALS], [])
|
||||
m4_pushdef([AT_YYLEX_RETURN], [yy::parser::symbol_type])
|
||||
m4_pushdef([AT_YYLEX_RETURN], [AT_NAMESPACE::parser::symbol_type])
|
||||
m4_pushdef([AT_YYLEX_ARGS], [])
|
||||
m4_pushdef([AT_USE_LEX_ARGS], [])
|
||||
m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
|
||||
@@ -390,6 +390,7 @@ AT_LOCATION_TYPE_SPAN_IF(
|
||||
|
||||
|
||||
AT_GLR_IF([AT_KEYWORDS([glr])])
|
||||
AT_PUSH_IF([AT_KEYWORDS([push])])
|
||||
])# _AT_BISON_OPTION_PUSHDEFS
|
||||
|
||||
|
||||
@@ -1169,11 +1170,16 @@ m4_define([AT_BISON_CHECK_XML],
|
||||
[cp xml-tests/test.output expout]
|
||||
AT_CHECK([[$XSLTPROC \
|
||||
`]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2text.xsl \
|
||||
xml-tests/test.xml]], [[0]], [expout])
|
||||
xml-tests/test.xml]], [[0]], [stdout])
|
||||
# xml2text and xml2dot always use '•', while --report uses '•' or '.'
|
||||
# depending on the locale, and the test suite is run with the plain
|
||||
# C locale.
|
||||
AT_CHECK([[sed -e 's/•/./g' stdout]], [], [expout])
|
||||
[sort xml-tests/test.gv > expout]
|
||||
AT_CHECK([[$XSLTPROC \
|
||||
`]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2dot.xsl \
|
||||
xml-tests/test.xml | sort]], [[0]], [expout])
|
||||
xml-tests/test.xml | sort | sed -e 's/•/./g']],
|
||||
[[0]], [stdout])
|
||||
[rm -rf xml-tests expout]
|
||||
AT_RESTORE_SPECIAL_FILES
|
||||
[fi]])
|
||||
@@ -1194,7 +1200,7 @@ m4_define([AT_BISON_CHECK_XML],
|
||||
# The testsuite verbose output, at least, will be incorrect, but nothing may
|
||||
# fail to make sure you notice.
|
||||
m4_define([AT_SET_ENV_IF],
|
||||
[[[COLUMNS=1000; export COLUMNS;]] m4_null_if($1, [], [[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS; ]]])])
|
||||
[[[COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;]] m4_null_if($1, [], [[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS; ]]])])
|
||||
|
||||
|
||||
# AT_SET_ENV
|
||||
|
||||
@@ -36,6 +36,14 @@ $(top_srcdir)/%D%/package.m4: $(top_srcdir)/configure
|
||||
} >$@.tmp
|
||||
$(AM_V_at)mv $@.tmp $@
|
||||
|
||||
|
||||
# Update the test cases. Consider the latest test results to be the
|
||||
# correct expectations, and change the test cases to match them.
|
||||
.PHONY: update-tests
|
||||
update-tests:
|
||||
$(AM_V_GEN)cd $(top_srcdir) \
|
||||
&& build-aux/update-test $(abs_builddir)/%D%/testsuite.dir/*/testsuite.log
|
||||
|
||||
## ------------------------- ##
|
||||
## Generate the test suite. ##
|
||||
## ------------------------- ##
|
||||
|
||||
+2
-2
@@ -759,7 +759,7 @@ AT_TEST([x1],
|
||||
])
|
||||
|
||||
# Check the CPP guard and Doxyen comments.
|
||||
AT_CHECK([sed -ne 's/#line [0-9]\+ "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/include/ast/loc.hh], [],
|
||||
AT_CHECK([[sed -ne 's/#line [0-9][0-9]* "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/include/ast/loc.hh]], [],
|
||||
[[ ** \file bar/include/ast/loc.hh
|
||||
** Define the x1::location class.
|
||||
#ifndef YY_YY_BAR_INCLUDE_AST_LOC_HH_INCLUDED
|
||||
@@ -771,7 +771,7 @@ AT_CHECK([sed -ne 's/#line [0-9]\+ "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out
|
||||
#endif // !YY_YY_BAR_INCLUDE_AST_LOC_HH_INCLUDED
|
||||
]])
|
||||
|
||||
AT_CHECK([sed -ne 's/^#line [0-9]\+ "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/x1.hh], [],
|
||||
AT_CHECK([[sed -ne 's/^#line [0-9][0-9]* "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/x1.hh]], [],
|
||||
[[ ** \file bar/x1.hh
|
||||
** Define the x1::parser class.
|
||||
#ifndef YY_YY_BAR_X1_HH_INCLUDED
|
||||
|
||||
+1
-1
@@ -1300,7 +1300,7 @@ dnl INPUT
|
||||
dnl BISON-STDERR
|
||||
[AT_COND_CASE([[LALR]],
|
||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
|
||||
input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
|
||||
]], [])],
|
||||
|
||||
dnl TABLES
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user