Compare commits

...
1097 Commits
Author SHA1 Message Date
Akim Demaille 7a11a9308c version 3.7.4
* NEWS: Record release date.
2020-11-14 12:04:26 +01:00
Akim Demaille d8cc6b073e c++: shorten the assertions that check whether tokens are correct
Before:

    YY_ASSERT (tok == token::YYEOF || tok == token::YYerror || tok == token::YYUNDEF || tok == 120 || tok == 49 || tok == 50 || tok == 51 || tok == 52 || tok == 53 || tok == 54 || tok == 55 || tok == 56 || tok == 57 || tok == 97 || tok == 98);

After:

    YY_ASSERT (tok == token::YYEOF
               || (token::YYerror <= tok && tok <= token::YYUNDEF)
               || tok == 120
               || (49 <= tok && tok <= 57)
               || (97 <= tok && tok <= 98));

Clauses are now also wrapped on several lines.  This is nicer to read
and diff, but also avoids pushing Visual C++ to its arbitrary
limits (640K and lines of 16380 bytes ought to be enough for anybody,
otherwise make an C2026 error).

The useless parens are there for the dummy warnings about
precedence (in the future, will we also have to put parens in
`1+2*3`?).

* data/skeletons/variant.hh (_b4_filter_tokens, b4_tok_in, b4_tok_in):
New.
(_b4_token_constructor_define): Use them.
2020-11-13 06:17:52 +01:00
Akim Demaille 0264b4bca0 c++: don't glue functions together
* data/skeletons/bison.m4 (b4_type_foreach): Accept a separator.
* data/skeletons/c++.m4: Use it.
And fix an incorrect comment.
2020-11-13 06:17:52 +01:00
Akim Demaille 8b424b865e lalr1.cc: YY_ASSERT should use api.prefix
Working on the previous commit I realized that YY_ASSERT was used in
the generated headers, so must follow api.prefix to avoid clashes when
multiple C++ parser with variants are used.

Actually many more macros should obey api.prefix (YY_CPLUSPLUS,
YY_COPY, etc.).  There was no complaint so far, so it's not urgent
enough for 3.7.4, but it should be addressed in 3.8.

* data/skeletons/variant.hh (b4_assert): New.
Use it.
* tests/local.at (AT_YYLEX_RETURN): Fix.
* tests/headers.at: Make sure variant-based C++ parsers are checked
too.
This test did find that YY_ASSERT escaped renaming (before the fix in
this commit).
2020-11-13 06:17:52 +01:00
Akim Demaille f4431ea115 c++: don't use YY_ASSERT at all if parse.assert is disabled
In some extreme situations (about 800 tokens), we generate a
single-line assertion long enough for Visual C++ to discard the end of
the line, thus falling into parse ends for the missing `);`.  On a
shorter example:

    YY_ASSERT (tok == token::TOK_YYEOF || tok == token::TOK_YYerror || tok == token::TOK_YYUNDEF || tok == token::TOK_ASSIGN || tok == token::TOK_MINUS || tok == token::TOK_PLUS || tok == token::TOK_STAR || tok == token::TOK_SLASH || tok == token::TOK_LPAREN || tok == token::TOK_RPAREN);

Whether NDEBUG is used or not is irrelevant, the parser dies anyway.

Reported by Jot Dot <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00002.html

We should avoid emitting lines so long.

We probably should also use a range-based assertion (with extraneous
parens to pacify fascist compilers):

    YY_ASSERT ((token::TOK_YYEOF <= tok && tok <= token::TOK_YYUNDEF)
               || (token::TOK_ASSIGN <= tok && ...)

But anyway, we should simply not emit this assertion at all when not
asked for.

* data/skeletons/variant.hh: Do not define, nor use, YY_ASSERT when it
is not enabled.
2020-11-13 06:17:52 +01:00
Akim Demaille fe8c36ddca c++: style: follow the Bison m4 quoting pattern
* data/skeletons/variant.hh: here.
2020-11-13 06:17:24 +01:00
Akim Demaille 21c147b6e5 yacc.c: provide the Bison version as an integral macro
Suggested by Balazs Scheidler.
https://github.com/akimd/bison/issues/55

* src/muscle-tab.c (muscle_init): Move/rename `b4_version` to/as...
* src/output.c (prepare): `b4_version_string`.
Also define `b4_version`.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/d.m4,
* data/skeletons/java.m4: Adjust.
* doc/bison.texi: Document it.
2020-11-11 09:08:57 +01:00
Akim Demaille d3c575a6c6 regen 2020-11-11 08:47:23 +01:00
Akim Demaille d8b49e2b73 style: make conversion of version string to int public
* src/parse-gram.y (str_to_version): Rename as/move to...
* src/strversion.h, src/strversion.c (strversion_to_int): these new
files.
2020-11-11 08:47:23 +01:00
Akim Demaille 14c65a35f0 %require: accept version numbers with three parts ("3.7.4")
* src/parse-gram.y (str_to_version): Support three parts.
* data/skeletons/location.cc, data/skeletons/stack.hh:
Adjust.
2020-11-11 08:47:23 +01:00
Todd C. MillerandAkim Demaille c47bb87f9f yacc.c: fix #definition of YYEMPTY
When generating a C parser, YYEMPTY is present in enum yytokentype but
there is no corresponding #define like there is for the other values.
There is a special case for YYEMPTY in b4_token_enums but no
corresponding case in b4_token_defines.

* data/skeletons/c.m4 (b4_token_defines): Do define YYEMPTY.
2020-11-11 08:47:21 +01:00
Akim Demaille 98c35e0025 gnulib: update 2020-11-10 07:56:13 +01:00
Akim Demaille bd6b046ce7 doc: fix incorrect section title
Reported by Gaurav Singh <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:12:27 +01:00
Nick GassonandAkim Demaille 7c6e7bd300 doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:36:43 +01:00
Akim Demaille 3cba59dd7f doc: fix typo
* README: here.
2020-10-14 21:12:04 +02:00
Akim Demaille a15879c623 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-10-13 07:23:28 +02:00
Akim Demaille 5d501ee728 version 3.7.3
* NEWS: Record release date.
2020-10-13 07:01:24 +02:00
Akim Demaille bc5e4541da build: don't link bison against libreadline
Reported by Paul Smith <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-10/msg00001.html

* src/local.mk (src_bison_LDADD): here.
2020-10-13 06:57:33 +02:00
Akim Demaille 567d1eaa19 gnulib: update 2020-10-13 06:46:06 +02:00
Akim Demaille c08e0863be glr.cc: fix: use symbol_name
* data/skeletons/glr.cc: here.
2020-09-27 09:22:02 +02:00
Akim Demaille 541943ee04 build: fix a concurrent build issue in examples
Reported by Thomas Deutschmann <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00010.html

* examples/c/lexcalc/local.mk: scan.o depends on parse.[ch].
2020-09-06 10:08:22 +02:00
Akim Demaille dcdd119f69 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-09-05 18:31:25 +02:00
Akim Demaille a0bc06b703 version 3.7.2
* NEWS: Record release date.
2020-09-05 18:06:16 +02:00
Akim Demaille 5e33dfe59d build: disable syntax-check warning
error_message_uppercase
etc/bench.pl.in-419-static int yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]});

* cfg.mk: here.
2020-09-05 17:59:56 +02:00
Akim Demaille 2a4e9a358f gnulib: update 2020-09-05 17:44:38 +02:00
Akim Demaille f7b642cff7 build: fix incorrect dependencies
Commit af000bab11 ("doc: work around
Texinfo 6.7 bug"), published in 3.4.91, added a dependency on the
"all" target.

This is a super bad idea, since "make all" will run this
target *before* "all", which builds bison.  It turns out that this new
dependency actually needed bison to be built.  So all the regular
process (i) build $(BUILT_SOURCES) and then (ii) build bison, was
wrecked since some of the $(BUILT_SOURCES) depended on bison...

It was "easy" to see in the logs of "make V=1" because we were
building bison files (such as src/files.o) *before* displaying the
banner for "all-recursive".  With this fix, we finally get again the
proper sequence:

    rm -f examples/c/reccalc/scan.stamp examples/c/reccalc/scan.stamp.tmp
    /opt/local/libexec/gnubin/mkdir -p examples/c/reccalc
    touch examples/c/reccalc/scan.stamp.tmp
    flex   -oexamples/c/reccalc/scan.c --header=examples/c/reccalc/scan.h ./examples/c/reccalc/scan.l
    mv examples/c/reccalc/scan.stamp.tmp examples/c/reccalc/scan.stamp
    rm -f lib/fcntl.h-t lib/fcntl.h && \
    { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
      ...
    } > lib/fcntl.h-t && \
    mv lib/fcntl.h-t lib/fcntl.h
    ...
    mv -f lib/alloca.h-t lib/alloca.h
    make  all-recursive

Reported by Mingli Yu <[email protected]>.
https://github.com/akimd/bison/issues/31
https://lists.gnu.org/r/bison-patches/2020-05/msg00055.html

Reported by Claudio Calvelli <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00001.html
https://bugs.gentoo.org/716516

* doc/local.mk (all): Rename as...
(all-local): this.
So that we don't compete with BUILT_SOURCES.
2020-09-05 17:42:20 +02:00
Akim Demaille 3da17724ad doc: updates
* NEWS, TODO: here.
2020-09-02 21:37:23 +02:00
Akim Demaille 68e3e442f9 gnulib: update 2020-08-30 17:32:43 +02:00
Akim Demaille e432619d11 tests: beware of sed portability issues
Reported by David Laxer <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00027.html

* tests/output.at: Don't use + with sed.
While at it, fix a quotation problem hidden by the use of '#'.
2020-08-30 17:16:18 +02:00
Akim Demaille a1b7fef045 c: always use YYMALLOC/YYFREE
Reported by Kovalex <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00015.html

* data/skeletons/yacc.c: Don't make direct calls to malloc/free.
* tests/calc.at: Check it.
2020-08-30 10:05:18 +02:00
Akim Demaille 067e35a8be build: beware of POSIX mode
Reported by Dennis Clarke.
https://lists.gnu.org/r/bug-bison/2020-08/msg00013.html

* examples/d/local.mk, examples/java/calc/local.mk,
* examples/java/simple/local.mk: Pass bison's options before its
argument, in case we're in POSIX mode.
2020-08-30 09:38:05 +02:00
Akim Demaille 0522047c96 doc: history of api.prefix
Reported by Matthew Fernandez <[email protected]>.
https://lists.gnu.org/r/help-bison/2020-08/msg00015.html

* doc/bison.texi (api.prefix): We move to {} in 3.0.
2020-08-30 09:29:00 +02:00
Akim Demaille 3724b50ef9 CI: intel moved the script for ICC
* .travis.yml: Adjust.
2020-08-11 07:18:48 +02:00
Akim Demaille b801b7b670 fix: unterminated \-escape
An assertion failed when the last character is a '\' and we're in a
character or a string.
Reported by Agency for Defense Development.
https://lists.gnu.org/r/bug-bison/2020-08/msg00009.html

* src/scan-gram.l: Catch unterminated escapes.
* tests/input.at (Unexpected end of file): New.
2020-08-08 07:53:33 +02:00
Akim Demaille b7aab2dbad fix: crash when redefining the EOF token
Reported by Agency for Defense Development.
https://lists.gnu.org/r/bug-bison/2020-08/msg00008.html

On an empty such as

    %token FOO
           BAR
           FOO 0
    %%
    input: %empty

we crash because when we find FOO 0, we decrement ntokens (since FOO
was discovered to be EOF, which is already known to be a token, so we
increment ntokens for it, and need to cancel this).  This "works well"
when EOF is properly defined in one go, but here it is first defined
and later only assign token code 0.  In the meanwhile BAR was given
the token number that we just decremented.

To fix this, assign symbol numbers after parsing, not during parsing,
so that we also saw all the explicit token codes.  To maintain the
current numbers (I'd like to keep no difference in the output, not
just equivalence), we need to make sure the symbols are numbered in
the same order: that of appearance in the source file.  So we need the
locations to be correct, which was almost the case, except for nterms
that appeared several times as LHS (i.e., several times as "foo:
...").  Fixing the use of location_of_lhs sufficed (it appears it was
intended for this use, but its implementation was unfinished: it was
always set to "false" only).

* src/symtab.c (symbol_location_as_lhs_set): Update location_of_lhs.
(symbol_code_set): Remove broken hack that decremented ntokens.
(symbol_class_set, dummy_symbol_get): Don't set number, ntokens and
nnterms.
(symbol_check_defined): Do it.
(symbols): Don't count nsyms here.
Actually, don't count nsyms at all: let it be done in...
* src/reader.c (check_and_convert_grammar): here.  Define nsyms from
ntokens and nnterms after parsing.
* tests/input.at (EOF redeclared): New.

* examples/c/bistromathic/bistromathic.test: Adjust the traces: in
"%nterm <double> exp %% input: ...", exp used to be numbered before
input.
2020-08-07 07:30:06 +02:00
Akim Demaille 89e42ffb4b style: fix missing space before paren
* cfg.mk (_space_before_paren_exempt): Be less laxist.
* src/output.c, src/reader.c: Fix space before paren issues.
Pacify the warnings where applicable.
2020-08-07 07:30:06 +02:00
Akim Demaille 6aae4a7378 style: fix comments and more debug trace
* src/location.c, src/symtab.h, src/symtab.c: here.
2020-08-07 07:30:06 +02:00
Akim Demaille 7d4a4300c2 style: more uses of const
* src/symtab.c: here.
2020-08-07 07:30:06 +02:00
Akim Demaille 31d4ec28bd bench: fix support for pure parser
* etc/bench.pl.in (is_pure): New.
(generate_grammar_calc): Use code provides where needed.
Use is_pure to call yylex properly.
Coding style fixes.
2020-08-07 07:29:16 +02:00
Akim Demaille 0a5bfb4fda portability: multiple typedefs
Older versions of GCC (4.1.2 here) don't like repeated typedefs.

      CC       src/bison-parse-simulation.o
    src/parse-simulation.c:61: error: redefinition of typedef 'parse_state'
    src/parse-simulation.h:74: error: previous declaration of 'parse_state' was here
    make: *** [Makefile:7876: src/bison-parse-simulation.o] Error 1

Reported by Nelson H. F. Beebe.

* src/parse-simulation.c (parse_state): Don't typedef,
parse-simulation.h did it already.
2020-08-03 07:30:35 +02:00
Akim Demaille 12d0b15679 style: revert "avoid warnings with GCC 4.6"
This reverts commit d0bec3175f (which
should have read "We have a clash...", not "With have a clash...").
Now that `max()` was renamed `max_int()`, we can use `max` again, as
elsewhere in the code.

* src/counterexample.c (visited_hasher): Alpha reconversion.
2020-08-02 10:20:23 +02:00
Akim Demaille cb7dcb011e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-08-02 09:32:34 +02:00
Akim Demaille 71579c7219 version 3.7.1
* NEWS: Record release date.
2020-08-02 09:10:02 +02:00
Akim Demaille 2f8a874215 portability: we use termios.h and sys/ioctl.h
Reported by Maarten De Braekeleer.
https://lists.gnu.org/r/bison-patches/2020-07/msg00079.html

* bootstrap.conf (gnulib_modules): Add termios and sys_ioctl.
2020-08-02 08:36:49 +02:00
Maarten De BraekeleerandAkim Demaille ad6f600bb1 portability: rename accept to acceptsymbol because of MSVC
MSVC already defines this symbol.

* src/symtab.h, src/symtab.c (accept): Rename as...
(acceptsymbol): this.
Adjust dependencies.
2020-08-02 08:32:57 +02:00
Akim Demaille de4f41eab7 regen 2020-08-02 08:32:57 +02:00
Maarten De BraekeleerandAkim Demaille e73f086b0d portability: use CHAR_LITERAL instead of CHAR because MSVC defines CHAR
* src/parse-gram.y, src/scan-gram.l: here.
2020-08-02 08:32:57 +02:00
Maarten De BraekeleerandAkim Demaille 8cf098415e portability: use INT_LITERAL instead of INT because MSVC defines INT
It is defined as a typedef, not a macro.
https://lists.gnu.org/r/bison-patches/2020-08/msg00001.html

* src/parse-gram.y, src/scan-gram.l: here.
2020-08-02 08:32:30 +02:00
Akim Demaille 977e19840d portability: beware of max () with MSVC
Reported by Maarten De Braekeleer.
https://lists.gnu.org/r/bison-patches/2020-07/msg00080.html

We don't want to use gnulib's min and max macros, since we use
function calls in min/max arguments.

* src/location.c (max_int, min_int): Move to...
* src/system.h: here.
* src/counterexample.c, src/derivation.c: Use max_int instead of max.
2020-08-02 08:19:35 +02:00
Akim Demaille d975c2f76e libtextstyle: be sure to have ostream_printf and hyperlink support
Older versions of libtextstyle do not support them, rule them out.

Reported by Lars Wendler
https://lists.gnu.org/r/bug-bison/2020-07/msg00030.html

and by Arnold Robbins
https://lists.gnu.org/r/bug-bison/2020-07/msg00041.html and
https://lists.gnu.org/mailman/private/gawk-devel/2020-July/003988.html

and by Nelson H. F. Beebe
https://lists.gnu.org/mailman/private/gawk-devel/2020-July/003993.html

With support from Bruno Haible in gnulib
https://lists.gnu.org/r/bug-gnulib/2020-08/msg00000.html
thread starting at
https://lists.gnu.org/r/bug-gnulib/2020-07/msg00148.html

* configure.ac: Require libtextstyle 0.20.5.
* gnulib: Update.
2020-08-02 08:19:35 +02:00
Akim Demaille 0676801b8c CI: comment changes 2020-08-01 10:02:44 +02:00
Akim Demaille 82aa96e9b1 regen 2020-08-01 08:54:46 +02:00
Akim Demaille cb65553449 diagnostics: better location for type redeclarations
From

    foo.y:1.7-11: error: %type redeclaration for bar
        1 | %type <foo> bar bar
          |       ^~~~~
    foo.y:1.7-11: note: previous declaration
        1 | %type <foo> bar bar
          |       ^~~~~

to

    foo.y:1.17-19: error: %type redeclaration for bar
        1 | %type <foo> bar bar
          |                 ^~~
    foo.y:1.13-15: note: previous declaration
        1 | %type <foo> bar bar
          |             ^~~

* src/symlist.h, src/symlist.c (symbol_list_type_set): There's no need
for the tag's location, use that of the symbol.
* src/parse-gram.y: Adjust.
* tests/input.at: Adjust.
2020-08-01 08:54:46 +02:00
Akim Demaille f47a1bd622 todo: updates for D 2020-07-30 07:14:57 +02:00
Akim Demaille 205d372c68 cex: style: comment changes
* src/parse-simulation.c: here.
2020-07-29 20:00:59 +02:00
Akim Demaille 07a1243b40 cex: style: prefer "res" for the returned value
* src/derivation.c (derivation_new): here.
2020-07-29 20:00:59 +02:00
Akim Demaille ece343d2c2 cex: style: prefer FOO_print to print_FOO
* src/state-item.h, src/state-item.c (print_state_item): Rename as...
(state_item_print): this.
* src/counterexample.c (print_counterexample): Rename as...
(counterexample_print): this.
2020-07-29 20:00:27 +02:00
Akim Demaille be95a4fe29 scanner: don't crash on strings containing a NUL byte
We crash if the input contains a string containing a NUL byte.
Reported by Suhwan Song.
https://lists.gnu.org/r/bug-bison/2020-07/msg00051.html

* src/flex-scanner.h (STRING_FREE): Avoid accidental use of
last_string.
* src/scan-gram.l: Don't call STRING_FREE without calling
STRING_FINISH first.
* tests/input.at (Invalid inputs): Check that case.
2020-07-28 19:01:48 +02:00
Akim Demaille 6accee7716 doc: refer to cex from sections dealing with conflicts
The documentation about -Wcex should be put forward.

* doc/bison.texi: Refer to -Wcex from the sections about conflicts.
2020-07-28 07:45:07 +02:00
Akim Demaille e63f22703e doc: factor ifnottex/iftex examples
* doc/bison.texi: Factor the common bits out of ifnottex/iftex.
2020-07-28 07:45:07 +02:00
Akim Demaille fa390dc311 doc: fix colors
The original Texinfo macros introducing colors were made for
diagnostics, which are printed in bold.  So by copy-paste accident the
styles we introduced for counterexamples were also in bold.  They
should not.

* doc/bison.texi: Separate the styling of diagnostics from the styling
for counterexamples.
Don't use bold in the latter case.
2020-07-28 07:45:07 +02:00
Akim Demaille 17fdf5eca2 doc: fixes
* doc/bison.texi: Fix spello.
Fix missing colors, and factor.
2020-07-28 07:45:07 +02:00
Akim Demaille 72b3c1a673 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-23 20:15:38 +02:00
Akim Demaille 6675d36e25 version 3.7
* NEWS: Record release date.
2020-07-23 19:58:16 +02:00
Akim Demaille d0bec3175f style: avoid warnings with GCC 4.6
With have a clash with the "max" function.

    src/counterexample.c: In function 'visited_hasher':
    src/counterexample.c:720:48: error: declaration of 'max' shadows a global declaration [-Werror=shadow]
    src/counterexample.c:116:12: error: shadowed declaration is here [-Werror=shadow]

* src/counterexample.c (visited_hasher): Alpha conversion.
2020-07-23 19:55:24 +02:00
Akim Demaille 79e68b6c4d doc: fix definition of -Wall
* doc/bison.texi (Diagnostics): here.
2020-07-23 09:17:18 +02:00
Akim Demaille 5cb74cacd8 gnulib: update
* bootstrap.conf: We need stpncpy.
2020-07-23 06:56:25 +02:00
Akim Demaille 9c8e6e05b6 tests: fixes
Fix 6b78e50cef, "cex: make "rerun with
'-Wcex'" a note instead of a warning"

* tests/conflicts.at (-W versus %expect and %expect-rr): Fix
expectations.
2020-07-23 06:33:30 +02:00
Akim Demaille 431774d1f6 cex: update NEWS for 3.7
* NEWS: Update to the current style of cex display.
2020-07-22 07:36:02 +02:00
Akim Demaille 7d5474e979 doc: catch up with the current display of cex
Unfortunately I found no way to use the ↳ glyph in Texinfo, so I used
@arrow{} instead, which has a different width, so we have to have all
the examples doubled, once for TeX, another for the rest of the world.

* doc/bison.texi: Use the current display in the examples.
* doc/calc.y, doc/ids.y, doc/if-then-else.y, doc/sequence.y: New.
2020-07-22 07:36:02 +02:00
Akim Demaille 6b78e50cef cex: make "rerun with '-Wcex'" a note instead of a warning
Currently the suggestion to rerun is a -Wother warning:

    warning: 2 shift/reduce conflicts [-Wconflicts-sr]
    warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]

Instead, let's attach it as a subnote of the diagnostic (in the
current case, -Wconflicts-sr):

    warning: 2 shift/reduce conflicts [-Wconflicts-sr]
    note: rerun with option '-Wcounterexamples' to generate conflict counterexamples

* src/conflicts.c (conflicts_print): Do that.
Adjust the test suite.
2020-07-21 18:57:56 +02:00
Akim Demaille 28769d608e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-20 07:58:03 +02:00
Akim Demaille a22588bcb9 version 3.6.93
* NEWS: Record release date.
2020-07-20 07:37:47 +02:00
Akim Demaille b8c5e5609f cex: label all the derivations by their initial action
From

    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example: A b .
      First derivation
        a
        `-> A b .
      Second derivation
        a
        `-> A b
              `-> b .

to

    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 .

* src/counterexample.c (print_counterexample): here.
Compute the width of the labels to properly align the values.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-20 07:36:38 +02:00
Akim Demaille b81229e1f9 cex: improve readability of the subsections
Now that the derivation is no longer printed on one line, aligning the
example and the derivation is no longer useful.  It can actually be
harmful, as it makes the overall structure less clear.

* src/derivation.h, src/derivation.c (derivation_print_leaves): Remove
the `prefix` argument.
* src/counterexample.c (print_counterexample): Put the example next to
its label.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-20 07:09:31 +02:00
Akim Demaille 815a76f558 cex: don't issue an empty line between counterexamples
Now that we use complain, the "sections" are clearer.

* src/counterexample.c (print_counterexample): Use the empty line only
in reports.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust.
2020-07-20 06:45:31 +02:00
Akim Demaille ea138cd1f1 cex: use usual routines for diagnostics about S/R conflicts
See previous commit.  We go from

    input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
    Shift/reduce conflict on token "⊕":
      Example              exp "+" exp • "⊕" exp
      Shift derivation
        exp
        ↳ exp "+" exp
                  ↳ exp • "⊕" exp

to

    input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
    input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples]
      Example              exp "+" exp • "⊕" exp
      Shift derivation
        exp
        ↳ exp "+" exp
                  ↳ exp • "⊕" exp

with an hyperlink on -Wcounterexamples.

* src/counterexample.c (counterexample_report_shift_reduce):
Use complain.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at:
Adjust.
2020-07-20 06:45:27 +02:00
Akim Demaille 9922f1f877 cex: use usual routines for diagnostics about R/R conflicts
This is more consistent, and brings benefits: users know that these
diagnostics are attached to -Wcounterexamples, and they can also click
on the hyperlink if permitted by their terminal.

We go from

    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 . ] ]

to

    warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example              A b .
      First derivation     a -> [ A b . ]
      Second derivation    a -> [ A b -> [ b . ] ]

with an hyperlink on -Wcounterexamples.

* src/counterexample.c (counterexample_report_reduce_reduce):
Use complain.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at:
Adjust.
2020-07-20 06:45:21 +02:00
Akim Demaille 1438b79e80 diagnostics: use hyperlinks to point to the only documentation
* src/complain.c (begin_hyperlink, end_hyperlink): New.
(warnings_print_categories): Use them.
* tests/local.at (AT_SET_ENV): Disable hyperlinks in the tests, they
contain random id's, and brackets (which is not so nice for M4).
2020-07-19 19:26:47 +02:00
Akim Demaille 01f3e2969b doc: add anchors for warnings
Unfortunately Texinfo somewhat mangles anchors such as `-Werror` into
`g_t_002dWerror`, so let's not include the dash.

* doc/bison.texi (Diagnostics): here.
2020-07-19 17:28:45 +02:00
Akim Demaille 744da03955 glyphs: fix types
The code was written on top of buffers of `char[26]`, and then was
changed to use `char *`, yet was still using `sizeof buf`, which
became `sizeof (char *)` instead of `sizeof (char[26])`.

Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-07/msg00023.html

* src/glyphs.h, src/glyphs.c: Get rid of uses of `char *`, use only
glyph_buffer_t.
2020-07-19 17:09:01 +02:00
Akim Demaille b28d67b6b0 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-19 09:45:36 +02:00
Akim Demaille cf890692f1 version 3.6.92
* NEWS: Record release date.
2020-07-19 09:24:57 +02:00
Akim Demaille 6932023f4d style: avoid strncpy
syntax-check seems to dislike strncpy.  The GNU Coreutils replaced
their uses of strncpy with stpncpy.

strlcpy is not an option.
  http://sources.redhat.com/ml/libc-alpha/2002-01/msg00159.html
  http://sources.redhat.com/ml/libc-alpha/2002-01/msg00011.html
  http://lists.gnu.org/archive/html/bug-gnulib/2004-09/msg00181.html

* src/glyphs.c: Use stpncpy.
2020-07-19 09:23:42 +02:00
Akim Demaille fff17fe8fe cex: display derivations as trees
Sometimes, understanding the derivations is difficult, because they
are serialized to fit in one line.  For instance, the example taken
from the NEWS file:

    %token ID
    %%
    s: a ID
    a: expr
    expr: expr ID ',' | "expr"

gave

    First example        expr • ID ',' ID $end
    Shift derivation     $accept → [ s → [ a → [ expr → [ expr • ID ',' ] ] ID ] $end ]
    Second example       expr • ID $end
    Reduce derivation    $accept → [ s → [ a → [ expr • ] ID ] $end ]

Printing as trees, it gives:

    First example        expr • ID ',' ID $end
    Shift derivation
      $accept
      ↳ s                      $end
        ↳ a                 ID
          ↳ expr
            ↳ expr • ID ','
    Second example       expr • ID $end
    Reduce derivation
      $accept
      ↳ s             $end
        ↳ a        ID
          ↳ expr •

* src/glyphs.h, src/glyphs.c (down_arrow, empty, derivation_separator):
New.
* src/derivation.c (derivation_print, derivation_print_impl): Rename
as...
(derivation_print_flat, derivation_print_flat_impl): These.
(fputs_if, derivation_depth, derivation_width, derivation_print_tree)
(derivation_print_tree_impl, derivation_print): New.
* src/counterexample.c (print_counterexample): Adjust.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-18 07:54:02 +02:00
Akim Demaille 5544615a59 cex: use the glyphs
* src/derivation.c: here.
* src/gram.h, src/gram.c (print_arrow, print_dot, print_fallback):
Remove.
2020-07-16 07:31:25 +02:00
Akim Demaille 346ba14f15 cex: factor the handling of graphical symbols
* src/glyphs.h, src/glyphs.c: New.
2020-07-16 07:31:24 +02:00
Akim Demaille 4d18195ebc cex: style changes
* src/counterexample.c: here.
2020-07-15 06:41:07 +02:00
Akim Demaille dd3e7b3895 cex: simplify tests
* tests/counterexample.at (AT_BISON_CHECK_CEX): Handle the keyword.
Simplify the signature.
2020-07-15 06:38:36 +02:00
Akim Demaille 64a3b6546a cex: more colors
Provided by Daniela Becker.

* data/bison-default.css: More colors.
2020-07-15 06:38:36 +02:00
Akim Demaille bad07a7f66 style: comments changes
* src/print.c: here.
2020-07-14 14:26:02 +02:00
Akim Demaille 88bd814bf1 doc: update GLR sections
Reported by Christian Schoenebeck.

* doc/bison.texi (GLR Parsers): Minor fixes.
(Compiler Requirements for GLR): Remove, quite useless today.
2020-07-14 06:56:15 +02:00
Akim Demaille 4f9ae5de07 cex: display shifts before reductions
When reporting counterexamples for s/r conflicts, put the shift first.
This is more natural, and displays the default resolution first, which
is also what happens for r/r conflicts where the smallest rule number
is displayed first, and "wins".

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

* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* NEWS, doc/bison.texi: Ditto.
2020-07-14 06:48:48 +02:00
Akim Demaille 78f72a4516 style: s/lookahead_tokens/lookaheads/g
Currently we use both names.  Let's stick to the short one.

* src/AnnotationList.c, src/conflicts.c, src/counterexample.c,
* src/getargs.c, src/getargs.h, src/graphviz.c, src/ielr.c,
* src/lalr.c, src/print-graph.c, src/print-xml.c, src/print.c,
* src/state-item.c, src/state.c, src/state.h, src/tables.c:
s/lookahead_token/lookahead/gi.
2020-07-14 06:48:48 +02:00
Akim Demaille c04693d651 cex: factor memory allocation
* src/counterexample.c (counterexample_report_state): Allocate once
per conflicted state, instead of once per r/r conflict.
2020-07-14 06:48:48 +02:00
Akim Demaille 12191911ba cex: use state_item_number consistently
* src/counterexample.c, src/state-item.c: here.
(counterexample_report_state): While at it, prefer c2 to j/k, to match
c1.
2020-07-14 06:48:48 +02:00
Akim Demaille d7f27477f4 cex: more consistent memory allocation/copy
* src/counterexample.c, src/parse-simulation.c: It is more usual in
Bison to use sizeof on expressions than on types, especially for
allocation.
Let the compiler do it's job instead of calling memcpy ourselves.
2020-07-14 06:48:48 +02:00
Akim Demaille 5bad15d7ea cex: minor renaming
* src/counterexample.c (has_common_prefix): Rename as...
(have_common_prefix): this.
2020-07-14 06:48:48 +02:00
Akim Demaille cd099edf2d cex: use better type names
There are too many gl_list_t in there, it's hard to understand what is
going on.  Introduce and use more precise types.  I sure can be wrong
in some places, it's hard to tell without proper tool support.

* src/counterexample.c, src/lssi.c, src/lssi.h, src/parse-simulation.c,
* src/parse-simulation.h, src/state-item.c, src/state-item.h
(si_bfs_node_list, search_state_list, ssb_list, lssi_list)
(state_item_list): New.
2020-07-14 06:48:48 +02:00
Akim Demaille 1e12219775 cex: minor style changes
* src/counterexample.h, src/derivation.h, src/derivation.c:
More comments.
Use `out` for FILE*, as elsewhere.
2020-07-14 06:48:48 +02:00
Akim Demaille d8c2af56c1 tests: beware of version numbers from git describe
* tests/report.at: Be robust to version numbers such as
3.6.4.133-fbac-dirty.
2020-07-14 06:48:48 +02:00
Akim Demaille cc11bb037c tests: fix expectations
Broken in ee86ea8839.

* tests/diagnostics.at: here.
2020-07-14 06:48:48 +02:00
Akim Demaille 121dd98508 doc: makeinfo wants @arrow{}, not @arrow
* doc/bison.texi: here.
2020-07-12 08:15:44 +02:00
Akim Demaille 2eddbd0ac4 gnulib: update 2020-07-11 19:11:19 +02:00
Akim Demaille ee86ea8839 cex: prefer → to ::=
It does not make a lot of sense to use ::= in our counterexamples,
that's not something that belongs to the Bison "vocabulary".  Using
the colon makes sense, but it's too discreet.  Let's use the arrow,
which we already use in some reports (HTML and Dot).

* src/gram.h (print_dot_fallback): Generalize into...
(print_fallback): this.
(print_arrow): New.
* src/derivation.c: Use it.

* NEWS, tests/conflicts.at, tests/counterexample.at,
* tests/diagnostics.at, tests/report.at: Adjust.
* doc/bison.texi: Ditto.
Unfortunately the literal `→` is output as `↦`.  So we need to use
@arrow.
2020-07-11 18:43:46 +02:00
Akim Demaille a2ad33dca6 style: cex: prefer the array notation
Prefer `&foos[i]` to `foos + i` when `foos` is an array.  IMHO, it
makes the semantics clearer.

* src/counterexample.c, src/lssi.c, src/parse-simulation.c,
* src/state-item.c: With arrays, prefer the array notation rather than
the pointer one.
2020-07-11 18:07:09 +02:00
Akim Demaille 5b2b7b1ffb style: cex: remove variables that don't make it simpler to read
* src/counterexample.c: With arrays, prefer the array notation rather
than the pointer one.
2020-07-11 18:07:09 +02:00
Akim Demaille dc72b3566d bistromathic: demonstrate caret-diagnostics
* examples/c/bistromathic/parse.y (user_context): We need the current
line.
(yyreport_syntax_error): Quote the guilty line, with squiggles.
* examples/c/bistromathic/bistromathic.test: Adjust.
2020-07-11 18:06:45 +02:00
Akim Demaille c47e1174d4 bistromathic: do not display parse errors on completion
Currently autocompletion on a line with errors leaks the error
messages.  It can be useful to let the user know, but GNU Readline
does not provide us with an nice way to display the error.  So we
actually break into the current line of the user.

So instead, do not show these errors.

* examples/c/bistromathic/parse.y (user_context): New.
Use %param to pass it to the parser and scanner.
Keep quiet when in computing autocompletion.
2020-07-11 18:05:50 +02:00
Akim Demaille 093eeb27e9 bistromathic: don't stupidly reset the location for each token
That quite defeats the whole point of locations...  But anyway, we
should not see these messages at all.

* examples/c/bistromathic/parse.y (expected_tokens): Fix (useless)
location tracking.
2020-07-11 18:05:41 +02:00
Akim Demaille dab23c4a21 bistromathic: promote yytoken_kind_t
* examples/c/bistromathic/parse.y: Use yytoken_kind_t rather than int.
2020-07-11 18:05:35 +02:00
Akim Demaille 38a169bec1 html: capitalize titles
* data/xslt/xml2xhtml.xsl: Use "State 0", not "state 0".
As we do in text reports.
2020-07-11 12:58:45 +02:00
Akim Demaille dc77d6500f html: don't define several times the same anchors
Currently when we output useless rules, they appear before the
grammar, but using the same invocation.  As a result, the anchor is
defined twice, and the wrong one, being first, is honored.

* data/xslt/xml2xhtml.xsl (rule): Take a new 'anchor' parameter to
decide whether being an anchor, or a target.
Let it be true when output the grammar.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille 8262c7dc22 html: simplify
* data/xslt/xml2xhtml.xsl: Merge two identical when-clauses.
2020-07-11 12:58:44 +02:00
Akim Demaille 44f28d10ee reports: let html reports catch up with --report and --graph
* data/xslt/xml2xhtml.xsl: Show the symbol types.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille 44ad466a32 reports: let xml reports catch up with --report and --graph
The text and Dot reports are expected to be identical when generated
directly (--report, --graph) or indirectly (via XML).  The xml
testsuite had not be run for ages, let it catch up a bit.

* src/print-xml.c: Pass the type of the symbols.
* data/xslt/xml2text.xsl
Catch up with the new layout.
Display the symbol types.
Use '•', not '.'
* tests/local.at: Smash '•' to '.' when matching against the direct
text report.
* tests/report.at: Adjust XML expectations.
2020-07-11 12:58:44 +02:00
Akim Demaille a839f4c461 reports: update html ouput
* data/xslt/xml2xhtml.xsl: Improve indentation.
Use ul/li rather that pre.
2020-07-11 12:58:44 +02:00
Akim Demaille 9a51c6a128 tests: check html
* tests/report.at: here.
2020-07-11 12:58:44 +02:00
Akim Demaille 2608b0cf12 style: factor complex expressions
* src/print-xml.c, src/print.c: Introduce a variable pointing to the
current symbol.
2020-07-11 12:58:44 +02:00
Akim Demaille aa766d1560 maint: make it easier to update expectations
* tests/local.mk (update-tests): New.
2020-07-11 12:58:44 +02:00
Akim Demaille a7ed13b25f maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-09 21:38:23 +02:00
Akim Demaille 2d90916067 version 3.6.91
* NEWS: Record release date.
2020-07-09 21:10:23 +02:00
Akim Demaille 91e5a23ff2 news: update 2020-07-09 20:29:24 +02:00
Akim Demaille d4ae66c371 gnulib: update 2020-07-09 20:26:16 +02:00
Akim Demaille 70fb574717 examples: add license headers
Prompted by Rici Lake.
https://stackoverflow.com/questions/62658368/#comment110853985_62661621
Discussed with Paul Eggert.

* doc/bison.texi, examples/c/bistromathic/parse.y,
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l,
* examples/c/pushcalc/calc.y, examples/c/reccalc/parse.y,
* examples/c/reccalc/scan.l, examples/d/calc.y,
* examples/java/calc/Calc.y, examples/java/simple/Calc.y:
Install the GPL3+ header.
2020-07-08 22:19:37 +02:00
Akim Demaille 0820f16ca8 style: update comments
* src/reader.c: action_obstack was removed in 2002...
* src/parse-gram.y: Better names.
* src/scan-code.h: More comments.
2020-07-05 09:59:45 +02:00
Akim Demaille 49f1e5f428 style: update comments in the skeletons
* data/skeletons/c++.m4, data/skeletons/glr.c, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Be more accurate about yychar and yytoken.
Don't name local variables as if they were members.
2020-07-05 09:59:25 +02:00
Akim Demaille 238692ad77 doc: more details about symbols in m4
* data/README.md: here.
* README-hacking.md (Vocabulary): More.
2020-07-05 09:18:27 +02:00
Akim Demaille 5f95583da7 regen 2020-07-05 08:18:51 +02:00
Akim Demaille 964fb2aa6f examples: include the generated header
* examples/c/bistromathic/parse.y, examples/c/lexcalc/parse.y,
* examples/c/reccalc/parse.y: here.
Add some comments.

* src/parse-gram.y (api_version): Pull out of handle_require.
Bump to 3.7.
2020-07-05 08:18:51 +02:00
Akim Demaille 7c0d36b760 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-04 12:37:45 +02:00
Akim Demaille b4d18c7fc6 version 3.6.90
* NEWS: Record release date.
2020-07-04 12:14:28 +02:00
Akim Demaille 3e6e51cf5c news: update 2020-07-04 12:12:33 +02:00
Akim Demaille d309bd9f9f package: fix syntax-check errors
* examples/c/bistromathic/bistromathic.test, po/POTFILES.in: here.
2020-07-04 12:10:15 +02:00
Akim Demaille 203f7230ec gnulib: update 2020-07-04 11:43:41 +02:00
Akim Demaille 156e548341 cex: give more details about -Wcex and -rcex
* data/bison-default.css: Cobalt does not seem to be supported.
* doc/bison.texi (Counterexamples): A new section.
(Understanding): Show the counterexamples as it shows in the report:
with its items.
(Bison Options): Document -Wcex and -rcex.
2020-07-04 11:43:35 +02:00
Akim Demaille 526ef45f30 news: update 2020-07-03 07:07:28 +02:00
Akim Demaille d7f7fcd9c7 dot: also use a dot in the output
* src/print-graph.c (print_core): Use a dot instead of a point.
* doc/figs/example-reduce.gv, doc/figs/example-reduce.txt,
* doc/figs/example-shift.gv, doc/figs/example-shift.txt,
* doc/figs/example.gv: Update.
* tests/output.at, tests/report.at: Adjust.
2020-07-03 06:51:57 +02:00
Akim DemailleandAkim Demaille 0fd542c3e0 doc: improve a sentence
* doc/bison.texi: here.
2020-07-02 07:21:33 +02:00
Akim Demaille 413908e5a4 news: formatting changes 2020-07-01 07:05:48 +02:00
Akim Demaille 84ef175287 news, todo: update 2020-07-01 07:05:41 +02:00
Akim Demaille 5234c8390f doc: clarify that the pcontext interface is *.c only
Reported by Rici Lake.
https://lists.gnu.org/r/bug-bison/2020-06/msg00054.html

* doc/bison.texi (Syntax Error Reporting Function): Make it clear that
this is not exported.
Remove C++ details that landed in the C doc.
2020-06-30 20:16:31 +02:00
Akim Demaille 21f7690570 doc: use color in the cex examples
* doc/bison.texi: here.
And use smallexample when it no longer fits in PDF.
2020-06-30 20:16:31 +02:00
Akim Demaille edb39c29a2 doc: repair the references to the Bibliography
In commit c80cdf2db2 ("doc: simplify
uses of @ref", Jan 27 2020, released in Bison 3.6), I broke the
references to the Bibliography.  For instance:

     For a more detailed exposition of the mysterious behavior in LALR parsers
    -and the benefits of IELR, @pxref{Bibliography,,Denny 2008 March}, and
    -@ref{Bibliography,,Denny 2010 November}.
    +and the benefits of IELR, @pxref{Bibliography}, and
    +@ref{Bibliography}.

which results in "see Bibliography" twice, instead of the more precise
reference.

* doc/bison.texi (@pcite, @tcite): New.
Use them instead of @ref to Bibliography.
Cite only the first author (that's what we did for the other entries).
2020-06-30 08:01:40 +02:00
Vincent ImbimboandAkim Demaille 1247d94ba6 doc: cex documentation
* NEWS, doc/bison.texi: Add documentation for conflict counterexample
generation.
2020-06-30 08:01:40 +02:00
Akim Demaille ed9a821caa doc: update Doxygen template file
* doc/Doxyfile.in: here.
2020-06-30 08:01:40 +02:00
Akim Demaille 330552ea49 yacc.c: push: don't clear the parser state when accepting/rejecting
Currently when a push parser finishes its parsing (i.e., it did not
return YYPUSH_MORE), it also clears its state.  It is therefore
impossible to see if it had parse errors.

In the context of autocompletion, because error recovery might have
fired, the parser is actually already in a different state.  For
instance on `(1 + + <TAB>` in the bistromathic, because there's a
`exp: "(" error ")"` recovery rule, `1 + +` tokens have already been
popped, replaced by `error`, and autocompletions think we are ready
for the closing ")".  So here, we would like to see if there was a
syntax error, yet `yynerrs` was cleared.

In the case of a successful parse, we still have a problem: if error
recovery succeeded, we won't know it, since, again, `yynerrs` is
clearer.

It seems much more natural to leave the parser state available for
analysis when there is a failure.

To reuse the parser, we should either:

1. provide an explicit means to reinitialize a parser state for future
   parses.

2. automatically reset the parser state when it is used in a new
   parse.

Option 2 requires to check whether we need to reinitialize the parser
each time we call `yypush_parse`, i.e., each time we give a new token.
This seems expensive compared to Option 1, but benchmarks revealed no
difference.  Option 1 is incompatible with the documentation
("After `yypush_parse` returns a status other than `YYPUSH_MORE`, the
parser instance `yyps` may be reused for a new parse.").

So Option 2 wins, reusing the private `yynew` member to record that a
parse was finished, and therefore that the state must reset in the
next call to `yypull_parse`.

While at it, this implementation now reuses the previously enlarged
stacks from one parse to another.

* data/skeletons/yacc.c (yypstate_new): Set up the stacks in their
initial configurations (setting their bottom to the stack array), and
use yypstate_clear to reset them (moving their top to their bottom).
(yypstate_delete): Adjust.
(yypush_parse): At the beginning, clear yypstate if needed, and at the
end, record when yypstate needs to be clearer.

* examples/c/bistromathic/parse.y (expected_tokens): Do not propose
autocompletion when there are parse errors.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-06-29 19:36:41 +02:00
Akim Demaille 7c609859ee bistromathic: don't display undefined locations
Currently, completion when there is a syntax error shows broken
locations.

* examples/c/bistromathic/parse.y (expected_tokens): Initialize the
location.
* examples/c/bistromathic/bistromathic.test: Check that.
2020-06-29 19:10:05 +02:00
Akim Demaille ed10c308fa yacc.c: simplify initialization of push parsers
The previous commit ("yacc.c: declare and initialize and the same
time") made b4_initialize_parser_state_variables useless.

* data/skeletons/yacc.c (b4_initialize_parser_state_variables): Inline
into...
(yypstate_clear): here.
2020-06-29 19:10:05 +02:00
Akim Demaille b91566edd1 regen 2020-06-29 19:10:05 +02:00
Akim Demaille 29520abb3b yacc.c: declare and initialize and the same time
In order to factor the code of push and pull parsers, the declaration
of the parser's state variable was common (being local variable in
pull parsers, and struct members in push parsers).  This result in
rather poor style in pull parser, with first variable declarations,
and then their initializations.

The initialization is about to differ between push and pull parsers,
so it is no longer worth keeping both cases together.

* data/skeletons/yacc.c (b4_declare_parser_state_variables): Accept an
argument, and when it is set, initialize the variables.
Adjust dependencies.
2020-06-29 19:10:05 +02:00
Akim Demaille 2491de1eef yacc.c: style changes in push mode
* data/skeletons/yacc.c: here.
2020-06-29 19:10:05 +02:00
Akim Demaille ec207d1bb2 yacc.c: simplify yypull_parse
Currently yypull_parse takes a yypstate* as argument, and accepts it
to be NULL.  This does not seem to make a lot of sense: rather it is
its callers that should do that.

I believe this is historical: yypull_parse was introduced
first (c3d503425f), with yyparse being a
macro.  So yyparse could hardly deal with memory allocation properly.
In 7172e23e8f that yyparse was turned
into a genuine function.  At that point, it should have allocated its
own yypstate*, which would have left yypull_parse deal with only one
single non-null ypstate* argument.

Fortunately, it is nowhere documented that it is valid to pass NULL to
yypull_parse.  It is now forbidden.

* data/skeletons/yacc.c (yypull_parse): Don't allocate a yypstate.
Needs a location to issue the error message.
(yyparse): Allocate the yypstate.
2020-06-29 19:10:05 +02:00
Akim Demaille 688b3404a2 doc: tidy the text files
* etc/README: Rename/reformat as...
* etc/README.md: this.
And ship it.
2020-06-29 19:10:05 +02:00
Akim Demaille cd6ef1e7d7 bench: simplify the rand target
* etc/bench.pl.in: There is no need to recompile the bench cases
themselves.
2020-06-29 19:10:05 +02:00
Akim Demaille 2b518d621f bench: make it easy to edit the generated files
* etc/bench.pl.in (&compile): Generate rules that compile the
generated files independently of the source files.
2020-06-29 19:08:15 +02:00
Akim Demaille 1ae4f1d329 tests: don't use $VERBOSE
It is used by the test suite itself, which results in this test
failing.

* tests/c++.at: Use $DEBUG, not $VERBOSE.
2020-06-29 06:45:44 +02:00
Akim Demaille 160df55c56 doc: overhaul of the readmes
* README-hacking.md (Working from the Repository): Make it first to
make it easier to find the instructions to build from the repo.
(Implementation Notes): New.
* README: Provide more links.
2020-06-28 14:57:41 +02:00
Akim Demaille e0b0a67b86 java: rename package as api.package
* data/skeletons/lalr1.java: here.
* doc/bison.texi: Update.
* src/muscle-tab.c: Ensure backward compat.
* tests/java.at: Check it.
2020-06-28 09:49:00 +02:00
Akim Demaille 0e5cbd38b2 style: shift/reduce, not shift-reduce
* src/reader.c: here.
2020-06-28 08:33:24 +02:00
Akim Demaille feb0bb0a59 style: rename endtoken as eoftoken
* src/symtab.h, src/symtab.c (endtoken): Rename as...
(eoftoken): this.
Adjust dependencies.
2020-06-27 17:31:59 +02:00
Akim Demaille d796e11f8f news: fixes
Reported by Jacob L. Mandelson.

* NEWS: here.
2020-06-27 17:04:50 +02:00
Akim Demaille 0895858d8e style: use 'nonterminal' consistently
* doc/bison.texi: Formatting changes.
* src/gram.h, src/gram.c (nvars): Rename as...
(nnterms): this.
Adjust dependencies.
(section): New.  Use it.
Replace "non terminal" and "non-terminal" by "nonterminal".
2020-06-27 11:39:32 +02:00
Akim Demaille 4efb2f7bd2 doc: parse.assert in C++ requires RTTI
* doc/bison.texi (%define Summary): Say it.
2020-06-27 10:31:59 +02:00
Akim Demaille eeafc706e8 c++: by default, use const std::string for file names
Reported by Martin Blais and Yuriy Solodkyy.
https://lists.gnu.org/r/help-bison/2020-05/msg00011.html
https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html

While at it, modernize filename_type as api.filename.type and document
it properly.

* data/skeletons/c++.m4 (filename_type): Rename as...
(api.filename.type): this.
Default to const std::string.
* data/skeletons/location.cc (position, location): Expose the
filename_type type.
Use api.filename.type.
* doc/bison.texi (%define Summary): Document api.filename.type.
(C++ Location Values): Document position::filename_type.
* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.
* tests/c++.at: Check that using const file names is ok.
tests/input.at: Check backward compat.
2020-06-27 10:06:00 +02:00
Akim Demaille cf6d8d0631 ielr: fix crash on memory management
Reported by Dwight Guth.
https://lists.gnu.org/r/bug-bison/2020-06/msg00037.html

* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
Beware that SBITSET__FOR_EACH nests _two_ for-loops, so "break" does
not actually break out of it.
That was the only occurrence in the code.
* src/Sbitset.h (SBITSET__FOR_EACH): Warn passersby.
2020-06-27 08:16:07 +02:00
Akim Demaille 8f44164443 style: factor the access to a rule from its items
* src/counterexample.c (item_rule): Move to...
* src/counterexample.h: here.
* src/AnnotationList.c, src/counterexample.c, src/ielr.c: Use it.
2020-06-25 19:36:07 +02:00
Akim Demaille 1001f48416 style: clean up nullable
* src/nullable.c: Reduce scopes.
Prefer `r` to `rules_ruleno`, which is truly an ugly name.
2020-06-25 19:36:07 +02:00
Akim Demaille 3be228f64c style: clean up ielr
* src/AnnotationList.c, src/ielr.c: Fix include order.
Prefer `res` to `result`.
Reduce scopes.
Be free of the oldish 76 cols limitation when it clutters too much the
code.
Denest when possible (we're starving for horizontal width).
2020-06-25 19:30:06 +02:00
Akim Demaille 670c7e7a75 don't use strlen to compute visual width
* src/output.c (prepare_symbol_names): Use mbswidth.
2020-06-23 08:27:26 +02:00
Akim Demaille c4b1a2b68f doc: use dot/'•' rather than point/'.'
AFAICT, "dotted rule" is a more frequent synonym of "item" than
"pointed rule".  So let's migrate to using "dot" only.

* doc/bison.texi: Use dot/'•' rather than point/'.'.

* src/print-xml.c (print_core): Use dot rather than point.  This is
not backward compatible, but AFAICT, we don't have actual user of the
XML output (but ourselves).  So...
* data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, tests/report.at: ... adjust.
2020-06-23 07:37:29 +02:00
Akim Demaille b65bd16e45 cex: display all the S/R conflicts, not just one per (state, rule)
Before this commit, on

    %%
    exp
    : "if" exp "then" exp
    | "if" exp "then" exp "else" exp
    | exp "+" exp
    | "num"

we used to not display the third counterexample below:

    Shift/reduce conflict on token "+":
      Example              exp "+" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ exp "+" exp . ] "+" exp ]
      Second derivation    exp ::=[ exp "+" exp ::=[ exp . "+" exp ] ]

    Shift/reduce conflict on token "else":
      Example              "if" exp "then" "if" exp "then" exp . "else" exp
      First derivation     exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . ] "else" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . "else" exp ] ]

    Shift/reduce conflict on token "+":
      Example              "if" exp "then" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ "if" exp "then" exp . ] "+" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp ::=[ exp . "+" exp ] ]

    Shift/reduce conflict on token "+":
      Example              "if" exp "then" exp "else" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ "if" exp "then" exp "else" exp . ] "+" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp "else" exp ::=[ exp . "+" exp ] ]

* src/counterexample.c (counterexample_report_state): Don't stop of
the first conflicts.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-06-23 06:56:04 +02:00
Akim Demaille 0f120354b6 cex: don't display twice unifying examples if there is no color
It makes no sense, and is actually confusing, to display twice the
same example with no visible difference.

* src/complain.h, src/complain.c (is_styled): New.
* src/counterexample.c (print_counterexample): Display the unified
example a second time only if it makes a difference.
* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* tests/diagnostics.at: Make sure we do display the unifying examples
twice when colors are enabled.  And check those colors.
2020-06-22 19:33:30 +02:00
Vincent ImbimboandAkim Demaille 69e3b405d9 cex: fix reporting of null nonterminals
I implemented this to print A ::= [ ], but A ::= [ %empty ] might be
clearer.

* src/parse-simulation.c (nullable_closure): Don't generate null
nonterminal derivations as leaves.
* src/derivation.c (derivation_print_impl): Don't print seperator
spaces for null nonterminal.
* tests/counterexample.at: Update test results.
2020-06-22 07:11:31 +02:00
Akim Demaille 3dd8f2305a cex: use the bullet in HTML
* data/xslt/xml2xhtml.xsl: here.
2020-06-22 07:02:29 +02:00
Akim Demaille 9e75066819 cex: style changes
* src/counterexample.c: Simplify a bit.
* src/parse-simulation.c, src/parse-simulation.h: Enforce coding style.
2020-06-19 08:02:18 +02:00
Akim Demaille efb65daa36 c++: get rid of global_tokens_and_yystype
This was a hack to make it easier for people to migrate from yacc.c to
lalr1.cc and from glr.c to glr.cc: when set, YYSTYPE and YYLTYPE were
`#defined`.  It was never documented (just mentioned in NEWS for Bison
2.2, 2006-05-19), but was used to simplify the test suite.  Stop that:
adjust the test suite to the skeletons, not the converse.

In C++ use yy::parser::semantic_type, yy::parser::location_type, and
yy::parser::token::MY_TOKEN, instead of YYSTYPE, YYLTYPE and MY_TOKEN.

* data/skeletons/glr.cc, data/skeletons/lalr1.cc: Remove its support.
* tests/actions.at, tests/c++.at, tests/calc.at: Adjust.
2020-06-16 08:14:42 +02:00
Akim Demaille e077bf1ebc cex: don't assume the terminal supports "•"
Use of print_unicode_char suggested by Bruno Haible.
https://lists.gnu.org/r/bug-gettext/2020-06/msg00012.html

* src/gram.h (print_dot_fallback, print_dot): New.
* src/gram.c, src/derivation.c: Use it.
* tests/counterexample.at, tests/report.at: Adjust the test suite.
* .travis.yml, README-hacking.md: Adjust.
2020-06-16 07:58:40 +02:00
Akim Demaille c35e829a76 cex: also include in the report on --report=counterexamples
And let --report=all include the counterexamples.

* src/getargs.h, src/getargs.c (report_cex): New.
* src/main.c: Compute counterexamples when -rcex is specified.
* src/print.c: Include the counterexamples when -rcex is specified.

* tests/conflicts.at, tests/existing.at, tests/local.at: Adjust.
2020-06-16 07:30:46 +02:00
Akim Demaille d4f854e5b2 cex: also include the counterexamples in the report
The report is the best place to show the details about
counterexamples, since we have the state right under the nose.

For instance:

State 7

    1 exp: exp . "⊕" exp
    2    | exp . "+" exp
    2    | exp "+" exp .  [$end, "+", "⊕"]
    3    | exp . "+" exp
    3    | exp "+" exp .  [$end, "+", "⊕"]

    "⊕"  shift, and go to state 6

    $end      reduce using rule 2 (exp)
    $end      [reduce using rule 3 (exp)]
    "+"       reduce using rule 2 (exp)
    "+"       [reduce using rule 3 (exp)]
    "⊕"       [reduce using rule 2 (exp)]
    "⊕"       [reduce using rule 3 (exp)]
    $default  reduce using rule 2 (exp)

    Conflict between rule 2 and token "+" resolved as reduce (%left "+").

    Shift/reduce conflict on token "⊕":
        2 exp: exp "+" exp .
        1 exp: exp . "⊕" exp
      Example                  exp "+" exp • "⊕" exp
      First derivation         exp ::=[ exp ::=[ exp "+" exp • ] "⊕" exp ]
      Example                  exp "+" exp • "⊕" exp
      Second derivation        exp ::=[ exp "+" exp ::=[ exp • "⊕" exp ] ]

    Reduce/reduce conflict on tokens $end, "+", "⊕":
        2 exp: exp "+" exp .
        3 exp: exp "+" exp .
      Example                  exp "+" exp •
      First derivation         exp ::=[ exp "+" exp • ]
      Example                  exp "+" exp •
      Second derivation        exp ::=[ exp "+" exp • ]

    Shift/reduce conflict on token "⊕":
        3 exp: exp "+" exp .
        1 exp: exp . "⊕" exp
      Example                  exp "+" exp • "⊕" exp
      First derivation         exp ::=[ exp ::=[ exp "+" exp • ] "⊕" exp ]
      Example                  exp "+" exp • "⊕" exp
      Second derivation        exp ::=[ exp "+" exp ::=[ exp • "⊕" exp ] ]

* src/conflicts.h, src/conflicts.c (has_conflicts): New.
* src/counterexample.h, src/counterexample.c (print_counterexample):
Add a `prefix` argument.
(counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Show the items when there's a
prefix.
* src/state-item.h, src/state-item.c (print_state_item):
Add a `prefix` argument.
* src/derivation.h, src/derivation.c (derivation_print)
(derivation_print_leaves): Add a prefix argument.
* src/print.c (print_state): When -Wcex is enabled, show the
conflicts.
* tests/report.at: Adjust.
2020-06-16 07:30:26 +02:00
Akim Demaille 35c0fe6789 cex: indent the diagnostics to highlight the structure
Instead of

    Shift/reduce conflict on token D:
    Example              A a • D
    First derivation     s ::=[ A a a ::=[ b ::=[ c ::=[ • ] ] ] d ::=[ D ] ]
    Example              A a • D
    Second derivation    s ::=[ A a d ::=[ • D ] ]

display

    Shift/reduce conflict on token D:
      Example              A a • D
      First derivation     s ::=[ A a a ::=[ b ::=[ c ::=[ • ] ] ] d ::=[ D ] ]
      Example              A a • D
      Second derivation    s ::=[ A a d ::=[ • D ] ]

* src/counterexample.c (print_counterexample): Indent.
* tests/counterexample.at: Adjust.
2020-06-16 07:29:46 +02:00
Akim Demaille 22f62414f9 cex: don't report the items
Showing the items (with the state numbers) is really something we
should restrict to the report.

* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Don't show the pointed rules,
we will do that in the report.
* tests/counterexample.at: Adjust.
2020-06-16 07:29:46 +02:00
Akim Demaille 9206b15c4e cex: make sure traces go to stderr
* src/parse-simulation.h, src/parse-simulation.c (print_parse_state):
here.
2020-06-16 07:29:46 +02:00
Akim Demaille 5edac5e15a cex: add an argument to the reporting functions to specify the stream
* src/conflicts.c (find_state_item_number, report_state_counterexamples):
Move to...
* src/counterexample.h, src/counterexample.c (find_state_item_number)
(counterexample_report_state): this.
Add support for `out` as an argument.
(counterexample_report_reduce_reduce, counterexample_report_shift_reduce):
Accept an `out` argument, and be static.
2020-06-16 07:29:46 +02:00
Akim Demaille 1c3189734c style: more uses of const
* src/print.c, src/state.h, src/state.c: here.
2020-06-16 07:29:46 +02:00
Akim Demaille c662b23735 Merge 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.4
  glr.cc: don't leak glr.c/glr.cc scaffolding to the user

Some fixes were needed to adjust to recent changes in glr.cc and
glr.c.

* data/skeletons/glr.cc: Stop messing with the user's epilogue to
insert glr.cc code.  We need that code to be inserted _before_ the
user's epilogue, not after.  So define b4_glr_cc_pre_epilogue.
* data/skeletons/glr.c: Use it.
2020-06-16 07:16:00 +02:00
Akim Demaille 627fecb19e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-15 20:39:01 +02:00
Akim Demaille 2a069f22c6 version 3.6.4
* NEWS: Record release date.
2020-06-15 20:18:50 +02:00
Akim Demaille 3f4ffea6f2 glr.cc: don't leak glr.c/glr.cc scaffolding to the user
Until we have a decent reimplementation of glr.cc, we have to use
tricks to shoehorn C++ symbols to the C engine of glr.c.  Some of them
are done via #define.  Unfortunately in Bison 3.6 some of these we
done in the header file, which broke valid user code.

Reported by Egor Pugin.
https://lists.gnu.org/r/bug-bison/2020-06/msg00003.html

* data/skeletons/glr.cc: Stop playing tricks with b4_pre_epilogue.
(b4_glr_cc_setup, b4_glr_cc_cleanup): New.
Much cleaner way to instal glr.cc's scaffolding around glr.c.
* data/skeletons/glr.c: Adjust to use them.
2020-06-15 20:18:47 +02:00
Akim Demaille 251e1b137f reports: the column width differs from the byte count
From

    "number"          shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

to

    "number"  shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

* src/print.c: Use mbswidth, not strlen, to compute visual columns.
* tests/report.at: Adjust.
2020-06-13 17:21:51 +02:00
Akim Demaille efbcadeca7 reports: don't escape the labels
Currently we use "quotearg" to escape the strings output in Dot.  As a
result, if the user's locale is C for instance, all the non-ASCII are
escaped.  Unfortunately graphviz does not interpret this style of
escaping.

For instance:

    5 -> 2 [style=solid label="\"\303\221\303\271\341\271\203\303\251\342\204\235\303\264\""]

was displayed as a sequence of numbers.  We now output:

    5 -> 2 [style=solid label="\"Ñùṃéℝô\""]

independently of the user's locale.

* src/system.h (obstack_backslash): New.
* src/graphviz.h, src/graphviz.c (escape): Remove, use
obstack_backslash instead.
* src/print-graph.c: Likewise.
* tests/report.at: Adjust.
2020-06-13 16:58:13 +02:00
Akim Demaille e4d33cf579 regen 2020-06-13 16:58:03 +02:00
Akim Demaille 5855da4722 parser: keep string aliases as the user wrote it
Currently our scanner decodes all the escapes in the strings, and we
later reescape the strings when we emit them.

This is troublesome, as we do not respect the user input.  For
instance, when the user writes in UTF-8, we destroy her string when we
write it back.  And this shows everywhere: in the reports we show the
escaped string instead of the actual alias:

    0 $accept: . exp $end
    1 exp: . exp "\342\212\225" exp
    2    | . exp "+" exp
    3    | . exp "+" exp
    4    | . "number"
    5    | . "\303\221\303\271\341\271\203\303\251\342\204\235\303\264"

    "number"                                                    shift, and go to state 1
    "\303\221\303\271\341\271\203\303\251\342\204\235\303\264"  shift, and go to state 2

This commit preserves the user's exact spelling of the string aliases,
instead of interpreting the escapes and then reescaping.  The report
now shows:

    0 $accept: . exp $end
    1 exp: . exp "⊕" exp
    2    | . exp "+" exp
    3    | . exp "+" exp
    4    | . "number"
    5    | . "Ñùṃéℝô"

    "number"          shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

Likewise, the XML (and therefore HTML) outputs are fixed.

* src/scan-gram.l (STRING, TSTRING): Do not interpret the escapes in
the resulting string.
* src/parse-gram.y (unquote, parser_init, parser_free, unquote_free)
(handle_defines, handle_language, obstack_for_unquote): New.
Use them to unquote where needed.
* tests/regression.at, tests/report.at: Update.
2020-06-13 16:56:40 +02:00
Akim Demaille 5d5e1df1dc tests: check reports with conflicts and UTF-8
This is to record the current state of the report, which escapes the
UTF-8 characters (as parse.error="verbose" does), but shouldn't (as
parse.error="detailed" does).

* tests/report.at: here.
2020-06-13 15:58:32 +02:00
Akim Demaille cef13e11f5 style: factor common bits about string scanning
* src/scan-gram.l: here.
2020-06-13 15:20:56 +02:00
Akim Demaille b7fbfd050e style: introduce & use STRING_1GROW
* src/flex-scanner.h (STRING_1GROW): New.
* src/scan-gram.l, src/scan-skel.l: Use it.
2020-06-13 15:20:56 +02:00
Akim Demaille e088b4f90f style: reduce scopes
* src/scan-gram.l (STRING_GROW_ESCAPE): Move the static_assert about
type sizes here.
2020-06-13 15:20:56 +02:00
Akim Demaille c857ed4f72 style: prefer 'FOO ()' to 'FOO' for function-like macros
* src/flex-scanner.h (STRING_GROW, STRING_FINISH, STRING_FREE):
Make them function-like macros.
Adjust dependencies.
2020-06-13 15:20:56 +02:00
Akim Demaille 1998606a90 regen 2020-06-11 19:11:33 +02:00
Akim Demaille b0bb4cde2e cex: suggest -Wcounterexamples when there are unexpected conflicts
Suggesting -Wcounterexamples when there are conflicts is probably not
what the user wants.  If she knows her conflicts and has set
%expect/%expect-rr appropriately, we shouldn't warn.

The commit also swaps the counterexamples and the report of conflicts,
into, IMHO, a more natural order: from

    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

to

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

* src/conflicts.c (rule_conflicts_print): Rename as...
(report_rule_expectation_mismatches): this.
Move the handling of report_counterexamples to...
(conflicts_print): Here.
Display this warning when applicable.
2020-06-10 09:51:39 +02:00
Akim Demaille d2acc4b401 cex: rename -Wcounterexample as -Wcounterexamples, and support -Wcex
Plural vs. singular is always a problem...

But we already have conflicts-sr and conflicts-rr, so counterexamples
makes more sense than counterexample.  Besides, -Wcounterexample will
still be accepted as an unambiguous prefix of -Wcounterexamples.

Add -Wcex as a convenient alias.

While at it, use only "counterexample", never "counter example".

* src/complain.h, src/complain.c
(Wcounterexample, warning_counterexample): Rename as...
(Wcounterexamples, warning_counterexamples): these.
(argmatch_warning_docs): Rename -Wcounterexample as -Wcounterexamples.
(argmatch_warning_args): Likewise.
Add support for -Wcex.
Adjust dependencies.
2020-06-10 07:53:44 +02:00
Akim Demaille a53c6026cd api.header.include: document it, and fix its default value
While defining api.header.include worked as expected, its default
value was incorrectly defined.  As a result, by default, the generated
parsers still duplicated the content of the generated header instead
of including it.

* data/skeletons/yacc.c (api.header.include): Fix its default value.
* tests/output.at: Check it.
* doc/bison.texi (%define Summary): Document api.header.include.
While at it, move the definition of api.namespace at the proper
place.
2020-06-09 08:09:26 +02:00
Akim Demaille ae5edcc23b cex: color the counterexamples
Use colors to show the counterexamples and the derivations in color,
to highlight their structure.  Align the outputs, and add i18n
support. Reduce width by using a one-space separator instead of
two-space.

From

    Example  A  •  B  C
    First  derivation  s ::=[ a ::=[ A  • ]  x ::=[ B  C ] ]
    Second derivation  s ::=[ y ::=[ A  •  B ]  c ::=[ C ] ]

to

    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

with colors.

* data/bison-default.css (cex-dot, cex-0, cex-1, cex-2, cex-3, cex-4)
(cex-5, cex-6, cex-7, cex-step, cex-leaf): New.
* src/derivation.c (derivation_print_styled_impl): New.
(derivation_print, derivation_print_leaves): Use it.
* src/counterexample.c: Reformat the output.
* tests/counterexample.at: Adjust.
2020-06-07 09:18:58 +02:00
Akim Demaille 296e2f90ab cex: enforce case for tokens/nonterminals
It's unfortunate that the traditions between formal language theory
and Yacc differs, but here, tokens should be upper case, and
nonterminals should be lower case.

* tests/counterexample.at: Comply with this.
2020-06-07 09:18:58 +02:00
Akim Demaille 1ccb4be02b cex: reformat the s/r and r/r reports
In Bison we refer to "shift/reduce" conflicts, not "shift-reduce" (in
Bison 3.6.3 186 occurrences vs 15).  Enforce consistency on this.

Instead of "spending" a second line for each conflict to report the
lookaheads, put that on the same line as the type of conflict.  Also,
prefer "token" to "symbol".  Maybe we should even prefer "lookahead".
While at it, enable internationalization, with plurals where
appropriate.

As a consequence, instead of

    Shift-Reduce Conflict:
    6:    3 b: . %empty
    6:    6 d: c . A
    On Symbol: A

display

    Shift/reduce conflict on token A:
    6:    3 b: . %empty
    6:    6 d: c . A

* NEWS, doc/bison.texi, src/conflicts.c: Spell it "shift/reduce", not
"shift-reduce".
* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Reformat and internationalize
output.
* tests/counterexample.at: Adjust expectations.
2020-06-07 09:18:58 +02:00
Akim Demaille 421662ec88 style: fix syntax-check issues
* src/counterexample.c, src/files.c, src/files.h, src/lssi.c,
* src/state-item.c: here.
2020-06-07 09:18:58 +02:00
Akim Demaille 39be113b1f all: show the rules in comments before the user actions
For instance, in the case of Bison's own parser:

    -  case 40:
    +  case 40:  /* grammar_declaration: "%code" "identifier" "{...}"  */
         {
           muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]),
                                     translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])),
                                     (yylsp[0]));
           code_scanner_last_string_free ();
         }
         break;

* data/skeletons/c.m4: Modified.
* data/skeletons/d.m4: Modified.
* data/skeletons/java.m4: Modified.
* src/output.c (output_escaped): New.
(quoted_output): Use it, and rename as...
(output_quoted): this.
Adjust dependencies.
(rule_output): New.
(user_actions_output): Use it.
* data/skeletons/c.m4, data/skeletons/d.m4, data/skeletons/java.m4
(b4_case): Add support for $3, an optional comment.
2020-06-07 06:50:58 +02:00
Akim Demaille 2101b0e210 CI: use GCC10 on ppc too
We were still using GCC9, because GCC10 was failing.

* .travis.yml (PPC64le): Use GCC10.
While at it, use -O2 instead of -O3: it's certainly nicer for the
CPUs, and allows to test different sets of compiler flags (we use -O3
in several other configurations).
2020-06-06 07:48:40 +02:00
Akim Demaille b1327c56f7 examples: fix missing includes
* examples/c/bistromathic/parse.y: Use abort rather than assert so
that the "unused result" warning is silenced even with -DNDEBUG.
2020-06-06 07:37:20 +02:00
Akim Demaille ae03b16785 warnings: fix -Wmissing-prototypes issues
* src/counterexample.c, src/lssi.c, src/parse-simulation.c,
* src/state-item.c:
Here.
2020-06-03 08:31:08 +02:00
Akim Demaille 7e16bd2cae Merge maint into HEAD
* upstream/maint:
  maint: post-release administrivia
  version 3.6.3
  build: check -Wmissing-prototypes
  tests: show logs
  c++: fix printing of state number on streams
2020-06-03 08:12:10 +02:00
Akim Demaille 508ac09939 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-03 07:52:30 +02:00
Akim Demaille 0535d2a608 version 3.6.3
* NEWS: Record release date.
2020-06-03 07:31:43 +02:00
Akim Demaille 94f7606db6 build: check -Wstrict-aliasing
* configure.ac (warn_common): Add -Wstrict-aliasing.
2020-06-01 18:52:23 +02:00
Akim Demaille de5be4a693 doc: using asan
* README-hacking.md: here.
2020-06-01 18:52:23 +02:00
Akim Demaille 03a6b439f6 style: fix includes
* src/fixits.c: Follow our usual pattern.
* src/scan-code.l, src/scan-gram.l, src/scan-skel.l: Prefer "" to
include src/ headers.
* README-hacking.md: Document the pattern.
2020-06-01 18:52:22 +02:00
Akim Demaille 742910838e lists: fix various issues with the use of gnulib's list
First, we should avoid code such as

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    derivation *child = NULL;
    while (gl_list_iterator_next (&it, (const void **) &child, NULL))
      {
        derivation_print (child, f);

because of -Wstrict-aliasing (whose job is to catch type-punning
issues).  See https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html.

Rather we need

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    const void **p = NULL;
    while (gl_list_iterator_next (&it, &p, NULL))
      {
        derivation *child = (derivation *) p;
        derivation_print (child, f);

Second, list iterators actually have destructors.  Even though they
are noop in the case of linked-lists, we should use them.

Let's address both issues with typed wrappers (such as
derivation_list_next) that take care of both issues, and besides allow
to scope the iterators within the loop:

    derivation *child;
    for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
         derivation_list_next (&it, &child);
         )
      {
        derivation_print (child, f);

* src/derivation.h, src/derivation.c (derivation_list_next): New.
Use it where appropriate.
* src/counterexample.c (search_state_list_next): New.
Use it where appropriate.
* src/parse-simulation.h, src/parse-simulation.c
* src/state-item.h (state_item_list_next): New.
Use it where appropriate.
2020-06-01 18:50:35 +02:00
Akim Demaille 52ce2a008b build: check -Wmissing-prototypes
pstate_clear is lacking a prototype.
Reported by Ryan
https://lists.gnu.org/r/bug-bison/2020-05/msg00101.html

Besides, none of the C examples were compiled with the warning flags.

* configure.ac (warn_c): Add -Wmissing-prototypes.
* data/skeletons/yacc.c (pstate_clear): Make it static.
* examples/local.mk (TEST_CFLAGS): New.
* examples/c/bistromathic/local.mk, examples/c/calc/local.mk,
* examples/c/lexcalc/local.mk, examples/c/mfcalc/local.mk,
* examples/c/pushcalc/local.mk, examples/c/reccalc/local.mk,
* examples/c/rpcalc/local.mk:
Use it.

GCC's warn_unused_result is not silenced by a cast to void, so we have
to "use" scanf's result.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Flex generated code produces too many warnings, including things such
as, with ICC:

    examples/c/lexcalc/scan.c(1088): error #1682: implicit conversion
              of a 64-bit integral type to a smaller integral type (potential portability problem)
    2259                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
    2260                ^
    2261
    2262

I am tired of trying to fix Flex's output.  The project does not seem
maintained.  We ought to avoid it.  So, for the time being, don't try
to enable warnings with Flex.

* examples/c/bistromathic/parse.y, examples/c/reccalc/scan.l: Fix
warnings.
* doc/bison.texi: Discard scanf's return value to defeat
-Werror=unused-result.
2020-06-01 08:29:53 +02:00
Akim Demaille bb311cfbed gnulib: update 2020-05-31 12:49:08 +02:00
Akim Demaille 518dc6ca26 style: make item_index a truly different type from item_number
See previous commit.

* src/gram.h (item_index): Make it unsigned.
Fix remaiming issues.
2020-05-25 07:41:05 +02:00
Vincent ImbimboandAkim Demaille 6a1a681fd2 style: decouple different uses of item_number
item_number is used for elements of ritem as well as indices into
ritem which is fairly confusing.  Introduce item_index to represent
indices into ritem.

* src/gram.h (item_index): Introduce it for ritem indices.
* src/closure.h, src/closure.c, src/ielr.c, src/lr0.c,
* src/print-graph.c, src/state.h, src/state.h:
Replace uses of item_number with item_index where appropriate.
2020-05-25 07:14:34 +02:00
Joshua WattandAkim Demaille dd878d1851 bison: add command line option to map file prefixes
Teaches bison about a new command line option, --file-prefix-map OLD=NEW
(based on the -ffile-prefix-map option from GCC) which causes it to
replace and file path of OLD in the text of the output file with NEW,
mainly for header guards and comments. The primary use of this is to
make builds reproducible with different input paths, and in particular
the debugging information produced when the source code is compiled. For
example, a distro may know that the bison source code will be located at
"/usr/src/bison" and thus can generate bison files that are reproducible
with the following command:

    bison --output=/build/bison/parse.c -d --file-prefix-map=/build/bison/=/usr/src/bison/ parse.y

Importantly, this will change the header guards and #line directives
from:

    #ifndef YY_BUILD_BISON_PARSE_H
    #line 100 "/build/bison/parse.h"

to

    #ifndef YY_USR_SRC_BISON_PARSE_H
    #line 100 "/usr/src/bison/parse.h"

which is reproducible.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00016.html
Signed-off-by: Joshua Watt <[email protected]>

* src/files.h, src/files.c (spec_mapped_header_file)
(mapped_dir_prefix, map_file_name, add_prefix_map): New.
* src/getargs.c (-M, --file-prefix-map): New option.
* src/output.c (prepare): Define b4_mapped_dir_prefix and
b4_spec_header_file.
* src/scan-skel.l (@ofile@): Output the mapped file name.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/location.cc,
* data/skeletons/yacc.c:
Adjust.
* doc/bison.texi: Document.
* tests/input.at, tests/output.at: Check.
2020-05-24 15:17:15 +02:00
Akim Demaille 6ed813c122 tests: fix expectations
Should have been part of 1ec93ca2a2.

* tests/counterexample.at: here.
2020-05-24 15:17:14 +02:00
Akim Demaille 1ec93ca2a2 cex: clean the display of conflicted symbols
Instead of `On Symbols: {b,c,}`, display `On Symbols: b, c`.

* src/counterexample.c (counterexample_report_reduce_reduce): We don't
need braces.
Use commas as a separator, not a terminator.
* tests/counterexample.at: Adjust.
2020-05-23 18:23:07 +02:00
Akim Demaille 12f4091de4 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 18:02:44 +02:00
Akim Demaille 8ece778cb8 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 18:02:24 +02:00
Akim Demaille f32ba07f94 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 17:45:03 +02:00
Vincent ImbimboandAkim Demaille 50cd3f16de cex: fix pruning crash
Fixes a crash on Cim's grammar.
https://lists.gnu.org/r/bison-patches/2020-05/msg00107.html

* src/state-item.c (prune_disabled_paths): Prune forward and backwards
paths in seperate passes.
(prune_forward, prune_backward): New.
(disable_state_item): Change function argument from state_item_number
to state_item.
(state_items_report): Add disabling to graph print-out.
* src/conflicts.c (find_state_item_number,
report_state_counterexamples): Add SI_DISABLED checks.
2020-05-23 17:35:19 +02:00
Akim Demaille 37da3c4b42 regen 2020-05-23 15:41:29 +02:00
Akim Demaille 79bae4d6bb kinds: use the symbol kinds where applicable
Instead of generating switch statements with numbers, let's use the
symbol kinds.  Not only is this more readable, it also makes reading
diff easier, as a change in symbol numbers won't have such a large
effect on the implementation of symbol actions.

* data/skeletons/bison.m4 (_b4_symbol_case): Use the symbol kind
rather than its number.
2020-05-23 15:41:29 +02:00
Akim Demaille 23f7554188 kinds: also define the possibly qualified symbol kinds
* data/skeletons/bison.m4 (b4_symbol_kind): Rename as...
(b4_symbol_kind_base): this.
(b4_symbol_kind): New, for fully qualified kind name.
* data/skeletons/lalr1.cc (b4_symbol_kind): New.
Adjust to use b4_symbol_kind where appropriate.
* src/parse-gram.h, src/parse-gram.c: regen.
2020-05-23 15:41:29 +02:00
Akim Demaille 3ff248ebfe m4: simplify useless quotation
* data/skeletons/bison.m4: The result of b4_symbol is "quoted"
already, no need for m4_expand.
2020-05-23 15:40:48 +02:00
Akim Demaille 4e1a5aae96 m4: use m4_shift2 etc.
* data/skeletons/bison.m4 (m4_shift4): New.
Use them where applicable.
2020-05-23 14:59:18 +02:00
Akim Demaille 8e70880af1 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 13:47:31 +02:00
Akim Demaille 3fea8fade8 style: spell fixes
* Makefile.am (codespell): New.
* doc/bison.texi: Fixes.
Use @option for options.
* src/lssi.c, src/lssi.h, src/parse-simulation.h, src/state-item.c:
Fix spellos.
2020-05-23 11:19:27 +02:00
Akim Demaille e7aff57122 style: rename user_token_number as code
This should have been done in 3.6, but I wanted to avoid introducing
conflicts into Vincent's work on counterexamples.  It turns out it's
completely orthogonal.

* data/README.md, data/skeletons/bison.m4, data/skeletons/c++.m4,
* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/java.m4,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/variant.hh, data/skeletons/yacc.c, src/conflicts.c,
* src/derives.c, src/gram.c, src/gram.h, src/output.c,
* src/parse-gram.c, src/parse-gram.y, src/print-xml.c, src/print.c,
* src/reader.c, src/symtab.c, src/symtab.h, tests/input.at,
* tests/types.at:
s/user_token_number/code/g.
Plus minor changes.
2020-05-23 08:43:58 +02:00
Akim Demaille 339d11badf Merge maint into master
* upstream/maint:
  fix generated comments
  traces: provide a means to get short m4 traces
  traces: show the full m4 invocation
2020-05-22 20:35:13 +02:00
Vincent ImbimboandAkim Demaille 99260caef9 cex: replace state-item data structures
* src/state-item.h: Add trans, prods, and revs edges to state-item
struct.
(si_trans, si_revs, si_prods_lookup): Remove.
* src/state-item.c, src/lssi.c, src/parse-simulation.c,
* src/counterexample.c: Update state-item API usage accordingly.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille c19af5cbb4 cex: fix bad reference counting
* src/counterexample.c (si_bfs_free): Fix reference_count
decrementing.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille b54181ff9b cex: fix miscellaneous leaks
* src/counterexample.c (unifying_counterexample): Always free
stage3result when it exists.
* src/conflicts.c (report_state_counterexamples): free leaked bitset.
* src/state-item.c (prune_disabled_paths): free leaked queue.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 86c45be582 cex: fix counterexample leak
* src/counterexample.c (free_counterexample): New.
Free counterexamples after printing.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille b5e0351c3e cex: fix lssi leaks
* src/lssi.c (shortest_path_from_start): Free the root of
shortest_path_from_start search.
Free eligible bitset.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 150b2318ed cex: fix parse state leaks
* src/parse_simulation.c: Fix bug in parse_state_free.
Free new_root when simulate_reduction generates zero states.

* src/parse-simulation.c, src/parse-simulation.h
(parse_state_list, parse_state_list_append): New.
* src/parse-simulation.c, src/parse-simulation.h,
* src/counterexample.c: Replace all uses of lists of parse states and
appends to parse_state_lists with the new API.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 35c4a8e65e cex: derivation reference counting
* src/derivation.h, src/derivation.c: Make derivation struct opaque.
Add derivation_list type for clarity.
(derivation_list_new): New.
(derivation_list_append): New.
(derivation_list_prepend): New.
(derivation_new_leaf): New constructor for derivations with no
children.
* src/counterexample.c, src/parse-simulation.c,
* src/parse-simulation.h: Replace uses of gl_list_t containing
derivations with derivation_list and its API.
Replace calls of dervation_new using null children with
derivation_new_leaf.
* src/parse-simulation.c: replace ps_chunk and its API with typed
versions si_chunk and deriv_chunk.
* src/parse-simlation.h, src/parse-simulation.c: Remove
parse_state_retain_deriv in favor of derivation reference counting.
* src/counterexample.c: Remove search_state_retain_deriv.
2020-05-22 08:45:44 +02:00
Akim Demaille fc39ccab6b cex: style changes in parse-simulation
* src/parse-simulation.c: Formatting changes.
(parse_state_list_new): New.
Use it.
2020-05-22 08:45:44 +02:00
Akim Demaille 9a33fb9317 cex: style: prefer res for returned value
* src/lssi.c, src/parse-simulation.c: here.
2020-05-22 08:45:44 +02:00
Akim Demaille 866bc6a49f cex: fix memory leaks when there are conflicts
* src/counterexample.c (production_step, reduction_step): Release
memory of temporary objects.
2020-05-22 08:45:43 +02:00
Akim Demaille e8619330e8 cex: be sure to always reclaim memory put in hashes
One call to hash_initialize did not provide a function to free memory.

* src/state-item.c (hash_pair_table_create): New.
Use it.
2020-05-22 08:45:43 +02:00
Akim Demaille 193dc86965 cex: properly reclaim hash's allocated memory
* src/state-item.c: Use hash_free where appropriate.
2020-05-22 08:45:43 +02:00
Akim Demaille 51fa2ab0a2 cex: avoid gratuitous heap allocations
There's no need to go for the heap when using gnulib's hash module.

* src/state-item.c (hash_pair_lookup, hash_pair_remove,
state_sym_lookup): Use the heap Luke.
That removes a leak from hash_pair_lookup.
(init_prods): Use hash_pair_insert instead of duplicating it.
2020-05-22 08:45:43 +02:00
Vincent ImbimboandAkim Demaille 2d8c3edbf8 cex: fix leaks
* src/state-item.c: Various functions were using heap allocated locals
and not freeing them.
2020-05-22 08:45:43 +02:00
Akim Demaille 4590071287 style: use hash_xinsert
* gnulib: Update to get hash_xinsert.
Use it where appropriate.
2020-05-22 08:45:43 +02:00
Akim Demaille ac3b6c18a5 cex: style changes in state-item
* src/state-item.h, src/state-item.c (state_item): Make the state
const.
(state_item_set): Make it clearer that it works in the state_items
global array.
2020-05-22 08:45:43 +02:00
Akim Demaille f3ef847539 cex: stylistic changes
* src/counterexample.c: Use 'res' as a variable name for returned
value, as elsewhere.
Avoid uninitialized variables, especially pointers.
Avoid assignment where possible.
2020-05-22 08:45:43 +02:00
Akim Demaille 16f2353723 cex: avoid uninitialized variables
* src/counterexample.c (item_rule_bounds): Split into...
(item_rule_start, item_rule_end): these.
Adjust dependencies.
* src/conflicts.c (find_state_item_number): New.
Use it to avoid uninitialized variables.
2020-05-22 08:45:29 +02:00
Akim Demaille da5317cc9d cex: isolate missing API from gl_list
* src/counterexample.c (list_get_end): New.
Use it.
Reduce scopes.
2020-05-22 07:52:27 +02:00
Akim Demaille e0cb91a922 cex: tests: be robust to variations in time limit reports
The CI has "failures" such as (253, "Null nonterminals"):

    @@ -21,7 +21,7 @@
     3:    3 b: . %empty
     3:    4 c: . %empty
     On Symbols: {A,}
    -time limit exceeded: 6.000000
    +time limit exceeded: 11.000000
     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

* tests/counterexample.at (AT_BISON_CHECK_CEX): New.
Use it to neutralize differences in timeout values.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 482b370540 cex: fix stack overflow
* src/parse-simulation.c: Replace reference counting with
parse_state_retain everywhere.
(free_parse_state): Make this function iterative instead of
recursive. Long parse_state chains were causing stack exhaustion.

* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 66283fb625 cex: fix crash from zombie result
Fixes the SEGV in test 247 (counterexample.at:195): "S/R after first
token".

* src/counterexample.c: here.
* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Akim Demaille 93c849ef0d cex: fixes, and enable tests
* src/counterexample.c, src/derivation.c:
Do not output diagnostics on stdout, that's the job of stderr, and the
testsuite heavily depend on this.
Do not leave trailing spaces in the output.
* tests/counterexample.at: Use AT_KEYWORDS.
Specify the expected outputs.
* tests/local.mk: Add counterexample.at.
2020-05-22 07:52:27 +02:00
Akim Demaille 6279945003 cex: fix a crash
* src/state-item.c (init_state_items): If the rule has no reductions
at all, don't read at all in its list of reduced rules.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille dcb6c972a2 cex: add tests
* tests/counterexample.at: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille af0441cfd2 cex: bind counterexample generation
* src/complain.h, src/complain.c: Add support for -Wcounterexample.
* src/conflicts.c (report_counterexamples): New.
(rule_conflicts_print): Use it when -Wcounterexample is given.
* src/getargs.h, src/getargs.c: Add support for --trace=cex.
* src/main.c (main): Init and deinit counterexample generation.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille bbb63b1ca9 cex: introduce counterexample search
* src/counterexample.h, src/counterexample.c: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille ac54d19eba cex: introduce the parse simulator
* src/derivation.h, src/derivation.c,
* src/parse-simulation.h, src/parse-simulation.c: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 5807dd9279 cex: add support for state-item pair graph generation
* src/lssi.h, src/lssi.c, src/state-item.h, src/state-item.c: New.
2020-05-22 07:52:27 +02:00
Akim Demaille 94bfdf3b4b cex: add gnulib dependencies
* bootstrap.conf (gnulib_modules): Add linked-list.
2020-05-22 07:52:27 +02:00
Akim Demaille f80890c4bb fix generated comments
In Bison 3.6.2, the comments with brackets lose their brackets, for
improper m4 quotation.

* data/skeletons/bison.m4 (b4_gsub): New.
* data/skeletons/c-like.m4 (_b4_comment): Use it.
* tests/m4.at: Check b4_gsub.
2020-05-21 20:14:59 +02:00
Akim Demaille 1ebc2ac55c traces: provide a means to get short m4 traces
Let --trace=m4-early dump all the logs from the start (as --trace=m4
used to do), and have --trace=m4 now start traces only when actually
working of the user's grammar.

Can make a big difference in the case of small inputs.  E.g.

    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4 |& wc
       3952   19446  251068
    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4-early |& wc
      19491  131904 1830495

* data/skeletons/traceon.m4: New.
* src/getargs.h, src/getargs.c: Introduce --trace=m4-early.
* src/output.c (output_skeleton): Adjust for --trace=m4 and --trace=m4-early.
2020-05-21 20:13:04 +02:00
Akim Demaille 94952779b6 traces: show the full m4 invocation
Unfortunately the effect of -dV is still position independent.

* src/output.c (output_skeleton): here.
2020-05-21 20:13:04 +02:00
Thomas PetazzoniandAkim Demaille ed7d5c2b5b src: make path to m4 relocatable
Commit a4ede8f85b ("package: make bison
a relocatable package") made Bison relocatable, but in fact it still
contains one absolute reference: the M4 variable, which points to the
M4 program. Let's fix that by using relocate(), see if an M4 binary is
available at the relocated location, and otherwise fallback to the
original M4 location.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00078.html,
and https://lists.gnu.org/r/bison-patches/2020-05/msg00087.html.

* src/files.h, src/files.c (m4path): New.
* src/output.c: Use it.
2020-05-20 08:09:27 +02:00
Akim Demaille 1ce02e13c3 CI: fix PPC recipe 2020-05-17 11:01:19 +02:00
Akim Demaille 8ef0b12eb7 Merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.2
  tests: improve update-test
  CI: add GCC 10 and Clang 10
  fix: do not emit nested comments
  todo: update
  examples: use markdown hyperlinks
  tests: don't use == to compare const char *...
  gnulib: update
2020-05-17 09:16:51 +02:00
Akim Demaille e6d83116ae c: more fixes for _Noreturn
The previous fix was insufficient.

    tests/types.at:366: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    ++ ccache clang++-mp-9.0 -Qunused-arguments -ggdb -Wall -Wextra -Wcast-align -Wchar-subscripts -fparse-all-comments -Wdocumentation -Wformat -Wimplicit-fallthrough -Wnull-dereference -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare -Wpointer-arith -Wshadow -Wwrite-strings -Wextra-semi -Wold-style-cast -Wundefined-func-template -Wweak-vtables -Wunreachable-code -Wundef -pedantic -Wconversion -Wdeprecated -Wsign-compare -Wsign-conversion -Wtautological-constant-out-of-range-compare -fno-color-diagnostics -Wno-keyword-macro -Werror -std=c++98 -I/Users/akim/src/gnu/bison/tests -isystem /opt/gostai/include -isystem /opt/local/include -L/opt/gostai/lib -L/opt/local/lib -o test test.cc /Users/akim/src/gnu/bison/_build/c9d/lib/libbison.a -lintl -Wl,-framework -Wl,CoreFoundation
    stderr:
    test.cc:955:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    test.cc:963:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    2 errors generated.

* data/skeletons/c.m4 (b4_attribute_define): Do not use _Noreturn at
all in C++, clang or not.
2020-05-17 09:16:41 +02:00
Akim Demaille 4d9fa28ba8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-17 08:55:47 +02:00
Akim Demaille a100a3c4c1 version 3.6.2
* NEWS: Record release date.
2020-05-17 08:30:46 +02:00
Akim Demaille b18ceb50f1 tests: improve update-test
* build-aux/update-test: When given a directory, use the testsuite.log
which it contains.
Do not accept empty "from"s, as substituting the empty string with
something is rarely a good idea.
2020-05-17 08:28:12 +02:00
Akim Demaille ff4d67ede8 CI: add GCC 10 and Clang 10
* .travis.yml: Here.
* tests/input.at, tests/regression.at: Beware of clang's -Wdocumentation.
2020-05-17 08:28:12 +02:00
Akim Demaille 465babb635 fix: do not emit nested comments
With input such as

    %token<fl> yVL_CLOCK "/*verilator sc_clock*/"

we generate

    yVL_CLOCK = 610,      /* "/*verilator sc_clock*/"  */

which is invalid since the comment will actually be closed on the
first "*/".  Let's turn "*/" into "*\/" to avoid this.  But GCC will
also warn about "/*" inside a comment, so let's "escape" it too.

Reported by Huang Rui.
https://github.com/akimd/bison/issues/38

* data/skeletons/c-like.m4 (_b4_comment): Escape comment delimiters in
comments.
* tests/input.at (Torturing the Scanner): Check thes cases.
* tests/m4.at: New.
2020-05-17 08:28:12 +02:00
Akim Demaille 22c3839168 c: restore definition of _Noreturn as [[noreturn]] in C++
c.m4 contains a definition of _Noreturn which is modeled after
gnulib's lib/_Noreturn.h.  The latter was recently
changed (b61bf2f0e8) to not using
[[noreturn]] at all, because the uses of _Noreturn in gnulib are
sometimes incompatible with the rules of [[noreturn]].

As a result glr.cc started to use _Noreturn in C++, which clang
refuses (all the glr.cc tests currently fail with Clang++).

* data/skeletons/c.m4 (b4_attribute_define): Restore the definition of
_Noreturn as [[noreturn]] in modern C++.
The generated code uses _Noreturn in places where [[noreturn]] is
valid.
2020-05-16 17:29:38 +02:00
Akim Demaille 4619b32dc0 examples: don't promote unchecked function calls
* etc/bench.pl.in, examples/c/bistromathic/parse.y,
* examples/c/calc/calc.y, examples/c/pushcalc/calc.y: Check scanf's
return value.
* doc/bison.texi: Likewise, but only for the second example, to avoid
cluttering the very simple case.
2020-05-16 14:39:57 +02:00
Akim Demaille ad921890c1 gnulib: update 2020-05-16 14:39:57 +02:00
Akim Demaille 6a28e6d412 todo: update 2020-05-15 07:18:15 +02:00
Akim Demaille f4495da337 examples: use markdown hyperlinks
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/README.md: here.
2020-05-14 07:26:55 +02:00
Akim Demaille dbaed0bbf2 tests: don't use == to compare const char *...
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00091.html

* tests/c++.at: here.
2020-05-14 07:26:34 +02:00
Akim Demaille 78c7fb6460 gnulib: update 2020-05-14 07:25:09 +02:00
Akim Demaille 14ce500508 tests: improve update-test
* build-aux/update-test: When given a directory, use the testsuite.log
which it contains.
Do not accept empty "from"s, as substituting the empty string with
something is rarely a good idea.
2020-05-13 19:48:03 +02:00
Akim Demaille acba58ac59 Merge branch maint
* maint:
  news: update
  maint: post-release administrivia
  version 3.6.1
  c++: style: reorder generated code
  c++: provide yy::parser::symbol_type::name
  c++: make parser::symbol_name public
  examples: beware of ~/.inputrc
  build: also provide lzip compressed tarballs
  style: minor fixes
  yacc.c: restore ansi-c compatibility
2020-05-10 17:33:12 +02:00
Akim Demaille da29809969 news: update 2020-05-10 17:32:28 +02:00
Akim Demaille 87e4895189 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-10 14:47:51 +02:00
Akim Demaille 01e3f45f83 version 3.6.1
* NEWS: Record release date.
2020-05-10 14:28:24 +02:00
Akim Demaille 9c21da3363 bench: add support to randomize the order of execution
It's amazing how much the order matters.  To a point that many of
these benches are meaningless.  For instance (some of the benches
where run with `make -C benches/latest rand
BENCHFLAGS=--benchmark_min_time=3`):

    compiler: g++ -std=c++11 -O2
      0. %define nofinal
      1.
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0            1543 ns       1541 ns     441660
    BM_y1            1521 ns       1520 ns     456535
    --------------------------------------------------
    BM_y0            1531 ns       1530 ns     440584
    BM_y1            1512 ns       1511 ns     457591
    --------------------------------------------------
    BM_y0            1539 ns       1538 ns    2749330
    BM_y1            1516 ns       1515 ns    2771500
    --------------------------------------------------
    BM_y0            1571 ns       1570 ns    2600782
    BM_y1            1542 ns       1541 ns    2708349
    --------------------------------------------------
    BM_y0            1530 ns       1529 ns    2670363
    BM_y1            1519 ns       1518 ns    2764096

    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y1            1529 ns       1528 ns     451937
    BM_y0            1508 ns       1507 ns     453944
    --------------------------------------------------
    BM_y1            1525 ns       1524 ns    2750684
    BM_y0            1516 ns       1515 ns    2794034
    --------------------------------------------------
    BM_y1            1526 ns       1525 ns    2749620
    BM_y0            1515 ns       1514 ns    2808112
    --------------------------------------------------
    BM_y1            1524 ns       1523 ns    4475844
    BM_y0            1502 ns       1501 ns    4611665

* etc/bench.pl.in: here.
2020-05-10 11:51:46 +02:00
Akim Demaille febf6115a0 bench: use a Makefile
This makes it much easier to toy with the benchs.

* etc/bench.pl.in: Generate a Makefile instead of directly compiling
the files.
2020-05-10 11:51:41 +02:00
Akim Demaille 11b5bac7bf examples: use markdown hyperlinks
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/README.md: here.
2020-05-10 11:51:17 +02:00
Akim Demaille b61bf2f0e8 don't use stdnoreturn
Reported by Paul Eggert.

* src/getargs.c: We don't need it anyway, since we use _Noreturn.
* data/skeletons/c.m4: While at it, update the definition of _Noreturn
stolen from gnulib.
2020-05-10 10:46:03 +02:00
Akim Demaille 091943f265 c++: style: reorder generated code
The implementation of yy::parser::symbol_name is emitted even before
the implementation of yy::parser::parser.  This makes little sense.

* data/skeletons/lalr1.cc (symbol_name): Move its implementation in
the same place as in the class definition: after "error" and before
"context".
2020-05-10 10:06:11 +02:00
Akim Demaille bf98d94f4f c++: provide yy::parser::symbol_type::name
* data/skeletons/c++.m4 (yy::parser::basic_symbol::name): New.
* data/skeletons/lalr1.cc (yy_print_): Use it.
* doc/bison.texi: Document.
* tests/c++.at: Check.
2020-05-10 10:01:35 +02:00
Akim Demaille 6bb37dbe27 c++: make parser::symbol_name public
Reported by Martin Blais <[email protected]>.
https://lists.gnu.org/r/help-bison/2020-05/msg00005.html

* data/skeletons/lalr1.cc (symbol_name): Make it public.
Add a private hidden hook to enable testing of private parts.
* tests/local.at (AT_DATA_GRAMMAR_PROLOGUE): Help Emacs find the right
language mode.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check that we
can read symbol_name.
2020-05-10 09:42:37 +02:00
Akim Demaille c3585f41ef examples: beware of ~/.inputrc
* examples/c/bistromathic/bistromathic.test: here.
2020-05-10 09:40:07 +02:00
Akim Demaille 6525abdc83 build: also provide lzip compressed tarballs
Suggested by Matias Fonzo <[email protected]>.

* cfg.mk: Post announcements to bison-announce.
* configure.ac: Build lzip packages.
* .travis.yml: Build only xz, we don't care about the other formats
here.
2020-05-10 08:03:49 +02:00
Akim Demaille 2b63c54f5a style: minor fixes
* examples/c/README.md: here.
2020-05-10 08:03:30 +02:00
Akim Demaille 2da399d15f yacc.c: restore ansi-c compatibility
Reported by neok-m4700.
https://github.com/akimd/bison/issues/37

* data/skeletons/yacc.c: Don't use // comments.
2020-05-09 17:05:03 +02:00
Akim Demaille 19f45df02b bench: use *.cc for C++
Using *.c is simpler, but triggers annoying warnings with Clang++.

* etc/bench.pl.in: Please the dictator.
2020-05-09 16:43:59 +02:00
Akim Demaille 2ab4058de0 style: minor fixes
* examples/c/README.md: here.
2020-05-09 16:43:59 +02:00
Akim Demaille f2277c3fec gnulib: update 2020-05-09 15:40:38 +02:00
Akim Demaille fb49a10e2c gnulib: update, and use the attribute module
* gnulib: Update.
* bootstrap.conf: Use attribute.
* src/system.h: Remove macros for attributes.
Adjust dependencies.
* src/scan-gram.l (DEPRECATED): Rename as...
(DEPRECATED_DIRECTIVE): this, to avoid the clash with the DEPRECATED macro.
2020-05-08 18:29:30 +02:00
Akim Demaille f049a57eec build: also provide lzip compressed tarballs
Suggested by Matias Fonzo <[email protected]>.

* cfg.mk: Post announcements to bison-announce.
* configure.ac: Build lzip packages.
* .travis.yml: Build only xz, we don't care about the other formats
here.
2020-05-08 18:29:21 +02:00
Akim Demaille 0c77d69721 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-08 10:15:38 +02:00
Akim Demaille 307fcdee00 version 3.6
* NEWS: Record release date.
2020-05-08 09:57:14 +02:00
Akim Demaille d26d10ad6c examples: beware of portability issue on Windows
Reported by Jannick.
https://lists.gnu.org/r/bug-bison/2020-05/msg00040.html
https://lists.gnu.org/r/bug-bison/2020-05/msg00066.html

* examples/test (diff_opts): Use --strip-trailing-cr if supported, to
avoid \n vs. \r\n issues.
* examples/c/bistromathic/bistromathic.test: When on MSYS, don't try
to check autocompletion.
2020-05-08 09:45:29 +02:00
Akim Demaille 1b4108da3e regen 2020-05-08 09:45:29 +02:00
Akim Demaille 53bfc7df94 doc: fix the generation of the man page
When there is no bison.1 at all, the procedure fails.

* doc/local.mk (bison.1): Be robust to cold starts.
2020-05-08 09:02:45 +02:00
Akim Demaille a5fb4a88ef news: prepare for 3.6 2020-05-08 07:34:30 +02:00
Akim Demaille 54df196d49 doc: complete the table of symbols
* doc/bison.texi: Add YYEMPTY, YYEOF and YYUNDEF.
2020-05-08 07:34:30 +02:00
Akim Demaille 52bb6f0525 doc: clarify the glossary item about kinds
* doc/bison.texi (Glossary): here.
2020-05-07 08:38:58 +02:00
Akim Demaille 76dab18af3 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-06 08:48:05 +02:00
Akim Demaille c982974f33 version 3.5.94
* NEWS: Record release date.
2020-05-06 08:28:36 +02:00
Akim Demaille dc2a3578b7 doc: document yypstate_expected_tokens
* doc/bison.texi (Push Parser Interface): Here.
2020-05-06 08:11:52 +02:00
Akim Demaille 9661b2fcbc doc: restructure the push parser documentation
I don't think it's fair to have yypstate_new, yypstate_delete,
yypush_parse and yypull_parse to have their own section, on par with
yyparse and yylex.  Let them be in a single section about push
parsers.  And show new/delete first.

* doc/bison.texi (Push Parser Interface): New.
Fuse the aforementioned sections into it.
2020-05-06 08:11:52 +02:00
Akim DemailleandAkim Demaille d9a9b054ae all: fix the interface of yyexpected_tokens
The user gives yyexpected_tokens a limit: the max number of tokens she
wants to hear about.  That's because an error message that reports a
bazillion of possible tokens is useless.

In that case yyexpected_tokens returned 0, so the user would not know
if there are too many expected tokens or none (yes, that's possible).

There are several ways to tell the user in which situation she's in:

- return some E2MANY, a negative value.  Then it makes the pattern

    int argsize = yypcontext_expected_tokens (ctx, arg, ARGS_MAX);
    if (argsize < 0)
      return argsize;

  no longer valid, as for E2MANY (i) the user must generate the error
  message anyway, and (ii) she should not return E2MANY

- return ARGS_MAX + 1.  Then it makes it dangerous for the user, as
  she has to iterate update `min (ARGS_MAX, argsize)`.

Returning 0 is definitely simpler and safer for the user, as it tells
her "this is not an error, just generate your message without a list
of expecting tokens".  So let's still return 0, but set arg[0] to the
empty token when the list is really empty.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.java
* data/skeletons/yacc.c (yyexpected_tokens): Put the empty symbol
first if there are no possible tokens at all.
* examples/c/bistromathic/parse.y: Demonstrate how to use that.
2020-05-06 08:11:52 +02:00
Akim Demaille cb9f4cb543 examples: fix handling of syntax errors
The shell grammar does not allow empty statements in then/else part of
an if, but examples/test failed to catch the syntax errors from the
script it ran.  So exited with success anyway.

You would expect 'set -e' to suffice, but with bash 3.2 actually it
does not.  As a matter of fact, I could find a way to have this behave
properly:

    $ cat test.sh
    set -e
    cleanup ()
    {
      status=$?
      echo "cleanup: $status"
      exit $status
    }
    trap cleanup 0 1 2 13 15
    . $1
    s=$?
    echo "test.sh: $s"
    exit $s

    $ cat bistro.test
    if true; then
    fi

    $ /bin/sh ./test.sh ./bistro.test
    ./bistro.test: line 2: syntax error near unexpected token `fi'
    cleanup: 0
    $ echo $?
    0

Remove the set -e (or the trap), and tada, it works...  So we have to
deal with the error by hand.

* examples/test ($exit): Replace with...
($status): this.
Preserve the exit status of the test case.
* examples/c/bistromathic/bistromathic.test: Fix syntax error.
2020-05-05 08:21:12 +02:00
Akim Demaille b86dcaf40b doc: beware of timestamp issues on Haiku
On Haiku, help2man is fired on a freshly extracted tarball.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00055.html

* doc/local.mk (bison.1): Be robust to a missing help2man.
2020-05-04 19:06:59 +02:00
Akim Demaille 0fafbbdefb tests: beware of wchar_t portability issues on AIX
https://lists.gnu.org/r/bug-bison/2020-05/msg00050.html
Reported by Bruno Haible.

* tests/diagnostics.at: here.
2020-05-04 08:09:22 +02:00
Akim Demaille 4b85b969d0 glr.c: beware of portability issues with PTRDIFF_MAX
For instance test 386, "glr.cc api.value.type={double}":

    types.at:366: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    test.cc: In function 'ptrdiff_t yysplitStack(yyGLRStack*, ptrdiff_t)':
    test.cc:490:4: error: 'PTRDIFF_MAX' was not declared in this scope
       (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
        ^
    test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
           ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
                                         ^~~~~~~~~
    test.cc:490:4: note: suggested alternative: '__PTRDIFF_MAX__'
       (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
        ^
    test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
           ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
                                         ^~~~~~~~~

The failing tests are using glr.cc only, which I don't understand, the
problem is rather in glr.c, so I would expect glr.c tests to also fail.

Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00053.html

* data/skeletons/yacc.c: Move the block that defines
YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, and
YYSIZEOF to...
* data/skeletons/c.m4 (b4_sizes_types_define): Here.
(b4_c99_int_type): Also take care of the #undefinition of short.
* data/skeletons/yacc.c, data/skeletons/glr.c: Use
b4_sizes_types_define.
* data/skeletons/glr.c: Adjust to use YYPTRDIFF_T/YYPTRDIFF_MAXIMUM,
YYSIZE_T/YYSIZE_MAXIMUM.
2020-05-04 07:44:42 +02:00
Akim Demaille 7727693711 todo: update 2020-05-04 07:37:40 +02:00
Akim Demaille ce27796b74 examples: beware of strnlen portability issues
One function missing on Solaris 10 Sparc:

     CCLD     examples/c/bistromathic/bistromathic
    Undefined                       first referenced
    symbol                             in file
    strnlen                             examples/c/bistromathic/bistromathic-parse.o
    ld: fatal: symbol referencing errors. No output written to examples/c/bistromathic/bistromathic

Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00048.html

* examples/c/bistromathic/parse.y (xstrndup): Don't use strnlen.
xstrndup is assembled from gnulib's xstrndup, strndup and strnlen...
2020-05-04 06:48:00 +02:00
Akim Demaille 6135fdc152 examples: beware of portability issues with sh's trap
On AIX 7.2, when invoking "exit 77", we actually exit with 127.  The
"cleanup" function, called via trap, received an incorrect exit
status, something described in Autoconf's doc.
Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00029.html
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00047.html

* examples/test (skip): New.
* examples/c/bistromathic/bistromathic.test,
* examples/c/reccalc/reccalc.test: Use it, to ensure $? is set to 77
when the trap is called.
2020-05-04 06:48:00 +02:00
Akim Demaille f1497356e8 tests: beware of portability issues with diff -u
AIX 7.1 supports diff -u, but its output does not match the expected
one.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00049.html

* tests/atlocal.in (DIFF_U_WORKS): New.
* tests/local.at (AT_DIFF_U_CHECK): New.
* tests/existing.at (_AT_TEST_EXISTING_GRAMMAR): Use AT_DIFF_U_CHECK.
2020-05-04 06:48:00 +02:00
Akim Demaille 1429569362 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-03 19:52:38 +02:00
Akim Demaille 506c368ab2 version 3.5.93
* NEWS: Record release date.
2020-05-03 19:32:15 +02:00
Akim Demaille 4f9dc3bdc1 news: update for 3.5.93 2020-05-03 19:32:03 +02:00
Akim Demaille 0d81be2dc7 gnulib: update 2020-05-03 19:32:03 +02:00
Akim Demaille 32f44f4bfb tests: really skip tricky multichar test on Cygwin
In Autotest, anything outside AT_SETUP/AT_CLEANUP is discarded.

* tests/diagnostics.at (AT_TEST): Accept a skip-if test.
Use it to skip on cygwin.
2020-05-03 19:08:16 +02:00
Akim Demaille 38a8287813 bistromathic: beware of portability issues of readline on AIX
Readline may emit escape sequences before the prompt.
Reported by Bruno Haible.
https://lists.gnu.org/r/platform-testers/2020-05/msg00001.html.

* examples/c/bistromathic/bistromathic.test: Trust readline _only_ if
we get what we expect on some reference computation.
2020-05-03 18:10:58 +02:00
Akim Demaille df752784c2 examples: beware of portability issues with cmp
As someone wrote nearly 20 years ago in Autoconf's documentation,
don't use cmp to compare text files, but diff.
https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=abad4f0576a7dc361e5385e19c7681449103cdb1
Reported by Jannick.

* examples/test: Use diff, not cmp.
2020-05-03 17:53:47 +02:00
Akim Demaille 292409e91e build: fix warnings (shown on IRIX)
Appearing on IRIX with gcc -mabi=n32.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html

* examples/c++/variant-11.yy, examples/c/bistromathic/parse.y: Don't
give chars to isdigit, cast them to unsigned char before.
* src/complain.c: Use c_isdigit.
* src/fixits.c (fixits_run): Avoid casts.
* src/lalr.c (goto_print): Use %zu for a size_t.
2020-05-03 17:37:34 +02:00
Akim Demaille eea56d70d9 c++: be compatible with the pre-3.6 way to get a symbol's kind
Reported by Pramod Kumbhar.
https://lists.gnu.org/r/bug-bison/2020-05/msg00025.html

* data/skeletons/c++.m4: here.
2020-05-03 17:06:13 +02:00
Akim Demaille 6e2de439e6 bistromathic: beware of portability issues with strndup
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00026.html

* examples/c/bistromathic/parse.y (xstrndup): New.
Use it.
2020-05-03 17:06:13 +02:00
Akim Demaille e33cd4b824 flex: fix incorrect use of Automake conditional
AM_CONDITIONAL does _not_ define a shell variable...
Reported privately by Denis Excoffier.

* configure.ac (LEX_CXX_WORKS): Fix its definition.
2020-05-03 17:04:15 +02:00
Bruno HaibleandAkim Demaille 0669780ff8 package: fix a link error on IRIX
https://lists.gnu.org/r/bug-bison/2020-05/msg00035.html

* src/local.mk (src_bison_LDADD): Mention libbison.a before, not after, the
system libraries.
2020-05-03 16:49:29 +02:00
Akim Demaille 160df220b1 bistromathic: beware of portability of readline
Don't try to build bistromathic if we don't have readline.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00028.html

* configure.ac (ENABLE_BISTROMATHIC): New.
* examples/c/bistromathic/local.mk: Use it.
* examples/c/bistromathic/bistromathic.test: Exit 77 for skip.
2020-05-03 16:38:34 +02:00
Akim Demaille da5c072a62 tests: beware of portability issues of sh
"foo || bar" does not invoke bar on AIX 7.2 when foo does not exist.
It just dies.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00029.html

* examples/c/reccalc/reccalc.test: Check for seq in a subshell.
2020-05-03 16:38:34 +02:00
Akim Demaille 73ac8ff409 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-03 13:07:08 +02:00
Akim Demaille 0e0fb0efc9 version 3.5.92
* NEWS: Record release date.
2020-05-03 12:48:16 +02:00
Akim Demaille bb1d776be0 news: update for 3.5.92 2020-05-03 12:47:21 +02:00
Akim Demaille d7e1abe656 gnulib: update 2020-05-03 12:43:55 +02:00
Akim Demaille 13a1537dba java: demonstrate push parsers
* data/skeletons/lalr1.java (Location): Make it a static class.
(Lexer.yylex, Lexer.getLVal, Lexer.getStartPos, Lexer.getEndPos):
These are not needed in push parsers.
* examples/java/calc/Calc.y: Demonstrate push parsers in the Java.
* doc/bison.texi: Push parsers have been supported for a long time,
remove incorrect statements stating the opposite.
2020-05-03 11:28:36 +02:00
Akim Demaille ac2ba46053 doc: clarify what a location is
Reported by Arthur Schwarz <[email protected]>
https://lists.gnu.org/r/help-bison/2013-12/msg00009.html

* doc/bison.texi (Location Type): here.
2020-05-03 11:28:36 +02:00
Akim Demaille 2a7a2c1d3a tests: beware of mbswidth portability issues
Shy away from these issues on Cygwin.
Reported Denis Excoffier.
https://lists.gnu.org/r/bug-bison/2020-05/msg00003.html

* tests/diagnostics.at (Tabulations and multibyte characters): Split
in two.
2020-05-03 11:28:36 +02:00
Akim Demaille c9b5b68c73 examples: beware of intl portability issues
Reported by Horst von Brand.
https://lists.gnu.org/r/bug-bison/2020-04/msg00033.html

* examples/c/bistromathic/Makefile: libintl might not be needed, but
libm probably is.
* examples/c/bistromathic/parse.y: Include locale.h.
2020-05-03 10:32:33 +02:00
Akim Demaille 26aef31552 examples: beware of portability issues with readline
On OpenBSD 6.5, the prompt is repeated, but not the actual command
line...  Don't try to cope with that.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00015.html

* examples/c/bistromathic/bistromathic.test: Skip when readline behave
this way.
2020-05-03 10:32:33 +02:00
Akim Demaille 392f3caef6 examples: beware of the portability of flex --header-file
The option --header was introduced in version 2.5.6.
The option --header-file was introduced in version 2.6.4.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00013.html

So use --header, and do bother with versions that don't support it.

* m4/flex.m4: Check whether flex supports --header.
* configure.ac (FLEX_WORKS, FLEX_CXX_WORKS): Set to false if it doesn't.
* * examples/c/reccalc/local.mk, examples/c/reccalc/Makefile:
Use --header rather than --header-file.
2020-05-03 10:32:32 +02:00
Akim Demaille ccaa8e29f9 c++: provide backward compatibility on by_type
To write unit tests for their scanners, some users depended on
symbol_type::token():

    Lexer lex("12345");
    symbol_type t = lex.nextToken();
    assert(t.token() == token::INTLIT);
    assert(t.value.as<int>() == 12345);

But symbol_type::token() was removed in Bison 3.5 because it relied on
a conversion table.  So users had to find other patterns, such as

    assert(t.type_get() == by_type(token::INTLIT).type_get());

which relies on several private implementation details.

As part of transitioning from "token type" to "token kind", and making
this a public and documented interface, "by_type" was renamed
"by_kind" and "type_get()" was renamed as "kind()".  The latter had
backward compatibility mechanisms, not the former.

In Bison 3.6 none of this should be used, but rather

    assert(t.kind() == symbol_kind::S_INTLIT);

Reported by Pramod Kumbhar.
https://lists.gnu.org/r/bug-bison/2020-05/msg00012.html

* data/skeletons/c++.m4 (by_type): Make it an alias to by_kind.
2020-05-03 09:20:08 +02:00
Akim Demaille 76c3bccf40 yacc.c: improve formatting of the generated code
* data/skeletons/yacc.c (yy_reduce_print): here.
2020-05-02 10:17:01 +02:00
Akim Demaille 6275137378 doc: java supports push parsers since 3.0 (2013-07-25)
* doc/bison.texi: Clarify this.
2020-05-02 09:29:05 +02:00
Akim Demaille d0571c846f java: fix coding style
I don't plan to fix everything in one go.  But this was in the way of
the next commit.

* data/skeletons/lalr1.java: Avoid space before parens.
* tests/java.at: Adjust.
2020-05-02 09:27:16 +02:00
Akim Demaille 8c1002e4b7 style: comment changes
* tests/java.at: here.
2020-05-02 09:08:26 +02:00
Akim Demaille dbd8fd71ba todo: more 2020-05-02 08:18:20 +02:00
Akim Demaille 95bac741c3 style: more documentation about errs
Suggested by Angelo Borsotti.
https://lists.gnu.org/r/bug-bison/2014-02/msg00003.html

* src/state.h: here.
2020-05-02 08:18:20 +02:00
Akim Demaille f8ab4d81c0 doc: document the exit status
Suggested by Alexandre Duret-Lutz.
https://lists.gnu.org/r/bug-bison/2013-09/msg00015.html

* doc/bison.texi (Invocation): Here.
2020-05-01 10:48:44 +02:00
Akim Demaille d55c9b001a java: add missing i18n requests
* data/skeletons/lalr1.java (reportSyntaxError): Here.
2020-05-01 10:36:05 +02:00
Akim Demaille 611495999f java: style: fix coding style of yyerror/reportSyntaxError
* data/skeletons/lalr1.java: here.
2020-05-01 10:36:05 +02:00
Akim Demaille 01d5f232a9 java: avoid useless work
* data/skeletons/lalr1.java (yySymbolPrint): Avoid the computation of
the argument if useless.
While at it, fix Java coding style.
2020-05-01 10:36:05 +02:00
Akim Demaille 0407acbc59 java: comment changes
* data/skeletons/lalr1.java, examples/java/calc/Calc.y: here.
2020-05-01 10:36:05 +02:00
Akim Demaille 0c0e778bd1 news: make it more consistent
* NEWS: Use the same pattern for titles.
2020-05-01 10:36:05 +02:00
Akim Demaille 30357ae942 c++: use modern idioms to make classes non-copyable
Reported by Don Macpherson.
https://lists.gnu.org/r/bug-bison/2019-05/msg00015.html
https://github.com/akimd/bison/issues/36

* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/variant.hh: Delete the copy-ctor and the copy operator.
2020-05-01 06:52:04 +02:00
Akim Demaille fb1d76d9a9 yacc.c: avoid the use of a temporary
* data/skeletons/yacc.c: Use YYLLOC_DEFAULT directly with the final
destination.
2020-04-30 08:07:55 +02:00
Akim Demaille a61bc3f9f8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-29 09:07:50 +02:00
Akim Demaille f0942df01a version 3.5.91
* NEWS: Record release date.
2020-04-29 08:47:35 +02:00
Akim Demaille 52ababbc89 build: fix syntax-check issues
* cfg.mk: We do want to gettextize the examples.
* po/POTFILES.in: Adjust.
2020-04-29 08:47:04 +02:00
Akim Demaille 8e11933e41 gnulib: update 2020-04-29 08:32:25 +02:00
Akim Demaille 99efa35369 doc: document YYEOF, YYUNDEF and YYerror
* doc/bison.texi (Special Tokens): New.
* examples/c/bistromathic/parse.y: Formatting changes.
2020-04-29 08:23:55 +02:00
Akim Demaille 547545a795 package: fix distcheck
Bison emits strings to translate in the generated code, for builtin
tokens.  So they appear only in generated parsers, which are not
shipped, so they are not in the src tree, so we cannot use them in our
POTFILE.

Except src/parse-gram.c, which is in the source tree.  And even in the
git repo.  But to avoid useless diffs in the repo, we do not keep the
src/parse-gram.c _with_ the #lines.  This is done in a dist-hook which
regenerates src/parse-gram.c when we run "make dist".

Unfortunately, then, update-po traverses the whole tree and sees that
the location of the strings to translate in src/parse-gram.c have
changed, so the bison.pot is to be updated.  And that is not possible
in the "make dist" which is run within "make distcheck"
(not the one preparing the dist for distcheck, the one run by
distcheck to check that a distributed tarball can build a tarball)
because then the src tree is read-only.

So let's not put src/parse-gram.c in the POTFILE, and expose these
strings to gettextize by hand.

* src/i18n-strings.c: New.
* po/POTFILES.in: Add it, and remove src/parse-gram.c.
2020-04-29 07:01:22 +02:00
Akim Demaille 1b5cf80e32 style: avoid gettextize warnings
* src/scan-gram.l, src/scan-skel.l: Help it see the start and end of
"character literals".
2020-04-29 07:01:22 +02:00
Akim Demaille 4c641c5189 tests: beware of portability of readline
* examples/test: here.
2020-04-29 07:01:22 +02:00
Akim Demaille 3b05de2d05 yacc.c: install backward compatibility for YYERRCODE
Some people have been using that symbol.  Some even have #defined it
themselves.
https://lists.gnu.org/r/bison-patches/2020-04/msg00138.html

Let's provide backward compatibility, having it point to YYUNDEF, so
that an error message is generated.

* data/skeletons/yacc.c (YYERRCODE): New, at the exact same location
it was defined before.
2020-04-28 08:26:49 +02:00
Akim Demaille 902a235ad3 style: c++: s/type/kind/ where appropriate
These are internal details.  `type_get ()` is still there to ensure
backward compatibility, `kind ()` being the modern way.

* data/skeletons/c++.m4 (by_type, by_type::type): Rename as...
(by_kind, by_kind::kind_): this.
Adjust dependencies.
2020-04-28 08:16:05 +02:00
Akim Demaille 11027558c8 java: clean up the definition of token kinds
From

    public interface Lexer {
      /* Token kinds.  */
      /** Token number, to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token number, to be returned by the scanner.  */
      static final int YYERRCODE = 256;
      /** Token number, to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token number, to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use b4_symbol(0, id) instead.  */
      public static final int EOF = YYEOF;

to

    public interface Lexer {
      /* Token kinds.  */
      /** Token "end of file", to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token error, to be returned by the scanner.  */
      static final int YYerror = 256;
      /** Token "invalid token", to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token "!", to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use YYEOF instead.  */
      public static final int EOF = YYEOF;

* data/skeletons/java.m4 (b4_token_enum): Display the symbol's tag in
comment.
* data/skeletons/lalr1.java: Address overquotation issue.
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: Use YYEOF,
not EOF.
2020-04-28 07:56:00 +02:00
Akim Demaille cd4e799da4 error: rename the error token from YYERRCODE to YYerror
See https://lists.gnu.org/r/bison-patches/2020-04/msg00162.html.

* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.java, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/scan-gram.l, src/symtab.c
(YYERRCODE): Rename as...
(YYerror): this.
Adjust dependencies.
2020-04-28 07:54:07 +02:00
Akim Demaille 7346163840 dogfooding: use YYERRCODE in our scanner
* src/scan-gram.l: Use it.
* tests/input.at: Adjust.
2020-04-27 08:21:50 +02:00
Akim Demaille 89c4e1becf scanner: avoid spurious errors about empty character literals
On an invalid character literal such as "'\777'" we used to produce
two errors:

    input.y:2.9-12: error: invalid number after \-escape: 777
    input.y:2.8-13: error: empty character literal

Get rid of the second one.

* src/scan-gram.l (STRING_GROW_ESCAPE): New.
* tests/input.at: Adjust.
2020-04-27 08:06:49 +02:00
Akim Demaille 3262747c5b scanner: bad character literals are errors
* src/scan-gram.l: These are errors, not warnings.
* tests/input.at: Adjust.
2020-04-27 07:17:04 +02:00
Akim Demaille 5f3cd49acc regen 2020-04-27 07:08:55 +02:00
Akim Demaille e6d928c4e8 todo: update 2020-04-26 19:55:52 +02:00
Akim Demaille b254b36db8 all: don't emit an error message when the scanner returns YYERRCODE
I'm quite pleased to see that the tricky case of glr.c was already
prepared by the changes to support syntax_error exceptions.  Better
yet, it is actually syntax_error that becomes a special case of the
general pattern: make yytoken be YYERRCODE.

* data/skeletons/glr.c (YYFAULTYTOK): Remove the now useless (Basil)
Faulty token.
Instead, use the error token.
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: When computing
the action, first check the case of the error token.

* tests/calc.at: Check cases for the error token symbols before and
after it.
2020-04-26 19:55:52 +02:00
Akim Demaille 58e79539fc c: don't emit an error message when the scanner returns YYERRCODE
* data/skeletons/yacc.c (yyparse): When the scanner returns YYERRCODE,
go directly to error recovery (yyerrlab1).
However, don't keep the error token as lookahead, that token is too
special.
* data/skeletons/lalr1.cc: Likewise.

* examples/c/bistromathic/parse.y (yylex): Use that feature to report
nicely invalid characters.
* examples/c/bistromathic/bistromathic.test: Check that.
* examples/test: Neutralize gratuitous differences such as rule
position.

* tests/calc.at: Check that case in C only.
The other case seem to be working, but that's an illusion that the
next commit will address (in fact, they can enter endless loops, and
report the error several times anyway).
2020-04-26 18:05:30 +02:00
Akim Demaille 60366b152b examples: bistromathic: demonstrate error recovery
* examples/c/bistromathic/parse.y: here.
* examples/c/bistromathic/bistromathic.test: Check it.
Included a stupid case where the error is actually ignored.
2020-04-26 16:08:47 +02:00
Akim Demaille c90110efd3 examples: bistromathic: when quitting, close the current line
When the user ctrl-d the line, we left the cursor not at col 0.
Let's fix that.
This revealed a few short-comings in the testing framework.

* examples/test (run): Also display the diffs.
And support -n.
* examples/c/bistromathic/bistromathic.test
* examples/c/bistromathic/parse.y
2020-04-26 16:08:47 +02:00
Akim Demaille 3b50adf7f4 examples: bistromathic: comment changes
* examples/c/bistromathic/parse.y: here.
2020-04-26 16:08:47 +02:00
Akim Demaille 3aaa971096 doc: hacking tricks
* README-hacking.md: Here.
2020-04-26 16:08:42 +02:00
Akim Demaille 7eabe1c70b c++: make valid to print the empty symbol
* data/skeletons/lalr1.cc (yy_print_): here.
2020-04-26 15:09:52 +02:00
Akim Demaille 7fec669e42 c++: always define symbol_name
* data/skeletons/lalr1.cc (symbol_name): Always define it, even when
it's actually yytname which is used.
2020-04-26 15:09:52 +02:00
Akim Demaille cbbbe12e02 c++: fix a few style issues
* data/skeletons/lalr1.cc (yystack_print_, yy_reduce_print_): Add
missing const.
(yystack_print_): Rename as...
(yy_stack_print_): this.
* data/skeletons/glr.cc (yy_symbol_value_print_, yy_symbol_print_):
Add missing const.
2020-04-26 15:09:52 +02:00
Akim Demaille 286d0755f8 all: prefer YYERRCODE to YYERROR
We will not keep YYERRCODE anyway, it causes backward compatibility
issues.  So as a first step, let all the skeletons use that name,
until we have a better one.

* data/skeletons/bison.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c, doc/bison.texi, tests/headers.at,
* tests/input.at:
here.
2020-04-26 15:09:51 +02:00
Akim Demaille 1c3d79b871 style: glr.c: clarify
* data/skeletons/glr.c: Make the code a bit clearer.
2020-04-26 14:49:26 +02:00
Akim Demaille 9c72d3c5a8 style: prefer b4_has_translations_if
* data/skeletons/glr.c, data/skeletons/yacc.c: here.
2020-04-26 13:34:30 +02:00
Akim Demaille bc083be055 style: glr.c: fix indentation issue
* data/skeletons/glr.c (yyparse): here.
2020-04-26 10:57:23 +02:00
Akim Demaille 22eeb1ab8a style: fix a few remaining 'type' instead of 'kind'
* data/skeletons/glr.c, data/skeletons/yacc.c (YY_SYMBOL_PRINT):
Here.
2020-04-26 10:57:22 +02:00
Akim Demaille c4dbc1776c skeletons: make the warning about implementation details clearer
* data/skeletons/bison.m4 (b4_disclaimer): Here.
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: Use it.
2020-04-26 10:57:02 +02:00
Akim Demaille b74fc07d21 style: c: fix a few minor issues about indentation of cpp directives
* README-hacking.md: More about cpp.
* data/skeletons/c.m4, data/skeletons/yacc.c: Style changes.
2020-04-25 12:16:57 +02:00
Akim Demaille 3ab12c1036 bench: store in benches/012 rather than in benches/12
* etc/bench.pl.in ($basedir): New.
Format $count with a least three digits.
2020-04-25 11:34:06 +02:00
Akim Demaille 30ce43b2b5 bench: minor improvements
* etc/bench.pl.in: Don't force parse.error=detailed
Use a simpler way to display the pseudo %bison directive.
(&bench_with_gbenchmark): Give details about the compiler.
2020-04-25 11:06:16 +02:00
Akim Demaille 150dc95395 style: clarify #endif
We could try to avoid the weird "#if 1", but then the indentation of
the inner #if would be wrong.  Let' keep it this way.

* data/skeletons/yacc.c: here.
Also, avoid sticking the comment to the directive.
2020-04-25 11:06:16 +02:00
Akim Demaille bb7c4a5508 style: minor fixes
* data/skeletons/bison.m4, doc/bison.texi: Spell check.
* examples/c/bistromathic/parse.y (N_): Remove, now useless.
2020-04-25 08:00:08 +02:00
Akim Demaille 5c9f50b545 examples: bistromathic: shorten token description
* examples/c/bistromathic/parse.y: "number" is enough.
* doc/bison.texi: Likewise.
2020-04-24 19:03:12 +02:00
Akim Demaille b42702d738 examples: bistromathic: demonstrate internationalization
Currently it was only using stubs.  Let's actually translate the
strings using gettext.

* examples/c/bistromathic/local.mk: Define LOCALEDIR, BISON_LOCALEDIR
and link with libintl.
* examples/c/bistromathic/parse.y: Use them.
Remove useless includes.
Take ENABLE_NLS into account.
(error_format_string): New.
(yyreport_syntax_error): Rewrite to rely on a format string, which is
more appropriate for internationalization.
* examples/c/bistromathic/Makefile: We no longer use Flex.
We need readline and intl.

* doc/bison.texi: Point to bistromathic for a better option for
internationalization.
* po/POTFILES.in: Add bistromathic.
2020-04-24 19:03:12 +02:00
Akim Demaille 401e7c5c36 todo: update for YYERRCODE 2020-04-24 19:03:12 +02:00
Akim Demaille 93fec67c46 regen 2020-04-24 08:23:27 +02:00
Akim Demaille 4378e2dc3c diagnostics: fix a typo
* src/complain.c: here.
2020-04-24 08:22:22 +02:00
Akim Demaille 81334eb5a0 c, c++: provide a default definition for N_
In C/C++, N_ is a no-op.  Define it if the user didn't.
Suggested by Frank Heckenbach.
https://lists.gnu.org/r/bug-bison/2020-04/msg00010.html

* src/output.c (prepare_symbol_names): Rename has_translations as
has_translations_flag.
* data/skeletons/bison.m4 (b4_has_translations_if): New.
* data/skeletons/java.m4 (b4_trans): Use it.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
(N_): Provide a default definition.
2020-04-20 07:37:45 +02:00
Akim Demaille df373f1ea1 i18n: also look in src/parse-gram.c
Some strings appears in the generated file only, e.g., translation of
"end of file".  So don't forget to go and see there.
2020-04-19 15:40:12 +02:00
Akim Demaille 9b7e7077dd style: fix comments
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c: here.
2020-04-19 15:40:12 +02:00
Akim Demaille 5ab0086157 tokens: clean up the translation of special symbols
* src/output.c (prepare_symbol_names): Don't play tricks with the
symbols, it's quite too late.
(has_translations): Move to...
* src/symtab.c: here.
(symbols_pack): Use it to enable translation for special symbols.
2020-04-19 15:40:12 +02:00
Akim Demaille 2831bd376f news: fix typo
Reported by Frank Heckenbach.
2020-04-19 08:20:57 +02:00
Akim Demaille 1d0e3ee896 tests: beware of portability issues with wc
On macOS, wc -l always prepends the result with a tab, even when fed
by stdin.  But anyway, we should have used `grep -c -v`, which appears
to be portable according to Autoconf's "Limitations of Usual Tools"
section.
Reported by Denis Excoffier.
https://lists.gnu.org/r/bug-bison/2020-04/msg00009.html

* tests/calc.at (_AT_CHECK_CALC): Use grep's -c instead.
2020-04-19 08:12:31 +02:00
Akim Demaille 0a64b76430 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-18 10:59:05 +02:00
Akim Demaille 0b948b7696 version 3.5.90
* NEWS: Record release date.
2020-04-18 10:41:20 +02:00
Akim Demaille 8b5fb7c4c3 examples: beware of readline on macOS
macOS' version of readline does not repeat stdin on stdout in
non-interactive mode, contrary to the current version of GNU readline.

* examples/test: Add support for strip_prompt.
* examples/c/bistromathic/bistromathic.test (strip_prompt): Set it
when needed.
Early exit when needed.
2020-04-18 10:37:13 +02:00
Akim Demaille d6ae95fb50 c++: give public access to the symbol kind
symbol_type::token () was removed: it returned the token kind of a
symbol.  To do that, one needs to convert from the symbol kind to the
token kind, which requires a table.

This broke some users' unit tests for scanners, see
https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html
https://lists.gnu.org/r/bug-bison/2020-03/msg00020.html
https://lists.gnu.org/r/help-bison/2020-04/msg00005.html

Instead of making this possible again, let's check the symbol's kind
instead.  So give proper access to a symbol's kind.

That feature existed, undocumented, as 'type_get()'.  Let's rename
this as 'kind()'.

* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc (type_get): Rename as...
(kind): This.
(type_get): Install a backward compatibility alias.
* doc/bison.texi (Complete Symbols): Document symbol_type and
symbol_type::kind.
2020-04-18 08:03:59 +02:00
Akim Demaille e86b14069d doc: token_kind_type in C++
* data/skeletons/c++.m4: Define the old names in terms on the new
ones, instead of the converse.
* doc/bison.texi (C++ Parser Interface): Be more extensive about
token_kind_type.
2020-04-17 08:53:37 +02:00
Akim Demaille 5d983253f7 doc: updates for 3.6
* doc/bison.texi: More s/token type/token kind/.
* NEWS: Update.
2020-04-16 08:44:36 +02:00
Akim Demaille caadfc552b skeletons: use symbol(-2, kind)
Not all the symbols have a fixed symbol code.  UNDEF's one is fixed:
-2.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c: here.
2020-04-16 07:35:06 +02:00
Akim Demaille c4c25e091c style: comments changes about error handling
* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: here.
* data/skeletons/lalr1.cc: Reduce scope.
2020-04-16 07:34:37 +02:00
Akim Demaille fc18b4313a examples: bistro: don't be lazy with switch
* examples/c/bistromathic/parse.y (yylex): Use the switch to
discriminate all the cases.
2020-04-14 08:20:05 +02:00
Akim Demaille 758172a8b9 doc: spell check
* doc/bison.texi, NEWS, README-hacking.md: here.
And elsewhere.
2020-04-13 18:50:05 +02:00
Akim Demaille e9454c3456 gnulib: update 2020-04-13 17:47:20 +02:00
Akim Demaille 8f01cf0269 doc: more about the coding style
* README-hacking.md: here.
(Troubleshooting): New.
2020-04-13 17:08:53 +02:00
Akim Demaille dab08da605 java: promote YYEOF rather that Lexer.EOF
* doc/bison.texi: here.
* data/skeletons/lalr1.java: Use YYEOF.
2020-04-13 17:08:53 +02:00
Akim Demaille 8cedb4b40e java: fix names
* data/skeletons/lalr1.java (yySymbolPrint): There are no pointers
here, remove the `p` suffix.
Use the appropriate type for locations.
2020-04-13 17:04:34 +02:00
Akim Demaille 258c2c967f doc: java: SymbolKind, etc.
Why didn't I think about this before???  symbolName should be a method
of SymbolKind.

* data/skeletons/lalr1.java (YYParser::yysymbolName): Move as...
* data/skeletons/java.m4 (SymbolKind::getName): this.
Make the table a static final table, not a local variable.
Adjust dependencies.
* doc/bison.texi (Java Parser Interface): Document i18n.
(Java Parser Context Interface): Document SymbolKind.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-13 16:54:48 +02:00
Akim Demaille 9a33570493 style: java: get closer to the Java style
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
2020-04-13 16:54:14 +02:00
Akim Demaille 42ab6c1e44 doc: c++: document parser::context
* doc/bison.texi (C++ Parser Context): New.

* data/skeletons/lalr1.cc (parser::yysymbol_name): Rename as...
(parser::symbol_name): this.
(A Complete C++ Example): Promote LAC, now that we have it.
Promote parse.error detailed over verbose.
* examples/c++/calc++/calc++.test, tests/local.at: Adjust.
2020-04-13 16:54:14 +02:00
Akim Demaille dc1035bada doc: promote YYEOF
* NEWS (Deep overhaul of the symbol and token kinds): New.
* doc/bison.texi: Promote YYEOF over "0" in scanners.
(Token Decl): No longer show YYEOF here, it now works by default.
(Token I18n): More details about YYEOF here.
(Calc++): Just use YYEOF.
2020-04-13 16:54:14 +02:00
Akim Demaille 71e3f6d4da d: put YYEMPTY in the TokenKind
* data/skeletons/d.m4, data/skeletons/lalr1.d (b4_token_enums): Rename
YYTokenType as TokenKind.
Define YYEMPTY.
* examples/d/calc.y, tests/calc.at, tests/scanner.at: Adjust.
2020-04-13 16:49:54 +02:00
Akim Demaille 3877b7210e regen 2020-04-13 16:49:54 +02:00
Akim Demaille 64aec0a8d8 c, c++: also define YYEMPTY in yytoken_kind_t
I have been hesitating a lot before doing it ---after all the user
must not use this kind, so what's the point of showing it in
yytoken_kind_t.  And eventually I chose to play it safe with the
typing system and make it possible to use yytoken_kind_t for all the
tokens, even the "empty token".

* data/skeletons/c.m4: Give an id and a tag to YYEMPTY.
(b4_token_enums): Define YYEMPTY.
* data/skeletons/c++.m4 (b4_token_enums): Define YYEMPTY.
* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/yacc.c:
(YYEMPTY): Remove.
Use b4_symbol(-2, id) instead.
2020-04-13 16:49:48 +02:00
Akim Demaille 5e2e9af56d doc: use "code", not "number", for token (and symbol) kinds
"Number" is too much about arithmethics.  "Code" conveys better the
"enum" nature of token kinds.  And of symbol kinds.

* doc/bison.texi: Here.
2020-04-12 19:24:44 +02:00
Akim Demaille 7a226860ef doc: promote yytoken_kind_t, not yytokentype
* data/skeletons/c.m4 (yytoken_kind_t): New.
* data/skeletons/c++.m4, data/skeletons/lalr1.cc (yysymbol_kind_type):
New.
* examples/c/lexcalc/parse.y, examples/c/reccalc/parse.y,
* tests/regression.at:
Use them.
* doc/bison.texi: Replace "enum yytokentype" by "yytoken_kind_t".
(api.token.raw): Explain that it forces "yytoken_kind_t" to coincide
with "yysymbol_kind_t".
(Calling Convention): Mention YYEOF.
(Table of Symbols): Add entries for "yytoken_kind_t" and
"yysymbol_kind_t".
(Glossary): Add entries for "Kind", "Token kind" and "Symbol kind".
2020-04-12 19:24:12 +02:00
Akim Demaille c973361138 doc: document yypcontext_t, and api.symbol.prefix
* doc/bison.texi (%define Summary): Document api.symbol.prefix.
(Syntax Error Reporting Function): Document yypcontext_t,
yypcontext_location, yypcontext_token, yypcontext_expected_tokens, and
yysymbol_kind_t.
2020-04-12 19:24:02 +02:00
Akim Demaille 5839f4d289 c: rename yyexpected_tokens as yypcontext_expected_tokens
The user should think of yypcontext fields as accessible only via
yypcontext_* functions.  So let's rename yyexpected_tokens to reflect
that.

Let's _not_ rename yyreport_syntax_error, as the user may define this
function, and is not allowed to access directly the fields of
yypcontext_t: she *must* use the "accessors".  This is comparable to
the case of C++/Java where the user defines
parser::report_syntax_error, not parser::context::report_syntax_error.

* data/skeletons/glr.c, data/skeletons/yacc.c (yyexpected_tokens):
Rename as...
(yypcontext_expected_tokens): this.
Adjust dependencies.
2020-04-12 19:23:40 +02:00
Akim Demaille ffa46e6516 skeletons: clarify the tag of special tokens
From

    GRAM_EOF = 0,                  /* $end  */
    GRAM_ERRCODE = 1,              /* error  */
    GRAM_UNDEF = 2,                /* $undefined  */

to

    GRAM_EOF = 0,                  /* "end of file"  */
    GRAM_ERRCODE = 1,              /* error  */
    GRAM_UNDEF = 2,                /* "invalid token"  */

* src/output.c (symbol_tag): New.
Use it to pass the token names and the symbol tags to the skeletons.

* tests/input.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille ff50f6f223 skeletons: use "invalid token" instead of "$undefined"
* src/output.c (prepare_symbol_names): Also handle undeftoken.
* tests/actions.at, tests/calc.at, tests/regression.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille 05be0fef95 skeletons: make the eof token translatable if i18n is enabled
* src/output.c (has_translations): New.
(prepare_symbol_names): Translate endtoken if the user already
translated tokens.

* examples/c/bistromathic/parse.y, src/parse-gram.y: Simplify.
2020-04-12 13:56:44 +02:00
Akim Demaille 72c9fa4510 skeletons: use "end of file" instead of "$end"
The name "$end" is nice in the report, in particular it avoids that
pointed-rules (aka items) be too long.  It also helps keeping them
"standard".

But it is bad in error messages, we should report "end of file" (or
maybe "end of input", this is debatable).  So, unless the user already
defined the alias for the error token herself, make it "end of file".
It should even be translated if the user already translated some
tokens, so that there is now no strong reason to redefine the $end
token.

* src/output.c (prepare_symbol_names): Issue "end of file" instead of
"$end".

* data/skeletons/lalr1.java (yytnamerr_): Remove the renaming hack.

* build-aux/update-test: Accept files with names containing a "+",
such as c++.at.
* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/glr-regression.at, tests/regression.at, tests/skeletons.at:
Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille a555b41990 diagnostics: replace "user token number" by "token code"
Yet, don't change the structure identifier to avoid introducing
conflicts in Vincent Imbimbo's PR (which, amusingly enough, is about
conflicts).

* src/symtab.c: here.
* tests/diagnostics.at, tests/input.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille ecf5cb7e0e c++: remove the yy prefix from some functions
yy::parser features a parse() function, not a yyparse() one.

* data/skeletons/lalr1.cc (yyreport_syntax_error)
(context::yyexpected_tokens): Rename as...
(report_syntax_error, context::expected_tokens): these.
2020-04-12 13:56:44 +02:00
Akim Demaille e50de09886 tokens: properly define the YYEOF token kind
Currently EOF is handled in an adhoc way, with a #define YYEOF 0 in
the implementation file.  As a result, the user has to define her own
EOF token if she wants to use it, which is a pity.

Give the $end token a visible kind name, YYEOF.  Except that in C,
where enums are not scoped, we would have collisions between all the
definitions of YYEOFs in the header files, so in C, make it
<api.PREFIX>EOF.

* data/skeletons/c.m4 (YYEOF): Override its name to avoid collisions.
Unless the user already gave it a different name.
* data/skeletons/glr.c (YYEOF): Remove.
Use ]b4_symbol(0, [id])[ instead.
Add support for "pre_epilogue", for glr.cc.
* data/skeletons/glr.cc: Remove dead code (never emitted #undefs).
* data/skeletons/yacc.c
* src/parse-gram.c
* src/reader.c
* src/symtab.c
* tests/actions.at
* tests/input.at
2020-04-12 13:56:44 +02:00
Akim Demaille 95421df67b tokens: define the "$undefined" token kind
* data/skeletons/bison.m4 (b4_symbol_token_kind): Give a definition to
$undefined.
(b4_token_visible_if): $undefined has an id.
* src/output.c (prepare_symbol_definitions): Stop lying: $undefined
_is_ a token.
* tests/input.at: Adjust.
2020-04-12 13:56:43 +02:00
Akim Demaille a4ed94bc13 tokens: properly define the "error" token kind
There are people out there that do use YYERRCODE (the token kind of
the error token).  See for instance
https://github.com/borbolla-automation/SPC_Machines/blob/3812012bb782bfdfe7b325950a35cd337925fcad/unixODBC-2.3.2/Drivers/nn/yylex.c.

Currently, YYERRCODE is defined by yacc.c in an adhoc way as a #define
in the *.c file only.  It belongs with the other token kinds.

YYERRCODE is not a nice name, it does not fit in our naming scheme.
YYERROR would be more logical, but it collides with the YYERROR macro.
Shall we keep the same name in all the skeletons?  Besides, to avoid
collisions in C, we need to apply the api prefix: YYERRCODE is
actually <PREFIX>ERRCODE.  This is not needed in the other languages.

* data/skeletons/bison.m4 (b4_symbol_token_kind): New.
Map the error token to "YYERRCODE".
* data/skeletons/yacc.c (YYERRCODE): Don't define it, it's handled by...
* src/output.c (prepare_symbol_definitions): this.
* tests/input.at (Redefining the error token): Check it.
2020-04-12 13:56:43 +02:00
Akim Demaille 07726f1178 tokens: style: minor fixes
* data/skeletons/bison.m4 (b4_symbol_kind): Dispatch on the UNDEF
token number rather than its name.
* data/skeletons/c++.m4, data/skeletons/c.m4, data/skeletons/java.m4:
Comment changes.
2020-04-12 13:56:43 +02:00
Akim Demaille e78596955d glr.cc: remove dead code
* data/skeletons/glr.cc: here.
2020-04-12 13:56:43 +02:00
Akim Demaille ecd5cae2d4 c++: fix generated headers
A forthcoming commit (tokens: properly define the "error" token kind)
revealed a problem in the C++ generated headers: they are not
self-contained.  With this file:

    %language "c++"
    %define api.value.type variant

    %code {
      static int yylex (yy::parser::semantic_type *lvalp);
    }

    %token <int> X

    %%

    exp:
      X { printf ("x\n"); }
    ;

    %%

    void
    yy::parser::error (const std::string& m)
    {
      std::cerr << m << '\n';
    }

    static
    int yylex (yy::parser::semantic_type *lvalp)
    {
      static int const input[] = {yy::parser::token::X, 0};
      static int toknum = 0;
      return input[toknum++];
    }

    int
    main (int argc, char const* argv[])
    {
      yy::parser p;
      return p.parse ();
    }

the generated header fails to compile cleanly (foo.cc just #includes
the generated header):

    $ clang++-mp-9.0 -c -Wundefined-func-template foo.cc
    In file included from foo.cc:1:
    bar.tab.hh:550:12: warning: instantiation of function 'yy::parser::basic_symbol<yy::parser::by_type>::basic_symbol' required here, but no definition is available
          [-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    bar.tab.hh:436:7: note: forward declaration of template entity is here
          basic_symbol (basic_symbol&& that);
          ^
    bar.tab.hh:550:12: note: add an explicit instantiation declaration to suppress this warning if 'yy::parser::basic_symbol<yy::parser::by_type>::basic_symbol' is explicitly instantiated
          in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 warning generated.

* data/skeletons/c++.m4 (b4_public_types_define): Move the
implementation of the basic_symbol move-ctor to...
(b4_public_types_define): here, its declaration.
* tests/headers.at (Sane headers): Use a declared token so that the
corresponding token constructor is declared.  Which triggers the
aforementioned issue.
2020-04-12 13:56:21 +02:00
Akim Demaille 8dcc25a1e4 style: rename YYNOMEM as YYENOMEM
This is clearer.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): Rename as...
(YYENOMEM): here.
2020-04-10 18:35:29 +02:00
Akim Demaille 1a5f74d2f6 todo: update 2020-04-10 18:35:29 +02:00
Akim Demaille 00a654c8ad c++: improvements on symbol kinds
Instead of

    /// (Internal) symbol kind.
    enum symbol_kind_type
    {
      YYNTOKENS = 5, ///< Number of tokens.
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      // END_OF_FILE
      YYSYMBOL_YYERROR = 1,                    // error
      YYSYMBOL_YYUNDEF = 2,                    // $undefined
      YYSYMBOL_TEXT = 3,                       // TEXT
      YYSYMBOL_NUMBER = 4,                     // NUMBER
      YYSYMBOL_YYACCEPT = 5,                   // $accept
      YYSYMBOL_result = 6,                     // result
      YYSYMBOL_list = 7,                       // list
      YYSYMBOL_item = 8                        // item
    };

generate

    /// Symbol kinds.
    struct symbol_kind
    {
      enum symbol_kind_type
      {
        YYNTOKENS = 5, ///< Number of tokens.
        S_YYEMPTY = -2,
        S_YYEOF = 0,                             // END_OF_FILE
        S_YYERROR = 1,                           // error
        S_YYUNDEF = 2,                           // $undefined
        S_TEXT = 3,                              // TEXT
        S_NUMBER = 4,                            // NUMBER
        S_YYACCEPT = 5,                          // $accept
        S_result = 6,                            // result
        S_list = 7,                              // list
        S_item = 8                               // item
      };
    };

* data/skeletons/c++.m4 (api.symbol.prefix): Define to S_.
Adjust all the uses.
(b4_public_types_declare): Nest the enum inside 'struct symbol_kind'.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* tests/headers.at, tests/local.at: Adjust.
2020-04-10 18:35:29 +02:00
Akim Demaille 6c5f690da4 d: improvements on symbol kinds
public enum SymbolKind
    {
      S_YYEMPTY = -2,    /* No symbol.  */
      S_YYEOF = 0,       /* $end  */
      S_YYERROR = 1,     /* error  */
      S_YYUNDEF = 2,     /* $undefined  */
      S_EQ = 3,          /* "="  */

* data/skeletons/d.m4 (api.symbol.prefix): Default to S_.
Output the symbol kind definitions with a comment.
2020-04-10 18:35:29 +02:00
Akim Demaille 007e1b5f0a symbols: minor fixes
* data/skeletons/bison.m4 (b4_symbol_kind): Series of _ are useless,
one is enough.
* data/skeletons/c.m4 (b4_token_enum): Fix overquoting.
2020-04-10 18:33:02 +02:00
Akim Demaille bbb9750b3e skeletons: introduce api.symbol.prefix
* data/skeletons/bison.m4 (b4_symbol_prefix): New.
(b4_symbol_kind): Use it.
* data/skeletons/c++.m4, data/skeletons/c.m4, data/skeletons/d.m4
* data/skeletons/java.m4 (api.symbol.prefix): Provide a default value.

* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java, data/skeletons/yacc.c:
Adjust: use b4_symbol_prefix instead of YYSYMBOL_.
2020-04-07 08:40:16 +02:00
Akim Demaille 52d0e77c2c java: also emit documenting comments for symbol kinds
* data/skeletons/java.m4 (b4_symbol_enum): here.
And stop defined YYSYMBOL_YYEMPTY, we no longer use it.
2020-04-07 08:39:54 +02:00
Akim Demaille 088d5668a9 todo: update
* TODO (YYERRCODE): Remove, handled by YYSYMBOL_ERROR.
2020-04-06 19:20:02 +02:00
Akim Demaille 87579e03e0 skeletons: beware not to use yyarg when it's null
Reported by Adrian Vogelsgesang.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Here.
2020-04-06 19:14:11 +02:00
Akim Demaille 11225a5d2f java: document new features
* data/skeletons/lalr1.java: More comments.
(Context.EMPTY): Remove.
* doc/bison.texi (Java Parser Context Interface): New.
2020-04-06 19:14:11 +02:00
Akim Demaille 3dcfb4fd88 java: prefer null to YYSYMBOL_YYEMPTY
That's one nice benefit from using enums.

* data/skeletons/lalr1.java (YYSYMBOL_YYEMPTY): No longer define it.
Use 'null' instead.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:11 +02:00
Akim Demaille c0ccb8e5b4 java: rename Lexer.yyreportSyntaxError as reportSyntaxError
* data/skeletons/lalr1.java: here.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:06 +02:00
Akim Demaille 79f967ac0d java: use getExpectedTokens, not yyexpectedTokens
* data/skeletons/lalr1.java, examples/java/calc/Calc.y, tests/local.at:
here.
2020-04-06 18:43:34 +02:00
Akim Demaille 0f6ab8e692 java: style: fix coding style
* data/skeletons/java.m4: Indent by two.
* data/skeletons/lalr1.java (yynnts_): Remove.
(yyfinal_, yyntokens_, yylast_, yyempty_): Rename as...
(YYFINAL_, YYNTOKENS_, YYLAST_, YYEMPTY_): these, they are constants.
2020-04-06 18:43:34 +02:00
Akim Demaille e657f04b62 c: make the symbol kind definition nicer to read
From

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,
      YYSYMBOL_YYERROR = 1,
      YYSYMBOL_YYUNDEF = 2,

to

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
      YYSYMBOL_YYERROR = 1,                    /* error  */
      YYSYMBOL_YYUNDEF = 2,                    /* $undefined  */

* data/skeletons/bison.m4 (b4_last_symbol): New.
(b4_symbol_enum, b4_symbol_enums): Reformat the output.
* data/skeletons/c.m4
2020-04-06 18:43:34 +02:00
Akim Demaille 10e61eec6d c: make the token kind definition nicer to read
From

    enum gram_tokentype
    {
      GRAM_EOF = 0,
      STRING = 3,
      TSTRING = 4,
      PERCENT_TOKEN = 5,

To

    enum gram_tokentype
    {
      GRAM_EOF = 0,                  /* "end of file"  */
      STRING = 3,                    /* "string"  */
      TSTRING = 4,                   /* "translatable string"  */
      PERCENT_TOKEN = 5,             /* "%token"  */

* data/skeletons/bison.m4 (b4_last_enum_token): New.
* data/skeletons/c.m4 (b4_token_enum, b4_token_enums): Show the
corresponding symbol.
2020-04-06 18:43:34 +02:00
Akim Demaille 149e280aab c: make the generated YYSTYPE nicer to read
From

    union GRAM_STYPE
    {
      /* precedence_declarator  */
      assoc precedence_declarator;
      /* "string"  */
      char* STRING;
      /* "translatable string"  */
      char* TSTRING;
      /* "{...}"  */
      char* BRACED_CODE;
      /* "%?{...}"  */

to

    union GRAM_STYPE
    {
      assoc precedence_declarator;             /* precedence_declarator  */
      char* STRING;                            /* "string"  */
      char* TSTRING;                           /* "translatable string"  */
      char* BRACED_CODE;                       /* "{...}"  */

* data/skeletons/c.m4 (b4_symbol_type_register): Use m4_format to
align the comments.
* src/parse-gram.h: Regen.
2020-04-06 18:43:34 +02:00
Akim Demaille e9fddab715 regen 2020-04-05 19:14:39 +02:00
Akim Demaille cc68bbf799 bison: use consistently "token kind", not "token type"
* src/output.c, src/reader.c, src/scan-gram.l, src/tables.c: here.
2020-04-05 19:14:39 +02:00
Akim Demaille f0bb82ae9e skeletons: use consistently "kind" instead of "type" in the code
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java:
Refer to the "kind" of a symbol, not its "type", where appropriate.
2020-04-05 19:14:39 +02:00
Akim Demaille 04d62346f3 doc: refer to the token kind rather than the token type
* doc/bison.texi: Replace occurrences of "token type" with "token
kind".
Stop referring to the "macro definitions" of the token kinds, just
name them "definitions".
2020-04-05 19:14:39 +02:00
Akim Demaille 9b70d69f39 m4: we don't need undef_token_number
It's replaced by YYSYMBOL_YYUNDEF.
2020-04-05 14:56:19 +02:00
Akim Demaille 2b7bde9d13 m4: rename b4_symbol_sid as b4_symbol_kind
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/d.m4, data/skeletons/java.m4
(b4_symbol_sid): Rename as...
(b4_symbol_kind): this.
Adjust dependencies.
* data/README.md: Document the kind.
2020-04-05 14:56:19 +02:00
Akim Demaille ff2fc62138 d, java: rename SymbolType as SymbolKind
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html.

* data/skeletons/d.m4, data/skeletons/lalr1.d,
* data/skeletons/java.m4, data/skeletons/lalr1.java
(SymbolType): Rename as...
(SymbolKind): this.
Adjust dependencies.
2020-04-05 14:56:19 +02:00
Akim Demaille 2c05fc750a c, c++: rename yysymbol_type_t as yysymbol_kind_t
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/yacc.c
(yysymbol_type_t): Rename as...
(yysymbol_kind_t): this.
Adjust dependencies.
* data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/lalr1.cc
(symbol_type_type): Rename as...
(symbol_kind_type): this.
Adjust dependencies.
2020-04-05 14:56:18 +02:00
Akim Demaille 57bc3c9013 doc: remove obsolete release instructions
* README-hacking.md: here.
2020-04-05 14:49:46 +02:00
Akim Demaille 7aee4586ca Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.4
  examples: reccalc: really compile cleanly in C99
  news: announce that Bison 3.6 drops YYERROR_VERBOSE
  news: update for 3.5.4
  style: fix spellos
  typo: succesful -> successful
  package: improve the readme
  java: check and fix support for api.token.raw
  java: style: prefer 'int[] foo' to 'int foo[]'
  build: fix syntax-check issues
  tests: recheck: work properly when the test suite was interrupted
  doc: c++: promote api.token.raw
  build: fix compatibility with old compilers
  examples: reccalc: compile cleanly in C99
2020-04-05 09:38:15 +02:00
Akim Demaille 6c44f2dce3 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-05 09:27:36 +02:00
Akim Demaille 5604903f7a version 3.5.4
* NEWS: Record release date.
2020-04-05 09:08:30 +02:00
Akim Demaille 225a67321b news: update the yyreport_syntax_error example
* examples/c/bistromathic/parse.y, tests/local.at
(yyreport_syntax_error): Fix use of YYSYMBOL_YYEMPTY.
* NEWS: Update.
2020-04-05 08:56:23 +02:00
Akim Demaille 4e3c06b0f8 todo: update 2020-04-05 08:56:23 +02:00
Akim Demaille 4e26809ab9 style: rename yysyntax_error_arguments as yy_syntax_error_arguments
It's a private implementation detail.

* NEWS, data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, doc/bison.texi: here.
2020-04-05 08:56:21 +02:00
Akim Demaille 678853da7e examples: reccalc: really compile cleanly in C99
The previous fix does not suffice, and actually managed to make things
worse by defining yyscan_t twice in parse.y...

Reported by kencu.
https://trac.macports.org/ticket/59927#comment:29

* examples/c/reccalc/parse.y (yyscan_t): Define it with the same
guards as used by Flex.
2020-04-05 08:34:40 +02:00
Akim Demaille 76e11b5a3e c: rename yyparse_context_t as yypcontext_t
The first name is too long.  We already have `yypstate`, so
`yypcontext` is ok.  We are also migrating to using `*_t` for our
types.

* NEWS, data/skeletons/glr.c, data/skeletons/yacc.c, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/parse-gram.y, tests/local.at:
(yyparse_context_t, yyparse_context_location, yyparse_context_token):
Rename as...
(yypcontext_t, yypcontext_location, yypcontext_token): these.
2020-04-04 19:20:29 +02:00
Akim Demaille f9c73eec5f readme: more about the coding style 2020-04-04 19:20:29 +02:00
Akim Demaille f6dcecb287 java: fixes in SymbolType
Reported by Paolo Bonzini.
https://github.com/akimd/bison/pull/34#issuecomment-609029634

* data/skeletons/java.m4 (SymbolType): Use 'final' where possible.
(get): Rewrite on top of an array instead of a switch.
2020-04-04 17:11:02 +02:00
Akim Demaille ad31c3cdf4 java: use SymbolType
The Java enums are very different from the C model.  As a consequence,
one cannot "build" an enum directly from an integer, we must retrieve
it.  That's the purpose of the SymbolType.get class method.

* data/skeletons/java.m4 (b4_symbol_enum, b4_case_code_symbol)
(b4_declare_symbol_enum): New.
* data/skeletons/lalr1.java: Use SymbolType,
SymbolType.YYSYMBOL_YYEMPTY, etc.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille 7fa23136ca examples: java: use explicit token identifiers
* examples/java/calc/Calc.y: Declare all the tokens, so that we are
compatibile with api.token.raw.
* examples/java/calc/Calc.test: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille 961ea2ac85 news: announce that Bison 3.6 drops YYERROR_VERBOSE
* NEWS: here.
2020-04-04 14:52:58 +02:00
Akim Demaille cc6e5cf854 news: update for 3.5.4 2020-04-04 10:56:47 +02:00
Akim Demaille 1376a7c6e2 style: fix spellos
* src/complain.c, src/print.c, src/print-xml.c, src/symtab.h: here.
2020-04-04 10:56:47 +02:00
Adrian VogelsgesangandAkim Demaille 1c273826d4 typo: succesful -> successful
* tests/calc.at: Here.
2020-04-04 10:56:47 +02:00
Akim Demaille 4a55a5ea9a package: improve the readme
* README: Describe what Bison is.
2020-04-04 10:56:46 +02:00
Akim Demaille 72f04ca80f java: check and fix support for api.token.raw
* tests/local.at (AT_LANG_MATCH, AT_YYERROR_DECLARE(java))
(AT_YYERROR_DECLARE_EXTERN(java), AT_PARSER_CLASS): New.
(AT_MAIN_DEFINE(java)): Use AT_PARSER_CLASS.
* tests/scanner.at: Add a test for Java.
* data/skeletons/lalr1.java (yytranslate_): Cast the result.
2020-04-04 10:34:53 +02:00
Akim Demaille fd98afaf10 d: use the SymbolType enum for symbol kinds
* data/skeletons/d.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/lalr1.d: Use them.
Use SymbolType, SymbolType.YYSYMBOL_YYEMPTY etc. where appropriate.
(undef_token_, token_number_type, yy_error_token_): Remove.
2020-04-04 10:31:50 +02:00
Akim Demaille cca8c73431 java: style: prefer 'int[] foo' to 'int foo[]'
* data/skeletons/java.m4 (b4_typed_parser_table_define): Here.
2020-04-04 08:08:07 +02:00
Akim Demaille cb40f5c624 build: fix syntax-check issues
* src/system.h, tests/local.mk: Fix indentation.
2020-04-04 08:04:11 +02:00
Akim Demaille 6c23b012b9 tests: recheck: work properly when the test suite was interrupted
* tests/local.mk (recheck): Look at the per-test logs, not the overall
log, which, when interrupted, contains only information about... the
tests that passed.
2020-04-02 07:32:48 +02:00
Akim Demaille ef88dfba81 doc: c++: promote api.token.raw
* doc/bison.texi (Calc++ Parser): Here.
2020-04-02 07:32:01 +02:00
Akim Demaille 6e89bc0fd2 build: fix compatibility with old compilers
GCC 4.2 dies with

    src/InadequacyList.c: In function 'InadequacyList__new_conflict':
    src/InadequacyList.c:37: error: #pragma GCC diagnostic not allowed inside functions
    src/InadequacyList.c:37: error: #pragma GCC diagnostic not allowed inside functions
    src/InadequacyList.c:40: error: #pragma GCC diagnostic not allowed inside functions

Reported by Evan Lavelle.
See https://lists.gnu.org/r/bug-bison/2020-03/msg00021.html
and https://trac.macports.org/ticket/59927.

* src/system.h (GCC_VERSION): New.
Use it to control IGNORE_TYPE_LIMITS_BEGIN and
IGNORE_TYPE_LIMITS_END.
2020-04-02 07:16:44 +02:00
Akim Demaille e3e21cc0d8 examples: reccalc: compile cleanly in C99
See https://trac.macports.org/ticket/59927.

* examples/c/reccalc/parse.y: C99 does not allow multiple typedefs.
2020-04-02 07:14:19 +02:00
Akim Demaille a0ee2a7543 c++: replace symbol_number_type with symbol_type_type
* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc: here.
2020-04-01 08:32:58 +02:00
Akim Demaille 7e28dbea11 c++: also use symbol_type_type
Because of the insane current implementation of glr.cc, things are a
bit nasty.  We will rename symbol_number_type as symbol_type_type
later, to keep this commit small.

* data/skeletons/c++.m4 (b4_declare_symbol_enum): New.
Also define YYNTOKENS to avoid type clashes when yyntokens_ was
actually defined in another enum.
Use it.
(symbol_number_type): Be an alias of symbol_type_type.
Use YYSYMBOL_YYEMPTY and the like.
Use symbol_number_type where appropriate.
(empty_symbol): Remove.
(yytranslate_): Use symbol_number_type, not token_number_type.
* data/skeletons/lalr1.cc: Use symbol_number_type where appropriate.
Adjust to the replacement of empty_symbol by YYSYMBOL_YYEMPTY.
(yy_error_token_, yy_undef_token_, yyeof_, yyntokens_): Remove.
Adjust dependencies.

* data/skeletons/glr.cc: Use symbol_number_type where appropriate.
Forward definitions of YYSYMBOL_YYEMPTY, etc. to glr.c.

* tests/headers.at: Accept YYNTOKENS and other YYSYMBOL_*.
* tests/local.at (AT_YYERROR_DEFINE(c++)): Use symbol_number_type.
2020-04-01 08:32:50 +02:00
Akim Demaille 65df8d6747 glr.c: remove the yySymbol alias
* data/skeletons/glr.c: Use yysymbol_type_t only.
2020-04-01 08:31:48 +02:00
Akim Demaille beea39b2ec regen 2020-04-01 08:31:48 +02:00
Akim Demaille 086506bf23 glr.c, yacc.c: propagate yysymbol_type_t
Now that yacc.c and glr.c both know yysymbol_type_t, convert the
common routines.

* data/skeletons/c.m4 (yydestruct, yy_symbol_value_print)
(yy_symbol_print): Use yysymbol_type_t instead of int.
* data/skeletons/glr.c: Use yySymbol where appropriate.
* data/skeletons/yacc.c (YY_ACCESSING_SYMBOL): New wrapper around
yystos.
Use it.
* tests/local.at (yyreport_syntax_error): Use yysymbol_type_t where
appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille 39792f57fb glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc.
Apply the same changes as in yacc.c.  Now yySymbol and yysymbol_type_t
are aliases.  We will remove the former later, to avoid cluttering
this commit.

* data/skeletons/glr.c: Use b4_declare_symbol_enum.
Use YYSYMBOL_YYEOF etc. where appropriate.
(YYUNDEFTOK, YYTERROR): Remove.
(YYTRANSLATE, yySymbol, yyexpected_tokens, yysyntax_error_arguments):
Adjust.
(yy_accessing_symbol): New.
Use it where appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille 65bbaf9598 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 9039c571f4 yacc.c: fix more errors from make maintainer-check-g++
* data/skeletons/yacc.c (yyexpected_tokens): Use casts where needed.
2020-04-01 08:31:48 +02:00
Akim Demaille d3db22d788 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 9434571f95 yacc.c: revert to not using yysymbol_type_t in the yytranslate table
This triggers warnings with several compilers.  For instance ICC fills
the logs with pages and pages of

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
             ^

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
                    ^

And so does G++9 when compiling yacc.c's (C) output

    input.c:545:8: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |        ^
          |        |
          |        int
    input.c:545:15: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |               ^
          |               |
          |               int

Clang++ is no exception

    input.c:545:8: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
           ^
    input.c:545:15: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
                  ^

At some point we could use yysymbol_type_t's enumerators to define
yytranslate.  Meanwhile...

* data/skeletons/yacc.c (yytranslate): Use the original integral type
to define it.
(YYTRANSLATE): Cast the result into yysymbol_type_t.
2020-04-01 08:31:48 +02:00
Akim Demaille 0cdbcee0ce regen 2020-04-01 08:31:48 +02:00
Akim Demaille fd37eb057e yysymbol_type_t: always assign an enumerator
Currently we define enumerators only for symbols that have an
identifier.  That rules out tokens such as '+', and nonterminals such
as foo-bar and foo.bar.  As a consequence we are taking chances: the
compiler might compile yysymbol_type_t as too small an integral type
for some symbol codes.

* data/skeletons/bison.m4 (b4_symbol_sid): Forge a unique symbol
identifier for symbols that don't have an ID.
2020-04-01 08:31:48 +02:00
Akim Demaille ecc3a13c34 bistromathic: use symbol numbers instead of YYTRANSLATE
* examples/c/bistromathic/parse.y: here.
2020-04-01 08:31:48 +02:00
Akim Demaille 04904e4d28 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 75a605454d yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error
* data/skeletons/bison.m4 (b4_symbol_sid): Map "error" to YYSYMBOL_YYERROR.
* data/skeletons/yacc.c: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille d7f39ac507 regen 2020-04-01 08:31:48 +02:00
Akim Demaille f3c18c8e80 yacc.c: also define a symbol number for the empty token
This is not only cleaner, it also protects us from mixing signed
values (YYEMPTY is #defined as -2) with unsigned types (the
yysymbol_type_t enum is typically compiled as a small unsigned).
For instance GCC 9:

    input.c: In function 'yyparse':
    input.c:1107:7: error: conversion to 'unsigned int' from 'int'
                           may change the sign of the result
                           [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |       ^~
    input.c:1107:10: error: conversion to 'int' from 'unsigned int'
                            may change the sign of the result
                            [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |          ^~~~~~~
    input.c:1108:47: error: comparison of integer expressions of
                            different signedness:
                            'yytype_int8' {aka 'const signed char'} and
                            'yysymbol_type_t' {aka 'enum yysymbol_type_t'}
                            [-Werror=sign-compare]
     1108 |   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
          |                                               ^~
    input.c:702:25: error: operand of ?: changes signedness from 'int'
                           to 'unsigned int' due to unsignedness of
                           other operand [-Werror=sign-compare]
      702 | #define YYEMPTY         (-2)
          |                         ^~~~
    input.c:1220:33: note: in expansion of macro 'YYEMPTY'
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                 ^~~~~~~
    input.c:1220:41: error: unsigned conversion from 'int' to
                            'unsigned int' changes value
                            from '-2' to '4294967294'
                            [-Werror=sign-conversion]
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                         ^

Eventually, it might be interesting to move away from -2 (which is the
only possible negative symbol number) and use the next available
number, to save bits.  We could actually even simply use "0" and shift
the rest, which would allow to write "!yytoken" to mean really
"yytoken != YYEMPTY".

* data/skeletons/c.m4 (b4_declare_symbol_enum): Define YYSYMBOL_YYEMPTY.
* data/skeletons/yacc.c: Use it.

* src/parse-gram.y (yyreport_syntax_error): Use YYSYMBOL_YYEMPTY, not
YYEMPTY, when dealing with a symbol.

* tests/regression.at: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille 00c80bc96c yacc.c: use yysymbol_type_t instead of int for yytoken
Now that we have a proper type for internal symbol numbers, let's use
it.  More code needs conversion, e.g., printers and destructors, but
they are shared with glr.c, which is not ready yet for this change.

It will also help us deal with warnings such as (GCC9 on GNU/Linux):

    input.c: In function 'int yyparse()':
    input.c:475:37: error: enumeral and non-enumeral type in conditional expression [-Werror=extra]
      475 |   (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF)
          |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    input.c:1024:17: note: in expansion of macro 'YYTRANSLATE'
     1024 |       yytoken = YYTRANSLATE (yychar);
          |                 ^~~~~~~~~~~

* data/skeletons/yacc.c (yytranslate, yysymbol_name)
(yyparse_context_t, yyexpected_tokens, yypstate_expected_tokens)
(yysyntax_error_arguments):
Use yysymbol_type_t instead of int.
2020-04-01 08:31:48 +02:00
Akim Demaille f62f1db298 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 3ba001baac yacc.c: introduce an enum that defines the symbol's number
There's a number of advantage in exposing the symbol (internal)
numbers:

- custom error messages can use them to decide how to represent a
  given symbol, or a set of symbols.

- we need something similar in uses of yyexpected_tokens.  For
  instance, currently, bistromathic's completion() reads:

    int ntokens = expected_tokens (line, tokens, YYNTOKENS);
    [...]
    for (int i = 0; i < ntokens; ++i)
      if (tokens[i] == YYTRANSLATE (TOK_VAR))
      [...]
      else if (tokens[i] == YYTRANSLATE (TOK_FUN))
      [...]
      else
      [...]

- now that it's a compile-time expression, we can easily build static
  tables, switch, etc.

- some users depended on the ability to get the token number from a
  symbol to write test cases for their scanners.  But Bison 3.5
  removed the table this feature depended upon (a reverse
  yytranslate).  Now they can check against the actual symbol number,
  without having pay (space and time) a conversion.
  See https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html, and
  https://lists.gnu.org/archive/html/bug-bison/2020-03/msg00015.html.

- it helps us clearly separate the internal symbol numbers from the
  external token numbers, whose difference is sometimes blurred in the
  code when values coincide (e.g. "yychar = yytoken = YYEOF").

- it allows us to get rid of ugly macros with inconsistent names such
  as YYUNDEFTOK and YYTERROR, and to group related definitions
  together.

- similarly it provides a clean access to the $accept symbol (which
  proves convenient in a current experimentation of mine with several
  %start symbols).

Let's declare this type as a private type (in the *.c file, not
the *.h one).  So it does not need to be influenced by the api prefix.

* data/skeletons/bison.m4 (b4_symbol_sid): New.
(b4_symbol): Use it.
* data/skeletons/c.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/yacc.c: Use b4_declare_symbol_enum.
(YYUNDEFTOK, YYTERROR): Remove.
Use the corresponding symbol enum instead.
2020-04-01 08:31:33 +02:00
Akim Demaille 4140320a0a style: comment changes about token numbers
* data/skeletons/bison.m4, data/skeletons/c.m4: here.
2020-03-30 08:41:12 +02:00
Akim Demaille af19fd7e0f tests: recheck: work properly when the test suite was interrupted
* tests/local.mk (recheck): Look at the per-test logs, not the overall
log, which, when interrupted, contains only information about... the
tests that passed.
2020-03-30 08:41:12 +02:00
Akim Demaille 2c74872991 java: move away from _ for internationalization
The "_" is becoming a keyword in Java, which causes tons of warnings
currently in our test suite.  GNU Gettext is now using "i18n" instead
of "_"
(https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=e89fea36545f27487d9652a13e6a0adbea1117d0).

* data/skeletons/java.m4: Use "i18n", not "_".
* examples/java/calc/Calc.y, tests/calc.at: Adjust.
2020-03-30 08:03:10 +02:00
Akim Demaille 50517d578c regen 2020-03-28 15:13:27 +01:00
Akim Demaille 59d820d1ef c: use YYNOMEM instead of -2
See 84b1972c96.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): New.
Use it.
2020-03-28 15:13:27 +01:00
Akim Demaille 90f0500ef8 todo: update
* TODO (Token Number): We have to clean this.
(Naming conventions, Symbol numbers): New.
(Bad styling): Addressed in e21ff47f5d.
2020-03-28 15:13:27 +01:00
Akim Demaille 17a9542c4f regen 2020-03-28 15:13:27 +01:00
Akim Demaille b7045aa706 java: make yysyntaxErrorArguments a private detail
* data/skeletons/lalr1.java (yysyntaxErrorArguments): Move it from the
context, to the parser object.
Generate only for detailed and verbose error messages.
* tests/local.at (AT_YYERROR_DEFINE(java)): Use yyexpectedTokens
instead.
2020-03-28 15:13:27 +01:00
Akim Demaille ee56b6e0f2 skeletons: make yysyntax_error_arguments a private detail
We could just "inline yysyntax_error_arguments back" in the routines
it was originally extracted from, but I think the code is nicer to
read this way.

* data/skeletons/glr.c (yysyntax_error_arguments): Generate only for
detailed and verbose error messages.
* data/skeletons/yacc.c: Likewise.
* data/skeletons/lalr1.cc (parser::context::yysyntax_error_arguments):
Move as...
(parser::yysyntax_error_arguments_): this.
And only for detailed and verbose error messages.
2020-03-28 15:13:27 +01:00
Akim Demaille 1edc98f793 lalr1.cc: avoid using yysyntax_error_arguments
* data/skeletons/lalr1.cc (context::token): New.
* tests/local.at (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
2020-03-28 15:13:27 +01:00
Akim Demaille 4192de1f41 bison: avoid using yysyntax_error_arguments
* src/parse-gram.y (yyreport_syntax_error): Use yyparse_context_token
and yyexpected_tokens.
2020-03-28 15:13:27 +01:00
Akim Demaille 00b0d02955 tests: yacc.c: avoid yysyntax_error_arguments
Because glr.c shares the same testing routines, we also need to
convert it.

* data/skeletons/glr.c (yyparse_context_token): New.
* tests/local.at (yyreport_syntax_error): here.
2020-03-28 15:13:27 +01:00
Akim Demaille 1045c8d0ef examples: don't use yysyntax_error_arguments
Suggested by Adrian Vogelsgesang.
https://lists.gnu.org/archive/html/bison-patches/2020-02/msg00069.html

* data/skeletons/lalr1.java (Context.EMPTY, Context.getToken): New.
(Context.yyntokens): Rename as...
(Context.NTOKENS): this.
Because (i) all the Java coding styles recommend upper case for
constants, and (ii) the Java Skeleton exposes Lexer.EOF, not
Lexer.YYEOF.
* data/skeletons/yacc.c (yyparse_context_token): New.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
* examples/java/calc/Calc.y (yyreportSyntaxError): Likewise.
2020-03-28 15:13:27 +01:00
Akim Demaille ef8965b5f5 skeletons: fix incorrect type for translatable tokens
* data/skeletons/glr.c, data/skeletons/lalr1.c, data/skeletons/yacc.c:
Fix confusion between the "translatable" and the "translate" tables.
2020-03-28 15:13:27 +01:00
Akim Demaille 84b1972c96 yacc.c: use negative numbers for errors in auxiliary functions
yyparse returns 0, 1, 2 since ages (accept, reject, memory exhausted).
Some of our auxiliary functions such as yy_lac and
yyreport_syntax_error also need to return error codes and also use 0,
1, 2.  Because it uses yy_lac, yyexpected_tokens also needs to return
"problem", "memory exhausted", but in case of success, it needs to
return the number of tokens, so it cannot use 1 and 2 as error code.
Currently it uses -1 and -2, which is later converted into 1 and 2 as
yacc.c expects it.

Let's simplify this and use consistently -1 and -2 for auxiliary
functions that are not exposed (or not yet exposed) to the user.  In
particular this will save the user from having to convert
yyexpected_tokens's -2 into yyreport_syntax_error's 2: both return -1
or -2.

* data/skeletons/yacc.c (yy_lac, yyreport_syntax_error)
(yy_lac_stack_realloc): Return -1, -2 for errors instead of 1, 2.
Adjust callers.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Do take
error codes into account.
Issue a syntax error message even if we ran out of memory.
* src/parse-gram.y, tests/local.at (yyreport_syntax_error): Adjust.
2020-03-23 07:02:36 +01:00
Akim Demaille 1079595b2a style: reduce length of private constant
* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
(YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(YYARGS_MAX): this.
* src/parse-gram.y (YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(ARGS_MAX): this.
2020-03-23 07:02:34 +01:00
Akim Demaille e364bcdbc5 doc: c++: promote api.token.raw
* doc/bison.texi (Calc++ Parser): Here.
2020-03-23 07:02:32 +01:00
Akim Demaille 5a8db8a739 bench: calc: no need for super long inputs
* etc/bench.pl.in ($iterations): Restore initial value, -1, meaning
"at least one second".
($calc_input): There is no need to generate 400 lines.
2020-03-22 15:59:22 +01:00
Akim Demaille 5acc29041e bench: calc: work on a string instead of a file
The cost of the file layer is large and makes benchmarks too coarse,
as seen for in following example, first with a file, then with a
literal string:

    0. %skeleton "yacc.c" %define parse.lac full
    1. %skeleton "yacc-v1.c" %define nofinal %define parse.lac full
    2. %skeleton "yacc-v2.c" %define nofinal %define parse.lac full
    3. %skeleton "yacc-v3.c" %define nofinal %define parse.lac full
    4. %skeleton "yacc.c"
    5. %skeleton "yacc-v1.c" %define nofinal
    6. %skeleton "yacc-v2.c" %define nofinal
    7. %skeleton "yacc-v3.c" %define nofinal
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0           32558 ns      32537 ns      21228
    BM_y1           32400 ns      32369 ns      21233
    BM_y2           33485 ns      33464 ns      20625
    BM_y3           32139 ns      32125 ns      21446
    BM_y4           31343 ns      31329 ns      21747
    BM_y5           31344 ns      31317 ns      22035
    BM_y6           31287 ns      31255 ns      22039
    BM_y7           31387 ns      31373 ns      22178
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0           10642 ns      10634 ns      63601
    BM_y1           10657 ns      10654 ns      63625
    BM_y2           10441 ns      10432 ns      65957
    BM_y3           10558 ns      10554 ns      64546
    BM_y4            9521 ns       9516 ns      72011
    BM_y5            9179 ns       9157 ns      75028
    BM_y6            9360 ns       9356 ns      73770
    BM_y7            9365 ns       9359 ns      72609

Of course, at the same time it is less realistic: most users read
files rather that strings, so it might lead to us to pay attention to
costs most people don't see.

* etc/bench.pl.in (&calc_input): Output into a file given as argument.
Output in C syntax.
(&generate_grammar_calc): Use it.
Simplify the grammar: remove operators we don't care about.
Rewrite the scanner to work on a char* instead of a FILE*.
2020-03-22 15:59:22 +01:00
Akim Demaille 5b0b0a1e08 bench: add a "latest" symlink
* etc/bench.pl.in: here.
2020-03-22 15:59:14 +01:00
Akim Demaille 1c694e08cc bench: use the same prefix in both bench methods
* etc/bench.pl.in (&bench_with_timethese): Also use y$i, as in
&bench_with_gbenchmark.
(&generate_grammar_calc): Don't add a prefix, let the callers do it.
2020-03-22 15:59:13 +01:00
Akim Demaille 4cfb067d93 bench: use a C++-11 compiler
See https://github.com/google/benchmark#a-faster-keeprunning-loop.

* etc/bench.pl.in ($cxx): Be C++11.
(&bench_with_gbenchmark): Adjust.
2020-03-22 15:59:13 +01:00
Akim Demaille cf60d0a617 bench: create a README file with benches
* etc/bench.pl.in (&bench_with_gbenchmark): Here.
2020-03-22 15:59:13 +01:00
Akim Demaille c0e8489605 bench: calc: add support for google benchmark
* etc/bench.pl.in (&compiler): New, extracted from...
(&compile): here.
Don't link when using gbm.
(&calc_input): Don't make massive input for micro
benchmarks.
(&generate_grammar_calc): When using gbm, use api.prefix to avoid name
collisions.
Be ready to issue BENCHMARKS instead of a main.
(&bench): Rename as...
(&bench_with_timethese): this.
(&bench_with_gbenchmark): New.
(&bench): New.
Dispatch on these two.
2020-03-21 18:19:14 +01:00
Akim Demaille 788b1a6858 bench: better error messages on invalid input
* etc/bench.pl.in: here.
2020-03-21 18:17:09 +01:00
Akim Demaille 56414791e9 bench: simplify the calc grammar
* etc/bench.pl.in (generate_grammar_calc): We don't need global_result
etc.
2020-03-21 18:17:02 +01:00
Akim Demaille 675dcf1962 bench: die clearly on incorrect --grammar arguments
* etc/bench.pl.in (getopt): here.
2020-03-21 14:52:41 +01:00
Akim Demaille 466fb66578 regen 2020-03-17 19:21:24 +01:00
Akim Demaille cbb967dbad yacc.c: style: prefer switch to if
* data/skeletons/yacc.c: Prefer switch to decode yy_lac's return value.
2020-03-17 19:21:07 +01:00
Akim Demaille 44ac18d136 yacc.c: yypstate_expected_tokens
In push parsers, when asking for the list of expected tokens at some
point, it makes no sense to build a yyparse_context_t: the yypstate
alone suffices (the only difference being the lookahead).  Instead of
forcing the user to build a useless shell around yypstate, let's offer
yypstate_expected_tokens.

See https://lists.gnu.org/r/bison-patches/2020-03/msg00025.html.

* data/skeletons/yacc.c (yypstate): Declare earlier, so that we can
use it for...
(yypstate_expected_tokens): this new function, when in push parsers.
Adjust dependencies.
* examples/c/bistromathic/parse.y: Simplify: use
yypstate_expected_tokens.
Style fixes.
Reduce scopes (reported by Joel E. Denny).
2020-03-17 19:20:13 +01:00
Akim Demaille 0c3dd3a669 examples: bistromathic: simplify
* examples/c/bistromathic/parse.y (expected_tokens): Remove useless "break".
2020-03-09 07:24:33 +01:00
Akim Demaille 951da960e6 merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.5.3
  news: update for 3.5.3
  yacc.c: make sure we properly propagated the user's number for error
  diagnostics: don't crash because of repeated definitions of error
  style: initialize some struct members
  diagnostics: beware of zero-width characters
  diagnostics: be sure to close the styling when lines are too short
  muscles: fix incorrect decoding of $
  code: be robust to reference with invalid tags
  build: fix typo
  doc: update recommandation for libtextstyle
  style: comment changes
  examples: use consistently the GFDL header for readmes
  style: remove useless declarations
  typo: succesful -> successful
  README: point to tests/bison, and document --trace
  gnulib: update
  maint: post-release administrivia
2020-03-08 10:13:16 +01:00
Akim Demaille 15ea35019f maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-03-08 08:50:10 +01:00
Akim Demaille f49684a577 version 3.5.3
* NEWS: Record release date.
2020-03-08 08:30:41 +01:00
Akim Demaille 044ad1288c news: update for 3.5.3 2020-03-08 08:17:13 +01:00
Akim Demaille e3812bb8c3 yacc.c: make sure we properly propagated the user's number for error
* data/skeletons/yacc.c (YYERRCODE): Be truthful.
* tests/input.at (Redefining the error token): Check that.
2020-03-08 08:10:11 +01:00
Akim Demaille cfcd823e16 diagnostics: don't crash because of repeated definitions of error
According to https://www.unix.com/man-page/POSIX/1posix/yacc/, the
user is allowed to specify her user number for the error token:

    The token error shall be reserved for error handling. The name
    error can be used in grammar rules. It indicates places where the
    parser can recover from a syntax error. The default value of error
    shall be 256. Its value can be changed using a %token
    declaration. The lexical analyzer should not return the value of
    error.

I think this feature is useless, the user should not have to deal with
that.  The intend is probably to give the user a means to use 256 if
she wants to, but provided "error" cleared the path first by being
assigned another number.  In the case of Bison, 256 is assigned to
"error" at the end if the user did not use it for a token of hers.  So
this feature is useless.

Yet it is valid, and if the user assigns twice a token number to
"error", then the second time we want to complain about it and want to
show the original definition.  At this point, we try to display the
built-in definition of "error", whose location is NULL, and we crash.

Rather, the location of the first user definition of "error" should
become its defining location.

Reported byg Ahcheong Lee.
https://lists.gnu.org/r/bug-bison/2020-03/msg00007.html

* src/symtab.c (symbol_class_set): If this is a declaration and the
symbol was not declared yet, keep this as defining location.
* tests/input.at (Redefining the error token): New.
2020-03-08 08:10:11 +01:00
Akim Demaille 2f02d9beae style: initialize some struct members
* src/symtab.c (sym_content_new): Initialize all the location members.
Not needed by the code, but disturbing values when using a debugger.
2020-03-08 08:10:11 +01:00
Akim Demaille b638603477 diagnostics: beware of zero-width characters
Currenly we rely on (visual) width of the characters to decide where
to open and close the styling of the quoted lines.  This breaks when
we deal with zero-width characters: we cannot just rely on (visual)
columns, we need to know whether we are before, inside, or after the
highlighted portion.

* src/location.c (location_caret): col_end: no longer add 1, "regular"
characters have a width of 1, only 0-width characters have 0-width.
opened: replace with 'state', a three-valued enum.
Don't reopen the style if we already did.
* tests/diagnostics.at (Zero-width characters): New.
2020-03-08 08:10:11 +01:00
Akim Demaille e21ff47f5d diagnostics: be sure to close the styling when lines are too short
bar.y:4.12-17: <error>error:</error> redefining user token number of foo
    -    4 | %token foo <error>123
    +    4 | %token foo <error>123</error>
           |            <error>^~~~~~</error>

* src/location.c (location_caret): Be sure to close.
* tests/diagnostics.at (Line is too short, and then you die): New.
2020-03-07 10:01:52 +01:00
Akim Demaille b82b387da9 muscles: fix incorrect decoding of $
Bug introduced in 458171e6df.
https://lists.gnu.org/archive/html/bison-patches/2013-11/msg00009.html

Reported by Ahcheong Lee.
https://lists.gnu.org/r/bug-bison/2020-03/msg00010.html

* src/muscle-tab.c (COMMON_DECODE): "$" is coded as "$][", not "$[][".
* tests/input.at ("%define" enum variables): Check that case.
2020-03-07 07:45:10 +01:00
Akim Demaille 641e326303 code: be robust to reference with invalid tags
Because we want to support $<a->b>$, we must accept -> in type tags,
and reject $<->$, as it is unfinished.
Reported by Ahcheong Lee.

* src/scan-code.l (yylex): Make sure "tag" does not end with -, since
-> does not close the tag.
* tests/input.at (Stray $ or @): Check this.
2020-03-06 17:29:26 +01:00
Akimn Demaille 192e9fdf77 build: fix typo
* build-aux/cross-options.pl: here.
2020-03-06 08:32:26 +01:00
Akim Demaille a4a3f08c11 doc: update recommandation for libtextstyle
* README: here.
2020-03-06 08:32:18 +01:00
Akim Demaille 666df338a7 style: comment changes
* src/symtab.h, src/lr0.c: here.
2020-03-06 08:32:03 +01:00
Akim Demaille b437b16603 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-06 08:31:34 +01:00
Akim Demaille b493c173c9 style: remove useless declarations
* src/reader.h: Don't duplicate what parse-gram.h already exposes.
* src/lr0.h: Remove useless include.
2020-03-06 08:30:21 +01:00
Adrian VogelsgesangandAkim Demaille aab3feb5a1 typo: succesful -> successful
* data/skeletons/lalr1.cc: here
* etc/bench.pl.in: here
* src/location.c: and here.
2020-03-06 08:29:58 +01:00
Akim Demaille b7942f2661 README: point to tests/bison, and document --trace
Reported by Victor Morales Cayuela.

* README, README-hacking.md: here.
2020-03-06 08:28:23 +01:00
Akim Demaille cefb538ab0 gnulib: update 2020-03-06 08:25:52 +01:00
Akim Demaille ecd922024e README: point to tests/bison, and document --trace
Reported by Victor Morales Cayuela.

* README, README-hacking.md: here.
2020-03-05 17:56:55 +01:00
Akim Demaille 2353ce7216 yacc.c: simplify yyparse_context_t member names
* data/skeletons/yacc.c (yyparse_context_t): Rename yyes_p and
yyes_capacity_p as...
(yyes, yyes_capacity): These.
2020-03-05 07:26:50 +01:00
Akim Demaille 9cc76ee62c yacc.c: yyerror_range does not need to be preserved accross calls
* data/skeletons/yacc.c (b4_parse_state_variable_macros): Don't define
yyerror_range.
(yyparse): Add yyerror_range as local variable.
2020-03-05 07:26:49 +01:00
Akim Demaille 2f83ef57f3 yacc.c: push: undefine the pstate macros for the epilogue
* data/skeletons/yacc.c (b4_macro_define, b4_macro_undef)
(b4_pstate_macro_define, b4_parse_state_variable_macros):
New.
Use them.
* examples/c/bistromathic/parse.y: Remove now useless undefs.
2020-03-05 07:26:49 +01:00
Akim Demaille 744171ddbf yacc.c: push: initialize the pstate variables in pstate_new
Currently pstate_new does not set up its variables, this task is left
to yypush_parse.  This was probably to share more code with usual pull
parsers, where these (local) variables are indeed initialized by
yyparse.

But as a consequence yyexpected_tokens crashes at the very beginning
of the parse, since, for instance, the stacks are not even set up.
See https://lists.gnu.org/r/bison-patches/2020-03/msg00001.html.

The fix could have very simple, but the documentation actually makes
it very clear that we can reuse a pstate for several parses:

    After yypush_parse returns a status other than YYPUSH_MORE, the
    parser instance yyps may be reused for a new parse.

so we need to restore the parser to its pristine state so that (i) it
is ready to run the next parse, (ii) it properly supports
yyexpected_tokens for the next run.

* data/skeletons/yacc.c (b4_initialize_parser_state_variables): New,
extracted from the top of yyparse/yypush_parse.
(yypstate_clear): New.
(yypstate_new): Use it when push parsers are enabled.
Define after the yyps macros so that we can use the same code as the
regular pull parsers.
(yyparse): Use it when push parsers are _not_ enabled.

* examples/c/bistromathic/bistromathic.test: Check the completion on
the beginning of the line.
2020-03-05 07:13:23 +01:00
Akim Demaille 4fd3282dd7 style: formatting changes
* data/skeletons/yacc.c, tests/torture.at: here.
2020-03-04 08:24:36 +01:00
Akim Demaille 67793793e8 bistromathic: properly compute the lcp, as expected by readline
Currently completion on "at" proposes only "atan", but does not
actually complete "at" into "atan".

* examples/c/bistromathic/parse.y (completion): Install the lcp in
matches[0].
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-03-04 08:24:36 +01:00
Akim Demaille f334775dbf bistromathic: don't require spaces after operators for completion
Currently "(1+<TAB>" does not work as expected, because "+" is not a
word breaking character.

* examples/c/bistromathic/parse.y (init_readline): Specify our word
breaking characters.
* examples/c/bistromathic/bistromathic.test: Avoid trailing spaces.
2020-03-04 08:24:35 +01:00
Akim Demaille feb1011c8b bistromathic: check completion
* examples/c/bistromathic/bistromathic.test: here.
* examples/c/bistromathic/parse.y (expected_tokens): Fix a memory
leak.
2020-03-02 06:58:25 +01:00
Akim Demaille 99bedadf23 m4: remove b4_function_define and b4_function_declare
* data/skeletons/c.m4: here.
2020-03-02 06:58:20 +01:00
Akim Demaille 79c3f2b8fd m4: decommission b4_function_declare
* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/yacc.c:
Stop using b4_function_declare.
2020-03-02 06:58:14 +01:00
Akim Demaille 4cca30d2e6 m4: decommission function generating macro
These macros have been extremely useful when we had to support K&R C,
which we dropped long ago.  Now, they merely make the code uselessly
hard to read.

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/yacc.c:
Stop using b4_function_define.
2020-03-02 06:57:50 +01:00
Akim Demaille 5789f9d91e examples: bistromathic: demonstrate the use of yyexpected_tokens
Let's use GNU readline and its TAB autocompletion to demonstrate the
use of yyexpected_tokens.

This shows a number of weaknesses in our current approach:

- some macros (yyssp, etc.) from push parsers "leak" in user code, we
  need to undefine them

- the context needed by yyexpected_tokens does not need the token,
  yypstate actually suffices

- yypstate is not properly setup when first allocated, which results
  in a crash of yyexpected_tokens if fired before a first token was
  read.  We should move initialization from yypush_parse into
  yypstate_new.

* examples/c/bistromathic/parse.y (yylex): Take input as a string, not
a file.
(EXIT): New token.
(input): Adjust to work only on a line.
(line): Remove.
(symbol_count, process_line, expected_tokens, completion)
(init_readline): New.
* examples/c/bistromathic/bistromathic.test: Adjust expectations.
2020-03-01 12:31:39 +01:00
Akim Demaille b269a45fa4 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/pushcalc/README.md, examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-01 07:56:02 +01:00
Akim Demaille 1478fccd23 gnulib: use readline 2020-03-01 06:23:49 +01:00
Akim Demaille 535281f0ff examples: bistromathic: don't use Flex
This example will soon use GNU readline, so its scanner should be easy
to use (concurrently) on strings, not streams.  This is not a place
where Flex shines, and anyway, these are examples of Bison, not Flex.
There's already lexcalc and reccalc that demonstrate the use of Flex.

* examples/c/bistromathic/scan.l: Remove.
* examples/c/bistromathic/parse.y (yylex): New.
Adjust dependencies.
2020-02-29 17:52:08 +01:00
Akim Demaille c4a7e7a1ab examples: bistromathic: strengthen tests
* examples/c/bistromathic/bistromathic.test: here.
* examples/test: Be clearer on failing tests.
2020-02-29 12:22:31 +01:00
Akim Demaille 388e12ac0f examples: lexcalc: demonstrate location tracking
The bistromathic example should not use Flex, it makes it too complex.
But it was the only example to show location tracking with Flex.

* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Demonstrate location tracking as is done
in bistromathic.
2020-02-29 12:15:19 +01:00
Akim Demaille b870d5fee4 c++: don't copy the lookahead
The current implementation of parser::context keeps a copy of the
lookahead.  This is troublesome since we support move-only types.
Besides, while GCC is happy with the current implementation, Clang
complains that the ctor it needs to build the copy of the lookahead is
not yet available.

    461. calc.at:1120: testing Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  ...
    calc.at:1120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    calc.at:1120: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    In file included from calc-lex.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    In file included from calc-main.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    stdout:
    calc.at:1120: exit code was 1, expected 0
    461. calc.at:1120: 461. Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  (calc.at:1120): FAILED (calc.at:1120)

* data/skeletons/lalr1.cc (context::yyla_): Make it a const-ref.
Move the implementation out of the declaration.
2020-02-27 21:49:56 +01:00
Akim Demaille 30d01b21e7 c++: minor fixes
Address compiler warnings such as

    warning: declaration of 'yyla' shadows a member of 'yy::parser::context' [-Wshadow]

* data/skeletons/lalr1.cc (context): Don't use the same names for
variables and members.
Use foo_ for private members, as in parser.
Also, use the + trick in array accesses to please ICC and provide it
with an int.
2020-02-27 21:31:09 +01:00
Adrian VogelsgesangandAkim Demaille c2cca46795 c++: add support for parse.error=custom
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added test cases
* tests/local.at: added yyreport_syntax_error implementation
   for C++ test cases
2020-02-27 18:13:44 +01:00
Adrian VogelsgesangandAkim Demaille 879530cb95 c++: add parser::context for syntax error handling
* data/skeletons/lalr1.cc: here
2020-02-27 18:13:44 +01:00
Adrian VogelsgesangandAkim Demaille 72acecb30c c++: add support for parse.error=detailed
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added a test case
2020-02-27 18:13:43 +01:00
Adrian VogelsgesangandAkim Demaille d4fcd5c3d0 skeletons: prefer b4_parse_error_{case,bmatch} over manual solution
Prefer b4_parse_error_case over the adhoc solution
`m4_case + b4_percent_define_get`. Same for b4_parse_error_bmatch.

* data/skeletons/glr.c: here
* data/skeletons/yacc.c: here
2020-02-27 18:13:43 +01:00
Adrian VogelsgesangandAkim Demaille 368fcf0af5 typo: succesful -> successful
* data/skeletons/lalr1.cc: here
* etc/bench.pl.in: here
* src/location.c: here
* tests/calc.at: and here
2020-02-27 18:10:39 +01:00
Akim Demaille 6fe063da8f bench.pl: clean up the dust
* etc/bench.pl.in: Adjust to the current use of %define's values.
Don't use %error-verbose.
Prefer Bison to CPP (e.g., api.value.type).
Avoid returning characters directly, so that %define api.token.raw works.
2020-02-24 08:42:16 +01:00
Akim Demaille 296660304c style: comment changes
* src/symtab.h, src/lr0.c: here.
2020-02-23 08:25:53 +01:00
Akim Demaille 323731ff74 style: avoid using 'this' as an identifier
LLDB insists on parsing 'this' as a C++ keyword, even when debugging a
C program.

* src/symtab.c: Please the dictator.
2020-02-23 08:25:53 +01:00
Akim Demaille 6f7f949708 style: remove useless declarations
* src/reader.h: Don't duplicate what parse-gram.h already exposes.
* src/lr0.h: Remove useless include.
2020-02-23 08:25:53 +01:00
Akim Demaille 15e57d9108 examples: fix c/calc
* examples/c/calc/calc.y: Remove experiment traces.
2020-02-19 14:58:39 +01:00
Akim Demaille 30ba94081c todo: update 2020-02-19 14:57:17 +01:00
Akim Demaille 0e7bc7a6d8 doc: update recommandation for libtextstyle
* README: here.
2020-02-15 11:17:33 +01:00
Akimn Demaille eff4d16175 build: fix typo
* build-aux/cross-options.pl: here.
2020-02-15 10:50:19 +01:00
Akim Demaille b0e11f4523 doc: simplify the cross references
* doc/bison.texi: here.
2020-02-15 09:59:50 +01:00
Akim Demaille d9b2270bed doc: document token internationalization
* doc/bison.texi (Parser Internationalization): Move most of its
content into...
(Enabling I18n): this new node.
(Token I18n): New.
(Token Decl): Refer to token internationalization.
(Error Reporting Function): Promote parse.error detailed.
2020-02-15 09:55:59 +01:00
Akim Demaille 7a28659495 regen 2020-02-15 08:28:57 +01:00
Victor Morales CayuelaandAkim Demaille e09a72eeb0 diagnostics: modernize the display of submessages
Since Bison 2.7, output was indented four spaces for explanatory
statements.  For example:

    input.y:2.7-13: error: %type redeclaration for exp
    input.y:1.7-11:     previous declaration

Since the introduction of caret-diagnostics, it became less clear.
Remove the indentation and display submessages as in GCC:

    input.y:2.7-13: error: %type redeclaration for exp
        2 | %type <float> exp
          |       ^~~~~~~
    input.y:1.7-11: note: previous declaration
        1 | %type <int> exp
          |       ^~~~~

* src/complain.h (SUB_INDENT): Remove.
(warnings): Add "note" to the enum.
* src/complain.h, src/complain.c (complain_indent): Replace by...
(subcomplain): this.
Adjust all dependencies.
* tests/actions.at, tests/diagnostics.at, tests/glr-regression.at,
* tests/input.at, tests/named-refs.at, tests/regression.at:
Adjust expectations.
2020-02-15 08:28:40 +01:00
Akim Demaille a09d0ae4d1 doc: simplify uses of references
This reverts "doc: work around problems with PDF generation", commit
d810aa3d8f.  Upstream issue is fixed.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00006.html

* gnulib: Update.
* doc/bison.texi: Simplify.
2020-02-13 19:22:51 +01:00
Akim Demaille 1e25cb44d1 java: provide a Context ctor
This is really a private auxiliary inner class, so it should not
matter.  But it's better style.

* data/skeletons/lalr1.java: here.
2020-02-13 19:22:10 +01:00
Akim Demaille 3ed42d2487 Merge tag 'v3.5.2'
bison 3.5.2

* tag 'v3.5.2':
  version 3.5.2
  news: 3.5.2
  gnulib: update
  doc: update Doxygen template
  java: avoid trailing white spaces
  m4: fix b4_token_format
  doc: clearly state that %yacc only makes sense with yacc.c
  doc: spell check
  examples: be more robust to spaces in paths
  larlr1.cc: Reject unsupported values for parse.lac
2020-02-13 19:19:11 +01:00
Akim Demaille 26c5f48c1c maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-02-13 19:11:16 +01:00
Akim Demaille 7f921d18dd version 3.5.2
* NEWS: Record release date.
2020-02-13 18:25:21 +01:00
Akim Demaille cc3760ef51 news: 3.5.2
* NEWS: Update.
2020-02-13 18:25:11 +01:00
Akim Demaille 2f23ca6f65 gnulib: update 2020-02-13 08:18:12 +01:00
Akim Demaille 468b68c5cd doc: update Doxygen template
* Doxyfile.in: Run doxygen -u on it.
2020-02-13 08:18:12 +01:00
Akim Demaille 9ed802a026 java: avoid trailing white spaces
* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
2020-02-13 08:18:12 +01:00
Akim Demaille fb554c2804 m4: fix b4_token_format
We used to emit:

    /** Token number,to be returned by the scanner.  */
    static final int NUM = 258;
    /** Token number,to be returned by the scanner.  */
    static final int NEG = 259;

with no space after the comma.  Fix that.

* data/skeletons/bison.m4 (b4_token_format): Quote where appropriate.
2020-02-13 08:18:11 +01:00
Akim Demaille 47850d4f58 doc: clearly state that %yacc only makes sense with yacc.c
* doc/bison.texi: here.
2020-02-13 08:18:11 +01:00
Akim Demaille 57b035a242 doc: spell check
* doc/bison.texi: here.
2020-02-13 08:18:11 +01:00
Akim Demaille e7a202d762 examples: bistromathic: demonstrate named references
* examples/c/bistromathic/parse.y: here.
2020-02-12 00:18:47 +01:00
Akim Demaille 11e2b755f0 c++: simplify
* data/skeletons/stack.hh (ssize): Remove, same as size.
2020-02-12 00:09:15 +01:00
Akim Demaille f3d33c3613 tests: check calls to yyerror from the user actions
This revealed a number of things I had not realized:

- the Java location tracking was aliasing the same pair of positions
  for all the symbols (see previous commit).

- in impure parsers, it's quite easy to use incorrect locations for
  diagnostics, since yyerror uses yylloc, which is the location of the
  lookahead, not that of the current lhs.  So we need something like

    {
      YYLTYPE old_yylloc = yylloc;
      yylloc = @$;
      yyerror (]AT_PARAM_IF([result, count, nerrs, ])[buf);
      yylloc = old_yylloc;
    }

  Maybe we should do that little yylloc dance in the skeleton instead
  of leaving it to the user?  It might be costly...  But that's only
  for users of the impure parsers, which are asking for trouble
  anyway.

- in glr.cc invoking yyerror is somewhat cumbersome: the C++ interface
  is not available as we are in yyparse (which in C), and yyerror is
  used by glr.cc itself to bind it to the user's parser::error.  If we
  call yyerror, we need:

    yyerror (]AT_LOCATION_IF([[&@$, ]])[yyparser, ]AT_PARAM_IF([result, count, nerrs, ])[msg);

  However calling yy::parser::error is easier, once we know that the
  current parser object is available as 'yyparser'.  Which also saves
  us from having to pass the parse-params ourselves:

    yyparser.error (]AT_LOCATION_IF([[@$, ]])[msg);

* tests/calc.at: Invoke yyerror by hand, instead of using fprintf etc.
Adjust expectations.
2020-02-12 00:00:05 +01:00
Akim Demaille 163a35d6dd java: beware not to alias the locations of the various symbols
* examples/java/calc/Calc.y, tests/calc.at, tests/local.at
(getStartPos, getEndPos): Always return a new object.
* doc/bison.texi: Clarify this.
2020-02-11 21:31:44 +01:00
Akim Demaille cdb42f7730 java: check that parse.error custom|detailed work with push parsers
* tests/calc.at: here.
2020-02-11 08:39:08 +01:00
Akim Demaille 126252333d java: don't expose the Context's members
* data/skeletons/lalr1.java (Context): Make data members private.
(Context.getLocation): New.
* examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.
2020-02-11 08:39:03 +01:00
Akim Demaille 8637f2c7d6 build: pacify syntax-check
* src/complain.c: Fix indentation.
* cfg.mk: Using strcmp is ok in the tests.
Test cases and examples don't need Bison's PO support.
2020-02-10 20:46:56 +01:00
Akim Demaille 6946149701 regen 2020-02-10 20:42:23 +01:00
Akim Demaille 1368b9dbc9 gnulib: update 2020-02-10 20:42:23 +01:00
Akim Demaille 0e96eaf612 build: prefer %D% and %C% to hard coded values
* doc/local.mk: here.
2020-02-10 20:15:46 +01:00
Akim Demaille 77bdcc6f0c parse.error: document and diagnose the incompatibility with %token-table
* doc/bison.texi (Tokens from Literals): Move to code using
%token-table to...
(Decl Summary: %token-table): here.
* data/skeletons/bison.m4: Implement mutual exclusion.
* tests/input.at: Check it.
* doc/local.mk: Be robust to the removal of doc/.
2020-02-10 20:15:46 +01:00
Akim Demaille 57647bb656 doc: spell check
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille 63cd2918ff doc: formatting changes
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille d810aa3d8f doc: work around problems with PDF generation
With texinfo.tex 2019-09-24.13, node names with + are not properly
handled.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00004.html

* doc/bison.texi: Always use the three-argument form for references to
node with a + in the name.
2020-02-10 20:15:41 +01:00
Akim Demaille ed1eedbbcb java: revert "style: avoid useless initializers"
This reverts commit ebab1ffca8.
This commit removed "useless" initializers, going from

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte yypact_[] = yypact_init ();
    private static final byte[] yypact_init ()
    {
      return new byte[]
      {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
      };
    }

to

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte[] yypact_ =
    {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
    };

But it turns out that this was on purpose, to work around the 64KB
limitation in JVM methods.  It was introduced on the 2008-11-10 by
Di-an Jan in 09ccae9b18: "Work around
Java's ``code too large'' problem for parser tables".  See
https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.  A real
test, where we would hit the JVM limitation, would be nice.

To avoid further regressions, add comments.
2020-02-10 07:34:07 +01:00
Akim Demaille bc74b4b15a skeletons: avoid b4_error_verbose_if, which is confusing
parse.error has more than two possible values.

* data/skeletons/bison.m4 (b4_error_verbose_if, b4_error_verbose_flag):
Remove.
(b4_parse_error_case, b4_parse_error_bmatch): New.
Adjust dependencies.
2020-02-10 07:24:38 +01:00
Akim Demaille 8dd8137c38 skeletons: decorelate %token-table from verbose error messages
Reported by Adrian Vogelsgesang.

* data/skeletons/bison.m4: Here.
* data/skeletons/lalr1.cc: Adjust.
2020-02-10 07:24:38 +01:00
Akim Demaille 1388e5b276 doc: formatting changes
* doc/bison.texi: here.
2020-02-10 07:24:38 +01:00
Akim Demaille 6f5465c917 doc: clearly state that %yacc only makes sense with yacc.c
* doc/bison.texi: here.
* tests/calc.at: Stop testing %yacc with non yacc.c skeletons.
2020-02-09 15:58:55 +01:00
Adrian VogelsgesangandAkim Demaille bb02acc2ed style: stylistic cleanups in the C skeletons
* data/skeletons/glr.c, data/skeletons/yacc.c:
Avoid duplicated declaration of yysymbol_name.
2020-02-09 15:58:27 +01:00
Akim Demaille 80a4389377 java: provide Context with a more OO interface
* data/skeletons/lalr1.java (yyexpectedTokens)
(yysyntaxErrorArguments): Make them methods of Context.
(Context.yysymbolName): New.
* tests/local.at: Adjust.
2020-02-08 16:17:53 +01:00
Akim Demaille ef097719ea java: add support for parse.error custom
* data/skeletons/lalr1.java: Add support for custom parse errors.
(yyntokens_): Make it public.  Under...
(yyntokens): this name.
(Context): Capture the location too.
* examples/c/bistromathic/parse.y,
* examples/c/bistromathic/bistromathic.test:
Improve error message.
* examples/java/calc/Calc.test, examples/java/calc/Calc.y: Use custom
error messages.
* tests/calc.at, tests/local.at: Check custom error messages.
2020-02-08 16:03:50 +01:00
Akim Demaille 0c90c59795 java: let the Context give access to yyntokens
* data/skeletons/lalr1.java (Context.yytokens): New.
2020-02-08 15:54:16 +01:00
Akim Demaille 18a7cfc7cf java: make the syntax error format string translatable
The error format should be translated, but contrary to the case of
C/C++, we cannot just depend on macros to adapt on the
presence/absence of '_'.  Let's consider that the message format is to
be translated iff there are some internationalized tokens.

* src/output.c (prepare_symbol_names): Define b4_has_translations.
* data/skeletons/java.m4 (b4_trans): New.
* data/skeletons/lalr1.java: Use it to emit translatable or not the
format string.
2020-02-08 11:24:53 +01:00
Akim Demaille 088356cb2f java: introduce yyexpectedTokens
And allow syntax error messages for 'detailed' and 'verbose' to be
translated.

* data/skeletons/lalr1.java (Context, yyexpectedTokens)
(yysyntaxErrorArguments): New.
(yysyntax_error): Use it.
2020-02-08 11:24:53 +01:00
Akim Demaille 52db24b2bc java: add support for parse.error=detailed
In Java there is no need for N_ and yytranslate_.  So instead of
hard-coding the use of N_ in the table of the symbol names, rely on
b4_symbol_translate.

* src/output.c (prepare_symbol_names): Use b4_symbol_translate instead
of N_.
* data/skeletons/c.m4 (b4_symbol_translate): New.
* data/skeletons/lalr1.java (yysymbolName): New.
Use it.
* examples/java/calc/Calc.y: Use parse.error=detailed.
* tests/calc.at: Check parse.error=detailed.
2020-02-08 11:24:53 +01:00
Akim Demaille 650b253843 m4: fix b4_token_format
We used to emit:

    /** Token number,to be returned by the scanner.  */
    static final int NUM = 258;
    /** Token number,to be returned by the scanner.  */
    static final int NEG = 259;

with no space after the comma.  Fix that.

* data/skeletons/bison.m4 (b4_token_format): Quote where appropriate.
2020-02-08 11:24:53 +01:00
Akim Demaille 7781254e01 java: tests: remove now redundant tests
* tests/javapush.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille fa226d773c java: tests: check push parsers like the others
Currently in javapush.at.

* tests/calc.at: Here.
2020-02-05 13:17:00 +01:00
Akim Demaille 1cc83505c5 java: tests: remove now redundant tests
* tests/java.at: Calculator tests are now in calc.at.
2020-02-05 13:17:00 +01:00
Akim Demaille 2d97fe86fd java: tests: check location tracking in the calculator
Unfortunately in the Java skeleton the user cannot override the way
locations are displayed, and locations don't know the structure of the
positions.  So they cannot implement the tricks used in the C/C++
skeletons to display "1.1" instead of "1.1-1.2".

* tests/local.at (Java): Add support for column tracking in the
locations, as we did in examples/java/calc.
* tests/calc.at: Use AT_CALC_YYLEX.
2020-02-05 13:17:00 +01:00
Akim Demaille 3239866f4a java: tests: prepare the replacement of calculator tests
Soon calculator tests for Java will move from java.at to calc.at.
Which implies improving the Java testing infrastructure in
local.at (for instance really tracking columns in positions, not just
token number).  Detach java.at from local.at.

* tests/java.at (AT_JAVA_POSITION_DEFINE_OLD): New.
Use it.
2020-02-05 13:17:00 +01:00
Akim Demaille ebab1ffca8 java: style: avoid useless initializers
Instead of

      /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte yypact_[] = yypact_init ();
      private static final byte[] yypact_init ()
      {
        return new byte[]
        {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
        };
      }

generate

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte[] yypact_ =
      {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
      };

I have no idea what motivated the previous approach.

* data/skeletons/java.m4 (b4_typed_parser_table_define): Here.
2020-02-05 13:17:00 +01:00
Akim Demaille f705e9abdb java: style: prefer putting the square brackets on the type
* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/local.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille d6f576102e java: examples: fix the tracking of locations
* examples/java/calc/Calc.y: The StreamTokenizer cannot "peek" for the
next character, it reads it, and keeps it for the next call.  So the
current location is one passed the end of the current token.  To avoid
this, keep the previous position, and use it to end the current token.
* examples/java/calc/Calc.test: Adjust.
2020-02-05 13:17:00 +01:00
Akim Demaille 0f587e9931 java: examples: prefer switch to chains of else-if
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
* examples/java/simple/Calc.y: Use the tokenizer's handling of blanks.
2020-02-05 13:17:00 +01:00
Akim Demaille 48be689a73 java: examples: split in two
* examples/java: Split in...
* examples/java/simple, examples/java/calc: these.
2020-02-05 13:17:00 +01:00
Akim Demaille d727e0ff23 traces: don't print the stack before the gotos
The C, C++ and D skeletons used to show the stack right after popping
the stack during the reduction.  Now that the stack is printed after
reaching a new state, that has become useless:

    Entering state 1
    Stack now 0 1
    Reducing stack by rule 5 (line 83):
       $1 = token "number" (1)
    -> $$ = nterm exp (1)
    Stack now 0
    Entering state 8
    Stack now 0 8

Remove the "Stack now 0" line.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Here.
2020-02-05 07:40:07 +01:00
Akim Demaille 37aeda6fb3 traces: show the stack after reading a token
Currently, if we have long rules and series of shift, we stack states
without showing stack.  Let's be more incremental, and do how the Java
skeleton does.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c:
Here.
Adjust test cases.
* tests/torture.at (AT_DATA_STACK_TORTURE): Disable stack traces: this
test produces a very large stack, and showing the stack each time we
shift a token goes quadatric.
2020-02-05 06:48:42 +01:00
Akim Demaille bba2f0a3a0 traces: write the "Reading a token" alone on its line
The Java skeleton displays

    Reading a token:
    Next token is token "number" (1)

while the other display

    Reading a token: Next token is token "number" (1)

When generating logs in the scanner, the first part is separated from
the second, and the end of the scanner logs have the second part
pasted in.  So let's propagate the Java way, but with the colon.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Do it.
Adjust test cases and doc.
2020-02-04 07:02:24 +01:00
Akim Demaille fe14fb1c40 java: use the same calc tests as the other skeletons
* tests/local.at (AT_LANG_MATCH): New.
(AT_YYERROR_DECLARE(java), AT_YYERROR_DECLARE_EXTERN(java)): New.
* tests/calc.at: The grammar file for Java is quite different for the
others, and continuing to assemble it from pieces makes the grammar
file hard to understand.  Let's also dispatch on the language to
assemble it, and isolate Java from the others.
Most of this comes from java.at.
2020-02-02 11:33:16 +01:00
Akim Demaille 88d1ab421a java: add access to the number of errors
* data/skeletons/lalr1.java (yynewrrs, getNumberOfErrors): New.
Formatting changes.
2020-02-02 11:33:16 +01:00
Akim Demaille edf495b38e java: formatting changes
* data/skeletons/java.m4, data/skeletons/lalr1.java: here.
2020-02-02 11:33:16 +01:00
Akim Demaille ba69beafac java: avoid trailing white spaces
* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
2020-02-02 11:33:16 +01:00
Akim Demaille c16fcaf2fb java: example: properly track the locations
This example, so far, was tracking the current token number, not the
current column number.  This is not nice for an example...

* examples/java/Calc.y (PositionReader): New.
Use it.
* examples/java/Calc.test: Check the output.
2020-02-02 11:33:13 +01:00
Akim Demaille 7e99f67592 java: example: improve
* examples/java/Calc.y: Propagate the exit status.
Support -p.
2020-02-02 11:33:03 +01:00
Akim Demaille d5f929d407 java: example: rely on autoboxing
AFAICT, autoboxing/unboxing was added in Java 5 (September 30, 2004).
I think we can afford to use it.  It should help us merge some Java
tests with the main ones.

However, beware that != does not unbox: it compares the object
addresses.

* examples/java/Calc.y, tests/java.at: Simplify.
* examples/java/Calc.test, tests/java.at: Improve tests.
2020-02-02 11:32:55 +01:00
Akim Demaille c5b215b5e6 tests: comment changes
* tests/calc.at: Shorten titles and reduce redundancy.
2020-02-02 11:28:45 +01:00
Akim Demaille 0774b2c6e3 skeletons: add support for %code epilogue
When building the test cases, emitting code in the epilogue is very
constraining.  Let's make it simpler thanks to %code epilogue.

However, I don't want to document this: it is bad style to use it (we
should avoid having too many ways to write the same thing,
TI!MTOWTDI), just put your code in the true epilogue section.

* data/skeletons/glr.c, data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c: Implement support for %code epilogue.
Remove useless comments.
* tests/calc.at, tests/java.at: Simplify.
2020-02-02 11:28:45 +01:00
Akim Demaille 493359b758 examples: bistromathic: fix location tracking
* examples/c/bistromathic/scan.l (LOCATION_STEP): New.
Use to properly ignore blanks.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-02-02 11:28:45 +01:00
Akim Demaille 23ba9e5dfa doc: document new features of parse.error
* doc/bison.texi (Error Reporting): Rename as...
(Error Reporting Function): this.
Adjust dependencies.
Make it a subsection of this...
(Error Reporting): new section.
(Syntax Error Reporting Function): New.
(parse.error): Update description.
2020-02-02 09:19:58 +01:00
Akim Demaille 792fc34016 glr.c: add support for parse.error=custom
* data/skeletons/glr.c (yyreportSyntaxError): Call the user's
yyreport_syntax_error in custom mode.
* tests/calc.at: Check it.
2020-01-29 19:48:16 +01:00
Akim Demaille c4a08d1899 glr.c: add support for parse.error=detailed
* data/skeletons/glr.c (yystrlen, yysymbol_name): New.
Implement parse.error detailed.
* tests/calc.at: Check it.
2020-01-29 19:48:12 +01:00
Akim Demaille 50fb1e6e0c glr.c: introduce yyexpected_tokens and yysyntax_error_arguments
Modeled after what was done in yacc.c, yet somewhat different since
yyGLRStack play the role of the full yyparse_context_t.  It will
probably be defined as a alias, to make interfaces compatible.

LAC is not supported here.  And is somewhat tricky.

* data/skeletons/glr.c (yyexpected_tokens, yysyntax_error_arguments): New.
2020-01-29 19:27:42 +01:00
Akim Demaille 6bd0527a50 glr.c: move code around
* data/skeletons/glr.c: Move the handling of error messages after the
definition of types.  Especially after yyGLRStack, which we will need
in forthcoming patches.
Simplify: yyGLRStack is defined at this point.
2020-01-29 19:27:24 +01:00
Akim Demaille 1aa9d40b24 glr.c: rename yyStateNum as yy_state_t
* data/skeletons/glr.c: here.
For consistency with yacc.c.
2020-01-29 07:15:19 +01:00
Akim Demaille a1da9b9fe8 yacc.c: fix misleading indentation
* data/skeletons/yacc.c: here.
2020-01-29 07:15:19 +01:00
Akim Demaille c80cdf2db2 doc: simplify uses of @ref
The PDF output is more consistent: some nodes were not pointed to with
their title.  The HTML output becomes "see section Foo" instead of
"see Foo", but this should be addressed in the next Texinfo release.
Info output is simplified, as it uses only the node name and not its
title.  But it's considered easier to read this way.
See https://lists.gnu.org/r/help-texinfo/2020-01/msg00031.html.

* doc/bison.texi: Set @xrefautomaticsectiontitle on.
Simplify all uses of ref.
2020-01-27 07:22:22 +01:00
Akim Demaille 3197d0fac9 examples: be more robust to spaces in paths
Reported by Nikki Valen.
https://lists.gnu.org/r/bug-bison/2020-01/msg00032.html

* examples/test ($prog): Remove, replaced by...
(prog): This new function, which pays attention to quoting shell
variables.
2020-01-27 07:22:22 +01:00
Akim Demaille 78e43ce8ff doc: don't pretend trigonometry is part of arithmetics
* doc/bison.texi (arith_funs): Rename as...
(funs): this.
2020-01-27 06:43:19 +01:00
Akim Demaille fe23e19323 doc: update Doxygen template
* Doxyfile.in: Run doxygen -u on it.
2020-01-27 06:43:19 +01:00
Akim Demaille f374310119 examples: add a complete example with all the bells and whistles
* examples/c/bistromathic/Makefile,
* examples/c/bistromathic/README.md,
* examples/c/bistromathic/bistromathic.test,
* examples/c/bistromathic/local.mk,
* examples/c/bistromathic/parse.y,
* examples/c/bistromathic/scan.l:
New.

* Makefile.am (AM_YFLAGS_WITH_LINES): Add -Wdangling-alias.
* examples/test: Make failure errors easier to read.
2020-01-27 06:41:11 +01:00
Akim Demaille 7bfff37f01 examples: add an example of a push parser
Add an example to demonstrate the use of push parser.  I'm pleasantly
surprised: parse.error=detailed works like a charm with push parsers.

* examples/c/local.mk, examples/c/pushcalc/Makefile
* examples/c/pushcalc/README.md, examples/c/pushcalc/calc.test,
* examples/c/pushcalc/calc.y, examples/c/pushcalc/local.mk:
New.
2020-01-26 14:02:08 +01:00
Akim Demaille 26fba6fc94 examples: more tests
* examples/c/mfcalc/mfcalc.test: here.
2020-01-26 14:02:08 +01:00
Akim Demaille c592202345 examples: clean up
* examples/c/calc/calc.y: Restore to its original state, with
parse.error=detailed instead of parse.error=custom (this example
should be simple).
* examples/c/calc/calc.test: Check syntax errors.
* examples/c/lexcalc/parse.y: Add comments.
2020-01-26 14:02:08 +01:00
Akim Demaille 0917f4dc76 tests: check custom error messages and push parsers
* tests/local.at (AT_LAC_IF): New.
* tests/calc.at: And also check the suppot for LAC.
2020-01-26 13:29:19 +01:00
Akim Demaille 0f792833c2 style: formatting changes
* data/skeletons/lalr1.java: here.
2020-01-26 13:29:19 +01:00
Akim Demaille b62e063df5 todo: update 2020-01-26 13:29:19 +01:00
Akim Demaille e6b0612f91 bison: pretend to 3.6 already
* src/parse-gram.y: here.
2020-01-26 13:29:18 +01:00
Akim Demaille 2eb3328afc git: update ignores
* lib/.gitignore: here.
2020-01-26 13:29:18 +01:00
Akim Demaille 81849520cd regen 2020-01-23 08:30:51 +01:00
Akim Demaille fc2191f137 diagnostics: modernize bison's syntax errors
We used to display the unexpected token first:

    $ bison foo.y
    foo.y:1.8-13: error: syntax error, unexpected %token, expecting character literal or identifier or <tag>
        1 | %token %token
          |        ^~~~~~

GCC uses a different format:

    $ gcc-mp-9 foo.c
    foo.c:1:5: error: expected identifier or '(' before ')' token
        1 | int()()()
          |     ^

and so does Clang:

    $ clang-mp-9.0 foo.c
    foo.c:1:5: error: expected identifier or '('
    int()()()
        ^
    1 error generated.

They display the unexpected token last (or not at all).  Also, they
don't waste width with "syntax error".  Let's try that.  It gives, for
the same example as above:

    $ bison foo.y
    foo.y:1.8-13: error: expected character literal or identifier or <tag> before %token
        1 | %token %token
          |        ^~~~~~

* src/complain.h, src/complain.c (syntax_error): New.
* src/parse-gram.y (yyreport_syntax_error): Use it.
2020-01-23 08:30:28 +01:00
Akim Demaille 6fb362c87a regen 2020-01-23 08:26:33 +01:00
Akim Demaille 46ab1d0cbe diagnostics: report syntax errors in color
* src/parse-gram.y (parse.error): Set to 'custom'.
(yyreport_syntax_error): New.
* data/bison-default.css (.expected, .unexpected): New.
* tests/diagnostics.at: Adjust.
2020-01-23 08:26:33 +01:00
Akim Demaille f54a5b303b regen 2020-01-23 08:26:33 +01:00
Akim Demaille 2cc361387c diagnostics: translate bison's own tokens
As a test case, support translations in Bison itself.

* src/parse-gram.y: Mark the translatable tokens.
While at it, use clearer names.
* tests/input.at: Adjust expectations.
2020-01-23 08:26:28 +01:00
Akim Demaille e6d1289f4a diagnostics: handle -fno-caret in the called functions
Don't force callers of location_caret to have to deal with flags that
disable it.

* src/location.h, src/location.c (location_caret)
(location_caret_suggestion): Early return if disabled.
* src/complain.c: Simplify.
2020-01-22 22:31:41 +01:00
Akim Demaille 16c77b4ba2 yacc.c: fixes
* data/skeletons/yacc.c: Avoid warnings about unused functions.
Fix typo.
2020-01-22 22:31:07 +01:00
Akim Demaille 1587a5ea9b examples: be more robust to spaces in paths
Reported by Nikki Valen.
https://lists.gnu.org/r/bug-bison/2020-01/msg00032.html

* examples/test ($prog): Remove, replaced by...
(prog): This new function, which pays attention to quoting shell
variables.
2020-01-21 07:01:34 +01:00
Adrian VogelsgesangandAkim Demaille 4ab2cf7450 larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:57:21 +01:00
Adrian VogelsgesangandAkim Demaille 172f103c1e larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:22:27 +01:00
Akim Demaille 6ada985ff3 parsers: issue tname with i18n markup
Some users would like to avoid having to "parse" the *.y file to find
the strings to translate.  Let's issue the translatable tokens with N_
to allow "parsing" the generated parsers instead.

See
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00015.html

* src/output.c (prepare_symbol_names): Issue symbol_names with N_()
markup.
2020-01-19 21:23:11 +01:00
Akim Demaille 2e12257803 tests: check token internationalization
* tests/calc.at: Check it.
2020-01-19 21:23:11 +01:00
Akim Demaille 1db962716a regen 2020-01-19 21:23:11 +01:00
Akim Demaille 9096955fba parsers: support translatable token aliases
In addition to

    %token NUM "number"

accept

    %token NUM _("number")

in which case the token will be translated in error messages.
Do not use _() in the output if there are no translatable tokens.

* src/symtab.h, src/symtab.c (symbol): Add a 'translatable' member.
* src/parse-gram.y (TSTRING): New token.
(string_as_id.opt): Replace with...
(alias): this.
Use it.
* src/scan-gram.l (SC_ESCAPED_TSTRING): New start conditions, to match
TSTRINGs.
* src/output.c (prepare_symbols): Define b4_translatable if there are
translatable strings.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c (yytnamerr): Receive b4_translatable, and use it.
2020-01-19 21:23:11 +01:00
Akim Demaille e9d404415a tests: check that detailed error messages preserve UTF-8 characters
* tests/regression.at: here.
2020-01-19 21:23:03 +01:00
Akim Demaille d9df62bfcd yacc.c: escape trigraphs in detailed parse.error
* src/output.c (escape_trigraphs, xescape_trigraphs): New.
(prepare_symbol_names): Use it.
* tests/regression.at: Check the handling of trigraphs with
parse.error = detailed.
2020-01-19 21:22:41 +01:00
Akim Demaille adac9a17f0 regen 2020-01-19 14:51:14 +01:00
Akim Demaille 3b4b157369 bison: use detailed error messages
* #: .
2020-01-19 14:51:14 +01:00
Akim Demaille 5c332d70d7 regen 2020-01-19 14:51:14 +01:00
Akim Demaille 91247f50d7 yacc.c: tests: check detailed error messages
* tests/local.at (AT_ERROR_DETAILED_IF): New.
(AT_ERROR_SIMPLE_IF): Adjust.
* tests/calc.at: Check parse.error=detailed.
2020-01-19 14:51:14 +01:00
Akim Demaille f443673450 yacc.c: add support for parse.error detailed
"detailed" error messages are almost like "verbose", except that we
don't double escape them, they don't get inner quotes, we don't use
yytnamerr, and we hide the table.

"custom" is exposed with the "detailed" tokens, not the "verbose"
ones: they are not double-quoted.

Because there's a risk that some people use yytname even without
"verbose", let's keep yytname (instead of yys_name) in "simple"
parse.error.

* src/output.c (prepare_symbol_names): Be ready to output symbol names
unquoted.
(prepare_symbol_names): Output both the old tname table, and the new
symbol_names one.
* data/skeletons/bison.m4: Accept 'detailed'.
* data/skeletons/yacc.c: When parse.error is 'detailed', don't emit
yytname and yytnamerr, just yysymbol_name with the table inside.
* tests/calc.at: Adjust.
2020-01-19 14:51:14 +01:00
Akim Demaille 8e6233353f c: use yysymbol_name in traces
Only parse.error verbose and simple will get the original yytname: the
other options will rely on a different table.  So let's move on top of
the yysymbol_name function.

* data/skeletons/c.m4 (yy_symbol_print): Use yysymbol_name.
* data/skeletons/glr.c (yytokenName): Rename as...
(yysymbol_name): this.
The change of naming scheme is unfortunate, but it's definitely glr.c
which is "wrong".
2020-01-19 14:51:14 +01:00
Akim Demaille e5a5da16ed glr.c: move some functions after the definition of types
Currently yy_symbol_print is defined before yytokenName, although it
should use it instead of read yytname directly.  Move blocks around to
avoid this.

* data/skeletons/glr.c (yy_symbol_print): Move its definition after
that of yytokenName.
2020-01-19 14:51:14 +01:00
Akim Demaille ebe427bbf3 Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.1
  news: update
  CI: use ICC again
  warnings: pacify ICC in lalr1.cc
  test: report.at: avoid tiny new failure
  git: update ignores
2020-01-19 14:50:09 +01:00
Akim Demaille 7e3a513d88 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-01-19 14:35:50 +01:00
Akim Demaille 57f64ebbf8 version 3.5.1
* NEWS: Record release date.
2020-01-19 14:17:48 +01:00
Akim Demaille c8d997cb5f news: update 2020-01-19 14:10:46 +01:00
Akim Demaille 61b8a8def5 CI: use ICC again
See https://github.com/nemequ/icc-travis/issues/15.
Thanks to Jeff Hammond and Evan Nemerson for their help.

* configure.ac (warn_common): Disable dubious warnings.
* .travis.yml: Use ICC again.
2020-01-19 11:36:47 +01:00
Akim Demaille 6990c5bde9 warnings: pacify ICC in lalr1.cc
See 139d065594.

* data/skeletons/yacc.c: If I might be a char, write a[+I] instead of
a[I], so that ICC does not complain.
2020-01-19 11:35:26 +01:00
Jim MeyeringandAkim Demaille 27e822abfd test: report.at: avoid tiny new failure
Be robust to newer versions of Autoconf where the package URL defaults
to https instead of http.

* configure.ac (AC_INIT): Use https.
* tests/report.at: Adjust expected output s/http/https/
to match updated URL.
2020-01-19 10:03:01 +01:00
Akim Demaille 21ba496083 git: update ignores 2020-01-19 10:02:55 +01:00
Akim Demaille c6e2dcabae regen 2020-01-17 06:51:24 +01:00
Akim Demaille e1197fcc3d yacc.c: portability to G++ 4.8
Currently we get warnings with GCC 4.8 when running the
maintainer-check-g++ tests:

    143. skeletons.at:85: testing Installed skeleton file names ...
    ../../tests/skeletons.at:120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret --skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y
    ../../tests/skeletons.at:121: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o input-cmd-line input-cmd-line.c $LIBS
    stderr:
    input-cmd-line.c: In function 'int yysyntax_error(long int*, char**, const yyparse_context_t*)':
    input-cmd-line.c:977:52: error: conversion to 'int' from 'long int' may alter its value [-Werror=conversion]
                                       YYSIZEOF (yyarg) / YYSIZEOF (*yyarg));
                                                        ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/skeletons.at:121: exit code was 1, expected 0

and

    429. calc.at:823: testing Calculator parse.error=custom %locations api.prefix={calc}  ...
    ../../tests/calc.at:823: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:823: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c $LIBS
    stderr:
    calc.y: In function 'int yyreport_syntax_error(const yyparse_context_t*)':
    calc.y:157:58: error: conversion to 'int' from 'long unsigned int' may alter its value [-Werror=conversion]
       int n = yysyntax_error_arguments (ctx, arg, sizeof arg / sizeof *arg);
                                                              ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:823: exit code was 1, expected 0

We could use a cast to avoid the warning, but it becomes too
cluttered.  We can also use YYPTRDIFF_T, but that forces the user to
use YYPTRDIFF_T too, although this is an array of tokens, which is
limited by YYNTOKENS, an int.  So let's completely avoid this warning.

* data/skeletons/yacc.c, tests/local.at (yyreport_syntax_error): Avoid
relying on sizeof to compute the array capacity.
2020-01-17 06:49:59 +01:00
Akim Demaille 1854429e40 yacc.c: pass the parse-params to yyreport_syntax_error
Enhance the calculator tests: show that passing arguments to yyerror
works.

* tests/calc.at: Add a new parse-param, nerrs, which counts the number
of syntax errors in a run.
* tests/local.at: Adjust to handle the new 'nerrs' argument, when
present.

The custom error reporting function show sees the user's additional
arguments.  Let's experiment with passing them as arguments to
yyreport_syntax_error, but maybe storing them in the context would be
a bettter alternative.

* data/skeletons/yacc.c (yyreport_syntax_error): Handle the
parse-params.
* tests/calc.at, tests/local.at: Adjust.
2020-01-17 06:49:59 +01:00
Akim Demaille cece227f95 tests: a clearer test for parse-params
Currently the parse-params are tested in calc.at by checking that the
global variable and the parse-params have the same value.  But it does
not check that value, that could remain being 0 just as well.

* tests/calc.at: Don't define the params when they are not used.
Check the final value of result and count.
Also, do count the number of line of logs.
2020-01-17 06:49:59 +01:00
Akim Demaille e83077c617 yacc.c: check custom error messages with parse-params
* tests/calc.at: Check with prefix and parse-params.
2020-01-17 06:49:59 +01:00
Akim Demaille fd33cc9c8b yacc.c: let custom error messages see the location
* data/skeletons/yacc.c (yyparse_context_t): Add yylloc when
applicable.
(yyparse_context_location): New.
* tests/local.at (AT_YYERROR_DEFINE(c)): Handle the location.
* tests/calc.at: Check it.
2020-01-17 06:49:59 +01:00
Akim Demaille 8637438cee yacc.c: isolate yyexpected_tokens
Provide users with a means to query for the currently allowed tokens.
Could be used for autocompletion for instance.

* data/skeletons/yacc.c (yyexpected_tokens): New, extracted from
yysyntax_error_arguments.
* examples/c/calc/calc.y (PRINT_EXPECTED_TOKENS): New.
Use it.
2020-01-17 06:49:59 +01:00
Akim Demaille ee97f37cb4 tests: compute verbose error messages from the custom ones
We use a different format to check parse.error custom.  Compute the
"verbose" one from it instead of forcing the test author to provide
the various formats of expected error messages.

* tests/calc.at (_AT_CHECK_CALC_ERROR): Handle this transformation
when needed.
Simplify callers.
2020-01-17 06:49:59 +01:00
Akim Demaille 68ef3a0466 yacc.c: check custom error messages
* tests/local.at (AT_ERROR_CUSTOM_IF, AT_ERROR_VERBOSE_IF)
(AT_ERROR_SIMPLE_IF): New.
(AT_YYERROR_DEFINE(c)): Generate yyreport_syntax_error.
* tests/calc.at (_AT_CHECK_CALC_ERROR): Accept custom error messages
as additional test case.
Use it.
Add a new test case for %define parse.error custom.
2020-01-17 06:49:59 +01:00
Akim Demaille cda1934606 yacc.c: add custom error message generation
When parse.error is custom, let users define a yyreport_syntax_error
function, and use it.

* data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'.
* data/skeletons/yacc.c: Implement it.
* examples/c/calc/calc.y: Experiment with it.
2020-01-17 06:49:59 +01:00
Akim Demaille 5b883180e6 yacc.c: style: avoid macros
* data/skeletons/yacc.c (YYSYNTAX_ERROR): Remove, the call is now
sufficiently small so that we can afford to duplicate it.
2020-01-17 06:49:59 +01:00
Akim Demaille 135d0336d5 yacc.c: store token numbers, not token strings
That allows users to cover more cases, such as easily filtering some
arguments they don't want to expose.  But they now have to call
yysymbol_name explicitly.

* data/skeletons/yacc.c (yysyntax_error_arguments, yysyntax_error):
Deal with symbol numbers instead of symbol names.
2020-01-17 06:49:59 +01:00
Akim Demaille cc6c647f00 yacc.c: extract yyerror_message_arguments
Isolate a function that returns the list of expected and unexpected
tokens.  It will be exposed to users willing to customize their error
messages.

* data/skeletons/yacc.c (yyparse_context_t): New.
(yyerror_message_arguments): New, extracted from yysyntax_error.
2020-01-17 06:49:59 +01:00
Akim Demaille a1aef9825a regen 2020-01-17 06:49:45 +01:00
Akim Demaille ece99a890c tests: make AT_PARSE_PARAMS usable at the end of arguments
When not empty, AT_PARSE_PARAMS was guaranteed to end with a comma.
Remove the trailing comma, so that we can use AT_PARSE_PARAMS at the
end of the arguments, not only at the beginning.

* tests/local.at: here.
Unfortunately, m4_append relies on the macro not being defined whereas
we would have preferred it to check for emptiness.  So use
m4_define/m4_undefine instead of m4_pushdef/m4_popdef.
2020-01-15 08:55:51 +01:00
Akim Demaille 169c2530e4 tests: fix AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS pairs
* tests/glr-regression.at, tests/java.at, tests/javapush.at:
Close properly what is opened.
Do not nest.
2020-01-15 08:54:52 +01:00
Akim Demaille c894a6e2ce d, java: use traces more alike that of C
Same order, same places, same content.

* data/skeletons/lalr1.d, data/skeletons/lalr1.java: here.
2020-01-15 06:23:46 +01:00
Akim Demaille 187c2ac344 c++: report the stack at the same places as in C
Let's have C be the reference, and match it elsewhere.  Maybe C is too
verbose and some adjustments are needed, but then that would be done
in another batch of patches.

* data/skeletons/lalr1.cc: Print the stack once we popped after
YYERROR, and before emptying the stack at the end of parsing.
2020-01-15 06:22:42 +01:00
Akim Demaille f06c0d2c05 c++: display the stack in the same order as in C
Currently the C and C++ parse traces differ in the order in which the
stack is displayed: bottom up in C, top down in C++.  Let's stick to
the C order.

* data/skeletons/stack.hh (stack::iterator, stack::const_iterator)
(begin, end): Be forward, not backward.
2020-01-15 06:22:31 +01:00
Akim Demaille 975be86ccc style: avoid redundancy in the tests
* tests/local.at (m4_rpatsubst): New.
Use it to handle %parse-params.
* tests/calc.at: Use %parse-params with several arguments.
2020-01-15 06:22:19 +01:00
Akim Demaille 1c0adb410d yacc.c: comment changes
In particular, import Adrian Vogelsgesang's comments about LAC from
lalr1.cc.

* data/skeletons/yacc.c: here.
2020-01-11 18:01:39 +01:00
Akim Demaille 32b529f038 yacc.c: style: double-quote the argument of b4_percent_define_get
* data/skeletons/yacc.c: Here, for consistency.
2020-01-11 17:35:24 +01:00
Akim Demaille 46cce832fd yacc.c: introduce yysymbol_name
Provide the users with a public API to get the name of the tokens.  A
thin wrapper around yytname.

* data/skeletons/yacc.c (yysymbol_name): New.
Use it.
2020-01-11 16:14:06 +01:00
Akim Demaille 98a1045bea CI: check on PPC64le, ARM64 and s390x
I was hoping it would help us catch warnings when char is
unsigned (see 78bb152a63), but it does
not seem to help.  It's a pity that the compiler is the same all over
the place, I would have preferred testing others.

* .travis.yml: here.
2020-01-11 16:11:45 +01:00
Akim Demaille 8426663631 todo: update 2020-01-11 08:59:51 +01:00
Akim Demaille a0675d707f Merge branch 'maint' into HEAD
* maint:
  gnulib: update
  lalr1.cc: avoid static_cast
  glr.c: add missing cast
  regen
  package: bump copyrights to 2020
  gitignore: update
2020-01-11 07:38:39 +01:00
Akim Demaille 9cf0a97aa9 gnulib: update 2020-01-11 06:03:51 +01:00
Akim Demaille 3dec8a4caf lalr1.cc: avoid static_cast
Reported by donmac703.
Fixes https://github.com/akimd/bison/issues/20.

* data/skeletons/lalr1.cc: here.
2020-01-10 19:31:00 +01:00
Akim Demaille 2cb52c5a91 glr.c: add missing cast
Reported by psjo.
Fixes https://github.com/akimd/bison/issues/19.

* data/skeletons/glr.c (yyprocessOneStack): Here.
2020-01-10 19:30:54 +01:00
Akim Demaille 04f3bfc596 regen 2020-01-10 19:21:35 +01:00
Akim Demaille c67daa9a97 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-10 19:16:23 +01:00
Akim Demaille 2ca8e86f83 gitignore: update 2020-01-10 19:16:16 +01:00
Akim Demaille e419eda5e2 regen 2020-01-10 18:38:02 +01:00
Akim Demaille 2116af766a yacc.c: simplify use of YYDPRINTF
* data/skeletons/yacc.c (YYDPRINTF): Expand to no-op (instead of
nothing) when disabled.
Simplify callers.
2020-01-09 09:02:55 +01:00
Akim Demaille 8036635251 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-05 10:26:35 +01:00
Akim Demaille c442b5de9d gitignore: update 2020-01-05 09:40:46 +01:00
Akim Demaille da4587fcd7 doc: YYERROR_VERBOSE is no longer supported
* doc/bison.texi (Table of Symbols): Remove last reference to it.
* NEWS: Be clear about that.
2020-01-04 09:14:19 +01:00
Akim Demaille 86a3ec0f8d glr.c: no longer support YYERROR_VERBOSE
* data/skeletons/glr.c: Rather, dispatch directly on parse.error's
value.
2020-01-04 09:14:19 +01:00
Akim Demaille 7122d747cf yacc.c: no longer support YYERROR_VERBOSE
Supporting YYERROR_VERBOSE via cpp is a nuisance: m4 is in charge of
handling alternatives.  When adding more options for %define
parse.error, supporting both CPP and M4 is too complex.  Anyway,
YYERROR_VERBOSE was deprecated long ago.

* data/skeletons/yacc.c: Use m4 only to handle verbose/simple error
messages.
2020-01-04 09:12:43 +01:00
Akim Demaille 69fe4b9eb6 yacc.c: avoid negations
* data/skeletons/yacc.c (yyerrlab): here.
2020-01-03 09:07:40 +01:00
Akim Demaille 385fb345bf glr.c: clarify yyreportSyntaxError
See the previous commit.

* data/skeletons/glr.c (yyreportSyntaxError): First compute the
arguments of the error message, _then_ th error message size.
2019-12-31 12:00:04 +01:00
Akim Demaille f983d00e77 yacc: restructure and fix yysyntax_error
I would like to offer new ways to build the error message.  As a first
step, let's simplify yysyntax_error whose first loop does two things
at the same time: (i) collect the tokens to be reported in the error
message, and (ii) accumulate their sizes and possibly return
"overflow".  Let's pull (ii) in a second step.

Then test 525 (regression.at:1193: parse.error=verbose overflow)
failed.  This test checks that we correctly report "memory overflow"
when the error message is too large.  However the test is mistaken: it
is triggered in a place where there are five (large) expected tokens,
so anyway we would not display them, so there is no (memory) overflow
here!  Transform this test to (i) check that indeed there is no
overflow, and (ii) create syntax_error3 which does check the intended
behavior, but with four expected tokens.

* data/skeletons/yacc.c (yysyntax_error): First compute the list of
arguments, then compute yysize.
* tests/regression.at (parse.error=verbose overflow): Enhance and fix.
2019-12-31 12:00:04 +01:00
Akim Demaille 78bb152a63 tests: also check -Wchar-subscripts
GCC's -Wchar-subscripts may report issues on platforms where char is
unsigned.  Unfortunately the current CI does not reproduce the
problem.  But that would allow contributors to report issues if the
warning appears somewhere.

See 139d065594.
Problem reported by Andy Fiddaman in:
https://lists.gnu.org/r/bug-bison/2019-12/msg00021.html

* configure.ac (warn_common): Add -Wchar-subscripts.
2019-12-31 12:00:02 +01:00
Akim Demaille 4d6ff4c5e5 CI: do not specify the language
When we give travis the langugage, it overrides our envvars.  Instead
of the MATRIX_EVAL trick, just stop specifying the language.
2019-12-30 15:28:15 +01:00
Akim Demaille 9bb5087ad1 CI: remove ICC support, we can no longer use it
https://github.com/nemequ/icc-travis/issues/15
2019-12-30 08:56:46 +01:00
Akim Demaille d29e40a047 doc: clean up the description of YYDEBUG
* doc/bison.texi: Make it clearer that %define parse.trace is the
preferred options.
Fix a typo about api.prefix.
2019-12-29 11:13:00 +01:00
Akim Demaille b10366f296 glr.cc: avoid compiler warnings
381. types.at:366: testing glr.cc api.value.type={double} ...
    test.cc:207:57: error: "__clang_major__" is not defined, evaluates to 0 [-Werror=undef]
      207 | #if defined __APPLE__ && YY_CPLUSPLUS < 201103L && 4 <= __clang_major__
          |                                                         ^~~~~~~~~~~~~~~

* data/skeletons/glr.cc: Check __clang_major__ before using it.
2019-12-29 11:13:00 +01:00
Paul Eggert 139d065594 warnings: pacify ‘gcc -Wchar-subscripts’ in yacc.c
Problem reported by Andy Fiddaman in:
https://lists.gnu.org/r/bug-bison/2019-12/msg00021.html
* data/skeletons/yacc.c (yy_reduce_print, yy_lac, yysyntax_error)
(yyreturn): If I might be a char, write a[+I] instead of a[I],
so that ‘gcc -Wchar-subscripts’ does not complain.
2019-12-18 13:35:28 -08:00
Akim Demaille 0d73c39bb7 doc: formatting changes
* doc/bison.texi: No output changes.
2019-12-14 17:19:53 +01:00
Akim Demaille 7f01adced9 tests: don't fail if seq is no available
As is the case on Solaris.
Reported by Dennis Clarke.
https://lists.gnu.org/archive/html/bug-bison/2019-12/msg00011.html

* examples/c/reccalc/reccalc.test: Skip if there is no seq.
2019-12-14 17:19:53 +01:00
Akim Demaille 3bad20352c maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-12-11 07:57:45 +01:00
Akim Demaille cb3bf6493d version 3.5
* NEWS: Record release date.
2019-12-11 07:41:51 +01:00
Akim Demaille 57503e2165 news: prepare for 3.5 2019-12-10 07:06:04 +01:00
Akim Demaille b3abe014f2 glr.cc: disable warnings from Clang on macOS
$ cat test.cc
    #include <stddef.h>
    #include <stdint.h>

    ptrdiff_t half_max_capacity = PTRDIFF_MAX;
    $ clang++-mp-9.0 -pedantic -std=c++98 /tmp/test.cc -c
    /tmp/test.cc:4:31: warning: 'long long' is a C++11 extension [-Wc++11-long-long]
    ptrdiff_t half_max_capacity = PTRDIFF_MAX;
                                  ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdint.h:149:23:
            note: expanded from macro 'PTRDIFF_MAX'
    #define PTRDIFF_MAX       INT64_MAX
                              ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdint.h:75:26:
            note: expanded from macro 'INT64_MAX'
    #define INT64_MAX        9223372036854775807LL
                             ^
    1 warning generated.

* data/skeletons/glr.cc: here.
2019-12-08 16:34:53 +01:00
Akim Demaille 80f3220fea api.token.raw: fix it in C++
Another breakage revealed by vcsn.

* data/skeletons/c++.m4 (yytranslate_): Do not hard code "yy" and
"parser", both can be changed by the user.
Actually, since we are in the parser itself, there's really no need to
qualify the type.
2019-12-08 16:07:50 +01:00
Akim Demaille fc2040a750 c++: fix comments for %code blocks
In a project of mine, vcsn, this commit fixes the following comments.

    --- /tmp/parse.hh	2019-12-08 15:51:24.792934703 +0100
    +++ lib/vcsn/rat/parse.hh	2019-12-08 16:00:59.137107503 +0100
    @@ -43,7 +43,7 @@

     #ifndef YY_YY_USERS_AKIM_SRC_LRDE_2_LIB_VCSN_RAT_PARSE_HH_INCLUDED
     # define YY_YY_USERS_AKIM_SRC_LRDE_2_LIB_VCSN_RAT_PARSE_HH_INCLUDED
    -// //                    "%code requires" blocks.
    +// "%code requires" blocks.
     #line 20 "/Users/akim/src/lrde/2/lib/vcsn/rat/parse.yy"

       #include <iostream>
    @@ -1851,7 +1851,7 @@

    -// //                    "%code provides" blocks.
    +// "%code provides" blocks.
     #line 60 "/Users/akim/src/lrde/2/lib/vcsn/rat/parse.yy"

       #define YY_DECL_(Class) \

* data/skeletons/bison.m4 (b4_percent_code_get): Pass an expanded
string to b4_comment.
2019-12-08 16:03:36 +01:00
Akim Demaille d55f240991 parser: pretend we are Bison 3.5
* src/parse-gram.y: Accept we're Bison 3.5.
2019-12-08 16:03:36 +01:00
Akim Demaille 4f961a706d c++: fix spello
* data/skeletons/lalr1.cc: here.
2019-12-08 15:42:41 +01:00
Akim Demaille ac203e6c3c todo: update
* TODO: Schedule some features for 3.6.
Remove obsolete stuff.
2019-12-08 10:12:02 +01:00
Akim Demaille 9141f0b79f maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-12-08 09:29:24 +01:00
Akim Demaille d57eab87e8 version 3.4.92
* NEWS: Record release date.
2019-12-08 09:12:30 +01:00
Akim Demaille bb901beb68 news: fixes
Reported by Paul Eggert.
https://lists.gnu.org/archive/html/bison-patches/2019-12/msg00014.html

* NEWS: here.
2019-12-08 09:12:07 +01:00
Akim Demaille fa00c56c17 doc: minor changes
* README-hacking.md: here.
2019-12-07 18:23:08 +01:00
Akim Demaille 5359c479bc gnulib: update 2019-12-07 15:29:43 +01:00
Akim Demaille 20107b77c0 doc: clearly deprecate YYPRINT
* doc/bison.texi (Prologue): Stop using YYPRINT as an example.
(The YYPRINT Macro): Clearly show this macro is deprecated.
2019-12-07 15:29:43 +01:00
Akim Demaille 5e71eef267 doc: formatting changes
* doc/bison.texi: here.
No change in content.
2019-12-07 15:29:43 +01:00
Akim Demaille 472531dc72 news: update 2019-12-07 15:29:43 +01:00
Akim Demaille 046f238826 d: obey parse.error
* data/skeletons/lalr1.d (yysyntax_error): Let the dispatch be
bison-time, not runtime.
2019-12-07 13:23:45 +01:00
Akim Demaille 9bf06f6963 c++: also prefer YY_ASSERT to YYASSERT
Like the other skeletons.

* data/skeletons/variant.hh: here.
2019-12-07 13:23:45 +01:00
Akim Demaille 357336d254 glr.c: obey the parse.assert %define variable
* data/skeletons/glr.c (YYASSERT): Rename as...
(YY_ASSERT): this, for consistency with yacc.c, and also to emphasize
the fact that this is not for the end user (YY_ prefix).
* tests/glr-regression.at: Define parse.assert.
2019-12-07 13:23:45 +01:00
Akim Demaille d4a6c3c58a c++: beware of short ranges for state numbers
Now that we use small integral types, possibly unsigned (e.g.,
unsigned char), to store state numbers, using -1 to denote an empty
state (i.e., a state that stores no semantical value) is very
dangerous: it will be confused with state 255, which might be
non-empty.

Rather than allocating a larger range of state numbers to keep the
empty-state apart, let's use the number of a state known to store no
value.  The initial state, numbered 0, seems to fit perfectly the job.

Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

* data/skeletons/lalr1.cc (empty_state): Be 0.
2019-12-07 09:22:55 +01:00
Akim Demaille 8976e0f567 api.token.raw: check it against api.token.constructor
* tests/scanner.at: here.
2019-12-07 08:57:14 +01:00
Akim Demaille 6dca1eb950 regen 2019-12-06 08:27:55 +01:00
Akim Demaille f8d82ff039 warnings: enable -Wuseless-cast, and eliminate warnings
Prompted by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html.

* configure.ac (warn_cxx): Add -Wuseless-cast.
* data/skeletons/c.m4 (b4_attribute_define): Define
YY_IGNORE_USELESS_CAST_BEGIN and YY_IGNORE_USELESS_CAST_END.
* data/skeletons/glr.c (YY_FPRINTF): New, replaces YYFPRINTF, wrapped
with YY_IGNORE_USELESS_CAST_BEGIN and YY_IGNORE_USELESS_CAST_END.
(YY_DPRINTF): Likewise.
* tests/actions.at: Remove useless cast.
* tests/headers.at: Adjust.
2019-12-06 08:27:55 +01:00
Akim Demaille 9e9e49224f diagnostics: style changes
* src/complain.h, src/complain.c: Comment changes.
* src/scan-skel.l: Reduce scopes.
* data/skeletons/bison.m4: Factor diagnostic functions.
2019-12-02 19:35:01 +01:00
Akim Demaille 8b53f4e022 glr.c: style changes
* data/skeletons/glr.c (yysplitStack): Reduce scopes.
* tests/atlocal.in: Formatting changes.
2019-12-02 19:34:48 +01:00
Akim Demaille 8c87a62308 c++: get rid of symbol_type::token ()
It is not used.  And its implementation was wrong when api.token.raw
was defined, as it was still mapping to the external token numbers,
instead of the internal ones.  Besides it was provided only when
api.token.constructor is defined, yet always declared.

* data/skeletons/c++.m4 (by_type::token): Remove, useless.
2019-12-01 10:05:48 +01:00
Akim Demaille 478cb5cf12 c++: remove useless cast about user_token_number_max_
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

The cast is needed when yytranslate_'s argument type is token_type,
i.e., when api.token.constructor is defined.

    373. types.at:138: testing lalr1.cc api.value.type=variant api.token.constructor ...
    ======== Testing with C++ standard flags: ''
    ../../tests/types.at:138: bison --color=no -fno-caret  -o test.cc test.y
    ../../tests/types.at:138: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    test.cc:966:16: error: result of comparison of constant 257 with
                    expression of type 'yy::parser::token_type'
                   (aka 'yy::parser::token::yytokentype') is always true
                   [-Werror,-Wtautological-constant-out-of-range-compare]
        else if (t <= user_token_number_max_)
                 ~ ^  ~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

It is because it is expected that when api.token.constructor is
defined, only symbol constructors will be used, that yytranslate_ then
takes a token_type.  But it is wrong: we still allow literal
characters in this case, as demonstrated by test 373 for instance.

    %define api.value.type variant
    %define api.token.constructor
    %token <std::pair<int, int>> '1' '2';
    [...]
    static yy::parser::symbol_type yylex ()
    {
      static char const input[] = "12";
      int res = input[toknum++];
      typedef yy::parser::symbol_type symbol;
      if (res)
        return symbol (res, std::make_pair (res - '0', res - '0' + 1));
      else
        return symbol (res);
    }

So let yytranslate_ always take an int, which makes the cast truly
useless.

* data/skeletons/c++.m4, data/skeletons/lalr1.cc (yytranslate_): here.
2019-12-01 08:53:58 +01:00
Akim Demaille 94f70bd861 c++: clean a few issues wrt special tokens
The C++ implementation of LAC did not skip the $undefined token,
probably because it was not exposed.  Expose it, and use clearer
names.

* data/skeletons/c++.m4: Don't define undef_token_ in yytranslate_,
but...
* data/skeletons/lalr1.cc (yy_undef_token_): here.
Use a more precise type to define yy_undef_token_ and yy_error_token_.
Unfortunately we move from a compile-time value defined via an enum to
a static const member.  Eventually we should make it constexpr.
Make LAC implementation more alike yacc.c's one.
2019-12-01 08:08:19 +01:00
Akim Demaille 9b4f0970fe d, java: improve yytranslate and neighbors
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: Don't expose
yyuser_token_number_max_ and yyundef_token_.  Do as in C++: scope them
into yytranslate_, and only when api.token.raw is not defined.
(yyterror_): Rename as...
(yy_error_token_): this.
* data/skeletons/lalr1.d (token_number_type): New.
Use it.
Can't be done in the Java backend, as Java does not have type aliases.
2019-12-01 07:59:23 +01:00
Akim Demaille 869028a66d d, java: get rid of a useless table
* data/skeletons/lalr1.d, data/skeletons/lalr1.java (yytoken_number_):
Remove, useless.
Was used in ancient C skeletons to support YYPRINT, long obsoleted by
%printer.
2019-12-01 07:38:31 +01:00
Akim Demaille 6f92a7f664 c++, d, java: remove yyerrcode
It is not used at all.  We will remove it also from yacc.c, but
later (see TODO).

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java (yyerrcode_):
Remove.
2019-11-30 17:30:48 +01:00
Akim Demaille 6a61b6b17e c++: improve typing
* data/skeletons/lalr1.cc (yysyntax_error_): symbol_type::type_get
returns a symbol_number_type (which is indeed an int).
2019-11-30 17:30:48 +01:00
Akim Demaille a4bf7cdf9e c++: remove useless cast about yyeof_
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

* data/skeletons/c++.m4 (b4_yytranslate_define): Don't use yyeof_ as
if it had two different types.
It is used once against the input argument, which is the value
returned by yylex, which is an "external token number", typically an
int.  It is also used as output type, an "internal symbol number".
It turns out that in both cases we mean "0", but let's keep yyeof_
only for the case "internal symbol number", i.e., _after_ conversion
by yytranslate.
This frees us from one cast.
2019-11-30 17:30:48 +01:00
Akim Demaille 9471a5ffe9 glr: style change
* data/skeletons/glr.c (YYDPRINTF): Expand into an empty statement,
instead of nothing.
Simplify callers.
2019-11-30 14:41:16 +01:00
Akim Demaille 24c5214ae8 glr: remove useless casts
Reported by GCC's -Wuseless-cast.

* data/skeletons/glr.c: Don't cast to yybool, it's useless.
2019-11-30 14:41:16 +01:00
Akim Demaille 2f7097d1b1 yacc.c, glr.c: fix crash when reporting errors in consistent states
The current code for yysyntax_error for %define parse.error verbose is
fishy (given that YYEMPTY is -2, invalid argument for yytname[]):

    static int
    yysyntax_error ([...])
    {
      YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
    [...]
      if (yytoken != YYEMPTY)

A nearby comment reports

    The only way there can be no lookahead present (in yychar) is if
    this state is a consistent state with a default action.  Thus,
    detecting the absence of a lookahead is sufficient to determine
    that there is no unexpected or expected token to report.  In that
    case, just report a simple "syntax error".

So it _is_ possible to call yysyntax_error with yytoken == YYEMPTY,
albeit quite difficult when meaning to, so virtually impossible by
accident (after all, there was never a bug report about this).

I failed to produce a test case, but Joel E. Denny provided me with
one (added to the test suite below).  The yacc.c skeleton fails on
this, and once fixed dies on a second problem.  The glr.c skeleton was
also dying, but immediately of this second problem.

Indeed we were not allocating space for the error message's final \0.
This was hidden by the fact that we only had error messages with at
least an unexpected token displayed, so with at least one "%s" in the
format string, whose size (2) was included (incorrectly) in the final
size of the message (where the %s have been replaced by the actual
content).

* data/skeletons/glr.c, data/skeletons/yacc.c (yysyntax_error):
Do not invoke yytnamerr on YYEMPTY.
Clarify the computation of the length of the _final_ error message,
with the NUL terminator but without the '%s's.
* tests/conflicts.at (Syntax error in consistent error state):
New, contributed by Joel E. Denny.
2019-11-29 18:21:43 +01:00
Akim Demaille 28369ecb5d tests: avoid creating files whose name collide with standard headers
Having a file named "exception" is risky: the compiler might use that
file in #include.
Reported by 马俊 <[email protected]>.

* tests/local.at (AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR): Generate
'exceptions', not 'exception'.
2019-11-26 08:05:32 +01:00
Akim Demaille b92f064e9b doc: more details about the test suite
* README-hacking.md: here.
2019-11-22 09:02:06 +01:00
Akim Demaille 98f19578aa maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-11-20 07:49:44 +01:00
Akim Demaille 7d9839c4a8 version 3.4.91
* NEWS: Record release date.
2019-11-20 07:13:38 +01:00
Akim Demaille ad32ec64c8 style: pacify syntax-check
* cfg.mk: No need to translate *.md files.
* data/skeletons/glr.c, data/skeletons/yacc.c: Fix space issues.
2019-11-20 07:10:27 +01:00
Akim Demaille 44cdc0f001 gnulib: update 2019-11-19 21:15:00 +01:00
Akim Demaille ca796220ec doc: don't promote dangling aliases
String literals as tokens serve two distinct purposes: freeing from
having to implement the keyword matching in the scanner, and improving
error messages.  Most of the time both can be achieved at the same
time, but on occasions, it does not work so well.

We promote their use for error messages.  We will also still support
the former case, but it is _not_ the recommended approach.

* doc/bison.texi (Tokens from Literals): Clearly state that we don't
recommend looking up the token types in the list of token names.
2019-11-18 09:15:35 +01:00
Akim Demaille 8a910107b3 diagnostics: complain about undeclared string tokens
String literals, which allow for better error messages, are (too)
liberally accepted by Bison, which might result in silent errors.  For
instance

    %type <exVal> cond "condition"

does not define “condition” as a string alias to 'cond' (nonterminal
symbols do not have string aliases).  It is rather equivalent to

    %nterm <exVal> cond
    %token <exVal> "condition"

i.e., it gives the type 'exVal' to the "condition" token, which was
clearly not the intention.

Introduce -Wdangling-alias to catch this.

* src/complain.h, src/complain.c: Add support for -Wdangling-alias.
(argmatch_warning_args): Sort.
* src/symtab.c (symbol_check_defined): Complain about dangling
aliases.
* doc/bison.texi: Document it.
* tests/input.at (Dangling aliases): New test.
2019-11-17 18:27:42 +01:00
Akim Demaille 28d1ca8f48 diagnostics: yacc reserves %type to nonterminals
On

    %token TOKEN1
    %type  <ival> TOKEN1 TOKEN2 't'
    %token TOKEN2
    %%
    expr:

bison -Wyacc gives

    input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |               ^~~~~~
    input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                             ^~~
    input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                      ^~~~~~

The messages appear to be out of order, but they are emitted when the
error is found.

* src/symtab.h (symbol_class): Add pct_type_sym, used to denote
symbols appearing in %type.
* src/symtab.c (complain_pct_type_on_token): New.
(symbol_class_set): Check that %type is not applied to tokens.
(symbol_check_defined): pct_type_sym also means undefined.
* src/parse-gram.y (symbol_decl.1): Set the class to pct_type_sym.
* src/reader.c (grammar_current_rule_begin): pct_type_sym also means
undefined.
* tests/input.at (Yacc's %type): New.
2019-11-17 09:45:25 +01:00
Akim Demaille 1817b475a6 doc: promote %nterm over %type
As an extension to POSIX Yacc, Bison's %type accepts tokens.
Unfortunately with string literals as implicit tokens, this is
misleading, and led some users to write

    %type <exVal> cond "condition"

believing that "condition" would be associated to the 'cond'
nonterminal (see https://github.com/apache/httpd/pull/72).

* doc/bison.texi: Promote %nterm rather than %type to declare the type
of nonterminals.
2019-11-16 12:54:44 +01:00
Akim Demaille 22ca07defa doc: formatting changes
* doc/bison.texi: No visible changes.
2019-11-16 12:54:44 +01:00
Akim Demaille dbd6975b5c doc: work around warnings when Flex C output is compiled in C++
* doc/bison.texi (calc++/scanner.ll): here.
While at it, clarify clang vs. warnings.
2019-11-16 12:54:44 +01:00
Akim Demaille cd726fdc4d tests: be robust to old Perl versions on Cygwin
Reported by Denis Excoffier.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00008.html.

* tests/output.at: Be sure to remove back up files.
2019-11-16 12:54:44 +01:00
Akim Demaille 60ebd8e210 regen 2019-11-16 12:54:44 +01:00
kaneko yandAkim Demaille 3765e3e790 gram.c: Fix condition of aver
* src/gram.c (grammar_dump): Fix condition of aver.
What we want to check is that rhs is followed by its rule.
2019-11-12 08:39:28 +01:00
Akim Demaille c313360deb doc: clarify build instructions
* README: A few fixes.
Explain how to install color support.
* README-hacking: Rename as...
* README-hacking.md: this, and convert to Markdown.
Improve typography.
Improve explanations about update-test.
2019-11-11 15:59:53 +01:00
Akim Demaille 25698b58c0 gnulib: update 2019-11-11 15:41:29 +01:00
Yuichiro KanekoandAkim Demaille 17d34c231b gram.c: also print terminals in grammar_dump
* src/gram.c (grammar_dump): Print terminals likewise non terminals.
* tests/sets.at (Reduced Grammar): Update test case to catch up the
change and add a test case where prec and assoc are used.
2019-11-11 10:37:30 +01:00
Akim Demaille af000bab11 doc: work around Texinfo 6.7 bug
When @code is used in a @deftype... definition, it issues quotes.
Remove them.
See https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html.

* doc/local.mk: here.
2019-11-10 14:59:11 +01:00
Akim Demaille b2347a3c3e doc: formatting changes
* doc/bison.texi: Wrap lines.
No semantical difference.
2019-11-09 07:57:05 +01:00
Akim Demaille 008d927f71 doc: use upper case for tokens
* doc/bison.texi: here.
2019-11-09 07:54:32 +01:00
Akim Demaille 1650c729d9 doc: type-face fixes
* doc/bison.texi: Use @code for types in function definitions.
2019-11-07 07:13:40 +01:00
Akim Demaille 7bdf7246fb c++: expose the type used to store line and column numbers
* data/skeletons/location.cc (position::counter_type)
(location::counter_type): New.
Use them.
* doc/bison.texi (C++ position, C++ location): Adjust.
2019-11-06 18:20:15 +01:00
Akim Demaille 583c193ffa tests: fix comment and adjust to locale names on GNU/Linux
Reported by Denis Excoffier.

* tests/diagnostics.at: here.
2019-11-03 10:32:22 +01:00
Akim Demaille 47b9ada6fa tests: really check complaints from m4
* tests/diagnostics.at (Locations from M4, Tabulations and multibyte
characters from M4): These tests are actually checking a message
coming from C, not from M4.  Replace with...
(Complaints from M4): This.
2019-11-03 10:32:22 +01:00
Akim Demaille dcd5bb26e3 tests: simplify prologue
* tests/testsuite.h: We no longer load gnulib in the tests.
2019-11-03 10:32:22 +01:00
Akim Demaille cce6c998b6 diagnostics: add missing translation
* src/muscle-tab.c (muscle_percent_define_check_kind): Here.
2019-11-03 09:24:12 +01:00
Akim Demaille 3398b0fa90 c++: fix old cast warnings
We still have a few old C casts in lalr1.cc, let's get rid of them.
Reported by Frank Heckenbach.

Actually, let's monitor all our casts using easy to grep macros.
Let's use these macros to use the C++ standard casts when we are in
C++.

* data/skeletons/c.m4 (b4_cast_define): New.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/yacc.c:
Use it and/or its casts.

* tests/actions.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/headers.at, tests/torture.at,
* tests/types.at:
Use YY_CAST instead of C casts.

* configure.ac (warn_cxx): Add -Wold-style-cast.
* doc/bison.texi: Disable it.
2019-11-02 16:40:50 +01:00
Akim Demaille 2bd1d9e20f tests: be robust to tput errors
Reported by Denis Excoffier.

* tests/bison.in: here.
2019-11-01 12:04:13 +01:00
Akim Demaille 1f2546396e git: update ignores
I don't understand what happened in
10acc148bb.
2019-11-01 12:04:13 +01:00
Akim Demaille 809268c1a4 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-10-29 21:58:53 +01:00
Akim Demaille 10acc148bb version 3.4.90
* NEWS: Record release date.
2019-10-29 21:41:00 +01:00
Akim Demaille 28f1e1546c C++: finish propagating the unsigned->signed conversion in locations
* data/skeletons/location.cc: Remove the u (for unsigned) suffix from
the initial line and column.
* NEWS: AFAICT, only C++ backends have their location types changed.
2019-10-29 09:15:25 +01:00
Akim Demaille c53b379784 style: fix cpp indentation
Reported by syntax-check.

* src/system.h: here.
2019-10-29 09:00:46 +01:00
Akim Demaille fead28d9e3 style: glr.c: comment changes
* data/skeletons/glr.c: here.
2019-10-29 08:59:18 +01:00
Akim Demaille 7e0b50c524 CI: pass -O1 to GCC8 with sanitizers
This build never finishes in the 50min credit given by Travis.  See if
with optimizations it works better.

* .travis.yml: here.
2019-10-26 10:39:01 +02:00
Akim Demaille 8228d96d33 reader: reduce the "scope" of global variables
We have too many global variables, adding structure would help.  For a
start, let's hide some of the variables closer to their usage.

* src/getargs.c, src/files.h (current_file): Move to...
* src/scan-gram.c: here.
* src/scan-gram.h (gram_in, gram__flex_debug): Remove, make them
private to the scanner.
* src/reader.h, src/reader.c (reader): Take a grammar file as argument.
Move the handling of scanner variables to...
* src/scan-gram.l (gram_scanner_open, gram_scanner_close): here.
(gram_scanner_initialize): Remove, replaced by gram_scanner_open.
* src/main.c: Adjust.
2019-10-26 10:39:01 +02:00
Akim Demaille a5fc4e3b44 regen 2019-10-26 10:39:01 +02:00
Akim Demaille 3be912e4af parser: use grammar_file instead of current_file
* src/parse-gram (%initial-action): here.
(handle_skeleton): Don't depend on the current file name to look for
"local" skeletons (subject to changes coming from "#lines"): depend
only on the initial file name, the one given on the command line.
2019-10-26 10:38:39 +02:00
Akim Demaille 4b4e532748 diagnostics: use grammar_file instead of current_file
Currently there are two globals denoting the input file: grammar_file
is the one from the command line, and current_file which might change
because of #line.  Use only the former.

* src/complain.c (error_message): here.
* tests/diagnostics.at: Adjust.
2019-10-26 09:11:40 +02:00
Akim Demaille 6e7d8ba6a7 reader: let symtab deal with the symbols
* src/reader.c (reader): Move the setting up of the builtin symbols to...
* src/symtab.c (symbols_new): here.
2019-10-25 07:48:07 +02:00
Akim Demaille c680300a29 style: remove incorrect comment
Reported by Paul Eggert.

* src/system.h: here.
2019-10-25 07:41:38 +02:00
Akim Demaille 0cbefb71e8 lalr1.cc: fix previous commit: printing of state numbers
* data/skeletons/lalr1.cc: Printing a char prints... a char.
Print ints instead.
2019-10-24 23:02:26 +02:00
Akim Demaille 402332c4b6 lalr1.cc: use computed state types
This skeleton uses a single stack of state structures, so it is less
likely to benefit from a stack size reduction than yacc.c (which uses
several stacks: state number, value and location).  But it will reduce
the size of the LAC stack.

This skeleton was already using int for state numbers, so, contrary to
yacc.c, this brings nothing for large automata.

Overall, it is still nicer to make the skeletons alike.

* data/skeletons/lalr1.cc (state_type): Here.
2019-10-24 18:16:01 +02:00
kaneko yandAkim Demaille aa244fc5fe README: Fix a typo
* README: Fix a typo. Git command name is submodule.
2019-10-24 18:13:17 +02:00
Akim Demaille 719395c9cd examples: fix missing dependencies
Reported by Thomas Petazzoni.
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00000.html

* examples/c/reccalc/local.mk: Complete dependencies, including for
earlier versions of Automake (for sake of our CI, on top of Ubuntu
Xenial/Bionic, which feature only Automake 1.15).
(%D%/scan.c %D%/scan.h): Upgrade to the full version provided in
Automake's documentation.
2019-10-24 18:01:53 +02:00
Akim Demaille fa9871a2fb diagnostics: simplify location handling
Locations start at line 1.  Don't accept line 0.

* src/location.c (location_print): Don't print locations with line 0.
(location_caret): Simplify.
2019-10-24 18:00:43 +02:00
Akim Demaille 76597d01f3 build: reenable -Wtype-limits
See https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html
to https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00073.html.

Paul Eggert's changes in gnulib do fix the issue for modern GCCs (7,
8, 9) on macOS.  Unfortunately these warnings are back on the
CI (GNU/Linux) with GCC 4.6, 4.7, (not 4.8) and 4.9.

Disable the warning locally.

* configure.ac (warn_common, warn_tests): Remove -Wtype-limits.
* src/system.h (IGNORE_TYPE_LIMITS_BEGIN, IGNORE_TYPE_LIMITS_END): New.
* src/InadequacyList.c, src/parse-gram.c, src/parse-gram.y,
* src/symtab.c: Use it.
2019-10-24 08:50:14 +02:00
Akim Demaille bc5efb558d build: remove dmalloc support
Today sanitizers are a better alternative.

* m4/dmalloc.m4: Remove.
* configure.ac, src/system.h: Adjust.
2019-10-24 07:22:17 +02:00
Akim Demaille 17e21f6158 gitignore: update 2019-10-23 23:09:56 +02:00
Paul Eggert 6ef8513e7c build: update gnulib submodule to latest 2019-10-23 13:44:58 -07:00
Yuichiro KanekoandAkim Demaille 3945beb1d2 style: update comment in reader.c
rrhs and rlhs were removed by b2ed6e5826.

* src/reader.c (packgram): Update comment.
2019-10-23 08:32:06 +02:00
kaneko yandAkim Demaille c86b7815fc yacc.c: fix a typo
* data/skeletons/yacc.c (yysetstate): fix comment.
2019-10-22 19:05:02 +02:00
Akim Demaille 048730c691 style: pacify syntax-check
* doc/.gitignore, src/complain.c, src/getargs.c,
* src/output.c: here.
2019-10-22 10:40:12 +02:00
Akim Demaille ec64a0bc7e main: also free memory on errors
* src/derives.c (derives_free): Beware of NULL.
* src/main.c (main): Let the 'finish' label include memory release.
2019-10-21 17:18:32 +02:00
Akim Demaille d6fe39cd18 gnulib: update
To get bitset_free accept NULL.  See
https://lists.gnu.org/archive/html/bug-gnulib/2019-10/msg00054.html
2019-10-21 17:18:32 +02:00
Akim Demaille d76ea5ce06 style: reduce scope in derives
* src/derives.c: here.
And prefer prefix to postfix increment.
2019-10-21 17:18:32 +02:00
Akim Demaille fdef997432 build: disable -Wtautological-constant-out-of-range-compare
Also see e31f92495c and
https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html

* configure.ac (warn_common): Disable
-Wtautological-constant-out-of-range-compare.
(warn_tests): Restore it.
2019-10-21 10:35:01 +02:00
Akim Demaille 0073b5ea5f CI: formatting changes
* .travis.yml: Use the single line form of lists, when reduced to a
singletons.
2019-10-21 08:53:07 +02:00
Akim Demaille 717be0a0f0 CI: rename jobs
* .travis.yml (compile, test): Rename as...
(dist, check): these, which are more traditional for GNU projects.
2019-10-21 08:53:07 +02:00
Akim Demaille c6e4b260e0 doc: update README
* README: Be clearer that README-hacking _must_ be read.
Convert to Markdown.
2019-10-21 08:53:06 +02:00
Akim Demaille 8b87da8d12 bootstrap: relieve developpers from Gettext version mismatch issues
* .travis.yml (compile): Move the workaround from here...
* bootstrap.conf (bootstrap_epilogue): to there.
2019-10-21 08:38:03 +02:00
Akim Demaille 41b1f828ae tests: beware of GCC9 warnings in push mode
This is really weird: GCC points to the LHS of the assignment...

    260. headers.at:184: testing Sane headers: api.pure api.push-pull=both ...
    tests/headers.at:184: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -d -o input.c input.y
    tests/headers.at:184: $CC $CFLAGS $CPPFLAGS  -c -o input.o input.c
    stderr:
    input.c: In function 'yyparse':
    input.c:1276:16: error: 'yylval' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1276 |         yylval = *yypushed_val;
          |         ~~~~~~~^~~~~~~~~~~~~~~
    input.c: In function 'yypull_parse':
    input.c:1276:16: error: 'yylval' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1276 |         yylval = *yypushed_val;
          |         ~~~~~~~^~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    stdout:
    tests/headers.at:184: exit code was 1, expected 0

See also d87c8ac79a
and 9645a2b20e.

* tests/headers.at (Several parsers, Several parsers): Disable these
warnings when in push parser.
2019-10-20 23:01:27 +02:00
Akim Demaille 4e0de4df8c CI: try GCC9 and Clang9
The logs show:

    Disallowing sources: llvm-toolchain-bionic-8, ubuntu-toolchain-r-test
    To add unlisted APT sources, follow instructions in
    https://docs.travis-ci.com/user/installing-dependencies#Installing-Packages-with-the-APT-Addon

* .travis.yml: Remove a few apt sources which are ignored in
Bionic (e.g., see
https://github.com/travis-ci/apt-source-safelist/issues/410).
Where needed, use sources/sourceline instead.
Also, don't use -DNDEBUG with older builds.
2019-10-20 17:57:28 +02:00
Akim Demaille 97d6da0c5b parser: clarify version checking
* src/parse-gram.y: Use the same conventions for gnulib as elsewhere:
<header.h>.
(str_to_version): New.
(handle_require): Use it.
Prefer < to >.
2019-10-20 17:57:28 +02:00
Akim Demaille e31f92495c build: disable -Wtype-limits, except in the test suite
The current implementation of lib/intprops.h results in "unsigned < 0"
comparisons, which triggers warnings.  See

https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html

* configure.ac (warn_common): Disable -Wtype-limits.
(warn_tests): Restore it.
2019-10-20 08:55:44 +02:00
Paul Eggert 54c5d5d1b4 c++: port to Sun C++ 5.12
The documentation for Oracle Solaris Studio 12.3 (Sun C++ 5.12
2011/11/16) says it supports C++03.  This compiler rejects the
location.cc use of std::max for some reason; I don’t know why
since I don’t use C++ as a rule.  The simplest workaround is to
open-code ‘max’.
* data/skeletons/location.cc (add_):
Do max by hand rather than relying on std::max.
Don’t include <algorithm.h>; no longer needed.
2019-10-17 12:25:05 -07:00
Paul Eggert 693e69f289 regen 2019-10-17 11:51:20 -07:00
Paul Eggert 5c2c9fcb17 tests: port to Solaris 10 grep
* tests/scanner.at (Token numbers: $1): Use $EGREP, not grep -E.
2019-10-17 11:51:20 -07:00
Paul Eggert 071f43d5b7 tests: port to Solaris 10 sed
As documented in the Autoconf manual, Solaris 10 sed rejects
script labels contianing more than 7 characters.  POSIX requires
support for at least 8 characters, but we might as well be portable
to Solaris 10 which is still supported.
* tests/local.at (AT_SETS_CHECK): Use only the first 7 characters
in sed labels.
2019-10-17 11:51:20 -07:00
Paul Eggert 8a4ec5d4e4 bison: check for int overflow in token numbers
* src/symtab.c: Include intprops.h
(symbol_user_token_number_set): Don’t allow user_token_number ==
INT_MAX because too much other code adds 1 to the user token number.
(symbols_token_translations_init): Complain on integer overflow
instead of indulging in undefined behavior.
2019-10-17 11:51:20 -07:00
Paul Eggert 052215a138 bison: check for int overflow when scanning
* src/scan-gram.l: Include errno.h, for errno.
(scan_integer, handle_syncline): Check for integer overflow.
* tests/input.at (too-large.y): Adjust to match new diagnostics.
2019-10-17 11:51:20 -07:00
Paul Eggert 15c1b913cf bison: check version numbers more carefully
* src/parse-gram.y: Include intprops.h.
(handle_require): Don’t indulge in undefined behavior if the major
or minor number is out of range.  Instead, check that the
resulting value is nonnegative, fits in int, and that the minor
number is less than 100.  Also, check that a number was parsed.
2019-10-17 11:51:20 -07:00
Paul Eggert 83c9051a64 c: port YY_ATTRIBUTE_UNUSED to Sun C 5.12
Sun C 5.12 defines __SUNPRO_C to 0x5120 but diagnoses
‘__attribute__ ((__unused__))’.  Change the ifdefs to use
the same method as Gnulib in this area.
* data/skeletons/c.m4 (YY_ATTRIBUTE): Remove, since
not all attributes were added in the same compiler version.
(YY_ATTRIBUTE_PURE, YY_ATTRIBUTE_UNUSED):
Use specific GCC version for each attribute.
Pay no attention to __SUNPRO_C.
* tests/headers.at (Several parsers): Tighten tests accordingly.
2019-10-17 11:51:20 -07:00
Paul Eggert 7a557ee7fe c: improve port of stdint.h usage to pre-C99
Oracle Solaris Studio 12.3 (Sun C 5.12 2011/11/16) by default does
not conform to C99; it defines __STDC_VERSION__ to be 199409L, so
the Bison code does not include <stdint.h> (not required by C89
amendment 1) even though this compiler does have <stdint.h>.  On
this platform <limits.h> defines INT_LEAST8_MAX (POSIX allows
this) so the skeleton got confused and thought that <stdint.h> had
been included even though it wasn’t.
* data/skeletons/c.m4 (b4_c99_int_type_define) [!__PTRDIFF_MAX__]:
Always include <limits.h>.
(YY_STDINT_H): Define when <stdint.h> was included.
All uses of expressions like ‘defined INT_LEAST8_MAX’ changed to
‘defined YY_STDINT_H’, since Sun C 5.12 <limits.h> defines macros
like INT_LEAST8_MAX but does not declare types like int_least8_t.
2019-10-17 11:51:20 -07:00
Paul Eggert 08dd5e9feb gnulib:update 2019-10-17 11:51:20 -07:00
Paul Eggert 68cc2631a4 autoconf:update 2019-10-17 11:51:20 -07:00
Akim Demaille b47340982b TODO: more updates 2019-10-15 08:40:50 +02:00
Akim Demaille ee35055b49 TODO: update 2019-10-15 07:28:33 +02:00
Akim Demaille e5cbac98b6 yacc: rename types for states
* data/skeletons/yacc.c (yy_state_num): Rename as...
(yy_state_t): this.
(yy_state_fast_t): New.
Use it.
2019-10-15 07:02:26 +02:00
Akim Demaille d563a01709 glr: style changes
* data/skeletons/glr.c (yytnamerr): here.
(yyprocessOneStack): Initialize variables.
2019-10-15 07:02:26 +02:00
Akim Demaille a428a9fa6c yacc: style changes
* data/skeletons/yacc.c: Move call to lac discard to clarify the
shifting of the token.
Like in lalr1.cc.
2019-10-15 07:02:26 +02:00
Akim Demaille 2a0185b693 tests: avoid $(...)
Reported by Paul Eggert.

* tests/local.at (AT_DATA_NO_FINAL_EOL): here.
2019-10-15 07:01:06 +02:00
Akim Demaille ab3621678a tests: use a portable 'truncate' implementation
Suggested by Paul Eggert.
https://lists.gnu.org/archive/html/bison-patches/2019-10/msg00044.html

* tests/local.at (AT_DATA_NO_FINAL_EOL): Use dd instead of perl.
2019-10-14 07:58:36 +02:00
Akim Demaille 8631f35bf9 tests: factor the generation of files without the final eol
AFAICT Autotest 2.69 still does not support AT_DATA without the final
eol.

* tests/local.at (AT_DATA_NO_FINAL_EOL): New.
* tests/input.at: Use it.
2019-10-13 09:55:44 +02:00
Akim Demaille c483b6593f tests: refactor the handling of Perl
Let's make a difference between places where Perl is required for the
test (AT_PERL_REQUIRE), and the places where it's used to run the
test, but it's not not to run the test (AT_PERL_CHECK).

* tests/local.at (AT_REQUIRE): New.
(AT_PERL_CHECK, AT_PERL_REQUIRE): New.
Use them where appropriate.

* tests/local.mk ($(TESTSUITE)): Beware not to start the line with
'-pi' if Perl is empty, as Make understands this as "it's ok to fail".
Which it is not.
2019-10-13 09:22:05 +02:00
Akim Demaille 59cb1f421c d: comment changes
* data/skeletons/lalr1.d: Here.
2019-10-12 12:11:42 +02:00
Akim Demaille d9d37a1196 i18n: don't push too hard for '…'
Suggested by Paul Eggert.

* src/location.c (ellipsis): Clarify comment for translators.
2019-10-12 10:43:53 +02:00
Akim Demaille c3db1394a1 regen 2019-10-11 08:52:04 +02:00
Akim Demaille 2c20ae9b41 glr: display line numbers in traces
Suggested by Lars Maier.

* data/skeletons/glr.c: Also display rule locations when rules are
deferred, and rejected.
2019-10-11 08:38:24 +02:00
Akim Demaille 0c56c195e0 tests: be really robust to Perl missing
My previous tests (with ./configure PERL=false) have been fooled by
configure, that managed to find perl anyway.  This time, I ran this on
a Fedora in Docker, without Perl.

* tests/calc.at, tests/diagnostics.at, tests/headers.at,
* tests/input.at, tests/local.at, tests/named-refs.at,
* tests/output.at, tests/regression.at, tests/skeletons.at,
* tests/synclines.at, tests/torture.at: Don't require Perl.
2019-10-11 06:53:45 +02:00
Akim Demaille 3dd2ae4415 configure: perl is not required
But it's used in various places, including in some tests.

* configure.ac: here.
2019-10-10 21:57:50 +02:00
Akim Demaille d50df39f1a news: update 2019-10-10 21:57:50 +02:00
Akim Demaille 2c66acfec0 diagnostics: prefer "…" to "..." if the locale supports it
* src/location.c (ellipsis, ellipsize): New.
Use them.
2019-10-10 21:57:50 +02:00
Paul Eggert 3f320159e3 c: improve patch for UCHAR_MAX etc. problem
* data/skeletons/c.m4 (b4_c99_int_type_define): Reorder to put the
signed types first, since they’re simpler and this keeps similar
code closer.  For signed types, don’t bother checking whether the
type promotes to int since the type must be signed anyway.  For
unsigned types, protect a test like ‘UCHAR_MAX <= INT_MAX’ with
‘!defined __UINT_LEAST8_MAX__’, as otherwise the logic is wrong
for oddball platforms; and once we do that, there should no need
for ‘defined INT_MAX’ so remove that.
2019-10-10 12:08:42 -07:00
Akim Demaille f41e0cf73c tests: do not depend on config.h
Currently we face test suite failures in different environments,
because of a conflict between the definitions of isnan by gnulib, and
by the C++ library:

    262. headers.at:186: testing Sane headers: %locations %debug c++ ...
    ./headers.at:186: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -d -o input.cc input.y
    ./headers.at:186: $CXX $CXXFLAGS $CPPFLAGS  -c -o input.o input.cc
    stderr:
    In file included from /usr/include/c++/4.8.2/cmath:44:0,
                     from /usr/include/c++/4.8.2/random:38,
                     from /usr/include/c++/4.8.2/bits/stl_algo.h:65,
                     from /usr/include/c++/4.8.2/algorithm:62,
                     from location.hh:41,
                     from input.hh:90,
                     from input.cc:50:
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h: In function 'bool isnan(double)':
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h:2849:1: error: new declaration 'bool isnan(double)'
     _GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, isnan, bool)
     ^
    In file included from /usr/include/features.h:375:0,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/os_defines.h:39,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++config.h:2097,
                     from /usr/include/c++/4.8.2/cstdlib:41,
                     from input.hh:48,
                     from input.cc:50:
    /usr/include/bits/mathcalls.h:235:1: error: ambiguates old declaration 'int isnan(double)'
     __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
     ^

There might be something to do in gnulib about this, but I believe
that gnulib should not be used in the test suite in the first place.

The test suite should work with other compilers than the one used to
compile the package.  For a start, Bison sources are more
demanding (C99) than the generated parsers.  Last time I tried, tcc
for example, was not able to compile Bison, yet our generated parsers
should compile cleanly with it.

Besides the problem at hand is with the C++ compiler, with is not the
one used to set up gnulib at configuration-time (config.h is mainly
built from probing the C compiler).

We should really not depend on gnulib in tests.

This was introduced in 2001 to check whether including
stdlib.h/string.h is safe thanks to STDC_HEADERS
(2ce1014469).  Today, we assume at least
a C90 compiler, it should be safe enough.

* tests/local.at, tests/testsuite.h: Do not include config.h.
* tests/atlocal.in (conftest.cc): Likewise.
(CPPFLAGS): Do not expose lib/, as because of this we might picked up
gnulib replacement headers for system headers.

* tests/input.at: Use int instead of ptrdiff_t, for easier portability
(some machine on the CI did not find ptrdiff_t).
* tests/c++.at: Add missing include for getchar.
2019-10-10 17:53:48 +02:00
Akim Demaille d6ce0521cf doc: spell check
* doc/bison.texi: Remove the index about yyoutput, it is no longer
documented.
Spell check.
2019-10-10 17:53:48 +02:00
Akim Demaille cf298ebb7d tests: style changes
* tests/actions.at: Prefer printf to fprintf.
Prefer yyo to yyoutput in %printer.
2019-10-10 17:53:48 +02:00
Akim Demaille 734db67004 tests: formatting changes
* tests/actions.at, tests/local.at: here.
2019-10-10 17:53:48 +02:00
Akim Demaille 7d47d51962 tests: add missing includes
* tests/actions.at, tests/c++.at, tests/headers.at,
* tests/regression.at: here.
2019-10-10 17:53:32 +02:00
Akim Demaille 602d562d6f c: don't assume that UCHAR_MAX, etc. are defined
A number of portability issues with GCC 4.6 .. 4.9 (inclusive):

    input.c:184:7: error: "UCHAR_MAX" is not defined [-Werror=undef]
     #elif UCHAR_MAX <= INT_MAX
           ^
    input.c:184:20: error: "INT_MAX" is not defined [-Werror=undef]
     #elif UCHAR_MAX <= INT_MAX
                        ^
    input.c:202:7: error: "USHRT_MAX" is not defined [-Werror=undef]
     #elif USHRT_MAX <= INT_MAX
           ^
    input.c:202:20: error: "INT_MAX" is not defined [-Werror=undef]
     #elif USHRT_MAX <= INT_MAX
                        ^

* data/skeletons/c.m4 (b4_c99_int_type_define): Don't assume they are
defined.
2019-10-10 16:01:43 +02:00
Akim Demaille 825150b085 configure: don't require Flex
Flex should not be required to build Bison or run the test suite (of
course it is needed for maintaining Bison).  Yet the Automake
conditional FLEX_WORKS does not work.

* m4/flex.m4 (_AC_PROG_LEX_YYTEXT_DECL): Since this is called
conditionally, don't define LEX_IS_FLEX here, but rather...
(AC_PROG_LEX): here.
* configure.ac: Be more cautious about possibly undefined variables.
2019-10-09 07:28:26 +02:00
Paul Eggert d4b6c86c7f Move the integer-type selection into c.m4
That way, glr.c can use it too.
* data/skeletons/c.m4 (b4_int_type):
Do not special-case ‘char’; it’s not worth the trouble,
as clang complains about char subscripts.
(b4_c99_int_type, b4_c99_int_type_define): New macros,
taken from yacc.c.
* data/skeletons/glr.c: Use b4_int_type_define.
* data/skeletons/yacc.c (b4_int_type): Remove, since there’s
no longer any need to redefine it.
Use b4_c99_int_type_define rather than its body.
2019-10-07 00:08:19 -07:00
Paul Eggert 5463291a91 Use “least” types for integers in Yacc tables
This changes the Yacc skeleton to use “least” integer types to
keep tables smaller on some platforms, which should lessen cache
pressure.  Since Bison uses the Yacc skeleton, it follows suit.
* data/skeletons/yacc.c: Include limits.h and stdint.h if this
seems to be needed.
(yytype_uint8, yytype_int8, yytype_uint16, yytype_int16):
If available, use GCC predefined macros __INT_MAX__ etc. to select
a “least” type, as this avoids namespace hassles.  Otherwise, if
available fall back on selecting a “least” type via the C99 macros
INT_MAX, INT_LEAST8_MAX, etc.  Otherwise, fall further back on one of
the builtin C99 types signed char, short, and int.  Make sure that
any selected type promotes to int.  Ignore any macros YYTYPE_INT16,
YYTYPE_INT8, YYTYPE_UINT16, YYTYPE_UINT8 defined by the user.
(ptrdiff_t, PTRDIFF_MAX): Simplify in the light of the above.
(yytype_uint8, yytype_uint16): Do not assume that unsigned char
and unsigned short promote to int, as this isn’t true on some
platforms (e.g., TI TMS320C55x).
* src/parse-gram.y (YYTYPE_INT16, YYTYPE_INT8, YYTYPE_UINT16)
(YYTYPE_UINT8): Remove, as these are no longer effective.
2019-10-07 00:08:19 -07:00
Paul Eggert 6373b90fc8 Port better to C++ platforms
* data/skeletons/yacc.c (YYPTRDIFF_T, YYPTRDIFF_MAXIMUM):
Default to long, not int.
(yy_lac_stack_realloc, yy_lac, yytnamerr, yyparse):
Avoid casts to YYPTRDIFF_T that were masking the problem.
2019-10-06 11:59:16 -07:00
Paul Eggert beceb2fa93 Work around GCC 4.8 false alarms without casts
* data/skeletons/yacc.c (yyparse):
Initialize yyes_capacity with a signed expression.
* tests/local.at (AT_YYLEX_DEFINE(c)):
Use enum to avoid cast.
2019-10-06 11:59:16 -07:00
Akim Demaille 58302c6079 regen 2019-10-06 17:48:51 +02:00
Akim Demaille d2a7a28438 tests: make recheck
* tests/local.mk (recheck): New.
2019-10-06 12:15:12 +02:00
Akim Demaille 9e6c5328d3 diagnostics: also show suggested %empty
* src/reader.c (grammar_rule_check_and_complete): Suggest to add %empty.
* tests/actions.at, tests/diagnostics.at: Adjust expectations.
2019-10-06 12:15:12 +02:00
Akim Demaille fec13ce2db diagnostics: sort symbols per location
Because the checking of the grammar is made by phases after the whole
grammar was read, we sometimes have diagnostics that look weird.  In
some case, within one type of checking, the entities are not checked
in the order in which they appear in the file.  For instance, checking
symbols is done on the list of symbols sorted by tag:

    foo.y:1.20-22: warning: symbol BAR is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                    ^~~
    foo.y:1.16-18: warning: symbol QUX is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                ^~~

Let's sort them by location instead:

    foo.y:1.16-18: warning: symbol 'QUX' is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                ^~~
    foo.y:1.20-22: warning: symbol 'BAR' is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                    ^~~

* src/location.h (location_cmp): Be robust to empty file names.
* src/symtab.c (symbol_cmp): Sort by location.
* tests/input.at: Adjust expectations.
2019-10-06 09:54:25 +02:00
Akim Demaille be3cf406af diagnostics: suggest fixes for undeclared symbols
From

    input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother]
         1 | %printer {} foo baz
           |                 ^~~

to

    input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules; did you mean 'bar'? [-Wother]
        1 | %printer {} foo baz
          |                 ^~~
          |                 bar

* bootstrap.conf: We need fstrcmp.
* src/symtab.c (symbol_from_uniqstr_fuzzy): New.
(complain_symbol_undeclared): Use it.
* tests/diagnostics.at (Suggestions): New.
* data/bison-default.css (insertion): Rename as...
(fixit-insert): this, as this is what GCC uses.
2019-10-06 09:54:25 +02:00
Akim Demaille 126c4622de style: isolate complain_symbol_undeclared
* src/symtab.c (complain_symbol_undeclared): New.
Use it.
Use quote on the guilty symbol (like GCC does, and we also do
elsewhere).
* tests/input.at: Adjust.
2019-10-06 09:54:25 +02:00
Akim Demaille dd64eaf9db style: simplify the handling of symbol and semantic_type tables
Both are stored in a hash, and back in the days, we used to iterate
over these tables using hash_do_for_each.  However, the order of
traversal was not deterministic, which was a nuisance for
deterministic output (and therefore also a problem for tests).  So at
some point (83b60c97ee) we generated a
sorted list of these symbols, and symbols_do actually iterated on that
list.  But we kept the constraints of using hash_do_for_each, which
requires a lot of ceremonial code, and makes it hard/unnatural to
preserve data between iterations (see the next commit).

Alas, this is C, not C++.

Let's remove this abstraction, and directly iterate on the sorted
tables.

* src/symtab.c (symbols_do): Remove.
Adjust callers to use a simple for-loop instead.
(table_sort): New.
(symbols_check_defined): Use it.
(symbol_check_defined_processor, symbol_pack_processor)
(semantic_type_check_defined_processor, symbol_translation_processor):
Remove.
Simplify the corresponding functions (that no longer need to return a
bool).
2019-10-06 09:54:20 +02:00
Akim Demaille 0b585c49ae diagnostics: display suggested update after the caret-info
This commit adds the suggestion in green, on the line below the
caret-and-tildes.

    foo.y:1.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
        1 | %error-verbose
          | ^~~~~~~~~~~~~~
          | %define parse.error verbose

The current approach, with location_caret_suggestion, is fragile:
there's a protocol of calls to the complain functions which is strict.
We should rather have a richer structure describing the diagnostics,
including with submessages such as the suggestions, passed in the end
to the routines in charge of formatting and printing them.

* src/location.h, src/location.c (location_caret_suggestion): New.
* src/complain.c (deprecated_directive): Use it.
* tests/diagnostics.at, tests/input.at: Adjust expectations.
2019-10-06 08:07:57 +02:00
Akim Demaille 37c4d0b175 diagnostics: isolate caret_set_column
* src/location.c (caret_info): Add width and skip members.
(caret_set_column): New.
Use it.
2019-10-06 08:07:57 +02:00
Akim Demaille 56bcccbc51 diagnostics: isolate caret_set_file
* src/location.c (caret_set_file): New.
Store the current line's length in caret_info.line_len.
Pay attention to fseek's return value.
Extracted from...
(location_caret): here.
2019-10-06 08:07:57 +02:00
Akim Demaille 17cc7da519 tests: use tput to get the number of columns
* tests/bison.in: here.
2019-10-06 08:07:57 +02:00
Akim Demaille 2713e7c4ff TODO: update
I no longer agree with that item, there are indeed two things to
report: lack of definition, and being useless.  We could have either
one without the other, they are not directly related.
2019-10-06 08:07:57 +02:00
Akim Demaille 32e5a91a91 yacc.c: work around warnings from G++ 4.8
input.c: In function 'int yyparse()':
input.c: error: conversion to 'long int' from 'long unsigned int'
                may change the sign of the result [-Werror=sign-conversion]
   yyes_capacity = sizeof yyesa / sizeof *yyes;
                                ^
cc1plus: all warnings being treated as errors

* data/skeletons/yacc.c: here.
2019-10-06 08:07:40 +02:00
Akim Demaille 5973d763c0 yacc.c: work around warnings from Clang++ 3.3 and 3.4
When we run the test suite with these C++ compilers to compile C code,
we get:

    239. synclines.at:440: testing syncline escapes: yacc.c ...
    ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS \"\\\"\".c -o \"\\\"\" ||
              exit 77
    stderr:
    stdout:
    ../../tests/synclines.at:440: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret  -o \"\\\"\".c \"\\\"\".y
    ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o \"\\\"\" \"\\\"\".c $LIBS
    stderr:
    "\"".c:1102:41: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
          YYPTRDIFF_T yysize = yyssp - yyss + 1;
                      ~~~~~~   ~~~~~~~~~~~~~^~~
    1 error generated.

    193. conflicts.at:545: testing parse.error=verbose and consistent errors: lr.type=canonical-lr parse.lac=full ...
    input.c:737:75: error: implicit conversion loses integer precision: 'long' to 'int'
                           [-Werror,-Wshorten-64-to-32]
      YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
                  ~~~~~~~~~~                               ~~~~~~~~~~~~~~~~~~~^~~
    input.c:901:48: error: implicit conversion loses integer precision: 'long' to 'int'
                           [-Werror,-Wshorten-64-to-32]
                YYPTRDIFF_T yysize = yyesp - *yyes + 1;
                            ~~~~~~   ~~~~~~~~~~~~~~^~~

* data/skeletons/yacc.c: Add more casts.
2019-10-06 08:03:43 +02:00
Akim Demaille 4246cd81df tests: avoid a GCC 4.8 warning
GCC 4.8 reports:

    input.y:57:33: error: conversion to 'int' from 'long unsigned int'
                          may alter its value [-Werror=conversion]
       int input_elts = sizeof input / sizeof input[0];
                                     ^

* tests/local.at (AT_YYLEX_DEFINE(c)): Add a cast (sorry, Paul!).
2019-10-05 23:00:05 +02:00
Paul Eggert e69b47cd18 * data/skeletons/glr.c (yysplitStack): Pacify Clang 8. 2019-10-05 03:42:24 -07:00
Paul Eggert 8f5aaa0e04 Avoid quiet conversion of pointer to bool
* src/location.c (caret_set_file):
* src/scan-code.l (contains_dot_or_dash):
Do not quietly convert pointer to bool, as Oracle Developer Studio
12.6 complains and it is arguably confusing style anyway.
2019-10-05 01:19:39 -07:00
Paul Eggert b75b055288 Port ARGMATCH_DEFINE_GROUP calls to C99
* src/complain.c, src/getargs.c: Omit ‘;’ after call
to ARGMATCH_DEFINE_GROUP, as C99 does not allow ‘;’ there.
2019-10-05 01:19:39 -07:00
Paul Eggert 41e84cddc7 Port lexcalc scan.l to Solaris 10
* examples/c/lexcalc/scan.l: Include errno.h.
2019-10-05 01:19:39 -07:00
Akim Demaille 5709f94a91 yacc.c: use casts instead of pragmas when losing integer width
For instance with Clang 4, 8, etc.:

    input.c:1166:12: error: implicit conversion loses integer precision: 'int' to 'yy_state_num' (aka 'signed char') [-Werror,-Wconversion]
      *yyssp = yystate;
             ~ ^~~~~~~

And GCC 8:

    input.c:1166:12: error: implicit conversion loses integer precision: 'int' to 'yy_state_num' (aka 'signed char') [-Werror,-Wimplicit-int-conversion]
      *yyssp = yystate;
             ~ ^~~~~~~

* data/skeletons/yacc.c (YY_CONVERT_INT_BEGIN): Remove.
Adjust callers.
2019-10-05 09:01:56 +02:00
Akim Demaille bc96b757ca yacc.c: fix warnings about undefined macros
For instance with GCC 4.9 and --enable-gcc-warnings:

    25. input.at:1201: testing Torturing the Scanner ...
    ../../tests/input.at:1344: $CC $CFLAGS $CPPFLAGS  -c -o input.o input.c
    stderr:
    input.c:239:18: error: "__STDC_VERSION__" is not defined [-Werror=undef]
     # elif 199901 <= __STDC_VERSION__
                      ^
    input.c:256:18: error: "__STDC_VERSION__" is not defined [-Werror=undef]
     # elif 199901 <= __STDC_VERSION__
                      ^

* data/skeletons/yacc.c: Check that __STDC_VERSION__ is defined before
using it.
2019-10-04 06:58:44 +02:00
Akim Demaille 1133220416 tests: check more state numbers
* tests/torture.at (State number type): Also check 128, 129 and
32768.
2019-10-04 06:58:44 +02:00
Paul Eggert 39eb80bdbc * doc/bison.texi (Table of Symbols): Mention memory exhaustion. 2019-10-03 11:17:18 -07:00
Paul Eggert 361004aabe Simplify mfcalc error handling
* doc/bison.texi (Mfcalc Symbol Table, Mfcalc Lexer):
Don’t abort on memory allocation failure or integer overflow.
Instead, comment that these things aren’t checked for.
2019-10-03 11:17:18 -07:00
Akim Demaille 032a52be6e c++: fix comments suggesting to use %require
* data/skeletons/location.cc, data/skeletons/stack.hh: Here.
2019-10-03 09:27:41 +02:00
Akim Demaille 843ef49bc3 lalr1.cc: simplify uses of size_t
* data/skeletons/stack.hh (stack::index_type): New type.
(stack::size, stack::operator[]): Be about an index_type rather than a
size_type and an int.
2019-10-03 09:27:41 +02:00
Akim Demaille 5df33278b4 c++: fixes for old compilers
On the CI with GCC 6:

    examples/c++/calc++/parser.cc:845:5: error: 'ptrdiff_t' was not declared in this scope
         ptrdiff_t yycount = 0;
         ^~~~~~~~~
    examples/c++/calc++/parser.cc:845:5: note: suggested alternatives:
    /usr/include/x86_64-linux-gnu/c++/6/bits/c++config.h:202:28: note:   'std::ptrdiff_t'
       typedef __PTRDIFF_TYPE__ ptrdiff_t;
                                ^~~~~~~~~

* data/skeletons/lalr1.cc: Qualify ptrdiff_t and size_t with std::.
2019-10-03 09:27:41 +02:00
Akim Demaille d96fff6115 tests: be robust to -DNDEBUG
input.y: In function 'yylex':
input.y:67:7: error: unused variable 'input_elts' [-Werror=unused-variable]
   int input_elts = sizeof input / sizeof input[0];
       ^~~~~~~~~~
cc1: all warnings being treated as errors

* tests/input.at, tests/local.at: Avoid that.
2019-10-03 09:27:40 +02:00
Akim Demaille be92ad1eb4 CI: remove the symlink before creating it
Currently we fail if we rerun a job that succeeded to push the
tarball.
2019-10-03 07:56:42 +02:00
Paul Eggert ff2f02815b Adjust ‘Big horizontal’ test case
* tests/torture.at (Big horizontal): Adjust to recent changes with
integers.  If there are states 0..256, Bison now uses a signed
rather than an unsigned 16-bit integer.
2019-10-02 18:37:35 -07:00
Paul Eggert 67dcef357c regen 2019-10-02 17:11:33 -07:00
Paul Eggert 133edcd248 Prefer signed to unsigned integers
This patch contains more fixes to prefer signed to unsigned
integer types, as modern tools like 'gcc -fsanitize=undefined'
can check for signed integer overflow but not unsigned overflow.
* NEWS: Document the API change.
* boostrap.conf (gnulib_modules): Add intprops.
* data/skeletons/glr.c: Include stddef.h and stdint.h,
since this skeleton can assume C99 or later.
(YYSIZEMAX): Now signed, and the minimum of SIZE_MAX and PTRDIFF_MAX.
(yybool) [!__cplusplus]: Now signed (which is how bool behaves).
(YYTRANSLATE): Avoid use of unsigned, and make the macro
safe even for values greater than UINT_MAX.
(yytnamerr, struct yyGLRState, struct yyGLRStateSet, struct yyGLRStack)
(yyaddDeferredAction, yyinitStateSet, yyinitGLRStack)
(yyexpandGLRStack, yymarkStackDeleted, yyremoveDeletes)
(yyglrShift, yyglrShiftDefer, yy_reduce_print, yydoAction)
(yyglrReduce, yysplitStack, yyreportTree, yycompressStack)
(yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError)
(yyparse, yy_yypstack, yypstack, yypdumpstack):
* tests/input.at (Torturing the Scanner):
Prefer ptrdiff_t to size_t.
* data/skeletons/c++.m4 (b4_yytranslate_define):
* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
* src/AnnotationList.h (AnnotationIndex):
* src/InadequacyList.h (InadequacyListNodeCount):
* src/closure.c (closure_new):
* src/complain.c (error_message, complains, complain_indent)
(complain_args, duplicate_directive, duplicate_rule_directive):
* src/gram.c (nritems, ritem_print, grammar_dump):
* src/ielr.c (ielr_compute_ritem_sees_lookahead_set)
(ielr_item_has_lookahead, ielr_compute_annotation_lists)
(ielr_compute_lookaheads):
* src/location.c (columns, boundary_print, location_print):
* src/muscle-tab.c (muscle_percent_define_insert)
(muscle_percent_define_check_values):
* src/output.c (prepare_rules, prepare_actions):
* src/parse-gram.y (id, handle_require):
* src/reader.c (record_merge_function_type, packgram):
* src/reduce.c (nuseless_productions, nuseless_nonterminals)
(inaccessable_symbols):
* src/relation.c (relation_print):
* src/scan-code.l (variant, variant_table_size, variant_count)
(variant_add, get_at_spec, show_sub_message, show_sub_messages)
(parse_ref):
* src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>)
(scan_integer, convert_ucn_to_byte, handle_syncline):
* src/scan-skel.l (at_complain):
* src/symtab.c (complain_symbol_redeclared)
(complain_semantic_type_redeclared, complain_class_redeclared)
(symbol_class_set, complain_user_token_number_redeclared):
* src/tables.c (conflict_tos, conflrow, conflict_table)
(conflict_list, save_row, pack_vector):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Prefer signed to unsigned integer.
* data/skeletons/lalr1.cc (yy_lac_check_):
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Omit now-unnecessary casts.
* data/skeletons/location.cc (b4_location_define):
* doc/bison.texi (Mfcalc Lexer, C++ position, C++ location):
Prefer int to unsigned for line and column numbers.
Change example to abort explicitly on memory exhaustion,
and fix an off-by-one bug that led to undefined behavior.
* data/skeletons/stack.hh (stack::operator[]):
Also allow ptrdiff_t indexes.
(stack::pop, slice::slice, slice::operator[]):
Index arg is now ptrdiff_t, not int.
(stack::ssize): New method.
(slice::range_): Now ptrdiff_t, not int.
* data/skeletons/yacc.c (b4_state_num_type): Remove.
All uses replaced by b4_int_type.
(YY_CONVERT_INT_BEGIN, YY_CONVERT_INT_END): New macros.
(yylac, yyparse): Use them around conversions that -Wconversion
would give false alarms about. 	Omit unnecessary casts.
(yy_stack_print): Use int rather than unsigned, and omit
a cast that doesn’t seem to be needed here any more.
* examples/c++/variant.yy (yylex):
* examples/c++/variant-11.yy (yylex):
Omit no-longer-needed conversions to unsigned.
* src/InadequacyList.c (InadequacyList__new_conflict):
Don’t assume *node_count is unsigned.
* src/output.c (muscle_insert_unsigned_table):
Remove; no longer used.
2019-10-02 17:11:33 -07:00
Paul EggertandAkim Demaille 4d9ff272cf Prefer signed types for indexes in skeletons
* NEWS: Mention this.
* data/skeletons/c.m4 (b4_int_type):
Prefer char if it will do, and prefer signed types to unsigned if
either will do.
* data/skeletons/glr.c (yy_reduce_print): No need to
convert rule line to unsigned long.
(yyrecoverSyntaxError): Put action into an int to
avoid GCC warning of using a char subscript.
* data/skeletons/lalr1.cc (yy_lac_check_, yysyntax_error_):
Prefer ptrdiff_t to size_t.
* data/skeletons/yacc.c (b4_int_type):
Prefer signed types to unsigned if either will do.
* data/skeletons/yacc.c (b4_declare_parser_state_variables):
(YYSTACK_RELOCATE, YYCOPY, yy_lac_stack_realloc, yy_lac)
(yytnamerr, yysyntax_error, yyparse): Prefer ptrdiff_t to size_t.
(YYPTRDIFF_T, YYPTRDIFF_MAXIMUM): New macros.
(YYSIZE_T): Fix "! defined YYSIZE_T" typo.
(YYSIZE_MAXIMUM): Take the minimum of PTRDIFF_MAX and SIZE_MAX.
(YYSIZEOF): New macro.
(YYSTACK_GAP_MAXIMUM, YYSTACK_BYTES, YYSTACK_RELOCATE)
(yy_lac_stack_realloc, yyparse): Use it.
(YYCOPY, yy_lac_stack_realloc): Cast to YYSIZE_T to pacify GCC.
(yy_reduce_print): Use int instead of unsigned long when int
will do.
(yy_lac_stack_realloc): Prefer long to unsigned long when
either will do.
* tests/regression.at: Adjust to these changes.
2019-10-02 07:10:03 +02:00
Akim Demaille 2ca6b71967 yacc: use the most appropriate integral type for state numbers
Currently we properly use the "best" integral type for tables,
including those storing state numbers.  However the variables for
state numbers used in yyparse (and its dependencies such as
yy_stack_print) still use int16_t invariably.  As a consequence, very
large models overflow these variables.

Let's use the "best" type for these variables too.  It turns out that
we can still use 16 bits for twice larger automata: stick to unsigned
types.

However using 'unsigned' when 16 bits are not enough is troublesome
and generates tons of warnings about signedness issues.  Instead,
let's use 'int'.

Reported by Tom Kramer.
https://lists.gnu.org/archive/html/bug-bison/2019-09/msg00018.html

* data/skeletons/yacc.c (b4_state_num_type): New.
(yy_state_num): Be computed from YYNSTATES.
* tests/linear: New.
* tests/torture.at (State number type): New.
Use it.
2019-09-30 18:31:55 +02:00
Akim Demaille 871c02b327 yacc: introduce a type for states
* data/skeletons/yacc.c (yy_state_num): New.
Use it for arrays of states.
2019-09-30 07:26:17 +02:00
Akim Demaille a57e74a5bf style: prefer symbolic values rather than litterals
Instead of

    #define YYPACT_NINF -130
    #define yypact_value_is_default(Yystate) \
      (!!((Yystate) == (-130)))

generate

    #define YYPACT_NINF (-130)
    #define yypact_value_is_default(Yyn) \
      ((Yyn) == YYPACT_NINF)

* data/skeletons/c.m4 (b4_table_value_equals): Add support for $4.
* data/skeletons/glr.c, data/skeletons/yacc.c: Use it.
Also, use shorter macro argument names, the name of the macro is clear
enough.
2019-09-30 07:25:56 +02:00
Akim Demaille 4971409e39 style: change misleading macro argument name
* data/skeletons/glr.c, data/skeletons/yacc.c
(yypact_value_is_default): It does not take a rule number as argument.
2019-09-30 07:25:48 +02:00
Akim Demaille b772baef24 Merge remote-tracking branch 'upstream/maint'
* upstream/maint:
  c++: add copy ctors for compatibility with the IAR compiler
  CI: show git status
  CI: disable ICC
  tests: pass -jN from Make to the test suite
  quotearg: avoid leaks
  maint: post-release administrivia
2019-09-28 08:09:33 +02:00
Akim Demaille 406e8c7c02 c++: add copy ctors for compatibility with the IAR compiler
Reported by Andreas Damm.
https://savannah.gnu.org/support/?110032

* data/skeletons/lalr1.cc (stack_symbol_type::operator=): New
overload, const, to please the IAR C++ compiler (version ca 2013).
2019-09-27 08:40:52 +02:00
Akim Demaille 97c4169f23 CI: show git status 2019-09-23 06:06:35 +02:00
Akim Demaille 8add45dbd9 CI: disable ICC
It seems that Intel changed something in their license management.
https://github.com/nemequ/icc-travis/issues/15
2019-09-23 06:06:26 +02:00
Akim Demaille b3e9c20227 tests: pass -jN from Make to the test suite
I am sooooo tired of typing "make -j5 TESTSUITEFLAGS=-j5"...
Should have done this years ago.

* cfg.mk (TESTSUITEFLAGS): here.
2019-09-23 06:05:39 +02:00
Akim Demaille b2c381cd25 quotearg: avoid leaks
Reported by Tomasz Kłoczko.
https://lists.gnu.org/archive/html/bug-bison/2019-09/msg00008.html

* src/main.c (main): Free quotearg's memory later.
2019-09-22 18:15:36 +02:00
Akim Demaille 67bff62e31 diagnostics: get the screen width from the terminal
* bootstrap.conf: We need winsz-ioctl and winsz-termios.
* src/location.c (columns): Use winsize to get the number of
columns.
Code taken from the GNU Coreutils.
* src/location.h, src/location.c (caret_init): New.
* src/complain.c (complain_init): Call it.
* tests/bison.in: Export COLUMNS so that users of tests/bison can
enjoy proper line truncation.
2019-09-22 09:12:08 +02:00
Akim Demaille 5f45cb05f1 diagnostics: don't print ellipsis on the caret line
From

    9 | ...TUVWXYZ  ABCDEFGHIJKLMNOPQRSTUVWXYZ  ABCDEFGHIJKL
      | ...         ^~~~~~~~~~~~~~~~~~~~~~~~~~

to

    9 | ...TUVWXYZ  ABCDEFGHIJKLMNOPQRSTUVWXYZ  ABCDEFGHI...
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~

* src/location.c (location_caret): here.
* tests/diagnostics.at: Adjust expectations.
2019-09-22 09:12:08 +02:00
Akim Demaille b61b0eb9ac diagnostics: also show truncation at the end of line with "..."
From

    9 | ...TUVWXYZ  ABCDEFGHIJKLMNOPQRSTUVWXYZ  ABCDEFGHIJKL
      | ...         ^~~~~~~~~~~~~~~~~~~~~~~~~~

to

    9 | ...TUVWXYZ  ABCDEFGHIJKLMNOPQRSTUVWXYZ  ABCDEFGHI...
      | ...         ^~~~~~~~~~~~~~~~~~~~~~~~~~

* src/location.c (location_caret): here.
* tests/diagnostics.at: Adjust expectations.
2019-09-22 09:12:08 +02:00
Akim Demaille 69277e109a diagnostics: check that quoted lines are truncated
* tests/diagnostics.at (Screen width: 60 columns, Screen width: 80
columns, Screen width: 200 columns): New tests.
2019-09-22 09:12:08 +02:00
Akim Demaille f716484627 diagnostics: truncate quoted sources to fit the screen
* src/location.c (min_int, columns): New.
(location_caret): Compute the line width.  Based on it, compute how
many columns must be skipped before the quoted location and truncated
after, to fit the sceen width.
* tests/local.at (AT_QUELL_VALGRIND): Transform into...
(AT_SET_ENV_IF, AT_SET_ENV): these.
Define COLUMNS to protect the test suite from the user's environment.
2019-09-22 09:12:08 +02:00
Akim Demaille 945b917da2 diagnostics: learn how to count column number with multibyte chars
So far diagnostics were cheating: in addition to the 'column' field of
locations (based on actual screen width per multibyte characters and
on tabulation expansion), the scanner sets the 'byte' field.
Diagnostics used this byte count to decide where to insert (color)
style.

We want to be able to truncate the quoted lines when there are too
wide to fit the screen.  This requires that the diagnostics learn how
to count columns, the byte-in-boundary trick no longer works.

Bytes are still used for fix-its.

* bootstrap.conf: We need mbfile for mbf_getc.
* src/location.c (caret_info): We need an mbfile.
(caret_set_file): Initialize it.
(caret_getc): Convert to mbfile.
(location_caret): Instead of relying on the byte position to decide
where to insert the color style, count the current column using
boundary_compute.
2019-09-22 09:12:08 +02:00
Akim Demaille 1ef407d923 diagnostics: style: rename member for clariy
* src/location.c (caret_info): Now that we no longer have a 'file'
member (see previous commit), rename 'source' as 'file'.
2019-09-22 09:12:08 +02:00
Akim Demaille 576b863e91 diagnostics: style: use a boundary to track the caret_info
* src/location.c (caret_info): Replace file and line with pos, a
boundary.  This will allow us to use features of the boundary type,
such as boundary_compute.
2019-09-22 09:12:08 +02:00
Akim Demaille 2274c34e91 diagnostics: extract boundary_compute from location_compute
The handling of the contributions of the tabulations in the columns is
burried inside location_compute.  We will soon be willing to use the
boundary part of the computation (to compute the current column number
each time we read a multibyte char).

* src/location.c (boundary_compute): New, extracted from...
(location_compute): here.
2019-09-22 09:12:08 +02:00
Akim Demaille fccab9bc40 diagnostics: style: add caret_set_file
To make the following commits easier to read.

* src/location.c (caret_set_file): New.
2019-09-22 09:12:08 +02:00
Akim Demaille 488607534a diagnostics: style: minor changes
* src/location.c (location_caret): Factor two branches of an if.
2019-09-22 09:12:08 +02:00
Akim Demaille 4db572dd21 CI: show git status 2019-09-22 09:12:08 +02:00
Akim Demaille 8faf075fd7 git: update ignores 2019-09-22 09:12:08 +02:00
Akim Demaille 453639dfac git: update ignores 2019-09-22 07:48:10 +02:00
Akim Demaille 4901ee115b quotearg: avoid leaks
Reported by Tomasz Kłoczko.
https://lists.gnu.org/archive/html/bug-bison/2019-09/msg00008.html

* src/main.c (main): Free quotearg's memory later.
2019-09-21 15:01:45 +02:00
Akim Demaille 6c7b2dfe51 tests: pass -jN from Make to the test suite
I am sooooo tired of typing "make -j5 TESTSUITEFLAGS=-j5"...
Should have done this years ago.

* cfg.mk (TESTSUITEFLAGS): here.
2019-09-14 10:19:13 +02:00
Akim Demaille a3e201de02 java: handle eof in yytranslate
* data/skeletons/lalr1.java (yytranslate_): Handle eof here, as is done
in lalr1.cc.
* tests/javapush.at: Adjust.
2019-09-14 10:09:08 +02:00
Akim Demaille 5e95bb6251 d: handle eof in yytranslate
This changes the traces from

    Reading a token:
    Now at end of input.

to

    Reading a token:
    Next token is token $end (7FFEE56E6474)

which is ok.  Actually it is even better, as it gives the location
when locations are enabled, and is clearer when rules explicitly use
the EOF token.

* data/skeletons/lalr1.d (yytranslate_): Handle eof here, as is done
in lalr1.cc.
2019-09-14 10:09:08 +02:00
Akim Demaille 569125a6bf regen 2019-09-14 10:09:08 +02:00
Akim Demaille 8ac28ba1f0 parser: use api.token.raw
* src/parse-gram.y: Here.
2019-09-14 10:09:08 +02:00
Akim Demaille 3ca713abd0 api.token.raw: document it
* doc/bison.texi: here.
2019-09-14 10:09:08 +02:00
Akim Demaille 8c18e3f18c api.token.raw: cannot be used with character literals
* src/parse-gram.y (CHAR): api.token.raw and character literals are
mutually exclusive.
* tests/input.at (Character literals and api.token.raw): New.
2019-09-14 10:09:08 +02:00
Akim Demaille 1e5e274972 api.token.raw: apply to the other skeletons
* data/skeletons/c++.m4, data/skeletons/glr.c,
* data/skeletons/lalr1.c, data/skeletons/lalr1.java:
Add support for api.token.raw.

* tests/scanner.at: Check them.
2019-09-14 09:55:17 +02:00
Akim Demaille b1679f8346 api.token.raw: check it
* tests/local.at (AT_TOKEN_RAW_IF): New.
* tests/local.mk: New.
Use it.
2019-09-14 09:55:17 +02:00
Akim Demaille 9861bcc540 api.token.raw: implement
Bison used to feature %raw, documented as follows:

    @item %raw
    The output file @file{@var{name}.h} normally defines the tokens with
    Yacc-compatible token numbers.  If this option is specified, the
    internal Bison numbers are used instead.  (Yacc-compatible numbers start
    at 257 except for single character tokens; Bison assigns token numbers
    sequentially for all tokens starting at 3.)

Unfortunately, as far as I can tell, it never worked: token numbers
are indeed changed in the generated tables (from external token number
to internal), yet the code was still applying the mapping from
external token numbers to internal token numbers.

This commit reintroduces the feature as it was expected to be.

* data/skeletons/bison.m4 (b4_token_format): When api.token.raw is
enabled, use the internal token number.
* data/skeletons/yacc.c (yytranslate): Don't emit if api.token.raw is
enabled.
(YYTRANSLATE): Adjust.
2019-09-14 09:55:17 +02:00
Akim Demaille d94d83e10b style: tidy yacc.c
* data/skeletons/yacc.c: Include 'c.m4' first.
Then sort the handling of %define variables.
* tests/input.at: Adjust.
2019-09-14 09:55:17 +02:00
Akim Demaille 2f6e377953 CI: disable ICC
It seems that Intel changed something in their license management.
https://github.com/nemequ/icc-travis/issues/15
2019-09-14 09:55:17 +02:00
Akim Demaille 32dff87c1d diagnostics: fix use of complain_indent
* src/symtab.c (symbol_class_set): Here.
* tests/diagnostics.at, tests/input.at, tests/regression.at: Adjust
expectations.
2019-09-14 09:47:49 +02:00
Akim Demaille 19da501e06 input: stop treating lone CRs as end-of-lines
We used to treat lone CRs (\r, aka ^M) as regular NLs (\n), probably
to please Classic MacOS.  As of today, it makes more sense to treat \r
like a plain white space character.

https://lists.gnu.org/archive/html/bison-patches/2019-09/msg00027.html

* src/scan-gram.l (no_cr_read): Remove.  Instead, use...
(eol): this new abbreviation denoting end-of-line.
* src/location.c (caret_getc): New.
(location_caret): Use it.
* tests/diagnostics.at (Carriage return): Adjust expectations.
(CR NL): New.
2019-09-14 09:23:47 +02:00
Akim Demaille 5e4133175d Merge tag 'v3.4.2' into HEAD
bison 3.4.2

* tag 'v3.4.2': (24 commits)
  version 3.4.2
  CI: always uninstall icc
  news: more bug fixes thanks to Marc Schönefeld
  diagnostics: beware of unexpected EOF when quoting the source file
  gnulib: update
  build: fix distcheck
  tests: add noexcept to please GCC 9
  news: update
  fix: don't die when EOF token is defined twice
  tests: check token redeclaration
  yacc.c: beware of GCC's -Wmaybe-uninitialized
  glr.c: initialize vector of bools
  gnulib: update
  check for memory exhaustion
  diagnostics: avoid global variables
  diagnostics: fix invalid error message indentation
  git: ignore files generated in gnulib-po
  c++: avoid duplicate definition of YYUSE
  gnulib: update
  CI: more compilers
  ...
2019-09-12 19:12:24 +02:00
Akim Demaille 0b093ac4d9 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-09-12 18:09:26 +02:00
Akim Demaille 69b22b49d4 version 3.4.2
* NEWS: Record release date.
2019-09-12 17:41:12 +02:00
Akim Demaille ec11f08fb3 CI: always uninstall icc 2019-09-12 13:16:30 +02:00
Akim Demaille 67444a6f0d news: more bug fixes thanks to Marc Schönefeld 2019-09-12 09:07:48 +02:00
Akim Demaille 4eed3a0f0c diagnostics: beware of unexpected EOF when quoting the source file
When the input file contains lone CRs (aka, ^M, \r), the locations see
a new line.  Diagnostics look only at \n as end-of-line, so sometimes
there is an offset in diagnostics.  Worse yet: sometimes we loop
endlessly waiting for \n to come from a continuous stream of EOF.

Fix that:
- check for EOF
- beware not to call end_use_class if begin_use_class was not
  called (which would abort).  This could happen if the actual
  line is shorter that the expected one.

Prompted by a (private) report from Marc Schönefeld.

* src/location.c (location_caret): here.
* tests/diagnostics.at (Carriage return): New.
2019-09-12 07:02:46 +02:00
Akim Demaille 84a6621c78 gnulib: update
Contains the creation of the xhash module.
https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00046.html

* src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
Use hash_xinitialize.
2019-09-11 09:07:27 +02:00
Akim Demaille 06a273625b build: fix distcheck
* configure.ac (gl_LIBOBJS): Adjust so that the generated files are
indeed the expected ones.
2019-09-11 08:27:27 +02:00
Akim Demaille d120a07e6b diagnostics: beware of unexpected EOF when quoting the source file
When the input file contains lone CRs (aka, ^M, \r), the locations see
a new line.  Diagnostics look only at \n as end-of-line, so sometimes
there is an offset in diagnostics.  Worse yet: sometimes we loop
endlessly waiting for \n to come from a continuous stream of EOF.

Fix that:
- check for EOF
- beware not to call end_use_class if begin_use_class was not
  called (which would abort).  This could happen if the actual
  line is shorter that the expected one.

Prompted by a (private) report from Marc Schönefeld.

* src/location.c (location_caret): here.
* tests/diagnostics.at (Carriage return): New.
2019-09-10 19:15:18 +02:00
Akim Demaille 741a58a504 gnulib: update
Contains the creation of the xhash module.
https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00046.html

* src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
Use hash_xinitialize.
2019-09-10 19:06:13 +02:00
Akim Demaille d80815ac23 build: fix distcheck
* configure.ac (gl_LIBOBJS): Adjust so that the generated files are
indeed the expected ones.
2019-09-10 19:06:13 +02:00
Akim Demaille 0b417c3479 tests: add noexcept to please GCC 9
bison/tests/c++.at:552: bison --color=no -fno-caret  -o list.cc list.y
    bison/tests/c++.at:552: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o list list.cc $LIBS
    stderr:
    gcc9/c++/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string]':
    gcc9/c++/bits/alloc_traits.h:482:2:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:888:67:   required from 'void std::__relocate_object_a(_Tp*, _Up*, _Allocator&) [with _Tp = string; _Up = string; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:920:47:   required from '_ForwardIterator std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:942:37:   required from '_ForwardIterator std::__relocate_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_vector.h:430:35:   required from 'static constexpr bool std::vector<_Tp, _Alloc>::_S_nothrow_relocate(std::true_type) [with _Tp = string; _Alloc = std::allocator<string>; std::true_type = std::integral_constant<bool, true>]'
    gcc9/c++/bits/stl_vector.h:446:28:   required from 'void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const string&}; _Tp = string; _Alloc = std::allocator<string>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<string*, std::vector<string> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = string*]'
    gcc9/c++/bits/stl_vector.h:1195:4:   required from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = string; _Alloc = std::allocator<string>; std::vector<_Tp, _Alloc>::value_type = string]'
    list.y:126:110:   required from here
    gcc9/c++/bits/vector.tcc:459:44:   in 'constexpr' expansion of 'std::vector<string>::_S_use_relocate()'
    list.y:41:7: error: but 'string::string(string&&)' does not throw; perhaps it should be declared 'noexcept' [-Werror=noexcept]
       41 |       string (string&& s)
          |       ^~~~~~

* tests/c++.at (Variants): Add noexcept where appropriate.
2019-09-08 12:04:36 +02:00
Akim Demaille f6fd9be688 tests: add noexcept to please GCC 9
bison/tests/c++.at:552: bison --color=no -fno-caret  -o list.cc list.y
    bison/tests/c++.at:552: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o list list.cc $LIBS
    stderr:
    gcc9/c++/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string]':
    gcc9/c++/bits/alloc_traits.h:482:2:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = string; _Args = {string}; _Tp = string; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:888:67:   required from 'void std::__relocate_object_a(_Tp*, _Up*, _Allocator&) [with _Tp = string; _Up = string; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:920:47:   required from '_ForwardIterator std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_uninitialized.h:942:37:   required from '_ForwardIterator std::__relocate_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = string*; _ForwardIterator = string*; _Allocator = std::allocator<string>]'
    gcc9/c++/bits/stl_vector.h:430:35:   required from 'static constexpr bool std::vector<_Tp, _Alloc>::_S_nothrow_relocate(std::true_type) [with _Tp = string; _Alloc = std::allocator<string>; std::true_type = std::integral_constant<bool, true>]'
    gcc9/c++/bits/stl_vector.h:446:28:   required from 'void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const string&}; _Tp = string; _Alloc = std::allocator<string>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<string*, std::vector<string> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = string*]'
    gcc9/c++/bits/stl_vector.h:1195:4:   required from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = string; _Alloc = std::allocator<string>; std::vector<_Tp, _Alloc>::value_type = string]'
    list.y:126:110:   required from here
    gcc9/c++/bits/vector.tcc:459:44:   in 'constexpr' expansion of 'std::vector<string>::_S_use_relocate()'
    list.y:41:7: error: but 'string::string(string&&)' does not throw; perhaps it should be declared 'noexcept' [-Werror=noexcept]
       41 |       string (string&& s)
          |       ^~~~~~

* tests/c++.at (Variants): Add noexcept where appropriate.
2019-09-08 12:02:30 +02:00
Akim Demaille 77dbdd0d59 news: update 2019-09-08 11:38:29 +02:00
Akim Demaille f8db8fe4d7 fix: don't die when EOF token is defined twice
With

    %token EOF 0 EOF 0

we get

    input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
        3 | %token EOF 0 EOF 0
          |              ^~~
    input.y:3.8-10: previous declaration
        3 | %token EOF 0 EOF 0
          |        ^~~
    Assertion failed: (nsyms == ntokens + nvars), function check_and_convert_grammar,
        file /Users/akim/src/gnu/bison/src/reader.c, line 839.

Reported by Marc Schönefeld.

* src/symtab.c (symbol_user_token_number_set): Register only the
first definition of the end of input token.
* tests/input.at (Symbol redeclared): Check that case.
2019-09-08 11:38:29 +02:00
Akim Demaille 375eb71489 tests: check token redeclaration
* src/symtab.c (symbol_class_set): Report previous definitions when
redeclared.
* tests/input.at (Symbol redeclared): New.
2019-09-08 11:38:29 +02:00
Akim Demaille d3a86f7b20 yacc.c: beware of GCC's -Wmaybe-uninitialized
Test 400 (calc.at:773: testing Calculator api.push-pull=both
api.pure=full parse.error=verbose %debug %locations %defines
api.prefix={calc} %verbose %yacc) fails on the CI with GCC 8 on
Bionic:

    400. calc.at:773: testing Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc  ...
    ../../tests/calc.at:773: bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:773: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c calc-lex.c calc-main.c $LIBS
    stderr:
    calc.y: In function 'int calcpush_parse(calcpstate*, int, const CALCSTYPE*, CALCLTYPE*)':
    calc.y:26:20: error: 'yylval.CALCSTYPE::ival' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     %printer { fprintf (yyo, "%d", $$); } <ival>;
                        ^
    calc.c:1272:9: note: 'yylval.CALCSTYPE::ival' was declared here
     YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
             ^~~~~~
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:773: exit code was 1, expected 0
    400. calc.at:773: 400. Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc  (calc.at:773): FAILED (calc.at:773)

* data/skeletons/c.m4 (yy_symbol_value_print): Disable the warning
locally.
2019-09-08 11:38:29 +02:00
Akim Demaille 29c75ef27f glr.c: initialize vector of bools
The CI, with CC='gcc-7 -fsanitize=undefined,address
-fno-omit-frame-pointer', reports:

    calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool'
    ../../tests/calc.at:867: cat stderr
    --- expout	2019-09-05 20:30:37.887257545 +0000
    +++ /home/travis/build/bison-3.4.1.72-79a1-dirty/_build/tests/testsuite.dir/at-groups/438/stdout	2019-09-05 20:30:37.887257545 +0000
    @@ -1 +1,2 @@
     syntax error
    +calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool'
    438. calc.at:867: 438. Calculator glr.cc  (calc.at:867): FAILED (calc.at:867)

The problem is that yylookaheadNeeds is not initialized in
yyinitStateSet, and when it is copied, the value is not 0 or 1.

* data/skeletons/glr.c (yylookaheadNeeds): Initialize yylookaheadNeeds.
2019-09-08 11:38:29 +02:00
Akim Demaille 628012d830 gnulib: update
Contains a fix for
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html.
See
https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00005.html.
Reported by 江 祖铭 (Zu-Ming Jiang).
2019-09-08 11:38:29 +02:00
Akim Demaille f788ba2ab6 check for memory exhaustion
hash_initialize returns NULL when out of memory.  Check for it, and
die cleanly instead of crashing.

Reported by 江 祖铭 (Zu-Ming Jiang).
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00015.html

* src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
Check the value returned by hash_initialize.
2019-09-08 11:38:29 +02:00
László VáradyandAkim Demaille 53526f31df diagnostics: avoid global variables
* src/complain.c (indent_ptr): Remove.
(error_message, complains): Take indent as an argument.
Adjust callers.
2019-09-08 11:38:29 +02:00
László VáradyandAkim Demaille e63811dd86 diagnostics: fix invalid error message indentation
https://lists.gnu.org/archive/html/bison-patches/2019-08/msg00007.html

When Bison is started with a flag that suppresses warning messages, the
error_message() function can produce a few gigabytes of indentation
because of a dangling pointer.

* src/complain.c (error_message): Don't reset indent_ptr here, but...
(complain_indent): here.
* tests/diagnostics.at (Indentation with message suppression): Check
this case.
2019-09-08 11:38:29 +02:00
Akim Demaille 47262c36bb git: ignore files generated in gnulib-po
Because of them, the CI generates "-dirty" tarballs.
2019-09-08 11:38:29 +02:00
Akim Demaille 1e452b1553 c++: avoid duplicate definition of YYUSE
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-06/msg00009.html

* data/skeletons/lalr1.cc (b4_shared_declarations): Remove the
duplicate definition of YYUSE, the other one coming from
b4_attribute_define.
2019-09-08 09:59:31 +02:00
Akim Demaille ed796869bb gnulib: update
This update brings file from Gettext 0.20, which is not available on
the CI yet.

.travis.yml: Adjust.
Use Bionic now that it's available.
2019-09-08 09:59:31 +02:00
Akim Demaille 12c412f6bb CI: more compilers
* .travis.yml: Bionic is now available, with GCC8.
GCC7 sanitizers work, but they are too longer: cover only part 1.
Redefine part 1 and part 2 so that part 1 is really the core of the
tests: not playing with POSIX and C++ compiler for C code.
2019-09-08 09:01:18 +02:00
Akim Demaille 2663035ea5 CI: fail fast 2019-09-08 09:01:11 +02:00
Akim Demaille de7c66ab41 CI: propagate sftp failures
* .travis.yml (stage: "compile"): here.
2019-09-08 09:00:58 +02:00
Akim Demaille feeacc2d57 CI: avoid useless git costs
Travis answered favorably to my suggestion to provide a means to
disable git clone on some jobs (issue 7542).  See
https://docs.travis-ci.com/user/customizing-the-build/#disabling-git-clone.

* .travis.yml: Disable git globally, enable it for i. the compile job,
and ii. the test job on ICC which needs the install-icc.sh script.
2019-09-08 09:00:49 +02:00
Akim Demaille cc10f9ab24 CI: factor
* .travis.yml (Clang 7 libc++ and ASAN part 2): Reuse bits from "Clang
7 libc++ and ASAN part 1".
2019-09-08 09:00:30 +02:00
Akim Demaille a9499e6ea2 regen 2019-09-08 08:58:55 +02:00
Akim Demaille 09a4bfdab4 gnulib: update
Contains a fix for
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00016.html.
See
https://lists.gnu.org/archive/html/bug-gnulib/2019-09/msg00005.html.
Reported by 江 祖铭 (Zu-Ming Jiang).
2019-09-08 08:40:17 +02:00
Akim Demaille 7d701f4378 fix: don't die when EOF token is defined twice
With

    %token EOF 0 EOF 0

we get

    input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
        3 | %token EOF 0 EOF 0
          |              ^~~
    input.y:3.8-10: previous declaration
        3 | %token EOF 0 EOF 0
          |        ^~~
    Assertion failed: (nsyms == ntokens + nvars), function check_and_convert_grammar,
        file /Users/akim/src/gnu/bison/src/reader.c, line 839.

Reported by Marc Schönefeld.

* src/symtab.c (symbol_user_token_number_set): Register only the
first definition of the end of input token.
* tests/input.at (Symbol redeclared): Check that case.
2019-09-07 17:09:43 +02:00
Akim Demaille 378963b139 tests: check token redeclaration
* src/symtab.c (symbol_class_set): Report previous definitions when
redeclared.
* tests/input.at (Symbol redeclared): New.
2019-09-07 17:09:43 +02:00
Akim Demaille 2dd882bce5 glr.c: initialize vector of bools
The CI, with CC='gcc-7 -fsanitize=undefined,address
-fno-omit-frame-pointer', reports:

    calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool'
    ../../tests/calc.at:867: cat stderr
    --- expout	2019-09-05 20:30:37.887257545 +0000
    +++ /home/travis/build/bison-3.4.1.72-79a1-dirty/_build/tests/testsuite.dir/at-groups/438/stdout	2019-09-05 20:30:37.887257545 +0000
    @@ -1 +1,2 @@
     syntax error
    +calc.cc:1652:50: runtime error: load of value 190, which is not a valid value for type 'bool'
    438. calc.at:867: 438. Calculator glr.cc  (calc.at:867): FAILED (calc.at:867)

The problem is that yylookaheadNeeds is not initialized in
yyinitStateSet, and when it is copied, the value is not 0 or 1.

* data/skeletons/glr.c (yylookaheadNeeds): Initialize yylookaheadNeeds.
2019-09-06 17:27:56 +02:00
Akim Demaille 989503b1ba yacc.c: beware of GCC's -Wmaybe-uninitialized
Test 400 (calc.at:773: testing Calculator api.push-pull=both
api.pure=full parse.error=verbose %debug %locations %defines
api.prefix={calc} %verbose %yacc) fails on the CI with GCC 8 on
Bionic:

    400. calc.at:773: testing Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc  ...
    ../../tests/calc.at:773: bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:773: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c calc-lex.c calc-main.c $LIBS
    stderr:
    calc.y: In function 'int calcpush_parse(calcpstate*, int, const CALCSTYPE*, CALCLTYPE*)':
    calc.y:26:20: error: 'yylval.CALCSTYPE::ival' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     %printer { fprintf (yyo, "%d", $$); } <ival>;
                        ^
    calc.c:1272:9: note: 'yylval.CALCSTYPE::ival' was declared here
     YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
             ^~~~~~
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:773: exit code was 1, expected 0
    400. calc.at:773: 400. Calculator api.push-pull=both api.pure=full parse.error=verbose %debug %locations %defines api.prefix={calc} %verbose %yacc  (calc.at:773): FAILED (calc.at:773)

* data/skeletons/c.m4 (yy_symbol_value_print): Disable the warning
locally.
2019-09-06 17:27:55 +02:00
Akim Demaille 61c2c40092 lalr1.cc: fix LAC support
* data/skeletons/lalr1.cc (ctor): Initialize yy_lac_established_.
This is quite painful to write, and ugly to read.
2019-09-06 17:27:55 +02:00
Akim Demaille 3953c61362 style: fix comment
* tests/atlocal.in: here.
2019-09-06 17:27:55 +02:00
Akim Demaille 39e584c018 CI: more compilers
* .travis.yml: Bionic is now available, with GCC8.
GCC7 sanitizers work, but they are too longer: cover only part 1.
Redefine part 1 and part 2 so that part 1 is really the core of the
tests: not playing with POSIX and C++ compiler for C code.
2019-09-06 17:26:00 +02:00
Akim Demaille 611eaffd28 CI: fail fast 2019-09-06 07:21:54 +02:00
Akim Demaille 3f4ad2cd24 gnulib: update
This update brings file from Gettext 0.20, which is not available on
the CI yet.

.travis.yml: Adjust.
Use Bionic now that it's available.
2019-09-04 18:17:38 +02:00
Akim Demaille 989a7aa865 check for memory exhaustion
hash_initialize returns NULL when out of memory.  Check for it, and
die cleanly instead of crashing.

Reported by 江 祖铭 (Zu-Ming Jiang).
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00015.html

* src/muscle-tab.c, src/state.c, src/symtab.c, src/uniqstr.c:
Check the value returned by hash_initialize.
2019-09-01 17:53:22 +02:00
Akim Demaille 95cbd56882 news: LAC for C++ 2019-08-30 11:16:57 -05:00
Akim Demaille 92124d27c1 d: remove useless imports
* examples/d/calc.y, tests/calc.at: here.
2019-08-29 07:26:33 -05:00
László VáradyandAkim Demaille 6d81b91ae0 diagnostics: avoid global variables
* src/complain.c (indent_ptr): Remove.
(error_message, complains): Take indent as an argument.
Adjust callers.
2019-08-18 09:40:58 -05:00
László VáradyandAkim Demaille 9145bd0b61 diagnostics: fix invalid error message indentation
https://lists.gnu.org/archive/html/bison-patches/2019-08/msg00007.html

When Bison is started with a flag that suppresses warning messages, the
error_message() function can produce a few gigabytes of indentation
because of a dangling pointer.

* src/complain.c (error_message): Don't reset indent_ptr here, but...
(complain_indent): here.
* tests/diagnostics.at (Indentation with message suppression): Check
this case.
2019-08-18 09:40:44 -05:00
Akim Demaille d7cf3f5b18 c++: use resize to shrink a vector
Suggested by Adrian Vogelsgesang.
https://lists.gnu.org/archive/html/bison-patches/2019-08/msg00009.html

* data/skeletons/lalr1.cc (yy_lac_check_): here.
2019-08-18 06:54:56 -05:00
Akim Demaille f49598a1e1 lalr1.cc: check LAC support
* tests/conflicts.at, tests/input.at, tests/regression.at: here.
2019-08-09 06:40:38 -05:00
Adrian VogelsgesangandAkim Demaille 72d4ae5306 lalr1.cc: add LAC support
Implement lookahead correction (LAC) for the C++ skeleton.  LAC is a
mechanism to make sure that we report the correct list of expected
tokens if a syntax error occurs.  So far, LAC was only supported for
the C skeleton "yacc.c".

* data/skeletons/lalr1.cc: Add LAC support.
* doc/bison.texi: Update.
2019-08-09 06:39:59 -05:00
Adrian VogelsgesangandAkim Demaille 996abe62d7 style: readability improvements to yacc.c
* data/skeletons/yacc.c (yysyntax_error): Change the nesting of `m4`
conditions slightly to make it more readable.
The generated C code stays unchanged.
2019-08-09 06:06:02 -05:00
Adrian VogelsgesangandAkim Demaille 0420362ee8 lalr1.cc: reduce "scope"
* data/skeletons/lalr1.cc (yy_lr_goto_state_): Make it static.
2019-08-09 06:06:00 -05:00
Adrian VogelsgesangandAkim Demaille 6f47eea7ab lalr1.cc: fix indentation of table declarations in the header
* data/skeletons/lalr1.cc: Fix indentation of table declarations in
the generated header.
2019-08-09 05:39:30 -05:00
Akim Demaille 99bfdc09cb tests: prepare LAC tests for more languages
* tests/regression.at: Use %expect to avoid warnings.
Set the keywords to facilitate running specific tests.
Use macros such as AT_YYLEX_DECLARE to facilitate tests for other
languages.
Likewise for AT_FULL_COMPILE.
2019-08-09 05:39:30 -05:00
Akim Demaille 52f21717f7 git: ignore files generated in gnulib-po
Because of them, the CI generates "-dirty" tarballs.
2019-08-09 05:38:19 -05:00
Akim Demaille cbdc22af10 diagnostics: use the modern argmatch interface
* src/complain.h (warnings): Remove Werror.
Adjust dependencies.
Sort.
Remove useless comments (see the doc in argmatch group).
* src/complain.c (warnings_args, warnings_types): Remove.
(warning_argmatch): Use argmatch_warning_value.
(warnings_print_categories): Use argmatch_warning_argument.
2019-07-26 07:57:15 +02:00
Akim Demaille 220c593a79 doc: avoid spurious empty lines in the option table
In Texinfo. empty lines in multitable rows generate empty lines in the
output.  Avoid them altogether.

With help from Gavin Smith.
https://lists.gnu.org/archive/html/bug-texinfo/2019-07/msg00000.html

* build-aux/cross-options.pl: Separate rows with empty lines.
So, to be more readable, generate a single line for each row.
Use Perl format to this end.
2019-07-19 07:46:09 +02:00
Akim Demaille e29ac453d0 --fixed-output-files: detach from --yacc
See the previous commit.  This option should be removed, -o suffices.

* src/getargs.c (FIXED_OUTPUT_FILES): New.
Add support for it.
(getargs): Define loc, and use it.
This is safer when we need to pass a pointer to a location.
2019-07-07 15:59:54 +02:00
Akim Demaille 44a56b20ac %fixed-output-files: detach from %yacc
The name fixed-output-files is pretty clear: generate y.tab.c, as Yacc
does.  So let's detach this from %yacc which does more: it requires
POSIX Yacc behavior.

This directive is obsolete since December 29th 2001
8c9a50bee1.  It does not show in the
doc.  I don't want to spend more time on improving its diagnostics, it
could be removed just as well as far as I'm concerned.

* src/scan-gram.l, src/parse-gram.y (%fixed-output-files): Detach from
%yacc.
2019-07-07 15:54:20 +02:00
Akim Demaille f99956b550 style: clarify control flow
* src/getargs.c (language_argmatch): Initialize msg.
Check it instead of relying on a return.
2019-07-07 15:01:45 +02:00
Akim Demaille 1f02348d6c remove MS-DOS support
DJGPP support was dropped in Bison 3.3
(c239e53bab).

AS_FILE_NAME was introduced in
ae40480115.

* src/getargs.c (AS_FILE_NAME): Remove.
2019-07-07 14:38:49 +02:00
Akim Demaille 421ff03018 style: declare options in the same order as in --help
* src/getargs.c (long_options): here.
2019-07-07 14:27:39 +02:00
Akim Demaille 5d3468e0d1 regen 2019-07-07 14:03:37 +02:00
Akim Demaille 40a8dddde1 gnulib: update
Contains a fix for argmatch to get proper man pages.
See https://lists.gnu.org/archive/html/bug-gnulib/2019-07/msg00038.html
2019-07-07 12:22:02 +02:00
Akim Demaille 9bdefd7984 style: comment change
* src/getargs.c: here.
2019-07-07 12:13:30 +02:00
Akim Demaille d233a2e314 doc: remove the --report=look-aheads alias
Years ago we moved from 'look-ahead' to 'lookahead', and that alias
was kept for backward compatibility.  But now that we use argmatch to
generate the documentation, that value clutters the doc.

* src/getargs.c (argmatch_report_args): Remove the
--report=look-aheads alias.
2019-07-07 08:11:35 +02:00
Akim Demaille d90023af5f doc: fix inaccuracies wrt --define and --force-define
The doc says that -Dfoo=bar is the same as %define foo "bar".  It is
not: the quotes are not added (and it makes a difference).

* doc/bison.texi (Tuning the Parser): Fix the definition of -D/-F
* src/getargs.c (usage): Likewise.
2019-07-07 08:11:35 +02:00
Akim Demaille 964c6508b1 doc: put diagnostics related options together
* doc/bison.texi (Diagnostics): New section.
Move --warning, --color and --style there.
* src/getargs.c (usage): Likewise.
2019-07-07 08:11:35 +02:00
Akim Demaille 4e3c6f59cc doc: move -y's documentation into "Tuning the Parser"
Let's clarify --help: use clearer "section" names, as in the doc.
Move --yacc to where it belongs.

* src/getargs.c (usage): Rename "Parser" as "Tuning the Parser", as in
the doc.
Rename "Output" as "Output Files"
Move --yacc to "Tuning the Parser".
* doc/bison.texi: Likewise.
2019-07-07 08:01:37 +02:00
Akim Demaille 801582b410 doc: document colorized diagnostics
* src/getargs.c (argmatch_color_group): New.
(usage): Document --color and --style.
* doc/bison.texi (Bison Options): Split into three subsections.
Document --color and --style.
2019-07-07 08:01:37 +02:00
Akim Demaille 6d35340556 gnulib: use new features of the argmatch module
It can now generate the usage message.

* src/complain.h (feature_fixit_parsable): Rename as...
(feature_fixit): this, for column economy.
Adjust dependencies.
(warning_usage): New.
Use it.
* src/complain.h, src/complain.c, src/getargs.h, src/getargs.c:
Use ARGMATCH_DEFINE_GROUP instead of the older interface.
2019-07-03 07:02:44 +02:00
Akim Demaille 1161649446 preserve the indentation in the ouput
Preserve the actions' initial indentation.  For instance, on

    | %define api.value.type {int}
    | %%
    | exp: exp '/' exp { if ($3)
    |                     $$ = $1 + $3;
    |                   else
    |                     $$ = 0; }

we used to generate

    |     { if (yyvsp[0])
    |                     yyval = yyvsp[-2] + yyvsp[0];
    |                   else
    |                    yyval = 0; }

now we produce

    |                  { if (yyvsp[0])
    |                     yyval = yyvsp[-2] + yyvsp[0];
    |                   else
    |                     yyval = 0; }

See https://lists.gnu.org/archive/html/bison-patches/2019-06/msg00012.html.

* data/skeletons/bison.m4 (b4_symbol_action): Output the code in
column 0, leave indentation matters to the C code.
* src/output.c (user_actions_output): Preserve the incoming
indentation in the output.
(prepare_symbol_definitions): Likewise for %printer/%destructor.
* tests/synclines.at (Output columns): New.
2019-07-02 07:38:52 +02:00
Akim Demaille 13577a809e style: prefer passing locations by pointer
The code is inconsistent: sometimes we pass by value, sometimes by
reference.  Let's stick to the last, more conventional for large
values in C.

* src/scan-code.l: Pass locations by reference.
2019-07-01 07:23:42 +02:00
Akim Demaille afc219a765 c++: avoid duplicate definition of YYUSE
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-06/msg00009.html

* data/skeletons/lalr1.cc (b4_shared_declarations): Remove the
duplicate definition of YYUSE, the other one coming from
b4_attribute_define.
2019-06-30 19:19:43 +02:00
Akim Demaille 21aa4b2713 style: comment changes
* examples/c/lexcalc/local.mk, examples/c/reccalc/local.mk:
Here.
2019-06-27 07:57:21 +02:00
Akim Demaille 63f4dca78f tests: restructure for clarity
* tests/calc.at (AT_CALC_MAIN, AT_CALC_LEX): Rewrite on top of
AT_LANG_DISPATCH.
2019-06-23 19:26:13 +02:00
Akim Demaille 0984f70e08 d: track locations
* configure.ac (DCFLAGS): Pass -g.
* data/skeletons/d.m4 (b4_locations_if): Remove, let bison.m4's one do
its job.
* data/skeletons/lalr1.d (position): Leave filename empty by default.
(position::toString): Don't print empty file names.
(location::this): New ctor.
(location::toString): Match the implementations of C/C++.
(yy_semantic_null): Leave undefined, the previous implementation does
not compile.
* tests/calc.at: Improve the implementation for D.
Enable more checks, in particular using locations.
* tests/local.at (AT_YYERROR_DEFINE(d)): Fix its implementation.
2019-06-23 11:20:18 +02:00
Akim Demaille f26bd45da3 d: style changes
* data/skeletons/lalr1.d: Use a more traditional quotation scheme.
Formatting changes.
2019-06-23 11:20:16 +02:00
Akim Demaille a3adc1701b d: put internal details inside the parser
Avoid name clashes, etc.

* data/skeletons/lalr1.d (YYStackElement, YYStack): Move inside the
parser.
2019-06-23 11:19:46 +02:00
Akim Demaille 7ab275214b gnulib: update 2019-06-22 09:03:19 +02:00
Akim Demaille 0428c429a1 remove "experimental" warnings
Sadly enough, AFAIK, there were never answers to the "More user
feedback will help to stabilize it" sentences.  Remove them.

* src/getargs.c: IELR, canonical LR and XML output are here to stay,
and they are no more experimental than some other features.
* doc/bison.texi: Likewise.
Also remove "experimental" warning for Java, LAC, LR tuning options,
and named references.
2019-06-22 08:29:06 +02:00
Akim Demaille 14fb2cc820 CI: propagate sftp failures
* .travis.yml (stage: "compile"): here.
2019-06-22 08:29:06 +02:00
Akim Demaille faf033957c d: honor %define parse.trace
* data/skeletons/lalr1.d: Don't generate debug code if parse.trace is
not enabled.
2019-06-20 06:57:27 +02:00
Akim Demaille 0555e25a41 d: style changes
* data/skeletons/lalr1.d: here.
2019-06-20 06:57:27 +02:00
Akim Demaille cde8c0a0e6 d: prefer delegation to duplication
* data/skeletons/lalr1.d: Delegate the construction of the scanner.
2019-06-20 06:57:27 +02:00
Akim Demaille 5b525e86a5 d: enable #line output
* data/skeletons/d.m4 (b4_sync_start): New.
2019-06-20 06:57:27 +02:00
Akim Demaille df77a98edf d: style changes
* data/skeletons/lalr1.d: here.
* examples/d/calc.y: Remove incorrect support for decimal numbers.
Formatting changes.
2019-06-20 06:57:27 +02:00
Akim Demaille c23fa0fc97 style: reduce scopes in glr.c
* data/skeletons/glr.c: here.
2019-06-20 06:57:27 +02:00
Akim Demaille 08c0571613 java: honor %define parse.trace
* data/skeletons/lalr1.java: Don't generate debug code if parse.trace
is not enabled.
2019-06-20 06:57:27 +02:00
Akim Demaille f2b210a901 java: fix support for api.prefix
* data/skeletons/java.m4: here.
* tests/java.at: Check it.
2019-06-19 19:15:31 +02:00
Akim Demaille 66ac4acc6c java: style changes
* data/skeletons/lalr1.java: Use more conventional function names for
Java.
Prefer < and <= to => and >.
Use the same approach for m4 quotation as in the other skeletons.
Fix indentation issues.

* tests/calc.at, tests/java.at, tests/javapush.at: Fix quotation style.
(main): Use 'args', not 'argv', the former seems more conventional and
is used elsewhere in Bison.
Prefer character literals to integers to denote characters.
* examples/java/Calc.y: Likewise.
2019-06-19 19:15:26 +02:00
Akim Demaille cd0f25df5f CI: avoid useless git costs
Travis answered favorably to my suggestion to provide a means to
disable git clone on some jobs (issue 7542).  See
https://docs.travis-ci.com/user/customizing-the-build/#disabling-git-clone.

* .travis.yml: Disable git globally, enable it for i. the compile job,
and ii. the test job on ICC which needs the install-icc.sh script.
2019-06-15 10:28:50 +02:00
Akim Demaille 0f46038589 style: simplify strings to translate
* src/conflicts.c (log_resolution): Don't translate indentation.
2019-06-12 21:41:16 +02:00
Akim Demaille 1105cf841b style: reduce scopes, propagate const
* src/conflicts.c (conflicts_output): here.
2019-06-12 21:41:16 +02:00
Akim Demaille a298a6d82b style: use clearer types
* src/conflicts.c (conflicts): Array of Booleans.
2019-06-12 06:59:31 +02:00
Akim Demaille 5f33acefd1 tests: prefer %empty
* tests/regression.at: here.
2019-06-11 20:40:36 +02:00
Akim Demaille 849ba01b8b CI: factor
* .travis.yml (Clang 7 libc++ and ASAN part 2): Reuse bits from "Clang
7 libc++ and ASAN part 1".
2019-06-09 11:11:14 +02:00
Akim Demaille 29c9cb3188 lr0: more debug traces
* src/lr0.c (kernel_check): New.
(new_itemsets, save_reductions): Add traces.
2019-06-09 11:11:12 +02:00
Akim Demaille ec4d49e129 traces: add some colors
This is an experiment.  Maybe more styles will be used (in which case
a short-hand function will be useful), maybe it will be just reverted.
* data/bison-default.css (.traces0): New.
* src/lalr.c (lalr): Use it.
2019-06-09 08:36:01 +02:00
Akim Demaille d84b245c63 tests: make sure the default action properly works in C++
See e3fdc37049: in C++ we generate
explicitly the code for the default action instead of simply copying
blindly the semantic value buffer.  This is important when copying
raw memory is not enough, as exemplified by move-only types.

This is currently tested by examples/c++/variant.yy and variant-11.yy.
But it is safer to also have a test in the main test suite.

* tests/local.at (AT_REQUIRE_CXX_STD): Fix.
(AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS): Define/undefine
AT_BISON_OPTIONS.
* tests/c++.at (Default action): New.
2019-06-09 08:36:01 +02:00
Akim Demaille 73797b2552 tests: main: support -s and -p
* tests/local.at (AT_MAIN_DEFINE(c), AT_MAIN_DEFINE(c++)): here.
2019-06-09 08:36:01 +02:00
Akim Demaille dfef525920 tests: remove useless support of '.' in integers
* tests/calc.at: here.
* doc/bison.texi: Avoid uninitialized variables.
2019-06-04 08:36:43 +02:00
Akim Demaille 7f017ae1c9 tests: refactor checks on sets
It will be convenient to check sets elsewhere.

* tests/sets.at (AT_EXTRACT_SETS): Transform into...
* tests/local.at (AT_SETS_CHECK): this.
* tests/sets.at: Adjust.
2019-05-29 08:38:16 +02:00
Akim Demaille 65126716d7 update-test: some file names have dashes in them
* build-aux/update-test (log): Rename as...
(trace): this, to avoid clashes with the log variable.
(getargs): Clarify the type of the arguments.
2019-05-29 08:26:20 +02:00
Akim Demaille 1dcd6068dd tests: take SHELL into account
Reported by Dennis Clarke.
http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00053.html

* examples/local.mk, tests/local.mk: here.
2019-05-26 15:29:37 +02:00
Akim Demaille 02f16dc799 gnulib: update to get gnulib translations
This update contains a fix needed for gnulib-po to work properly.
https://lists.gnu.org/archive/html/bug-gnulib/2019-05/msg00146.html
2019-05-26 09:35:31 +02:00
Akim Demaille aa21c457f2 doc: clarify the purpose of symbol_type constructors
Reported by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2019-02/msg00006.html

* doc/bison.texi (Complete Symbols): Here.
2019-05-25 10:28:12 +02:00
Akim Demaille 9f26e6d6b3 thanks: fix an address 2019-05-22 18:09:04 +02:00
Akim Demaille 8d3e782e05 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-05-22 07:45:49 +02:00
280 changed files with 28915 additions and 11928 deletions
-3
View File
@@ -1,9 +1,6 @@
/ABOUT-NLS~
*.eps
*.log
*.o
*.pdf
*.png
*.stamp
*.trs
*~
+1 -1
View File
@@ -1 +1 @@
3.4
3.7.3
+282 -176
View File
@@ -1,14 +1,8 @@
# Travis defines and exports CC and CXX *after* we have defined our
# environment variables via 'env'. So, do not use 'env' to define them.
# Instead, put their definitions in MATRIX_EVAL, which we eval after the
# definitions from Travis.
language: cpp
version: ~> 1.0
env:
global:
# ICC serial number.
# See https://github.com/nemequ/icc-travis.
secure: B3manbbi0anCAGDJTdAa9TlodzRHeiYD87FKmFzS877dPm8Cm0BDvtUhKBUpBvP8+nbHOWFGrgDmLugSZjTGU+mAxtuQpamUFHvinu0BIk3qtjlqouwvbtIqUu8iiZ3Uqu+xKeAANKRy0YVZGLlEb9F3N119tJ/Fxp1p9bXL1qph+CZ25OFbUgZ2s4F+/AyHMUxJlNXKFe3Qean65hC6edhU3zoaKzr/g/wtbhRmcyWbkOa1dJqzr2yKotcPvrnApGhDzgMKFtohg/t7xfMADDVv6sGS5XNpt25Z+MUCmLg4Z9eD7u109jvRV1eu/jgVafqsthWEhXbuMiFgFhKBKGCNZ0dACIfKZSkFZI6FdM7ovJ6aNhSlxZ2169Ybd22rN1UTHeCQWySPcVVOg5taLVpqe+E8Xhnv4hBO5NrzElWwCMLxIdPUSwVStYvtDr8ZytHWzfot50vSnFKIFpTOr9hP4+AJMVmmqJfaJo2MLBft/q2xkztrMv3lQSj3m4+ma9kPDwXIu9uCutjlnhc00jNx9qegi5VfpAjxcG1R+pX4T20az6ByHk/7LPQsANkT31RJq/jAeD9LEuMOy8miha83q4QuvbFaqPK3PY0el/O1LZaXqLsV2aQ0uqH8YX0l4r5NzHdhb+3lYgvpMBO5ytr/EWJiEyNYV518050IUDE=
# If the language is set to C or C++, Travis defines and exports CC
# and CXX *after* we have defined our environment variables via 'env'.
language: minimal
# Run in two steps:
# 1. Build the tarball
@@ -17,31 +11,31 @@ env:
# Less dependencies, and little git content (we would like to have none, but it's not
# an option on Travis).
stages:
- compile
- test
- dist
- check
# The 'check' jobs do not need the repo at all, only the 'dist'
# does. Let's save time, bandwith, energy, and polar bears.
git:
# Manually handle submodules so that we don't have to uselessly waste 150s
# to download gnulib in the 'test' jobs.
submodules: false
# For the same reasons, we would like to not clone the repo either, but it
# does not seem to be possible.
depth: 1
clone: false
# matrix.include and jobs.include are aliases
# (https://docs.travis-ci.com/user/conditional-builds-stages-jobs/).
jobs:
include:
- stage: "compile"
dist: xenial
- stage: dist
name: "Make dist"
git:
clone: true
dist: bionic
script:
- sudo apt-get install -qq autoconf automake autopoint flex gettext graphviz help2man m4 texinfo
- sudo apt-get install -qq autoconf automake autopoint flex gettext gperf graphviz help2man m4 texinfo
- autoconf --version
- automake --version
- autopoint --version
- dot -V
- gettext --version
- gperf --version
- help2man --version
- makeinfo --version
- m4 --version
@@ -51,191 +45,309 @@ jobs:
- git submodule update --init --recursive
- ./bootstrap
- ./configure --enable-gcc-warnings CC="$CC" CXX="$CXX" $CONFIGUREFLAGS || { cat config.log && false; }
- ./configure --enable-gcc-warnings || { cat config.log && false; }
- make -j2
- make -j2 dist
- 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
# git history (because git describe --abbrev=4 may use more than 4 characters if there are
# conflicts). Besides, one day we would like not to depend on the repository at all in the
# 'test' jobs. So also expose this tarball on a name that only depends on the Travis build
# number.
- sftp [email protected] <<< "put $dist"$'\n'"ln -s $dist bison-$TRAVIS_BUILD_NUMBER.tar.xz"
# conflicts).
#
# So for the sake of the 'check' jobs (that don't even have the repo at all), also expose this
# tarball on a name that only depends on the Travis build number.
#
# Without -b -, exit status is always 0.
#
# If we rerun a job that was already uploaded, 'ln -s' will fail: remove beforehand.
- sftp -b - [email protected] <<< "put $dist"$'\n'"-rm bison-$TRAVIS_BUILD_NUMBER.tar.xz"$'\n'"ln -s $dist bison-$TRAVIS_BUILD_NUMBER.tar.xz"
## ------- ##
## First. ##
## ------- ##
# Start with three completely different environments, to get
# errors asap.
# Start with three completely different environments, to get errors asap.
- name: "GCC 7 -O3"
stage: test
- name: "GCC 10 -O3"
stage: check
os: linux
dist: xenial
addons:
dist: bionic
addons: &gcc10
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-10
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'"
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
# ASAN is time consuming, and we timeout the 50min granted by
# Travis if we run all the tests in one go. Run in two parts.
- name: "Clang 7 libc++ and ASAN part 1"
stage: test
- name: "Clang 10 libc++ and ASAN part 1"
stage: check
os: linux
dist: xenial
addons:
dist: bionic
addons: &clang10
apt:
sources:
- llvm-toolchain-xenial-7
- ubuntu-toolchain-r-test
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-7
- libc++-7-dev
- libc++abi-7-dev
- clang-10
- libc++-10-dev
- libc++abi-10-dev
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- MATRIX_EVAL="PART=1 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'"
- CC='clang-10 -fsanitize=address'
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
- PART=1
- name: "Clang 7 libc++ and ASAN part 2"
stage: test
- name: "Clang 10 libc++ and ASAN part 2"
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- llvm-toolchain-xenial-7
- ubuntu-toolchain-r-test
packages:
- clang-7
- libc++-7-dev
- libc++abi-7-dev
dist: bionic
addons: *clang10
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- MATRIX_EVAL="PART=2 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'"
- CC='clang-10 -fsanitize=address'
- 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: test
stage: check
os: linux
dist: xenial
compiler: icc
env:
# ICC's warnings are often very wrong (e.g., it thinks foo ?
# "bar" : "baz" is char* instead of const char*), so don't try
# to work around the, and obviously, don't die on them.
- MATRIX_EVAL="CC=icc && CXX=icpc"
- MAKE_ARGS='WERROR_CFLAGS= WERROR_CXXFLAGS='
- CC=icc
- CXX=icpc
install:
- source /opt/intel/oneapi/compiler/latest/env/vars.sh
addons:
apt:
sources:
- sourceline: 'deb https://apt.repos.intel.com/oneapi all main'
key_url: 'https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB'
packages:
- intel-oneapi-icc
- name: "ARM64: GCC 10 -O2 part 1"
stage: check
os: linux
arch: arm64
dist: bionic
addons: *gcc10
env:
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "PPC64le: GCC 10 -O2 part 1"
stage: check
os: linux
arch: ppc64le
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-10
env:
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "s390x: GCC 10 -O2 part 1"
stage: check
os: linux
arch: s390x
dist: bionic
addons: *gcc10
env:
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
## ----- ##
## GCC. ##
## ----- ##
#- name: "GCC 8 with sanitizers"
# os: linux
# dist: xenial
# addons:
# apt:
# sources:
# - ubuntu-toolchain-r-test
# packages:
# - g++-8
# env:
# # Can't use UBSAN: I get:
# # configure:4951: gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer conftest.c
# # /usr/bin/ld: unrecognized option '--push-state' (on trusty)
# # /usr/bin/ld: unrecognized option '--push-state--no-as-needed' (on xenial)
# #
# # https://stackoverflow.com/questions/50024731/ suggests using the gold linker.
# - MATRIX_EVAL="CC='gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer' CXX='g++-8 -fsanitize=undefined,address -fno-omit-frame-pointer'"
- name: "GCC 9 with sanitizers part 1"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-9
env:
- CC='gcc-9 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CXX='g++-9 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CONFIGUREFLAGS='CFLAGS=-O1 CXXFLAGS=-O1'
- PART=1
- name: "GCC 8"
stage: check
os: linux
dist: bionic
addons:
apt:
packages: g++-8
env:
- CC=gcc-8
- CXX=g++-8
- name: "GCC 7"
stage: check
os: linux
dist: bionic
addons:
apt:
packages: g++-7
env:
- CC=gcc-7
- CXX=g++-7
- name: "GCC 6"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
sources: ubuntu-toolchain-r-test
packages: g++-6
env:
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
- CC=gcc-6
- CXX=g++-6
- name: "GCC 5"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
sources: ubuntu-toolchain-r-test
packages: g++-5
env:
- MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
- CC=gcc-5
- CXX=g++-5
- name: "GCC 4.9"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
sources: ubuntu-toolchain-r-test
packages: g++-4.9
env:
- MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
- CC=gcc-4.9
- CXX=g++-4.9
- name: "GCC 4.8"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
sources: ubuntu-toolchain-r-test
packages: g++-4.8
env:
- MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"
- CC=gcc-4.8
- CXX=g++-4.8
- name: "GCC 4.7"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.7
sources: ubuntu-toolchain-r-test
packages: g++-4.7
env:
- MATRIX_EVAL="CC=gcc-4.7 && CXX=g++-4.7"
- CC=gcc-4.7
- CXX=g++-4.7
- name: "GCC 4.6"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.6
sources: ubuntu-toolchain-r-test
packages: g++-4.6
env:
- MATRIX_EVAL="CC=gcc-4.6 && CXX=g++-4.6"
- CC=gcc-4.6
- CXX=g++-4.6
## ------- ##
## Clang. ##
## ------- ##
- name: "Clang 6 -O3 and libc++"
stage: test
- name: "Clang 9 -O3"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-9
- libc++-9-dev
- libc++abi-9-dev
env:
- CC='clang-9'
- CXX='clang++-9 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- name: "Clang 8"
stage: check
os: linux
dist: bionic
addons:
apt:
packages:
- clang-8
- libc++-8-dev
- libc++abi-8-dev
env:
- CC=clang-8
- CXX='clang++-8 -stdlib=libc++'
- name: "Clang 7"
stage: check
os: linux
dist: bionic
addons:
apt:
packages:
- clang-7
- libc++-7-dev
- libc++abi-7-dev
env:
- CC=clang-7
- CXX='clang++-7 -stdlib=libc++'
- name: "Clang 6 and libc++"
stage: check
os: linux
dist: xenial
addons:
@@ -247,51 +359,49 @@ jobs:
- clang-6.0
- libc++-dev
env:
- MATRIX_EVAL="CC=clang-6.0 && CXX='clang++-6.0 -stdlib=libc++'"
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- CC=clang-6.0
- CXX='clang++-6.0 -stdlib=libc++'
- name: "Clang 5"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- llvm-toolchain-xenial-5.0
sources: llvm-toolchain-xenial-5.0
packages:
- clang-5.0
- libc++-dev
env:
- MATRIX_EVAL="CC='clang-5.0' CXX='clang++-5.0'"
- CC='clang-5.0'
- CXX='clang++-5.0'
- name: "Clang 4"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- llvm-toolchain-xenial-4.0
packages:
- clang-4.0
sources: llvm-toolchain-xenial-4.0
packages: clang-4.0
env:
- MATRIX_EVAL="CC=clang-4.0 && CXX=clang++-4.0"
- CC=clang-4.0
- CXX=clang++-4.0
- name: "Clang 3.9"
stage: test
stage: check
os: linux
dist: xenial
addons:
apt:
sources:
- llvm-toolchain-xenial-3.9
packages:
- clang-3.9
sources: llvm-toolchain-xenial-3.9
packages: clang-3.9
env:
- MATRIX_EVAL="CC=clang-3.9 && CXX=clang++-3.9"
- CC=clang-3.9
- CXX=clang++-3.9
- name: "Clang 3.8"
stage: test
stage: check
os: linux
dist: xenial
addons:
@@ -299,13 +409,13 @@ jobs:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- clang-3.8
packages: clang-3.8
env:
- MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8"
- CC=clang-3.8
- CXX=clang++-3.8
- name: "CLang 3.7"
stage: test
stage: check
os: linux
dist: xenial
addons:
@@ -313,13 +423,13 @@ jobs:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
packages:
- clang-3.7
packages: clang-3.7
env:
- MATRIX_EVAL="CC=clang-3.7 && CXX=clang++-3.7"
- CC=clang-3.7
- CXX=clang++-3.7
- name: "Clang 3.6"
stage: test
stage: check
os: linux
dist: xenial
addons:
@@ -327,13 +437,13 @@ jobs:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- clang-3.6
packages: clang-3.6
env:
- MATRIX_EVAL="CC=clang-3.6 && CXX=clang++-3.6"
- CC=clang-3.6
- CXX=clang++-3.6
- name: "Clang 3.5"
stage: test
stage: check
os: linux
dist: xenial
addons:
@@ -341,37 +451,37 @@ jobs:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.5
packages:
- clang-3.5
packages: clang-3.5
env:
- MATRIX_EVAL="CC=clang-3.5 && CXX=clang++-3.5"
- CC=clang-3.5
- CXX=clang++-3.5
- name: "Clang 3.4"
stage: test
stage: check
os: linux
# Not available on Xenial.
dist: trusty
addons:
apt:
packages:
- clang-3.4
packages: clang-3.4
env:
# No versioned name installed, but beware that Travis installs
# a more modern clang earlier in the default PATH.
- MATRIX_EVAL='CC=/usr/bin/clang && CXX=/usr/bin/clang++'
- CC=/usr/bin/clang
- CXX=/usr/bin/clang++
- name: "Clang 3.3"
stage: test
stage: check
os: linux
# Not available on Xenial.
dist: trusty
addons:
apt:
packages:
- clang-3.3
packages: clang-3.3
env:
# See comment for 3.4.
- MATRIX_EVAL='CC=/usr/bin/clang && CXX=/usr/bin/clang++'
- CC=/usr/bin/clang
- CXX=/usr/bin/clang++
## From https://docs.gitlab.com/ce/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor.
## Applies to Travis too. Applied to all the 'script's (of all the jobs).
@@ -387,22 +497,18 @@ before_script:
- echo '|1|bpc51UGxoDZjCPiwRlCStW32trI=|rfh6mLoLZv/vAvOVrpZXI1hTLxg= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIR+ckMoJTNXHvAQLHWSfrRnrNJGW2ZR6kr5pBVDGCkz1v1RcQ5rleq0NAt9kS3v4hgnuLiEVnK7KDRzcEH3ikc=' >>~/.ssh/known_hosts
- chmod 600 ~/.ssh/known_hosts
# Applies only to the jobs that don't have a 'script', i.e., applies to all the 'test' jobs, but not the 'compile' one.
# Applies only to the jobs that don't have a 'script', i.e., applies to all the 'check' jobs, but not the 'dist' one.
script:
- eval "$MATRIX_EVAL"
# Beware not too leak $SSH_PRIVATE_KEY.
# - env
- sudo apt-get install -qq doxygen flex m4
# Install and activate ICC.
- if [[ $CC == "icc" ]]; then build-aux/install-icc.sh; fi
- if [[ -f ~/.bashrc ]]; then source ~/.bashrc; fi
# Install and activate dmd.
- mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
- source $(source ~/dlang/install.sh dmd -a)
- source $(source ~/dlang/install.sh dmd -a) || true
- $CC --version
- $CXX --version
- dmd --version
- dmd --version || true
- doxygen --version
- flex --version
- ld --version
@@ -413,6 +519,9 @@ script:
# with `Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m`, which makes
# the test suite fail.
- unset _JAVA_OPTIONS
# Fail fast from now on.
- set -e
- sftp [email protected]:bison-$TRAVIS_BUILD_NUMBER.tar.xz
- tar xf bison-$TRAVIS_BUILD_NUMBER.tar.xz
- dir=$(tar tf bison-$TRAVIS_BUILD_NUMBER.tar.xz | sed 1q)
@@ -422,8 +531,5 @@ script:
- ../configure --enable-gcc-warnings CC="$CC" CXX="$CXX" $CONFIGUREFLAGS || { cat config.log && false; }
- make -j2 $MAKE_ARGS
- if test ${PART-1} = 1; then make check VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat test-suite.log && cat tests/testsuite.log && false; }; fi
- if test ${PART-1} = 1; then make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
- if test ${PART-2} = 2; then make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
- if test ${PART-2} = 2; then make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
after_script:
- if [[ $CC == "icc" ]]; then uninstall_intel_software; fi
+1 -1
View File
@@ -24,7 +24,7 @@ and nasty bugs.
-----
Copyright (C) 1998-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 1998-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+1 -1
View File
@@ -26733,7 +26733,7 @@
-----
Copyright (C) 1987-1988, 1991-2015, 2018-2019 Free Software
Copyright (C) 1987-1988, 1991-2015, 2018-2020 Free Software
Foundation, Inc.
Copying and distribution of this file, with or without
+14 -2
View File
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in.
# Copyright (C) 2001-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc.
#
# 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
@@ -42,7 +42,7 @@ dependencies = $(BISON_IN) $(src_bison_SOURCES) $(dist_skeletons_DATA)
BISON = $(top_builddir)/tests/bison
BISON_IN = $(top_srcdir)/tests/bison.in
YACC = $(BISON) -o y.tab.c
AM_YFLAGS_WITH_LINES = --defines -Werror -Wall --report=all
AM_YFLAGS_WITH_LINES = --defines -Werror -Wall,dangling-alias --report=all
AM_YFLAGS = $(AM_YFLAGS_WITH_LINES) --no-lines
# Initialization before completion by local.mk's.
@@ -127,3 +127,15 @@ gen-ChangeLog:
--since=$(gen_start_date) > $$cl.tmp && \
mv -f $$cl.tmp $$cl; \
fi
# Useful to debug.
.c.i:
$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -o $@ -E $<
.PHONY: codespell
codespell:
$(AM_V_GEN) cd $(srcdir) \
&& codespell \
--regex "[\\w\\-'\`]+\+*" \
--ignore-words-list "ba,circularly,cloneable,copyable,define'd,dout,froms,iff,ifset,od,ois" \
$$(git ls-files data doc lib src tests)
+999 -81
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -36,7 +36,7 @@ to the bison package.
-----
Copyright (C) 2002, 2005, 2009-2015, 2018-2019 Free Software Foundation,
Copyright (C) 2002, 2005, 2009-2015, 2018-2020 Free Software Foundation,
Inc.
This file is part of Bison, the GNU Compiler Compiler.
+86 -38
View File
@@ -1,26 +1,77 @@
This package contains the GNU Bison parser generator.
GNU Bison is a general-purpose parser generator that converts an annotated
context-free grammar into a deterministic LR or generalized LR (GLR) parser
employing LALR(1) parser tables. Bison can also generate IELR(1) or
canonical LR(1) parser tables. Once you are proficient with Bison, you can
use it to develop a wide range of language parsers, from those used in
simple desk calculators to complex programming languages.
* Installation
** Build from git
Here are basic installation instructions for a repository checkout:
Bison is upward compatible with Yacc: all properly-written Yacc grammars
work with Bison with no change. Anyone familiar with Yacc should be able to
use Bison with little trouble. You need to be fluent in C, C++ or Java
programming in order to use Bison.
$ git submodules update --init
Bison and the parsers it generates are portable, they do not require any
specific compilers.
GNU Bison's home page is https://gnu.org/software/bison/.
# Installation
## Build from git
The [README-hacking.md file](README-hacking.md) is about building, modifying
and checking Bison. See its "Working from the Repository" section to build
Bison from the git repo. Roughly, run:
$ git submodule update --init
$ ./bootstrap
then proceed with the usual 'configure && make' steps.
then proceed with the usual `configure && make` steps.
README-hacking contains more information about building and modifying the
software.
## Build from tarball
See the [INSTALL file](INSTALL) for generic compilation and installation
instructions.
** Build for tarball
See the file INSTALL for generic compilation and installation instructions.
Bison requires GNU m4 1.4.6 or later. See
https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz.
Bison requires GNU m4 1.4.6 or later. See:
## Running a non installed bison
Once you ran `make`, you might want to toy with this fresh bison before
installing it. In that case, do not use `src/bison`: it would use the
*installed* files (skeletons, etc.), not the local ones. Use `tests/bison`.
https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz
## Colored diagnostics
As an experimental feature, diagnostics are now colored, controlled by the
`--color` and `--style` options.
** Relocatability
If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
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.
- never, no: Disable colors.
- auto, tty (default): Enable colors if the output device is a tty.
To customize the styles, create a CSS file, say `bison-bw.css`, similar to
/* bison-bw.css */
.warning { }
.error { font-weight: 800; text-decoration: underline; }
.note { }
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.
A relocatable program can be moved or copied to a different location on the
file system. It can also be used through mount points for network sharing.
@@ -29,7 +80,7 @@ invoke them through the symlink.
See "Enabling Relocatability" in the documentation.
** Internationalization
## Internationalization
Bison supports two catalogs: one for Bison itself (i.e., for the
maintainer-side parser generation), and one for the generated parsers (i.e.,
for the user-side parser execution). The requirements between both differ:
@@ -39,49 +90,46 @@ generated parsers could have been localized. See
http://lists.gnu.org/archive/html/bug-bison/2009-08/msg00006.html for more
details.
* Questions
# Questions
See the section FAQ in the documentation (doc/bison.info) for frequently
asked questions. The documentation is also available in PDF and HTML,
provided you have a recent version of Texinfo installed: run "make pdf" or
"make html".
provided you have a recent version of Texinfo installed: run `make pdf` or
`make html`.
If you have questions about using Bison and the documentation does not
answer them, please send mail to <[email protected]>.
* Bug reports
# Bug reports
Please send bug reports to <[email protected]>. Be sure to include the
version number from 'bison --version', and a complete, self-contained test
version number from `bison --version`, and a complete, self-contained test
case in each bug report.
* Copyright statements
# Copyright statements
For any copyright year range specified as YYYY-ZZZZ in this package, note
that the range specifies every single year in that closed interval.
-----
<!--
LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american md
LocalWords: MERCHANTABILITY GLR LALR IELR submodule init README src bw
LocalWords: Relocatability symlinks symlink
Local Variables:
mode: outline
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2019 Free
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2020 Free
Software Foundation, Inc.
This file is part of GNU 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.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
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/>.
# LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american
# LocalWords: MERCHANTABILITY
-->
+1 -1
View File
@@ -12,7 +12,7 @@ the problems you encounter.
-----
Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation,
Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation,
Inc.
This file is part of GNU Bison.
-511
View File
@@ -1,511 +0,0 @@
This file attempts to describe the rules to use when hacking Bison.
Don't put this file into the distribution.
Everything related to the development of Bison is on Savannah:
http://savannah.gnu.org/projects/bison/
* Administrivia
** If you incorporate a change from somebody on the net:
First, if it is a large change, you must make sure they have signed the
appropriate paperwork. Second, be sure to add their name and email address
to THANKS.
** If a change fixes a test, mention the test in the commit message.
** Bug reports
If somebody reports a new bug, mention his name in the commit message and in
the test case you write. Put him into THANKS.
The correct response to most actual bugs is to write a new test case which
demonstrates the bug. Then fix the bug, re-run the test suite, and check
everything in.
* Hacking
** Visible changes
Which include serious bug fixes, must be mentioned in NEWS.
** Translations
Only user visible strings are to be translated: error messages, bits of the
.output file etc. This excludes impossible error messages (comparable to
assert/abort), and all the --trace output which is meant for the maintainers
only.
** Horizontal tabs
Do not add horizontal tab characters to any file in Bison's repository
except where required. For example, do not use tabs to format C code.
However, make files, ChangeLog, and some regular expressions require tabs.
Also, test cases might need to contain tabs to check that Bison properly
processes tabs in its input.
* Working from the repository
These notes intend to help people working on the checked-out sources.
These requirements do not apply when building from a distribution tarball.
** Requirements
We've opted to keep only the highest-level sources in the repository. This
eases our maintenance burden, (fewer merges etc.), but imposes more
requirements on anyone wishing to build from the just-checked-out sources.
For example, you have to use the latest stable versions of the maintainer
tools we depend upon, including:
- Autoconf <http://www.gnu.org/software/autoconf/>
- Automake <http://www.gnu.org/software/automake/>
- Flex <http://www.gnu.org/software/flex/>
- Gettext <http://www.gnu.org/software/gettext/>
- Graphviz <http://www.graphviz.org>
- Gzip <http://www.gnu.org/software/gzip/>
- Help2man <http://www.gnu.org/software/help2man/>
- Perl <http://www.cpan.org/>
- Rsync <http://samba.anu.edu.au/rsync/>
- Tar <http://www.gnu.org/software/tar/>
- Texinfo <http://www.gnu.org/software/texinfo/>
Valgrind <http://valgrind.org/> is also highly recommended, if it supports
your architecture.
If you're using a GNU/Linux distribution, the easiest way to install the
above packages depends on your system. The following shell command should
work for Debian-based systems such as Ubuntu:
sudo apt-get install \
autoconf automake autopoint flex graphviz help2man texinfo valgrind
Bison is written using Bison grammars, so there are bootstrapping issues.
The bootstrap script attempts to discover when the C code generated from the
grammars is out of date, and to bootstrap with an out-of-date version of the
C code, but the process is not foolproof. Also, you may run into similar
problems yourself if you modify Bison.
Only building the initial full source tree will be a bit painful. Later,
after synchronizing from the repository a plain 'make' should be sufficient.
Note, however, that when gnulib is updated, running './bootstrap' again
might be needed.
** First checkout
Obviously, if you are reading these notes, you did manage to check out this
package from the repository. For the record, you will find all the relevant
information on:
http://savannah.gnu.org/git/?group=bison
Bison uses Git submodules: subscriptions to other Git repositories. In
particular it uses gnulib, the GNU portability library. To ask Git to
perform the first checkout of the submodules, run
$ git submodule update --init
The next step is to get other files needed to build, which are extracted
from other source packages:
$ ./bootstrap
Bootstrapping updates the submodules to the versions registered in the
top-level directory. To change gnulib, first check out the version you want
in `gnulib`, then commit this change in Bison's repository, and finally run
bootstrap.
If it fails with missing symbols (e.g., "error: possibly undefined macro:
AC_PROG_GNU_M4"), you are likely to have forgotten the submodule
initialization part. To recover from it, run `git reset --hard HEAD`, and
restart with the submodule initialization. Otherwise, there you are! Just
$ ./configure
$ make
$ make check
At this point, there should be no difference between your local copy, and
the master copy:
$ git diff
should output no difference.
Enjoy!
** Updating
If you have git at version 1.8.2 or later, the command
$ git submodule update --recursive --remote
will be useful for updating to the latest version of all submodules.
Under earlier versions, use of submodules make things somewhat different
because git does not yet support recursive operations: submodules must be
taken care of explicitly.
*** Updating Bison
If you pull a newer version of a branch, say via "git pull", you might
import requests for updated submodules. A simple "git diff" will reveal if
the current version of the submodule (i.e., the actual contents of the
gnulib directory) and the current request from the subscriber (i.e., the
reference of the version of gnulib that the Bison repository requests)
differ. To upgrade the submodules (i.e., to check out the version that is
actually requested by the subscriber, run "git submodule update".
$ git pull
$ git submodule update
*** Updating a submodule
To update a submodule, say gnulib, do as follows:
Get the most recent version of the master branch from git.
$ cd gnulib
$ git fetch
$ git checkout -b master --track origin/master
Make sure Bison can live with that version of gnulib.
$ cd ..
$ ./bootstrap
$ make distcheck
Register your changes.
$ git checkin ...
For a suggestion of what gnulib commit might be stable enough for a formal
release, see the ChangeLog in the latest gnulib snapshot at:
http://erislabs.net/ianb/projects/gnulib/
The Autoconf files we use are currently:
m4/m4.m4
lib/m4sugar/m4sugar.m4
lib/m4sugar/foreach.m4
These files don't change very often in Autoconf, so it should be relatively
straight-forward to examine the differences in order to decide whether to
update.
* Test suite
** make check
Use liberally.
** Updating the expectations
Sometimes some changes have a large impact on the test suite (e.g., when we
added the "[-Wother]" part to all the warnings). Part of the update can be
done with a crude tool: tests/update-test. Read it for more information.
** TESTSUITEFLAGS
To run just the testsuite (not the tests related to the examples), run `make
check-local`.
The default is for make check-local to run all tests sequentially. This can
be very time consuming when checking repeatedly or on slower setups. This
can be sped up in two ways:
Using -j, in a make-like fashion, for example:
$ make check-local TESTSUITEFLAGS='-j8'
Running only the tests of a certain category, as specified in the AT files
with AT_KEYWORDS([[category]]). Categories include:
- c++, for c++ parsers
- deprec, for tests concerning deprecated constructs.
- glr, for glr parsers
- java, for java parsers
- report, for automaton dumps
To run a specific set of tests, use -k (for "keyword"). For example:
$ make check-local TESTSUITEFLAGS='-k c++'
Both can be combined.
** Typical errors
If the test suite shows failures such as the following one
.../bison/lib/getopt.h:196:8: error: redefinition of 'struct option'
/usr/include/getopt.h:54:8: error: previous definition of 'struct option'
it probably means that some file was compiled without
AT_DATA_SOURCE_PROLOGUE. This error is due to the fact that our -I options
pick up gnulib's replacement headers, such as getopt.h, and this will go
wrong if config.h was not included first.
See tests/local.at for details.
** make maintainer-check-valgrind
This target uses valgrind both to check bison, and the generated parsers.
This is not mature on Mac OS X. First, Valgrind does support the way bison
calls m4, so Valgrind cannot be used to check bison on Mac OS X.
Second, there are many errors that come from the platform itself, not from
bison. build-aux/darwin11.4.0.valgrind addresses some of them.
Third, valgrind issues warnings such as:
--99312:0:syswrap- WARNING: Ignoring sigreturn( ..., UC_RESET_ALT_STACK );
which cause the test to fail uselessly. It is hard to ignore these errors
with a major overhaul of the way instrumentation is performed in the test
suite. So currently, do not try to run valgrind on Mac OS X.
** Release checks
Try to run the test suite with more severe conditions before a
release:
- Configure the package with --enable-gcc-warnings, so that one checks that
1. Bison compiles cleanly, 2. the parsers it produces compile cleanly too.
- Maybe build with -DGNULIB_POSIXCHECK, which suggests gnulib modules that
can fix portability issues. See if you really want to pay attention to
its warnings; there's no need to obey blindly to it
(<http://lists.gnu.org/archive/html/bison-patches/2012-05/msg00057.html>).
- Check with "make syntax-check" if there are issues diagnosed by gnulib.
- run "make maintainer-check" which:
- runs "valgrind -q bison" to run Bison under Valgrind.
- runs the parsers under Valgrind.
- runs the test suite with G++ as C compiler...
- run "make maintainer-check-push", which runs "make maintainer-check" while
activating the push implementation and its pull interface wrappers in many
test cases that were originally written to exercise only the pull
implementation. This makes certain the push implementation can perform
every task the pull implementation can.
- run "make maintainer-check-xml", which runs "make maintainer-check" while
checking Bison's XML automaton report for every working grammar passed to
Bison in the test suite. The check just diffs the output of Bison's
included XSLT style sheets with the output of --report=all and --graph.
- running "make maintainer-check-release" takes care of running
maintainer-check, maintainer-check-push and maintainer-check-xml.
- Change tests/atlocal/CFLAGS to add your preferred options.
- Test with a very recent version of GCC for both C and C++. Testing with
older versions that are still in use is nice too.
** gnulib
To run tests on gnulib components (e.g., on bitset):
cd gnulib
./gnulib-tool --test bitset-tests
possibly within a specified environment:
CC='gcc-mp-8 -fsanitize=undefined' ./gnulib-tool --test bitset-tests
To be able to run the tests several times, and to use symlinks instead of
copies so that one can update the origin gnulib directory and immediately
re-run the tests, run:
./gnulib-tool --symlink --create-test --dir=/tmp/gnutest bitset-tests
cd /tmp/gnutest
./configure CC='gcc-mp-8 -fsanitize=undefined'
make check
* Release Procedure
This section needs to be updated to take into account features from gnulib.
In particular, be sure to read README-release.
** Update the submodules. See above.
** Update maintainer tools, such as Autoconf. See above.
** Try to get the *.pot files to the Translation Project at least one
week before a stable release, to give them time to translate them. Before
generating the *.pot files, make sure that po/POTFILES.in and
runtime-po/POTFILES.in list all files with translatable strings. This
helps: grep -l '\<_(' *.
** Tests
See above.
** Update the foreign files
Running "./bootstrap" in the top level should update them all for you. This
covers PO files too. Sometimes a PO file contains problems that causes it
to be rejected by recent Gettext releases; please report these to the
Translation Project.
** Update README
Make sure the information in README is current. Most notably, make sure it
recommends a version of GNU M4 that is compatible with the latest Bison
sources.
** Check copyright years.
We update years in copyright statements throughout Bison once at the start
of every year by running "make update-copyright". However, before a
release, it's good to verify that it's actually been run. Besides the
copyright statement for each Bison file, check the copyright statements that
the skeletons insert into generated parsers, and check all occurrences of
PACKAGE_COPYRIGHT_YEAR in configure.ac.
** Update NEWS, commit and tag.
See do-release-commit-and-tag in README-release. For a while, we used beta
names such as "2.6_rc1". Now that we use gnulib in the release procedure,
we must use "2.5.90", which has the additional benefit of being properly
sorted in "git tag -l".
** make alpha, beta, or stable
See README-release.
** Upload
There are two ways to upload the tarballs to the GNU servers: using gnupload
(from gnulib), or by hand. Obviously prefer the former. But in either
case, be sure to read the following paragraph.
*** Setup
You need "gnupg".
Make sure your public key has been uploaded at least to keys.gnupg.net. You
can upload it with:
gpg --keyserver keys.gnupg.net --send-keys F125BDF3
where F125BDF3 should be replaced with your key ID.
*** Using gnupload
You need "ncftp".
At the end "make stable" (or alpha/beta) will display the procedure to run.
Just copy and paste it in your shell.
*** By hand
The generic GNU upload procedure is at:
http://www.gnu.org/prep/maintain/maintain.html#Automated-FTP-Uploads
Follow the instructions there to register your information so you're permitted
to upload.
Here's a brief reminder of how to roll the tarballs and upload them:
*** make distcheck
*** gpg -b bison-2.3b.tar.gz
*** In a file named "bison-2.3b.tar.gz.directive", type:
version: 1.1
directory: bison
filename: bison-2.3b.tar.gz
*** gpg --clearsign bison-2.3b.tar.gz.directive
*** ftp ftp-upload.gnu.org # Log in as anonymous.
*** cd /incoming/alpha # cd /incoming/ftp for full release.
*** put bison-2.3b.tar.gz # This can take a while.
*** put bison-2.3b.tar.gz.sig
*** put bison-2.3b.tar.gz.directive.asc
*** Repeat all these steps for bison-2.3b.tar.xz.
** Update Bison manual on www.gnu.org.
The instructions below are obsolete, and left in case one would like to run
the commands by hand. Today, one just needs to run
$ make web-manual-update
See README-release.
*** You need a non-anonymous checkout of the web pages directory.
$ cvs -d [email protected]:/web/bison checkout bison
*** Get familiar with the instructions for web page maintainers.
http://www.gnu.org/server/standards/readme_index.html
http://www.gnu.org/server/standards/README.software.html
especially the note about symlinks.
*** Build the web pages.
Assuming BISON_CHECKOUT refers to a checkout of the Bison dir, and
BISON_WWW_CHECKOUT refers to the web directory created above, do:
$ cd $BISON_CHECKOUT/doc
$ make stamp-vti
$ ../build-aux/gendocs.sh -o "$BISON_WWW_CHECKOUT/manual" \
bison "Bison - GNU parser generator"
$ cd $BISON_WWW_CHECKOUT
Verify that the result looks sane.
*** Commit the modified and the new files.
*** Remove old files.
Find the files which have not been overwritten (because they belonged to
sections that have been removed or renamed):
$ cd manual/html_node
$ ls -lt
Remove these files and commit their removal to CVS. For each of these
files, add a line to the file .symlinks. This will ensure that hyperlinks
to the removed files will redirect to the entire manual; this is better than
a 404 error.
** Announce
The "make release" command just created a template,
$HOME/announce-bison-X.Y. Otherwise, to generate it, run:
make RELEASE_TYPE=alpha gpg_key_ID=F125BDF3 announcement
where alpha can be replaced by beta or stable and F125BDF3 should be
replaced with your key ID.
Complete/fix the announcement file. The generated list of recipients
([email protected], [email protected], [email protected],
[email protected], and [email protected]) is
appropriate for a stable release or a "serious beta". For any other
release, drop at least [email protected]. For an example of how to fill out
the rest of the template, search the mailing list archives for the most
recent release announcement.
For a stable release, send the same announcement on the comp.compilers
newsgroup by sending email to [email protected]. Do not make any Cc as the
moderator will throw away anything cross-posted or Cc'ed. It really needs
to be a separate message.
** Prepare NEWS
So that developers don't accidentally add new items to the old NEWS entry,
create a new empty entry in line 3 (without the two leading spaces):
* Noteworthy changes in release ?.? (????-??-??) [?]
Push these changes.
-----
Copyright (C) 2002-2005, 2007-2015, 2018-2019 Free Software Foundation,
Inc.
This file is part of GNU Bison.
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/>.
LocalWords: Automake Autoconf Gettext Gzip Rsync Valgrind gnulib submodules
LocalWords: submodule init cd distcheck checkin ChangeLog valgrind sigreturn
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
LocalWords: symlinks vti html lt POSIX Cc'ed
Local Variables:
mode: outline
fill-column: 76
End:
+610
View File
@@ -0,0 +1,610 @@
This file attempts to describe the rules to use when hacking Bison.
Don't put this file into the distribution.
Everything related to the development of Bison is on Savannah:
http://savannah.gnu.org/projects/bison/.
Working from the Repository
===========================
These notes intend to help people working on the checked-out sources. These
requirements do not apply when building from a distribution tarball.
## Requirements
We've opted to keep only the highest-level sources in the repository. This
eases our maintenance burden, (fewer merges etc.), but imposes more
requirements on anyone wishing to build from the just-checked-out sources.
For example, you have to use the latest stable versions of the maintainer
tools we depend upon, including:
- Autoconf <http://www.gnu.org/software/autoconf/>
- Automake <http://www.gnu.org/software/automake/>
- Flex <http://www.gnu.org/software/flex/>
- Gettext <http://www.gnu.org/software/gettext/>
- Gperf <http://www.gnu.org/software/gperf/>
- Graphviz <http://www.graphviz.org>
- Gzip <http://www.gnu.org/software/gzip/>
- Help2man <http://www.gnu.org/software/help2man/>
- Perl <http://www.cpan.org/>
- Rsync <http://samba.anu.edu.au/rsync/>
- Tar <http://www.gnu.org/software/tar/>
- Texinfo <http://www.gnu.org/software/texinfo/>
Valgrind <http://valgrind.org/> is also highly recommended, if it supports
your architecture.
If you're using a GNU/Linux distribution, the easiest way to install the
above packages depends on your system. The following shell command should
work for Debian-based systems such as Ubuntu:
sudo apt-get install \
autoconf automake autopoint flex gperf graphviz help2man texinfo valgrind
Bison is written using Bison grammars, so there are bootstrapping issues.
The bootstrap script attempts to discover when the C code generated from the
grammars is out of date, and to bootstrap with an out-of-date version of the
C code, but the process is not foolproof. Also, you may run into similar
problems yourself if you modify Bison.
Only building the initial full source tree will be a bit painful. Later,
after synchronizing from the repository a plain 'make' should be sufficient.
Note, however, that when gnulib is updated, running './bootstrap' again
might be needed.
## First checkout
Obviously, if you are reading these notes, you did manage to check out this
package from the repository. For the record, you will find all the relevant
information on http://savannah.gnu.org/git/?group=bison.
Bison uses Git submodules: subscriptions to other Git repositories. In
particular it uses gnulib, the GNU portability library. To ask Git to
perform the first checkout of the submodules, run
$ git submodule update --init
The next step is to get other files needed to build, which are extracted
from other source packages:
$ ./bootstrap
Bootstrapping updates the submodules to the versions registered in the
top-level directory. To change gnulib, first check out the version you want
in `gnulib`, then commit this change in Bison's repository, and finally run
bootstrap.
If it fails with missing symbols (e.g., `error: possibly undefined macro:
AC_PROG_GNU_M4`), you are likely to have forgotten the submodule
initialization part. To recover from it, run `git reset --hard HEAD`, and
restart with the submodule initialization. Otherwise, there you are! Just
$ ./configure
$ make
$ make check
At this point, there should be no difference between your local copy, and
the master copy:
$ git diff
should output no difference.
Enjoy!
## Updating
If you have git at version 1.8.2 or later, the command
$ git submodule update --recursive --remote
will be useful for updating to the latest version of all submodules.
Under earlier versions, use of submodules make things somewhat different
because git does not yet support recursive operations: submodules must be
taken care of explicitly.
### Updating Bison
If you pull a newer version of a branch, say via `git pull`, you might
import requests for updated submodules. A simple `git diff` will reveal if
the current version of the submodule (i.e., the actual contents of the
gnulib directory) and the current request from the subscriber (i.e., the
reference of the version of gnulib that the Bison repository requests)
differ. To upgrade the submodules (i.e., to check out the version that is
actually requested by the subscriber, run `git submodule update`.
$ git pull
$ git submodule update
### Updating a submodule
To update a submodule, say gnulib, do as follows:
Get the most recent version of the master branch from git.
$ cd gnulib
$ git fetch
$ git checkout -b master --track origin/master
Make sure Bison can live with that version of gnulib.
$ cd ..
$ ./bootstrap
$ make distcheck
Register your changes.
$ git commit ...
For a suggestion of what gnulib commit might be stable enough for a formal
release, see the ChangeLog in the latest gnulib snapshot at
http://erislabs.net/ianb/projects/gnulib/.
The Autoconf files we use are currently:
- m4/m4.m4
- lib/m4sugar/m4sugar.m4
- lib/m4sugar/foreach.m4
These files don't change very often in Autoconf, so it should be relatively
straight-forward to examine the differences in order to decide whether to
update.
## Troubleshooting
Bison is self-hosted: its parser is generated by Bison. We don't force
ourselves to use the previous release of Bison, we use the current git
master for several reasons:
- dogfooding: let Bison be its first user
- monitoring: seeing the diff on the generated parsers with git is very
helpful, as it allows to see easily the impact of the changes on a real
case parser.
If you are unlucky the generated files, src/parse-gram.[ch], may be older
than their source, src/parse-gram.y. And your current version of Bison
might not be able to grok it. In that case, first refresh the generated
files:
$ touch src/parse-gram.[ch]
Then proceed.
In case you wrecked your current copy of the parser, get back the previous
version, compile bison, then force it to recreate the files:
$ git checkout HEAD^ src/parse-gram.[ch]
$ make -C _build
$ touch src/parse-gram.y
$ make -C _build
Administrivia
=============
## If you incorporate a change from somebody on the net:
First, if it is a large change, you must make sure they have signed the
appropriate paperwork. Second, be sure to add their name and email address
to THANKS.
## If a change fixes a test, mention the test in the commit message.
## Bug reports
If somebody reports a new bug, mention his name in the commit message and in
the test case you write. Put him into THANKS.
The correct response to most actual bugs is to write a new test case which
demonstrates the bug. Then fix the bug, re-run the test suite, and check
everything in.
Hacking
=======
## Visible Changes
Which include serious bug fixes, must be mentioned in NEWS.
## Translations
Only user visible strings are to be translated: error messages, bits of the
.output file etc. This excludes impossible error messages (comparable to
assert/abort), and all the --trace output which is meant for the maintainers
only.
## Vocabulary
- "lookahead", not "look-ahead".
- "midrule", not "mid-rule".
- "nonterminal", not "variable" or "non-terminal" or "non terminal".
Abbreviated as "nterm".
- "shift/reduce" and "reduce/reduce", not "shift-reduce" or "shift reduce",
etc.
## Syntax Highlighting
It's quite nice to be in C++ mode when editing lalr1.cc for instance.
However tools such as Emacs will be fooled by the fact that braces and
parens do not nest, as in `[[}]]`. As a consequence you might be misguided
by its visual pairing to parens. The m4-mode is safer. Unfortunately the
m4-mode is also fooled by `#` which is sees as a comment, stops pairing with
parens/brackets that are inside...
## Implementation Notes
There are several places with interesting details about the implementation:
- [Understanding C parsers generated by GNU
Bison](https://www.cs.uic.edu/~spopuri/cparser.html) by Satya Kiran Popuri,
is a wonderful piece of work that explains the implementation of Bison,
- [src/gram.h](src/gram.h) documents the way the grammar is represented
- [src/tables.h](src/tables.h) documents the generated tables
- [data/README.md](data/README.md) contains details about the m4 implementation
## Coding Style
Do not add horizontal tab characters to any file in Bison's repository
except where required. For example, do not use tabs to format C code.
However, make files, ChangeLog, and some regular expressions require tabs.
Also, test cases might need to contain tabs to check that Bison properly
processes tabs in its input.
Prefer `res` as the name of the local variable that will be "return"ed by
the function.
In writing arithmetic comparisons, use "<" and "<=" rather than ">" and ">="
(http://www.gelato.unsw.edu.au/archives/git/0505/4507.html).
### Bison
Follow the GNU Coding Standards.
Don't reinvent the wheel: we use gnulib, which features many components.
Actually, Bison has legacy code that we should replace with gnulib modules
(e.g., many ad hoc implementations of lists).
#### Includes
The `#include` directives follow an order:
- first section for *.c files is `<config.h>`. Don't include it in header
files
- then, for *.c files, the corresponding *.h file
- then possibly the `"system.h"` header
- then the system headers.
Consider headers from `lib/` like system headers (i.e., `#include
<verify.h>`, not `#include "verify.h"`).
- then headers from src/ with double quotes (`#include "getargs.h"`).
Keep headers sorted alphabetically in each section.
See also the [Header
files](https://www.gnu.org/software/gnulib/manual/html_node/Header-files.html)
and the [Implementation
files](https://www.gnu.org/software/gnulib/manual/html_node/Implementation-files.html#Implementation-files)
nodes of the gnulib documentation.
Some source files are in the build tree (e.g., `src/scan-gram.c` made from
`src/scan-gram.l`). For them to find the headers from `src/`, we actually
use `#include "src/getargs.h"` instead of `#include "getargs.h"`---that
saves us from additional `-I` flags.
### Skeletons
We try to use the "typical" coding style for each language.
#### CPP
We indent the CPP directives this way:
```
#if FOO
# if BAR
# define BAZ
# endif
#endif
```
Don't indent with leading spaces in the skeletons (it's OK in the grammar
files though, e.g., in `%code {...}` blocks).
On occasions, use `cppi -c` to see where we stand. We don't aim at full
correctness: depending `-d`, some bits can be in the *.c file, or the *.h
file within the double-inclusion cpp-guards. In that case, favor the case
of the *.h file, but don't waste time on this.
Don't hesitate to leave a comment on the `#endif` (e.g., `#endif /* FOO
*/`), especially for long blocks.
There is no consistency on `! defined` vs. `!defined`. The day gnulib
decides, we'll follow them.
#### C/C++
Follow the GNU Coding Standards.
The `glr.c` skeleton was implemented with `camlCase`. We are migrating it
to `snake_case`. Because we are gradually standardizing the code, it is
currently inconsistent.
Use `YYFOO` and `yyfoo` for entities that are exposed to the user. They are
part of our contract with the users wrt backward compatibility.
Use `YY_FOO` and `yy_foo` for private matters. Users should not use them,
we are free to change them without fear of backward compatibility issues.
Use `*_t` for types, especially for `yy*_t` in which case we shouldn't worry
about the C standard introducing such a name.
#### C++
Follow the [C++ Core
Guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
The [Google ones](https://google.github.io/styleguide/cppguide.html) may be
interesting too.
Our enumerators, such as the kinds (symbol and token kinds), should be lower
case, but it was too late to follow that track for token kinds, and symbol
kind enumerators are made to be consistent with them.
Use `*_type` for type aliases. Use `foo_get()` and `foo_set(v)` for
accessors, or simply `foo()` and `foo(v)`.
Use the `yy` prefix for private stuff, but there's no need for it in the
public API. The `yy` prefix is already taken care of via the namespace.
#### Java
We follow the [Java Code
Conventions](https://www.oracle.com/technetwork/java/codeconventions-150003.pdf)
and [Google Java Style
Guide](https://google.github.io/styleguide/javaguide.html). Unfortunately
at some point some GNU Coding Style was installed in Java, but it's an
error. So we should for instance stop putting spaces in function calls.
Because we are standardizing the code, it is currently inconsistent.
Use a 2-space indentation (Google) rather than 4 (Oracle).
Don't use the "yy" prefix for public members: "getExpectedTokens", not
"yyexpectedTokens" or "yygetExpectedTokens".
## Commit Messages
Imitate the style we use. Use `git log` to get sources of inspiration.
If the changes have a small impact on Bison's generated parser, embed these
changes in the commit itself. If the impact is large, first push all the
changes except those about src/parse-gram.[ch], and then another commit
named "regen" which is only about them.
## Debugging
Bison supports tracing of its various steps, via the `--trace` option.
Since it is not meant for the end user, it is not displayed by `bison
--help`, nor is it documented in the manual. Instead, run `bison
--trace=help`.
## Documentation
Use `@option` for options and options with their argument if they have no
space (e.g., `@option{-Dfoo=bar}`). However, use `@samp` elsewhere (e.g.,
`@samp{-I foo}`).
Test Suite
==========
## make check
Consume without moderation. It is composed of two kinds of tests: the
examples, and the main test suite.
### The Examples
In examples/, there is a number of ready-to-use examples (see
[examples/README.md](examples/README.md)). These examples have small test
suites run by `make check`. The test results are in local `*.log` files
(e.g., `$build/examples/c/calc/calc.log`).
### The Main Test Suite
The main test suite, in tests/, is written on top of GNU Autotest, which is
part of Autoconf. Run `info autoconf 'Using Autotest'` to read the
documentation, not only about how to write tests, but also where are the
logs, how to read them etc.
The main test suite generates a log for each test (e.g.,
`$build/tests/testsuite.dir/004/testsuite.log` for test #4), and a main log
file in `$build/tests/testsuite.log`. The latter is meant for end users: it
contains lots of details that should help diagnosing issues, including build
issues. The per-test logs are more convenient when working locally.
#### TESTSUITEFLAGS
To run just the main test suite, run `make check-local`.
The default is for make check-local to run all tests sequentially. This can
be very time consuming when checking repeatedly or on slower setups. This
can be sped up in two ways:
Using -j, in a make-like fashion, for example:
$ make check-local TESTSUITEFLAGS='-j8'
Actually, when using GNU Make, TESTSUITEFLAGS defaults to the -jN passed to
it, so you may simply run
$ make check-local -j8
Running only the tests of a certain category, as specified in the AT files
with AT_KEYWORDS([[category]]). Categories include:
- c++, for c++ parsers
- deprec, for tests concerning deprecated constructs.
- glr, for glr parsers
- java, for java parsers
- report, for automaton dumps
To get a list of all the tests (and their keywords for -k), run
$ ./tests/testsuite -l
To run a specific set of tests, use -k (for "keyword"). For example:
$ make check-local TESTSUITEFLAGS='-k c++'
Both can be combined.
$ make check-local TESTSUITEFLAGS='-j8 -k c++'
To rerun the tests that failed:
$ make recheck -j5
#### Updating the Expectations
Sometimes some changes have a large impact on the test suite (e.g., when we
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 `make update-tests`. Or, by hand, from the *source* tree:
$ ./build-aux/update-test $build/tests/testsuite.dir/*/testsuite.log
where `$build` would be your build tree. This will hopefully update most
tests. Re-run the test suite. It might be interesting to run `update-test`
again, since some early failures may stop latter tests from being run. Yet
at some point, you'll have to fix remaining issues by hand...
## Running Java parsers
Use the `javaexec.sh` script. For instance to run the parser of test case
504:
$ sh ./_build/javaexec.sh -cp ./_build/tests/testsuite.dir/504 Calc
## Using Sanitizers
Address sanitizer (ASAN) and undefined-behavior sanitizer (UBSAN) are very
useful. Here's one way to set ASAN up with GCC 10 on Mac Ports
1. Configure with
$ ./configure -C --enable-gcc-warnings \
CPPFLAGS='-isystem /opt/local/include' \
CC='gcc-mp-10 -fsanitize=address' \
CFLAGS='-ggdb' \
CXX='g++-mp-10.0 -fsanitize=address' \
CXXFLAGS='-ggdb' \
LDFLAGS='-L/opt/local/lib'
2. Compile
3. Generate debug symbols:
$ dsymutil src/bison
4. Run the tests with leak detection enabled
(`ASAN_OPTIONS=detect_leaks=1`). E.g. for counterexamples:
$ make check-local TESTSUITEFLAGS='-j5 -k cex' ASAN_OPTIONS=detect_leaks=1
## make maintainer-check-valgrind
This target uses valgrind both to check bison, and the generated parsers.
This is not mature on Mac OS X. First, Valgrind does support the way bison
calls m4, so Valgrind cannot be used to check bison on Mac OS X.
Second, there are many errors that come from the platform itself, not from
bison. build-aux/darwin11.4.0.valgrind addresses some of them.
Third, valgrind issues warnings such as:
--99312:0:syswrap- WARNING: Ignoring sigreturn( ..., UC_RESET_ALT_STACK );
which cause the test to fail uselessly. It is hard to ignore these errors
with a major overhaul of the way instrumentation is performed in the test
suite. So currently, do not try to run valgrind on Mac OS X.
## Release checks
Try to run the test suite with more severe conditions before a
release:
- Configure the package with --enable-gcc-warnings, so that one checks that
1. Bison compiles cleanly, 2. the parsers it produces compile cleanly too.
- Maybe build with -DGNULIB_POSIXCHECK, which suggests gnulib modules that
can fix portability issues. See if you really want to pay attention to
its warnings; there's no need to obey blindly to it
(<http://lists.gnu.org/archive/html/bison-patches/2012-05/msg00057.html>).
- Check with `make syntax-check` if there are issues diagnosed by gnulib.
- run `make maintainer-check` which:
- runs `valgrind -q bison` to run Bison under Valgrind.
- runs the parsers under Valgrind.
- runs the test suite with G++ as C compiler...
- run `make maintainer-check-push`, which runs `make maintainer-check` while
activating the push implementation and its pull interface wrappers in many
test cases that were originally written to exercise only the pull
implementation. This makes certain the push implementation can perform
every task the pull implementation can.
- run `make maintainer-check-xml`, which runs `make maintainer-check` while
checking Bison's XML automaton report for every working grammar passed to
Bison in the test suite. The check just diffs the output of Bison's
included XSLT style sheets with the output of --report=all and --graph.
- running `make maintainer-check-release` takes care of running
maintainer-check, maintainer-check-push and maintainer-check-xml.
- Change tests/atlocal/CFLAGS to add your preferred options.
- Test with a very recent version of GCC for both C and C++. Testing with
older versions that are still in use is nice too.
## gnulib
To run tests on gnulib components (e.g., on bitset):
cd gnulib
./gnulib-tool --test bitset-tests
possibly within a specified environment:
CC='gcc-mp-8 -fsanitize=undefined' ./gnulib-tool --test bitset-tests
To be able to run the tests several times, and to use symlinks instead of
copies so that one can update the origin gnulib directory and immediately
re-run the tests, run:
./gnulib-tool --symlink --create-test --dir=/tmp/gnutest bitset-tests
cd /tmp/gnutest
./configure -C CC='gcc-mp-8 -fsanitize=undefined' CFLAGS='-ggdb'
make check
Release Procedure
=================
See the [README-release file](README-release), created when the package is
bootstrapped.
<!--
Copyright (C) 2002-2005, 2007-2015, 2018-2020 Free Software Foundation,
Inc.
This file is part of GNU Bison.
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/>.
Local Variables:
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
LocalWords: Automake Autoconf Gettext Gzip Rsync Valgrind gnulib submodules
LocalWords: submodule init cd distcheck ChangeLog valgrind sigreturn sudo
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
LocalWords: symlinks vti html lt POSIX Cc'ed Graphviz Texinfo autoconf jN
LocalWords: automake autopoint graphviz texinfo PROG Wother parsers YYFOO
LocalWords: TESTSUITEFLAGS deprec struct gnulib's getopt config ggdb yyfoo
LocalWords: bitset fsanitize symlink CFLAGS MERCHANTABILITY ispell wrt YY
LocalWords: american Administrivia camlCase yy accessors namespace src hoc
LocalWords: getExpectedTokens yyexpectedTokens yygetExpectedTokens parens
LocalWords: regen dogfooding Autotest testsuite getargs CPP BAZ endif cppi
LocalWords: cpp javaexec cp Calc ASAN UBSAN CPPFLAGS isystem CXX cex Gperf
LocalWords: CXXFLAGS LDFLAGS dsymutil gperf
-->
Symlink
+1
View File
@@ -0,0 +1 @@
README
+31 -3
View File
@@ -4,12 +4,15 @@ it is today without the invaluable help of these people:
Aaro Koskinen [email protected]
Аскар Сафин [email protected]
Adam Sampson [email protected]
Adrian Vogelsgesang [email protected]
Ahcheong Lee [email protected]
Airy Andre [email protected]
Akim Demaille akim@lrde.epita.fr
Akim Demaille akim@gnu.org
Albert Chin-A-Young [email protected]
Alexander Belopolsky [email protected]
Alexandre Duret-Lutz [email protected]
Andre da Costa Barros [email protected]
Andreas Damm [email protected]
Andreas Schwab [email protected]
Andrew Suffield [email protected]
Angelo Borsotti [email protected]
@@ -17,6 +20,7 @@ Anthony Heading [email protected]
Antonio Silva Correia [email protected]
Arnold Robbins [email protected]
Art Haas [email protected]
Arthur Schwarz [email protected]
Askar Safin [email protected]
Balázs Scheidler [email protected]
Baron Schwartz [email protected]
@@ -41,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]
@@ -54,11 +59,15 @@ Derek M. Jones [email protected]
Di-an Jan [email protected]
Dick Streefland [email protected]
Didier Godefroy [email protected]
Don Macpherson [email protected]
Dwight Guth [email protected]
Efi Fogel [email protected]
Enrico Scholz [email protected]
Eric Blake [email protected]
Eric S. Raymond [email protected]
Étienne Renault [email protected]
Evan Lavelle [email protected]
Evan Nemerson [email protected]
Evgeny Stambulchik [email protected]
Fabrice Bauzac [email protected]
Ferdinand Thiessen [email protected]
@@ -76,8 +85,10 @@ Guido Trentalancia [email protected]
H. Merijn Brand [email protected]
Hans Åberg [email protected]
Horst Von Brand [email protected]
Jacob L. Mandelson [email protected]
Jan Nieuwenhuizen [email protected]
Jannick [email protected]
Jeff Hammond [email protected]
Jerry Quinn [email protected]
Jesse Thilo [email protected]
Jim Kent [email protected]
@@ -94,12 +105,18 @@ Kees Zeelenberg [email protected]
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]
Marc Schönefeld [email protected]
Mark Boyall [email protected]
Martin Blais [email protected]
Martin Jacobs [email protected]
Martin Mokrejs [email protected]
Martin Nylin [email protected]
@@ -124,6 +141,7 @@ Nick Bowler [email protected]
Nicolas Bedon [email protected]
Nicolas Burrus [email protected]
Nicolas Tisserand [email protected]
Nikki Valen [email protected]
Noah Friedman [email protected]
Odd Arild Olsen [email protected]
Oleg Smolsky [email protected]
@@ -144,11 +162,13 @@ Petr Machata [email protected]
Pho [email protected]
Piotr Gackiewicz [email protected]
Piotr Marcińczyk [email protected]
Pramod Kumbhar [email protected]
Quentin Hocquet [email protected]
Quoc Peyrot [email protected]
R Blake [email protected]
Raja R Harinath [email protected]
Ralf Wildenhues [email protected]
Ryan [email protected]
Rich Wilson [email protected]
Richard Stallman [email protected]
Rici Lake [email protected]
@@ -167,21 +187,25 @@ 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]
Thomas Jahns [email protected]
Thomas Petazzoni [email protected]
Tim Josling [email protected]
Tim Landscheidt [email protected]
Tim Van Holder [email protected]
Tobias Frost [email protected]
Todd Freed [email protected]
Tom Kramer [email protected]
Tom Lane [email protected]
Tom Tromey [email protected]
Tomasz Kłoczko [email protected]
Tommy Nordgren [email protected]
Troy A. Johnson [email protected]
Tys Lefering [email protected]
Uxio Prego uxio[email protected]
Uxio Prego uxio@uma.es
Valentin Tolmer [email protected]
wcventure [email protected]
Victor Khomenko [email protected]
@@ -196,8 +220,12 @@ Wolfgang Thaller [email protected]
Wolfram Wagner [email protected]
Wwp [email protected]
xolodho [email protected]
Yuichiro Kaneko [email protected]
Yuriy Solodkyy [email protected]
Zack Weinberg [email protected]
江 祖铭 [email protected]
長田偉伸 [email protected]
马俊 [email protected]
Many people are not named here because we lost track of them. We
thank them! Please, help us keeping this list up to date.
@@ -209,7 +237,7 @@ End:
-----
Copyright (C) 2000-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Parser Generator.
+557 -195
View File
@@ -1,82 +1,167 @@
* Bison 3.4
** bad diagnostics
%token <val> NUM
%type <val> expr term fact
* 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?
res: expr { printf ("%d\n", $1); };
expr: expr '+' term { $$ = $1 + $3; } | term;
term: NUM | { $$ = 0; };
** Cex
*** Improve gnulib
Don't do this (counterexample.c):
The second warning about fact is... useless.
// This is the fastest way to get the tail node from the gl_list API.
gl_list_node_t
list_get_end (gl_list_t list)
{
gl_list_node_t sentinel = gl_list_add_last (list, NULL);
gl_list_node_t res = gl_list_previous_node (list, sentinel);
gl_list_remove_node (list, sentinel);
return res;
}
$ bison /tmp/bar.y
/tmp/bar.y:2.24-27: warning: symbol fact is used, but is not defined as a token and has no rules [-Wother]
%type <val> expr term fact
^~~~
/tmp/bar.y: warning: 1 nonterminal useless in grammar [-Wother]
/tmp/bar.y:2.24-27: warning: nonterminal useless in grammar: fact [-Wother]
%type <val> expr term fact
^~~~
*** Ambiguous rewriting
If the user is stupid enough to have equal rules, then the derivations are
harder to read:
Reduce/reduce conflict on tokens $end, "+", "⊕":
2 exp: exp "+" exp .
3 exp: exp "+" exp .
Example exp "+" exp •
First derivation exp ::=[ exp "+" exp • ]
Example exp "+" exp •
Second derivation exp ::=[ exp "+" exp • ]
Do we care about this? In color, we use twice the same color here, but we
could try to use the same color for the same rule.
*** XML reports
Show the counterexamples. This is going to be really hard and/or painful.
Unless we play it dumb (little structure).
** Bistromathic
- How about not evaluating incomplete lines when the text is not finished
(as shells do).
** Questions
*** Java
- Should i18n be part of the Lexer? Currently it's a static method of
Lexer.
- is there a migration path that would allow to use TokenKinds in
yylex?
- define the tokens as an enum too.
- promote YYEOF rather than EOF.
** YYerror
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
should be updated to not use YYERRCODE. Returning an undef token is good
enough.
** Java
*** calc.at
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 over-quotation issues.
* Bison 3.5
** doc
I feel its ugly to use the GNU style to declare functions in the doc. It
I feel it's ugly to use the GNU style to declare functions in the doc. It
generates tons of white space in the page, and may contribute to bad page
breaks.
Also, we seem to teach YYPRINT very early on, although it should be
considered deprecated: %printer is superior.
** consistency
token vs terminal.
** glr.cc
move glr.c into the yy namespace
** api.token.raw
The YYUNDEFTOK could be assigned a semantic value so that yyerror could be
used to report invalid lexemes.
** improve syntax errors (UTF-8, internationalization)
Bison depends on the current locale. For instance:
** push parsers
Consider deprecating impure push parsers. They add a lot of complexity, for
a bad feature. On the other hand, that would make it much harder to sit
push parsers on top of pull parser. Which is currently not relevant, since
push parsers are measurably slower.
%define parse.error verbose
%code top {
#include <stdio.h>
#include <stdlib.h>
void yyerror(const char* msg) { fprintf(stderr, "%s\n", msg); }
int yylex() { return 0; }
}
%%
exp: "↦" | "🎅🐃" | '\n'
%%
int main() { return yyparse(); }
** %define parse.error formatted
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:
gives different results with/without LC_ALL=C.
const char *
error_format_string (int argc)
{
switch (argc)
{
default: /* Avoid compiler warnings. */
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
// "unexpected token", and '%0e', '%1e'... are expected tokens
// at this point.
//
// For instance on the expression "1 + * 2", you'd get
//
// 1.5: syntax error: expected - or ( or number or function or variable before *
case 2: return _("%@: syntax error: expected %0e before %u");
case 3: return _("%@: syntax error: expected %0e or %1e before %u");
case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
}
}
$ LC_ALL=C /opt/local/bin/bison /tmp/mangle.y -o ascii.c
$ /opt/local/bin/bison /tmp/mangle.y -o utf8.c
$ diff -u ascii.c utf8.c -I#line
--- ascii.c 2019-01-12 08:15:35.878010093 +0100
+++ utf8.c 2019-01-12 08:15:38.856495929 +0100
@@ -415,9 +415,8 @@
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
- "$end", "error", "$undefined", "\"\\342\\206\\246\"",
- "\"\\360\\237\\216\\205\\360\\237\\220\\203\"", "'\\n'", "$accept",
- "exp", YY_NULLPTR
+ "$end", "error", "$undefined", "\"↦\"", "\"🎅🐃\"", "'\\n'",
+ "$accept", "exp", YY_NULLPTR
};
#endif
The message would have to be generated in a string, and pushed to yyerror.
Which will be a pain in the neck in yacc.c.
$ gcc ascii.c -o ascii && ./ascii
syntax error, unexpected $end, expecting "\342\206\246" or "\360\237\216\205\360\237\220\203" or '\n'
$ gcc utf8.c -o utf8 && ./utf8
syntax error, unexpected $end, expecting ↦ or 🎅🐃 or '\n'
If we want to do that, we should think very carefully about the syntax of
the format string.
** yyclearin does not invoke the lookahead token's %destructor
https://lists.gnu.org/r/bug-bison/2018-02/msg00000.html
Rici:
While at it, we should stop using "$end" by default, in favor of "end of
file", or "end of input", whatever.
> Modifying yyclearin so that it calls yydestruct seems like the simplest
> solution to this issue, but it is conceivable that such a change would
> break programs which already perform some kind of workaround in order to
> destruct the lookahead symbol. So it might be necessary to use some kind of
> compatibility %define, or to create a new replacement macro with a
> different name such as yydiscardin.
>
> At a minimum, the fact that yyclearin does not invoke the %destructor
> should be highlighted in the documentation, since it is not at all obvious.
* Bison 3.6
** Unit rules
** Issues in i18n
Les catégories d'avertissements incluent :
conflicts-sr conflits S/R (activé par défaut)
conflicts-rr conflits R/R (activé par défaut)
dangling-alias l'alias chaîne n'est pas attaché à un symbole
deprecated construction obsolète
empty-rule règle vide sans %empty
midrule-values valeurs de règle intermédiaire non définies ou inutilisées
precedence priorité et associativité inutiles
yacc incompatibilités avec POSIX Yacc
other tous les autres avertissements (activé par défaut)
all tous les avertissements sauf « dangling-alias » et « yacc »
no-CATEGORY désactiver les avertissements dans CATEGORIE
none désactiver tous les avertissements
error[=CATEGORY] traiter les avertissements comme des erreurs
Line -1 and -3 should mention CATEGORIE, not CATEGORY.
* Bison 3.8
** Rewrite glr.cc
Get rid of scaffolding in glr.c.
** Unit rules / Injection rules (Akim Demaille)
Maybe we could expand unit rules (or "injections", see
https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
transform
@@ -95,10 +180,12 @@ Practice' is impossible to find, but according to 'Parsing Techniques: a
Practical Guide', it includes information about this issue. Does anybody
have it?
** Injection rules
See above.
** clean up (Akim Demaille)
Do not work on these items now, as I (Akim) have branches with a lot of
changes in this area (hitting several files), and no desire to have to fix
conflicts. Addressing these items will happen after my branches have been
merged.
** clean up
*** lalr.c
Introduce a goto struct, and use it in place of from_state/to_state.
Rename states1 as path, length as pathlen.
@@ -116,18 +203,305 @@ 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
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
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
See also
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
https://research.swtch.com/yyerror
http://gallium.inria.fr/~fpottier/publis/fpottier-reachability-cc2016.pdf
* Modernization
Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
and older C++ compilers. Currently the code defaults to defining it to
'long' for non-GCC compilers, but it should use the proper C++ magic 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.
- push parsers: glr.cc, lalr1.cc
- ielr: C++ and Java
- glr: Java
- token constructors: Java and C
- lac: D, Java (easy)
- push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
- token constructors: Java, C, D (a bit difficult)
- glr: D, Java (super difficult)
* Bugs
** Autotest has quotation issues
@@ -139,20 +513,42 @@ $ ./tests/testsuite -l | grep errors | sed q
38: input.at:1730 errors
* Short term
** consistency
token vs terminal
** Get rid of YYPRINT and b4_toknum
Besides yytoknum is wrong when api.token.raw is defined.
** C++
Move to int everywhere instead of unsigned? stack_size, etc. The parser
itself uses int (for yylen for instance), yet stack is based on size_t.
** Better design for diagnostics
The current implementation of diagnostics is ad hoc, it grew organically.
It works as a series of calls to several functions, with dependency of the
latter calls on the former. For instance:
Maybe locations should also move to ints.
complain (&sym->location,
sym->content->status == needed ? complaint : Wother,
_("symbol %s is used, but is not defined as a token"
" and has no rules; did you mean %s?"),
quote_n (0, sym->tag),
quote_n (1, best->tag));
if (feature_flag & feature_caret)
location_caret_suggestion (sym->location, best->tag, stderr);
** C
Introduce state_type rather than spreading yytype_int16 everywhere?
We should rewrite this in a more FP way:
** glr.c
yyspaceLeft should probably be a pointer diff.
1. build a rich structure that denotes the (complete) diagnostic.
"Complete" in the sense that it also contains the suggestions, the list
of possible matches, etc.
2. send this to the pretty-printing routine. The diagnostic structure
should be sufficient so that we can generate all the 'format' of
diagnostics, including the fixits.
If properly done, this diagnostic module can be detached from Bison and be
put in gnulib. It could be used, for instance, for errors caught by
xgettext.
There's certainly already something alike in GCC. At least that's the
impression I get from reading the "-fdiagnostics-format=FORMAT" part of this
page:
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html
** Graphviz display code thoughts
The code for the --graph option is over two files: print_graph, and
@@ -170,12 +566,9 @@ 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.
Also, the underscore in print_graph.[ch] isn't very fitting considering the
dashes in the other filenames.
Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
** push-parser
@@ -233,57 +626,14 @@ since it is no longer bound to a particular parser, it's just a
(standalone symbol).
* Various
** Rewrite glr.cc in C++
** Rewrite glr.cc in C++ (Valentin Tolmer)
As a matter of fact, it would be very interesting to see how much we can
share between lalr1.cc and glr.cc. Most of the skeletons should be common.
It would be a very nice source of inspiration for the other languages.
** YYERRCODE
Defined to 256, but not used, not documented. Probably the token
number for the error token, which POSIX wants to be 256, but which
Bison might renumber if the user used number 256. Keep fix and doc?
Throw away?
Valentin Tolmer is working on this.
Also, why don't we output the token name of the error token in the
output? It is explicitly skipped:
/* Skip error token and tokens without identifier. */
if (sym != errtoken && id)
Of course there are issues with name spaces, but if we disable we have
something which seems to be more simpler and more consistent instead
of the special case YYERRCODE.
enum yytokentype {
error = 256,
// ...
};
We could (should?) also treat the case of the undef_token, which is
numbered 257 for yylex, and 2 internal. Both appear for instance in
toknum:
const unsigned short
parser::yytoken_number_[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
while here
enum yytokentype {
TOK_EOF = 0,
TOK_EQ = 258,
so both 256 and 257 are "mysterious".
const char*
const parser::yytname_[] =
{
"\"end of command\"", "error", "$undefined", "\"=\"", "\"break\"",
** yychar == yyempty_
** yychar == YYEMPTY
The code in yyerrlab reads:
if (yychar <= YYEOF)
@@ -307,10 +657,13 @@ other improvements and also made it faster (probably because memory
management is performed once instead of three times). I suggest that
we do the same in yacc.c.
** yysyntax_error
The code bw glr.c and yacc.c is really alike, we can certainly factor
some parts.
(Some time later): it's also very nice to have three stacks: it's more dense
as we don't lose bits to padding. For instance the typical stack for states
will use 8 bits, while it is likely to consume 32 bits in a struct.
We need trustworthy benchmarks for Bison, for all our backends. Akim has a
few things scattered around; we need to put them in the repo, and make them
more useful.
* Report
@@ -338,28 +691,37 @@ undocumented ''features''. Maybe an empty action ought to be
presented too. Shall we try to make a single grammar with all these
features, or should we have several very small grammars?
** --report=conflict-path
Provide better assistance for understanding the conflicts by providing
a sample text exhibiting the (LALR) ambiguity. See the paper from
DeRemer and Penello: they already provide the algorithm.
** Statically check for potential ambiguities in GLR grammars
See <http://www.lsv.fr/~schmitz/pub/expamb.pdf> for an approach.
An Experimental Ambiguity Detection Tool Sylvain Schmitz
LORIA, INRIA Nancy - Grand Est, Nancy, France
* Extensions
** More languages?
Well, only if there is really some demand for it.
*** PHP
https://github.com/scfc/bison-php/blob/master/data/lalr1.php
*** Python
https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
** Multiple start symbols
Would be very useful when parsing closely related languages.
Would be very useful when parsing closely related languages. The idea is to
declare several start symbols, for instance
** 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
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
%start stmt expr
%%
stmt: ...
expr: ...
See also
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
and https://research.swtch.com/yyerror.
and to generate parse(), parse_stmt() and parse_expr(). Technically, the
above grammar would be transformed into
%start yy_start
%token YY_START_STMT YY_START_EXPR
%%
yy_start: YY_START_STMT stmt | YY_START_EXPR expr
so that there are no new conflicts in the grammar (as would undoubtedly
happen with yy_start: stmt | expr). Then adjust the skeletons so that this
initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
corresponding parse function.
** %include
This is a popular demand. We already made many changes in the parser that
@@ -368,6 +730,12 @@ should make this reasonably easy to implement.
Bruce Mardle <[email protected]>
https://lists.gnu.org/archive/html/bison-patches/2015-09/msg00000.html
However, there are many other things to do before having such a feature,
because I don't want a % equivalent to #include (which we all learned to
hate). I want something that builds "modules" of grammars, and assembles
them together, paying attention to keep separate bits separated, in pseudo
name spaces.
** Push parsers
There is demand for push parsers in Java and C++. And GLR I guess.
@@ -394,6 +762,10 @@ must be in the scanner: we must not parse what is in a switched off
part of %if. Akim Demaille thinks it should be in the parser, so as
to avoid falling into another CPP mistake.
(Later): I'm sure there's actually good case for this. People who need that
feature can use m4/cpp on top of Bison. I don't think it is worth the
trouble in Bison itself.
** XML Output
There are couple of available extensions of Bison targeting some XML
output. Some day we should consider including them. One issue is
@@ -409,10 +781,6 @@ XML output for GNU Bison and gcc
XML output for GNU Bison
http://yaxx.sourceforge.net/
** Counterexample generation
https://lists.gnu.org/archive/html/bug-bison/2016-06/msg00000.html
http://www.cs.cornell.edu/andru/papers/cupex/
* Coding system independence
Paul notes:
@@ -430,7 +798,7 @@ Paul notes:
tokens, either via escapes (e.g., "x\0y") or via a NUL byte in
the source code. This should get fixed.
* Broken options ?
* Broken options?
** %token-table
** Skeleton strategy
Must we keep %token-table?
@@ -442,15 +810,7 @@ It is unfortunate that there is a total order for precedence. It
makes it impossible to have modular precedence information. We should
move to partial orders (sounds like series/parallel orders to me).
* $undefined
From Hans:
- If the Bison generated parser experiences an undefined number in the
character range, that character is written out in diagnostic messages, an
addition to the $undefined value.
Suggest: Change the name $undefined to undefined; looks better in outputs.
This is a prerequisite for modules.
* Pre and post actions.
From: Florian Krohm <[email protected]>
@@ -483,46 +843,48 @@ to bison. If you're interested, I'll work on a patch.
* Better graphics
Equip the parser with a means to create the (visual) parse tree.
* Complaint submessage indentation.
We already have an implementation that works fairly well for named
reference messages, but it would be nice to use it consistently for all
submessages from Bison. For example, the "previous definition"
submessage or the list of correct values for a %define variable might
look better with indentation.
However, the current implementation makes the assumption that the
location printed on the first line is not usually much shorter than the
locations printed on the submessage lines that follow. That assumption
may not hold true as often for some kinds of submessages especially if
we ever support multiple grammar files.
Here's a proposal for how a new implementation might look:
http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00086.html
-----
# 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-2019 Free Software
Copyright (C) 2001-2004, 2006, 2008-2015, 2018-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/>.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
+4 -4
View File
@@ -1,10 +1,10 @@
#! /bin/sh
# Print a version string.
scriptversion=2019-01-04.17; # UTC
scriptversion=2020-04-13.15; # UTC
# Bootstrap this package from checked-out sources.
# Copyright (C) 2003-2019 Free Software Foundation, Inc.
# Copyright (C) 2003-2020 Free Software Foundation, Inc.
# 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
@@ -166,7 +166,7 @@ bootstrap_epilogue() { :; }
# specified directory. Fill in the first %s with the destination
# directory and the second with the domain name.
po_download_command_format=\
"wget --mirror --level=1 -nd -q -A.po -P '%s' \
"wget --mirror --level=1 -nd -nv -A.po -P '%s' \
https://translationproject.org/latest/%s/"
# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
@@ -970,7 +970,7 @@ bootstrap_post_import_hook \
# Uninitialized submodules are listed with an initial dash.
if $use_git && git submodule | grep '^-' >/dev/null; then
die "some git submodules are not initialized. " \
"Run 'git submodule init' and bootstrap again."
"Run 'git submodule update --init' and bootstrap again."
fi
# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
+25 -7
View File
@@ -1,6 +1,6 @@
# Bootstrap configuration.
# Copyright (C) 2006-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2006-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -17,37 +17,46 @@
# gnulib modules used by this package.
gnulib_modules='
argmatch array-list assert assure
argmatch array-list assert assure attribute
bitsetv
calloc-posix close closeout config-h c-strcase
configmake
dirname
error extensions fdl fopen-safer
error extensions
fdl fopen-safer fstrcmp
getopt-gnu
gettext-h git-version-gen gitlog-to-changelog
gpl-3.0 hash inttypes isnan javacomp-script
gpl-3.0 intprops inttypes isnan javacomp-script
javaexec-script
ldexpl
libtextstyle-optional
linked-list
malloc-gnu
mbswidth
mbfile mbswidth
non-recursive-gnulib-prefix-hack
obstack
obstack-printf
perror progname
quote quotearg
rbtreehash-list
readline
readme-release
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
unistd unistd-safer unlink unlocked-io
unicodeio unistd unistd-safer unlink unlocked-io
update-copyright unsetenv verify
warnings
winsz-ioctl
winsz-termios
xalloc
xalloc-die
xconcat-filename
xhash
xlist
xmemdup0
xstrndup
@@ -56,6 +65,8 @@ gnulib_modules='
vsnprintf-posix vsprintf-posix
'
checkout_only_file=README-hacking.md
# Additional xgettext options to use. Use "\\\newline" to break lines.
XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
--from-code=UTF-8\\\
@@ -86,6 +97,13 @@ bootstrap_epilogue()
touch src/parse-gram.[ch]
perl -pi -e "s/\@PACKAGE\@/$package/g" README-release
# Bison currently uses Gettext 0.19, but the gnulib-po module
# imports files from more recent versions of Gettext that are not
# yet available widely enough (e.g., not in bionic, used by the CI).
# Work around this. Don't use autopoint, which sends some other
# files in the past.
cp po/Makefile.in.in gnulib-po
}
# Keep our bootstrap script in sync with gnulib's. If we ever need to
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc.
# 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
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc.
# 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
+31 -10
View File
@@ -1,5 +1,24 @@
#! /usr/bin/env perl
# Generate a release announcement message.
# Copyright (C) 2007-2020 Free Software Foundation, Inc.
#
# 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 <https://www.gnu.org/licenses/>.
#
# Written by Akim Demaille.
use warnings;
use 5.005;
use strict;
@@ -12,7 +31,7 @@ while (<STDIN>)
{
if (/^\s* # Initial spaces.
(?:(-\w),\s+)? # $1: $short: Possible short option.
(--[-\w]+) # $2: $long: Long option.
(--[-\w]+) # $2: $long: Mandatory long option.
(\[?) # $3: $opt: '[' iff the argument is optional.
(?:=(\S+))? # $4: $arg: Possible argument name.
\s # Spaces.
@@ -32,7 +51,6 @@ while (<STDIN>)
# if $opt, $arg contains the closing ].
substr ($arg, -1) = ''
if $opt eq '[';
$arg =~ s/^=//;
$arg = lc ($arg);
my $dir_arg = $arg;
# If the argument is complete (e.g., for --define[=NAME[=VALUE]]),
@@ -72,12 +90,15 @@ while (<STDIN>)
my $sep = '';
foreach my $long (sort keys %option)
{
# Avoid trailing spaces.
print $sep;
$sep = "\n";
print '@item @option{', $long, "}\n\@tab";
print ' @option{', $option{$long}, '}' if $option{$long};
print "\n\@tab";
print ' @code{', $directive{$long}, '}' if $directive{$long};
print "\n";
# Couldn't find a means to escape @ in the format (for @item, @tab), so
# pass it as a literal to print.
format STDOUT =
@item @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @tab @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @tab @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
'@', '@option{' . $long . '}',
'@', $option{$long} ? ('@option{' . $option{$long} . '}') : '',
'@', $directive{$long} ? ('@code{' . $directive{$long} . '}') : ''
}
.
write;
}
+1 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2000-2015, 2018-2019 Free Software Foundation, Inc.
## Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc.
##
## 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
+1 -1
View File
@@ -3,7 +3,7 @@
# Update b4_copyright invocations or b4_copyright_years definitions to
# include the current year.
# Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc.
# 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
+1 -1
View File
@@ -2,7 +2,7 @@
# In configure.ac, update PACKAGE_COPYRIGHT_YEAR to the current year.
# Copyright (C) 2010-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2010-2015, 2018-2020 Free Software Foundation, Inc.
#
# 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
+42 -13
View File
@@ -1,8 +1,29 @@
#! /usr/bin/env python
# usage:
# update-test _build/8d/tests/testsuite.dir/*.testsuite.log
# Update expectations in an Autotest test suite.
# Copyright (C) 2019-2020 Free Software Foundation, Inc.
#
# 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 <https://www.gnu.org/licenses/>.
#
# Written by Akim Demaille.
# usage:
#
# update-test _build/8d/tests/testsuite.dir/*/testsuite.log
#
# from your source tree.
import argparse
import os
import re
@@ -11,8 +32,8 @@ import re
def getargs():
p = argparse.ArgumentParser(description='Update test cases.')
opt = p.add_argument
opt('tests', metavar='test', nargs='+', type=str, default=None,
help='test files to update')
opt('logs', metavar='log', nargs='+', type=str, default=None,
help='log files to process')
opt('-v', '--verbose', action='store_true',
help='Be verbose')
return p.parse_args()
@@ -21,14 +42,14 @@ args = getargs()
subst = dict()
def log(*args_):
def trace(*args_):
if args.verbose:
print(*args_)
def contents(file):
'''The contents of a file.'''
log(file)
trace(file)
f = open(file)
return f.read()
@@ -52,6 +73,11 @@ def diff_to_re(match):
is_diff = True
to.append(l)
if is_diff:
# Do not run s//SOMETHING/g (with an emty pattern), that won't
# work well...
if frm == []:
trace("no from for", match.group(1))
return
frm = "\n".join(frm)
to = "\n".join(to)
subst[frm] = to
@@ -60,9 +86,9 @@ def diff_to_re(match):
def update(at_file, logfile):
test = contents(at_file)
if os.path.isfile(logfile):
log("LOG: ", logfile)
trace("LOG: ", logfile)
l = contents(logfile)
log("LOG: ", l)
trace("LOG: ", l)
global subst
subst = {}
re.sub(r'(?:^@@.*\n)((?:^[-+ ].*\n)+)',
@@ -71,7 +97,7 @@ def update(at_file, logfile):
if subst:
# Turn "subst{frm} -> to" into a large RE.
frm = '|'.join([re.escape(x) for x in subst])
log("FROM:", frm)
trace("FROM:", frm)
test = re.sub("(" + frm + ")",
lambda m: subst[m.group(1)],
test, flags=re.MULTILINE)
@@ -81,13 +107,16 @@ def update(at_file, logfile):
def process(logfile):
log = contents(logfile)
# Look for the file to update.
m = re.search(r'^\d+\. (\w+\.at):\d+: ', log, re.MULTILINE)
m = re.search(r'^\d+\. ([\-\+\w]+\.at):\d+: ', log, re.MULTILINE)
if not m:
trace("no diff found:", logfile)
return
at_file = 'tests/' + m.group(1)
print(at_file)
update(at_file, logfile)
for t in args.tests:
log("FILE:", t)
process(t)
for logfile in args.logs:
trace("FILE:", logfile)
if os.path.isdir(logfile):
logfile = os.path.join(logfile, 'testsuite.log')
process(logfile)
+9 -5
View File
@@ -1,5 +1,5 @@
## Customize maint.mk -*- makefile -*-
## Copyright (C) 2008-2015, 2018-2019 Free Software Foundation, Inc.
## Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
## 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
@@ -26,6 +26,9 @@ regen: _version
manual_title = The Yacc-compatible Parser Generator
gendocs_options_ = -I $(abs_top_srcdir)/doc -I $(abs_top_builddir)/doc
# By default, propagate -j from make to Bison's test suite.
TESTSUITEFLAGS = $(filter -j%,$(MAKEFLAGS))
# It's useful to run maintainer-check* targets during development, but we
# don't want to wait on a recompile because of an update to $(VERSION). Thus,
# override the _is-dist-target from GNUmakefile so that maintainer-check*
@@ -48,7 +51,7 @@ gnulib_dir = $(srcdir)/gnulib
bootstrap-tools = autoconf,automake,flex,gettext,gnulib
announcement_Cc_ = \
[email protected], [email protected], bison-patches@gnu.org, \
[email protected], bison-announce@gnu.org, \
[email protected]
update-copyright: update-b4-copyright update-package-copyright-year
@@ -123,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 \
@@ -153,7 +156,8 @@ exclude = \
$(call exclude, \
bindtextdomain=^lib/main.c$$ \
cast_of_argument_to_free=^src/muscle-tab.c$$ \
po_check=^po/POTFILES.in$$ \
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$$ \
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
@@ -162,7 +166,7 @@ $(call exclude,
prohibit_doubled_word=^tests/named-refs.at$$ \
prohibit_magic_number_exit=^doc/bison.texi$$ \
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
prohibit_strcmp=^doc/bison\.texi|examples|tests/local\.at$$ \
prohibit_strcmp=^doc/bison\.texi|examples|tests \
prohibit_tab_based_indentation=install-icc.sh|\.(am|mk)$$|^\.git|tests/input.at|Makefile$$ \
require_config_h=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
require_config_h_first=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
+85 -22
View File
@@ -1,6 +1,6 @@
# Configure template for GNU Bison. -*-Autoconf-*-
#
# Copyright (C) 2001-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc.
#
# 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
@@ -26,15 +26,18 @@ m4_pattern_allow([^BISON_USE_NLS$])
AC_INIT([GNU Bison],
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
[[email protected]])
AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2019])
[[email protected]],
[],
[https://www.gnu.org/software/bison/])
AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2020])
AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR],
[The copyright year for this package])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
# We use Automake 1.14's %D% and %C%.
# When we move to Automake 1.16, simplify examples/c/reccalc/local.mk.
# Our CI build the packages on Bionic, which has only Automake 1.15.
#
# We want gnits strictness only when rolling a stable release. For
# release candidates, we use version strings like 2.4.3_rc1, but gnits
@@ -42,7 +45,7 @@ AC_CONFIG_MACRO_DIR([m4])
# releases, we want to be able run make dist without being required to
# add a bogus NEWS entry. In that case, the version string
# automatically contains a dash, which we also let disable gnits.
AM_INIT_AUTOMAKE([1.14 dist-xz nostdinc
AM_INIT_AUTOMAKE([1.15 dist-lzip dist-xz nostdinc
color-tests parallel-tests
silent-rules]
m4_bmatch(m4_defn([AC_PACKAGE_VERSION]), [[-_]],
@@ -57,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],
@@ -94,13 +100,49 @@ AC_ARG_ENABLE([gcc-warnings],
[enable_gcc_warnings=no])
AM_CONDITIONAL([ENABLE_GCC_WARNINGS], [test "$enable_gcc_warnings" = yes])
if test "$enable_gcc_warnings" = yes; then
warn_common='-Wall -Wextra -Wno-sign-compare -Wcast-align
# -Wno-tautological-constant-out-of-range-compare for Clang 3.3 and
# 3.4 on GNU/Linux that choke on intprops.h's INT_MULTIPLY_WRAPV,
# etc.
#
# ICC: -wr188
#
# 1669 warnings warnings_default =
# ../src/complain.c(318): error #188: enumerated type mixed with another type
# 1670 Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
# 1671 ^
# 1672
# 1673../src/complain.c(393): error #188: enumerated type mixed with another type
# 1674 warnings w = 1 << wbit;
# 1675 ^
#
# ICC: -wr3179
#
# char const *usefulness
# = rule_useless_in_grammar_p (&rules[r]) ? "useless-in-grammar"
# : rule_useless_in_parser_p (&rules[r]) ? "useless-in-parser"
# : "useful";
#
# gives
#
# error #3179: deprecated conversion of string literal to char* (should be const char*)
#
# ICC: -wr2259 (that's in C, in spite of what the error messages which seems to be about C++).
# error #2259: non-pointer conversion from "int" to "yybool={signed char}" may lose significant bits
# yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR;
# ^
warn_common='-Wall -Wextra
-Wcast-align -Wchar-subscripts
-fparse-all-comments -Wdocumentation
-Wformat -Wimplicit-fallthrough -Wnull-dereference
-Wpointer-arith -Wshadow
-Wwrite-strings'
warn_c='-Wbad-function-cast -Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept -Wundefined-func-template -Wweak-vtables'
-Wno-sign-compare -Wno-tautological-constant-out-of-range-compare
-Wpointer-arith -Wshadow -Wstrict-aliasing
-Wwrite-strings
-wr188 -wr2259 -wr3179'
warn_c='-Wbad-function-cast
-Wmissing-prototypes
-Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept -Wold-style-cast -Wundefined-func-template
-Wweak-vtables'
# Warnings for the test suite only.
#
# -fno-color-diagnostics: Clang's use of colors in the error
@@ -112,6 +154,7 @@ if test "$enable_gcc_warnings" = yes; then
# details for lalr1.cc.
warn_tests='-Wundef -pedantic -Wconversion
-Wdeprecated -Wsign-compare -Wsign-conversion
-Wtautological-constant-out-of-range-compare
-fno-color-diagnostics
-Wno-keyword-macro'
@@ -142,8 +185,6 @@ if test "$enable_gcc_warnings" = yes; then
# Warnings for the test suite, and maybe for bison if GCC is modern
# enough.
gl_WARN_ADD([-Wmissing-declarations], [WARN_CFLAGS_TEST])
gl_WARN_ADD([-Wmissing-prototypes], [WARN_CFLAGS_TEST])
test $lv_cv_gcc_pragma_push_works = yes &&
AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
@@ -170,6 +211,14 @@ if test "$enable_gcc_warnings" = yes; then
[[if (sizeof (long) < sizeof (int)) return 1;]])])
gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
[AC_LANG_PROGRAM([], [nullptr])])
# Before GCC6, the pragmas don't work well enough to neutralize
# this warning.
gl_WARN_ADD([-Wuseless-cast], [WARN_CXXFLAGS],
[AC_LANG_PROGRAM([], [
#if defined __GNUC__ && ! defined __ICC && ! defined __clang__ && __GNUC__ < 6
syntax error
#endif
])])
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
# Warnings for the test suite only.
for i in $warn_tests;
@@ -192,7 +241,7 @@ BISON_CXX_COMPILER_POSIXLY_CORRECT
# D.
AC_CHECK_PROGS([DC], [dmd])
AC_CHECK_PROGS([DCFLAGS], [])
AC_CHECK_PROGS([DCFLAGS], [-g])
AM_CONDITIONAL([ENABLE_D], [test x"$DC" != x])
# Java.
@@ -211,13 +260,13 @@ AC_CONFIG_FILES([src/yacc], [chmod +x src/yacc])
# Checks for programs.
AM_MISSING_PROG([DOT], [dot])
AC_PROG_LEX
$LEX_IS_FLEX || test "X$LEX" = X: || {
if ! "$LEX_IS_FLEX" || test "X$LEX" = X:; then
AC_MSG_WARN([bypassing lex because flex is required])
LEX=:
}
AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX])
fi
AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT])
AM_CONDITIONAL([FLEX_CXX_WORKS],
[$LEX_IS_FLEX && test $bison_cv_cxx_works = yes])
[$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT && test $bison_cv_cxx_works = yes])
AC_PROG_YACC
AC_PROG_RANLIB
AC_PROG_GNU_M4
@@ -225,9 +274,6 @@ AC_DEFINE_UNQUOTED([M4], ["$M4"], [Define to the GNU M4 executable name.])
AC_DEFINE_UNQUOTED([M4_GNU_OPTION], ["$M4_GNU"], [Define to "-g" if GNU M4
supports -g, otherwise to "".])
AC_PATH_PROG([PERL], [perl])
if test -z "$PERL"; then
AC_MSG_ERROR([perl not found])
fi
AM_MISSING_PROG([HELP2MAN], [help2man])
AC_PATH_PROG([XSLTPROC], [xsltproc])
AC_SUBST([XSLTPROC])
@@ -244,7 +290,6 @@ gl_INIT
# Checks for library functions.
AC_CHECK_FUNCS_ONCE([setlocale])
AM_WITH_DMALLOC
# Gettext.
# We use gnulib, which is only guaranteed to work properly with the
@@ -274,7 +319,7 @@ uname=`uname`
case $VALGRIND:$uname in
'':*) ;;
*:Darwin)
# See README-hacking.
# See README-hacking.md.
VALGRIND=;;
*:*)
suppfile=build-aux/$uname.valgrind
@@ -290,6 +335,13 @@ AC_MSG_RESULT([$suppfile])
# Whether we cannot run the compiled bison.
AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
# Build bistromathic if we have the lib and both readline/readline.h
# and readline/history.h.
AM_CONDITIONAL([ENABLE_BISTROMATHIC],
[test "$gl_cv_lib_readline" != no &&
test "$ac_cv_header_readline_readline_h" = yes &&
test "$ac_cv_header_readline_history_h" = yes])
AM_MISSING_PROG([AUTOM4TE], [autom4te])
# Needed by tests/atlocal.in.
AC_SUBST([GCC])
@@ -297,4 +349,15 @@ AC_SUBST([GCC])
AC_CONFIG_FILES([Makefile
po/Makefile.in
doc/yacc.1])
# Fix LIBOBJS to give the Makefile the right file names. Otherwise
# compilation works, but with unexpected file names, so clean rules don't
# remove the actual files and distcheck fails.
AC_CONFIG_COMMANDS_PRE([
case $am__api_version in
1.14*|1.15*) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/lib_libbison_a-,g'`;;
*) gl_LIBOBJS=`echo "$gl_LIBOBJS" | sed -e 's, lib/, lib/libbison_a-,g'`;;
esac
])
AC_OUTPUT
+30 -15
View File
@@ -1,6 +1,6 @@
This directory contains data needed by Bison.
# Directory content
# Directory Content
## Skeletons
Bison skeletons: the general shapes of the different parser kinds, that are
specialized for specific grammars by the bison program.
@@ -48,7 +48,7 @@ various formats.
- xml2xhtml.xsl
Conversion into XHTML.
# Implementation note about the skeletons
# Implementation Notes About the Skeletons
"Skeleton" in Bison parlance means "backend": a skeleton is fed by the bison
executable with LR tables, facts about the symbols, etc. and they generate
@@ -83,26 +83,39 @@ field), where field can `has_id`, `id`, etc.: see
The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
- `has_id`: 0 or 1.
- `has_id`: 0 or 1
Whether the symbol has an `id`.
Whether the symbol has an id.
- `id`: string (e.g., `exp`, `NUM`, or `TOK_NUM` with api.token.prefix)
If `has_id`, the name of the token kind (prefixed by api.token.prefix if
defined), otherwise empty. Guaranteed to be usable as a C identifier.
This is used to define the token kind (i.e., the enum used by the return
value of yylex). Should be named `token_kind`.
- `id`: string
If has_id, the id (prefixed by api.token.prefix if defined), otherwise
defined as empty. Guaranteed to be usable as a C identifier.
- `tag`: string
A human readable representation of the symbol. Can be `'foo'`,
`'foo.id'`, `'"foo"'` etc.
- `tag`: string.
A representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
- `user_number`: integer
- `code`: integer
The token code associated to the token kind `id`.
The external number as used by yylex. Can be ASCII code when a character,
some number chosen by bison, or some user number in the case of
%token FOO <NUM>. Corresponds to yychar in yacc.c.
some number chosen by bison, or some user number in the case of `%token
FOO <NUM>`. Corresponds to `yychar` in `yacc.c`.
- `is_token`: 0 or 1
Whether this is a terminal symbol.
- `kind_base`: string (e.g., `YYSYMBOL_exp`, `YYSYMBOL_NUM`)
The base of the symbol kind, i.e., the enumerator of this symbol (token or
nonterminal) which is mapped to its `number`.
- `kind`: string
Same as `kind_base`, but possibly with a prefix in some languages. E.g.,
EOF's `kind_base` and `kind` are `YYSYMBOL_YYEOF` in C, but are
`S_YYEMPTY` and `symbol_kind::S_YYEMPTY` in C++.
- `number`: integer
The code associated to the `kind`.
The internal number (computed from the external number by yytranslate).
Corresponds to yytoken in yacc.c. This is the same number that serves as
key in b4_symbol(NUM, FIELD).
@@ -166,7 +179,7 @@ The data corresponding to the symbol `#POS`, where the current rule has
Expansion of `$<TYPE>POS`, where the current rule has `RULE-LENGTH` symbols
on RHS.
-----
<!--
Local Variables:
mode: markdown
@@ -174,7 +187,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2002, 2008-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2002, 2008-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of GNU Bison.
@@ -190,3 +203,5 @@ 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/>.
-->
+38 -1
View File
@@ -1,5 +1,5 @@
/* Default styling rules for Bison when doing terminal output.
Copyright (C) 2019 Free Software Foundation, Inc.
Copyright (C) 2019-2020 Free Software Foundation, Inc.
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
@@ -17,8 +17,45 @@
/* This is an experimental feature. The class names may change in the
future. */
/* Diagnostics. */
.warning { color: purple; }
.error { color: red; }
.note { color: cyan; }
.fixit-insert { color: green; }
/* Semantic values in Bison's own parser traces. */
.value { color: green; }
/* "Sections" in traces (--trace). */
.trace0 { color: green; }
/* Syntax error messages. */
.expected { color: green; }
.unexpected { color: red; }
/* Counterexamples. */
/* Cex: point in rule. */
.cex-dot { color: red; }
/* Cex: coloring various rules. */
.cex-0 { color: yellow; }
.cex-1 { color: green; }
.cex-2 { color: blue; }
.cex-3 { color: purple; }
.cex-4 { color: violet; }
.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; }
/* Cex: leaves of a derivation. */
.cex-leaf { font-weight: 600; }
+2 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2002, 2005-2015, 2018-2019 Free Software Foundation,
## Copyright (C) 2002, 2005-2015, 2018-2020 Free Software Foundation,
## Inc.
## This program is free software: you can redistribute it and/or modify
@@ -34,6 +34,7 @@ dist_skeletons_DATA = \
data/skeletons/lalr1.java \
data/skeletons/location.cc \
data/skeletons/stack.hh \
data/skeletons/traceon.m4 \
data/skeletons/variant.hh \
data/skeletons/yacc.c
+2 -2
View File
@@ -27,7 +27,7 @@ public interface Lexer
* to the next token and prepares to return the semantic value
* and beginning/ending positions of the token.
* @return the token identifier corresponding to the next token. */
YYTokenType yylex ();
TokenKind yylex ();
/**
* Entry point for error reporting. Emits an error
@@ -39,7 +39,7 @@ public interface Lexer
void yyerror (YYLocation loc, string s);
}
- semantic types are handled by D usions (same as for C/C++ parsers)
- semantic types are handled by D unions (same as for C/C++ parsers)
- the following (non-standard) %defines are supported:
+137 -52
View File
@@ -2,7 +2,7 @@
# Language-independent M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation,
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
@@ -19,6 +19,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...)
# ----------------------------------------------
# m4 equivalent of
#
# $_ = STRING;
# s/RE1/SUBST1/g;
# s/RE2/SUBST2/g;
# ...
#
# Really similar to m4_bpatsubsts, but behaves properly with quotes.
# See m4.at's "Generating Comments". Super inelegant, but so far, I
# did not find any better solution.
m4_define([b4_gsub],
[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]],
[$2], [$3]),
[$4], [$5]),
[$6], [$7])])
# m4_shift2 and m4_shift3 are provided by m4sugar.
m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
## ---------------- ##
## Identification. ##
## ---------------- ##
@@ -26,7 +49,7 @@
# 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])
@@ -72,8 +95,9 @@ version 2.2 of Bison.])
# -------------
# Issue a warning about private implementation details.
m4_define([b4_disclaimer],
[b4_comment([Undocumented macros, especially those whose name start with YY_,
are private implementation details. Do not rely on them.])
[b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed.])
])
@@ -161,7 +185,7 @@ m4_define([b4_error],
[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
[m4_if([$#], [4], [],
[m4_foreach([b4_arg],
m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
m4_dquote(m4_shift4($@)),
[[@,]b4_arg])])[@)]])])
# b4_warn(FORMAT, [ARG1], [ARG2], ...)
@@ -192,7 +216,7 @@ m4_define([b4_error],
# @warn(1@)
# @warn(1@,2@)
m4_define([b4_warn],
[b4_error([[warn]], [], [], $@)])
[b4_warn_at([], [], $@)])
# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
# ---------------------------------------------------
@@ -210,7 +234,7 @@ m4_define([b4_warn_at],
#
# See b4_warn example.
m4_define([b4_complain],
[b4_error([[complain]], [], [], $@)])
[b4_complain_at([], [], $@)])
# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
# -------------------------------------------------------
@@ -226,8 +250,7 @@ m4_define([b4_complain_at],
#
# See b4_warn example.
m4_define([b4_fatal],
[b4_error([[fatal]], [], [], $@)dnl
m4_exit(1)])
[b4_fatal_at([], [], $@)])
# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
# ----------------------------------------------------
@@ -370,6 +393,7 @@ m4_define([b4_$3_if],
# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
b4_define_flag_if([defines]) # Whether headers are requested.
b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([has_translations]) # Whether some tokens are internationalized.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
@@ -385,37 +409,72 @@ m4_define([b4_glr_cc_if],
## Symbols. ##
## --------- ##
# For a description of the Symbol handling, see README.
# For a description of the Symbol handling, see README.md.
#
# The following macros provide access to symbol related values.
# __b4_symbol(NUM, FIELD)
# -----------------------
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
# undefined.
# Fetch FIELD of symbol #NUM. Fail if undefined.
m4_define([__b4_symbol],
[m4_indir([b4_symbol($1, $2)])])
# _b4_symbol(NUM, FIELD)
# ----------------------
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
# undefined.
# Fetch FIELD of symbol #NUM (or "orig NUM", see README.md).
# Fail if undefined.
m4_define([_b4_symbol],
[m4_ifdef([b4_symbol($1, number)],
[__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)],
[__b4_symbol([$1], [$2])])])
# b4_symbol_token_kind(NUM)
# -------------------------
# The token kind of this symbol.
m4_define([b4_symbol_token_kind],
[b4_percent_define_get([api.token.prefix])dnl
_b4_symbol([$1], [id])])
# b4_symbol_kind_base(NUM)
# ------------------------
# Build the name of the kind of this symbol. It must always exist,
# otherwise some symbols might not be represented in the enum, which
# might be compiled into too small a type to contain all the symbol
# numbers.
m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])])
m4_define([b4_symbol_kind_base],
[b4_percent_define_get([api.symbol.prefix])dnl
m4_case([$1],
[-2], [[YYEMPTY]],
[0], [[YYEOF]],
[1], [[YYerror]],
[2], [[YYUNDEF]],
[m4_case(b4_symbol([$1], [tag]),
[$accept], [[YYACCEPT]],
[b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]),
[m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])])
# b4_symbol_kind(NUM)
# -------------------
# Same as b4_symbol_kind, but possibly with a prefix in some
# languages. E.g., EOF's kind_base and kind are YYSYMBOL_YYEOF in C,
# but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++.
m4_copy([b4_symbol_kind_base], [b4_symbol_kind])
# b4_symbol(NUM, FIELD)
# ---------------------
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
# undefined. If FIELD = id, prepend the token prefix.
# Fetch FIELD of symbol #NUM (or "orig NUM"). Fail if undefined.
#
# If FIELD = id, prepend the token prefix.
m4_define([b4_symbol],
[m4_case([$2],
[id], [m4_do([b4_percent_define_get([api.token.prefix])],
[_b4_symbol([$1], [id])])],
[id], [b4_symbol_token_kind([$1])],
[kind_base], [b4_symbol_kind_base([$1])],
[kind], [b4_symbol_kind([$1])],
[_b4_symbol($@)])])
@@ -438,9 +497,9 @@ m4_define([b4_symbol_tag_comment],
])
# b4_symbol_action(SYMBOL-NUM, KIND)
# ----------------------------------
# Run the action KIND (destructor or printer) for SYMBOL-NUM.
# b4_symbol_action(SYMBOL-NUM, ACTION)
# ------------------------------------
# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
m4_define([b4_symbol_action],
[b4_symbol_if([$1], [has_$2],
[b4_dollar_pushdef([(*yyvaluep)],
@@ -449,7 +508,7 @@ m4_define([b4_symbol_action],
[(*yylocationp)])dnl
_b4_symbol_case([$1])[]dnl
b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
b4_symbol([$1], [$2])
b4_symbol([$1], [$2])
b4_syncline([@oline@], [@ofile@])dnl
break;
@@ -464,21 +523,21 @@ m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
# b4_symbol_actions(KIND, [TYPE = yytype])
# ----------------------------------------
# Emit the symbol actions for KIND ("printer" or "destructor").
# Dispatch on TYPE.
# b4_symbol_actions(ACTION, [KIND = yykind])
# ------------------------------------------
# Emit the symbol actions for ACTION ("destructor" or "printer").
# Dispatch on KIND.
m4_define([b4_symbol_actions],
[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
m4_ifval(m4_defn([b4_actions_]),
[switch (m4_default([$2], [yytype]))
[switch (m4_default([$2], [yykind]))
{
m4_defn([b4_actions_])[]dnl
default:
break;
}dnl
],
[YYUSE (m4_default([$2], [yytype]));])dnl
[YYUSE (m4_default([$2], [yykind]));])dnl
m4_popdef([b4_actions_])dnl
])
@@ -488,7 +547,7 @@ m4_popdef([b4_actions_])dnl
# easier to use with m4_map, but then, use []dnl to suppress the last
# one.
m4_define([_b4_symbol_case],
[case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])])
[case b4_symbol([$1], [kind]): b4_symbol_tag_comment([$1])])
])
@@ -508,13 +567,14 @@ m4_define([b4_symbol_map],
# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
# -------------------------------------------
# Whether NUM denotes a token that has an exported definition (i.e.,
# shows in enum yytokentype).
# Whether NUM denotes a token kind that has an exported definition
# (i.e., shows in enum yytokentype).
m4_define([b4_token_visible_if],
[b4_symbol_if([$1], [is_token],
[b4_symbol_if([$1], [has_id], [$2], [$3])],
[$3])])
# b4_token_has_definition(NUM)
# ----------------------------
# 1 if NUM is visible, nothing otherwise.
@@ -531,13 +591,27 @@ m4_define([b4_any_token_visible_if],
# b4_token_format(FORMAT, NUM)
# ----------------------------
# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER.
m4_define([b4_token_format],
[b4_token_visible_if([$2],
[m4_quote(m4_format([$1],
[b4_symbol([$2], [id])],
[b4_symbol([$2], [user_number])]))])])
[m4_format([[$1]],
b4_symbol([$2], [id]),
b4_symbol([$2], b4_api_token_raw_if([[number]], [[code]])))])])
# b4_last_enum_token
# ------------------
# The code of the last token visible token.
m4_define([_b4_last_enum_token],
[b4_token_visible_if([$1],
[m4_define([b4_last_enum_token], [$1])])])
b4_symbol_foreach([_b4_last_enum_token])
# b4_last_symbol
# --------------
# The code of the last symbol.
m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1))
## ------- ##
## Types. ##
## ------- ##
@@ -559,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]))])
@@ -604,7 +678,7 @@ m4_define([b4_sync_end], [ b4_comment([$2:$1])]
# This generates dependencies on the Bison skeletons hence lots of
# useless 'git diff'. This location is useless for the regular
# user (who does not care about the skeletons) and is actually not
# useful for Bison developpers too (I, Akim, never used this to locate
# useful for Bison developers too (I, Akim, never used this to locate
# the code in skeletons that generated output). So disable it
# completely. If someone thinks this was actually useful, a %define
# variable should be provided to control the level of verbosity of
@@ -684,7 +758,7 @@ m4_define([b4_check_user_names],
[m4_pushdef([b4_occurrence], b4_occurrence)dnl
m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_end], m4_shift2(b4_occurrence))dnl
m4_ifndef($3[(]m4_quote(b4_user_name)[)],
[b4_complain_at([b4_start], [b4_end],
[[%s '%s' is not used]],
@@ -976,8 +1050,8 @@ m4_define([b4_percent_code_get],
[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
m4_ifdef(b4_macro_name,
[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
[["%code ]$1["]])[ blocks.]])
[b4_comment(m4_if([$#], [0], [[[Unqualified %code blocks.]]],
[[["%code ]$1[" blocks.]]]))
b4_user_code([m4_indir(b4_macro_name)])])dnl
m4_popdef([b4_macro_name])])
@@ -1002,6 +1076,7 @@ m4_define([b4_percent_code_ifdef],
# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
# b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT])
# ----------------------------------------------------------
b4_percent_define_if_define([api.token.raw])
b4_percent_define_if_define([token_ctor], [api.token.constructor])
b4_percent_define_if_define([locations]) # Whether locations are tracked.
b4_percent_define_if_define([parse.assert])
@@ -1016,21 +1091,23 @@ m4_define([b4_bison_locations_if],
[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
# %define parse.error "(custom|detailed|simple|verbose)"
# ------------------------------------------------------
# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
# b4_error_verbose_flag.
b4_percent_define_default([[parse.error]], [[simple]])
b4_percent_define_check_values([[[[parse.error]],
[[simple]], [[verbose]]]])
m4_define([b4_error_verbose_flag],
[m4_case(b4_percent_define_get([[parse.error]]),
[simple], [[0]],
[verbose], [[1]])])
b4_define_flag_if([error_verbose])
[[custom]], [[detailed]], [[simple]], [[verbose]]]])
# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE)
# ----------------------------------------------------------
m4_define([b4_parse_error_case],
[m4_case(b4_percent_define_get([[parse.error]]), $@)])
# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE)
# ------------------------------------------------------------------
m4_define([b4_parse_error_bmatch],
[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)])
# yytoken_table is needed to support verbose errors.
b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
@@ -1116,3 +1193,11 @@ b4_percent_define_ifdef([api.value.type],
# api.value.union.name.
b4_percent_define_check_kind([api.value.union.name], [keyword])
# parse.error (custom|detailed) >< token-table.
b4_token_table_if(
[b4_parse_error_bmatch([custom\|detailed],
[b4_complain_at(b4_percent_define_get_loc([parse.error]),
[['%s' and '%s' cannot be used together]],
[%token-table],
[%define parse.error (custom|detailed)])])])
+1 -1
View File
@@ -2,7 +2,7 @@
# C++ skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
+157 -102
View File
@@ -2,7 +2,7 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2019 Free Software Foundation, Inc.
# Copyright (C) 2002-2020 Free Software Foundation, Inc.
# 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
@@ -22,6 +22,8 @@ b4_percent_define_ifdef([[api.value.union.name]],
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
[named %union is invalid in C++])])
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
m4_include(b4_skeletonsdir/[c.m4])
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
@@ -103,7 +105,7 @@ b4_percent_define_default([[api.parser.class]], [[parser]])
#
# b4_percent_define_default([[api.location.type]], [[location]])
b4_percent_define_default([[filename_type]], [[std::string]])
b4_percent_define_default([[api.filename.type]], [[const std::string]])
# Make it a warning for those who used betas of Bison 3.0.
b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
@@ -160,20 +162,42 @@ m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
## ------------- ##
## Token kinds. ##
## ------------- ##
# b4_token_enums
# --------------
# Output the definition of the tokens as enums.
# Output the definition of the token kinds.
m4_define([b4_token_enums],
[[enum yytokentype
[[enum token_kind_type
{
]m4_join([,
],
b4_symbol_map([b4_token_enum]))[
};]dnl
]b4_symbol([-2], [id])[ = -2,
]b4_symbol_foreach([b4_token_enum])dnl
[ };]dnl
])
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[enum symbol_kind_type
{
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
]b4_symbol(-2, kind_base)[ = -2,
]b4_symbol_foreach([ b4_symbol_enum])dnl
[ };]])
## ----------------- ##
## Semantic Values. ##
@@ -231,23 +255,31 @@ m4_define([b4_public_types_declare],
location_type location;])[
};
/// Tokens.
/// Token kinds.
struct token
{
]b4_token_enums[
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype;
};
/// (External) token type, as returned by yylex.
typedef token::yytokentype token_type;
/// Token kind, as returned by yylex.
typedef token::yytokentype token_kind_type;
/// Symbol type: an internal symbol number.
typedef int symbol_number_type;
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type token_type;
/// The symbol type number to denote an empty symbol.
enum { empty_symbol = -2 };
/// Symbol kinds.
struct symbol_kind
{
]b4_declare_symbol_enum[
};
/// Internal symbol number for tokens (subsumed by symbol_number_type).
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
/// (Internal) symbol kind.
typedef symbol_kind::symbol_kind_type symbol_kind_type;
/// The number of tokens.
static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
]])
@@ -258,8 +290,8 @@ m4_define([b4_public_types_declare],
m4_define([b4_symbol_type_define],
[[ /// A complete symbol.
///
/// Expects its Base type to provide access to the symbol type
/// via type_get ().
/// Expects its Base type to provide access to the symbol kind
/// via kind ().
///
/// Provide access to semantic value]b4_locations_if([ and location])[.
template <typename Base>
@@ -276,14 +308,22 @@ m4_define([b4_symbol_type_define],
#if 201103L <= YY_CPLUSPLUS
/// Move constructor.
basic_symbol (basic_symbol&& that);
basic_symbol (basic_symbol&& that)
: Base (std::move (that))
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
, location (std::move (that.location))])[
{]b4_variant_if([
b4_symbol_variant([this->kind ()], [value], [move],
[std::move (that.value)])
])[}
#endif
/// 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])[);
@@ -303,21 +343,47 @@ m4_define([b4_symbol_type_define],
void clear ()
{]b4_variant_if([[
// User destructor.
symbol_number_type yytype = this->type_get ();
symbol_kind_type yykind = this->kind ();
basic_symbol<Base>& yysym = *this;
(void) yysym;
switch (yytype)
switch (yykind)
{
]b4_symbol_foreach([b4_symbol_destructor])dnl
[ default:
break;
}
// Type destructor.
]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
// Value type destructor.
]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[
Base::clear ();
}
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of this symbol.
std::string name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]])[
/// Backward compatibility (Bison 3.6).
symbol_kind_type type_get () const YY_NOEXCEPT;
/// Whether empty.
bool empty () const YY_NOEXCEPT;
@@ -338,49 +404,51 @@ m4_define([b4_symbol_type_define],
};
/// Type access provider for token (enum) based symbols.
struct by_type
struct by_kind
{
/// Default constructor.
by_type ();
by_kind ();
#if 201103L <= YY_CPLUSPLUS
/// Move constructor.
by_type (by_type&& that);
by_kind (by_kind&& that);
#endif
/// Copy constructor.
by_type (const by_type& that);
by_kind (const by_kind& that);
/// The symbol type as needed by the constructor.
typedef token_type kind_type;
/// The symbol kind as needed by the constructor.
typedef token_kind_type kind_type;
/// Constructor from (external) token numbers.
by_type (kind_type t);
by_kind (kind_type t);
/// Record that this symbol is empty.
void clear ();
/// Steal the symbol type from \a that.
void move (by_type& that);
/// Steal the symbol kind from \a that.
void move (by_kind& that);
/// The (internal) type number (corresponding to \a type).
/// \a empty when empty.
symbol_number_type type_get () const YY_NOEXCEPT;
symbol_kind_type kind () const YY_NOEXCEPT;
/// The token.
token_type token () const YY_NOEXCEPT;
/// Backward compatibility (Bison 3.6).
symbol_kind_type type_get () const YY_NOEXCEPT;
/// The symbol type.
/// \a empty_symbol when empty.
/// An int, not token_number_type, to be able to store empty_symbol.
int type;
/// The symbol kind.
/// \a ]b4_symbol_prefix[YYEMPTY when empty.
symbol_kind_type kind_;
};
/// Backward compatibility for a private implementation detail (Bison 3.6).
typedef by_kind by_type;
/// "External" symbols: returned by the scanner.
struct symbol_type : basic_symbol<by_type>
struct symbol_type : basic_symbol<by_kind>
{]b4_variant_if([[
/// Superclass.
typedef basic_symbol<by_type> super_type;
typedef basic_symbol<by_kind> super_type;
/// Empty symbol.
symbol_type () {}
@@ -396,25 +464,13 @@ m4_define([b4_symbol_type_define],
# Provide the implementation needed by the public types.
m4_define([b4_public_types_define],
[[ // basic_symbol.
#if 201103L <= YY_CPLUSPLUS
template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (basic_symbol&& that)
: Base (std::move (that))
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
, location (std::move (that.location))])[
{]b4_variant_if([
b4_symbol_variant([this->type_get ()], [value], [move],
[std::move (that.value)])
])[}
#endif
template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
: Base (that)
, value (]b4_variant_if([], [that.value]))b4_locations_if([
, location (that.location)])[
{]b4_variant_if([
b4_symbol_variant([this->type_get ()], [value], [copy],
b4_symbol_variant([this->kind ()], [value], [copy],
[YY_MOVE (that.value)])
])[}
@@ -439,13 +495,20 @@ m4_define([b4_public_types_define],
, location (YY_MOVE (l))])[
{]b4_variant_if([[
(void) v;
]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
template <typename Base>
]b4_parser_class[::symbol_kind_type
]b4_parser_class[::basic_symbol<Base>::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
template <typename Base>
bool
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
{
return Base::type_get () == empty_symbol;
return this->kind () == ]b4_symbol(-2, kind)[;
}
template <typename Base>
@@ -453,67 +516,58 @@ m4_define([b4_public_types_define],
]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s)
{
super_type::move (s);
]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move],
]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move],
[YY_MOVE (s.value)])],
[value = YY_MOVE (s.value);])[]b4_locations_if([
location = YY_MOVE (s.location);])[
}
// by_type.
]b4_inline([$1])b4_parser_class[::by_type::by_type ()
: type (empty_symbol)
// by_kind.
]b4_inline([$1])b4_parser_class[::by_kind::by_kind ()
: kind_ (]b4_symbol(-2, kind)[)
{}
#if 201103L <= YY_CPLUSPLUS
]b4_inline([$1])b4_parser_class[::by_type::by_type (by_type&& that)
: type (that.type)
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that)
: kind_ (that.kind_)
{
that.clear ();
}
#endif
]b4_inline([$1])b4_parser_class[::by_type::by_type (const by_type& that)
: type (that.type)
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that)
: kind_ (that.kind_)
{}
]b4_inline([$1])b4_parser_class[::by_type::by_type (token_type t)
: type (yytranslate_ (t))
]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t)
: kind_ (yytranslate_ (t))
{}
]b4_inline([$1])[void
]b4_parser_class[::by_type::clear ()
]b4_parser_class[::by_kind::clear ()
{
type = empty_symbol;
kind_ = ]b4_symbol(-2, kind)[;
}
]b4_inline([$1])[void
]b4_parser_class[::by_type::move (by_type& that)
]b4_parser_class[::by_kind::move (by_kind& that)
{
type = that.type;
kind_ = that.kind_;
that.clear ();
}
]b4_inline([$1])[int
]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT
]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT
{
return type;
return kind_;
}
]b4_token_ctor_if([[
]b4_inline([$1])b4_parser_class[::token_type
]b4_parser_class[::by_type::token () const YY_NOEXCEPT
]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT
{
// YYTOKNUM[NUM] -- (External) token number corresponding to the
// (internal) symbol number NUM (which must be that of a token). */
static
const ]b4_int_type_for([b4_toknum])[
yytoken_number_[] =
{
]b4_toknum[
};
return token_type (yytoken_number_[type]);
return this->kind ();
}
]])[]dnl
])
]])
# b4_token_constructor_define
@@ -528,27 +582,28 @@ m4_define([b4_token_constructor_define], [])
# Define yytranslate_. Sometimes used in the header file ($1=hh),
# sometimes in the cc file.
m4_define([b4_yytranslate_define],
[ b4_inline([$1])b4_parser_class[::token_number_type
]b4_parser_class[::yytranslate_ (]b4_token_ctor_if([token_type],
[int])[ t)
[ b4_inline([$1])b4_parser_class[::symbol_kind_type
]b4_parser_class[::yytranslate_ (int t)
{
// YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
]b4_api_token_raw_if(
[[ return static_cast<symbol_kind_type> (t);]],
[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
// TOKEN-NUM as returned by yylex.
static
const token_number_type
const ]b4_int_type_for([b4_translate])[
translate_table[] =
{
]b4_translate[
};
const unsigned user_token_number_max_ = ]b4_user_token_number_max[;
const token_number_type undef_token_ = ]b4_undef_token_number[;
// Last valid token kind.
const int code_max = ]b4_code_max[;
if (static_cast<int> (t) <= yyeof_)
return yyeof_;
else if (static_cast<unsigned> (t) <= user_token_number_max_)
return translate_table[t];
if (t <= 0)
return symbol_kind::]b4_symbol_prefix[YYEOF;
else if (t <= code_max)
return YY_CAST (symbol_kind_type, translate_table[t]);
else
return undef_token_;
return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
}
]])
+8 -2
View File
@@ -2,7 +2,7 @@
# Common code for C-like languages (C, C++, Java, etc.)
# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -17,15 +17,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# _b4_comment(TEXT, OPEN, CONTINUE, END)
# --------------------------------------
# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
# Avoid adding indentation to the first line, as the indentation comes
# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close
# the comments before its end.
#
# Prefix all the output lines with PREFIX.
m4_define([_b4_comment],
[$2[]m4_bpatsubst(m4_expand([[$1]]), [
[$2[]b4_gsub(m4_expand([$1]),
[[*]/], [*\\/],
[/[*]], [/\\*],
[
\(.\)], [
$3\1])$4])
+1 -1
View File
@@ -2,7 +2,7 @@
# C skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
+309 -120
View File
@@ -2,7 +2,7 @@
# C M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation,
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
@@ -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], [[
@@ -101,6 +101,7 @@ m4_define_default([b4_prefix], [b4_api_prefix])
b4_percent_define_default([[api.value.union.name]],
[b4_api_PREFIX[][STYPE]])
b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]])
## ------------------------ ##
## Pure/impure interfaces. ##
@@ -129,6 +130,13 @@ m4_define([b4_user_args],
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
# b4_user_formals
# ---------------
# The possible parse-params formal arguments preceded by a comma.
m4_define([b4_user_formals],
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
# b4_parse_param
# --------------
# If defined, b4_parse_param arrives double quoted, but below we prefer
@@ -167,38 +175,158 @@ b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
# b4_int_type(MIN, MAX)
# ---------------------
# Return the smallest int type able to handle numbers ranging from
# MIN to MAX (included).
# Return a narrow int type able to handle integers ranging from MIN
# to MAX (included) in portable C code. Assume MIN and MAX fall in
# 'int' range.
m4_define([b4_int_type],
[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
b4_ints_in($@, [-128], [127]), [1], [signed char],
[m4_if(b4_ints_in($@, [-127], [127]), [1], [signed char],
b4_ints_in($@, [0], [255]), [1], [unsigned char],
b4_ints_in($@, [-32767], [32767]), [1], [short],
b4_ints_in($@, [0], [65535]), [1], [unsigned short],
b4_ints_in($@, [-32768], [32767]), [1], [short],
m4_eval([0 <= $1]), [1], [unsigned],
[int])])
# b4_c99_int_type(MIN, MAX)
# -------------------------
# Like b4_int_type, but for C99.
# b4_c99_int_type_define replaces b4_int_type with this.
m4_define([b4_c99_int_type],
[m4_if(b4_ints_in($@, [-127], [127]), [1], [yytype_int8],
b4_ints_in($@, [0], [255]), [1], [yytype_uint8],
b4_ints_in($@, [-32767], [32767]), [1], [yytype_int16],
b4_ints_in($@, [0], [65535]), [1], [yytype_uint16],
[int])])
# b4_c99_int_type_define
# ----------------------
# Define private types suitable for holding small integers in C99 or later.
m4_define([b4_c99_int_type_define],
[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl
[#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */
#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
# define YY_STDINT_H
# endif
#endif
/* Narrow types that promote to a signed type and that can represent a
signed or unsigned integer of at least N bits. In tables they can
save space and decrease cache pressure. Promoting to a signed type
helps avoid bugs in integer arithmetic. */
#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif
#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif]])
# b4_sizes_types_define
# ---------------------
# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM,
# and YYSIZEOF.
m4_define([b4_sizes_types_define],
[[#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
]])
# b4_int_type_for(NAME)
# ---------------------
# Return the smallest int type able to handle numbers ranging from
# Return a narrow int type able to handle numbers ranging from
# 'NAME_min' to 'NAME_max' (included).
m4_define([b4_int_type_for],
[b4_int_type($1_min, $1_max)])
# b4_table_value_equals(TABLE, VALUE, LITERAL)
# --------------------------------------------
# b4_table_value_equals(TABLE, VALUE, LITERAL, SYMBOL)
# ----------------------------------------------------
# Without inducing a comparison warning from the compiler, check if the
# literal value LITERAL equals VALUE from table TABLE, which must have
# TABLE_min and TABLE_max defined.
# TABLE_min and TABLE_max defined. SYMBOL denotes
m4_define([b4_table_value_equals],
[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
|| m4_indir([b4_]$1[_max]) < $3), [1],
[[0]],
[(!!(($2) == ($3)))])])
[(($2) == $4)])])
## ----------------- ##
@@ -210,34 +338,40 @@ m4_define([b4_table_value_equals],
# Provide portable compiler "attributes". If "noreturn" is passed, define
# _Noreturn.
m4_define([b4_attribute_define],
[[#ifndef YY_ATTRIBUTE
# if (defined __GNUC__ \
&& (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
|| defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
[[#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define YY_ATTRIBUTE(Spec) /* empty */
# define YY_ATTRIBUTE_PURE
# endif
#endif
#ifndef YY_ATTRIBUTE_PURE
# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
#endif
#ifndef YY_ATTRIBUTE_UNUSED
# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
# define YY_ATTRIBUTE_UNUSED
# endif
#endif
]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */
]dnl This is an exact copy of lib/_Noreturn.h.
]dnl This is close to lib/_Noreturn.h, except that we do enable
dnl the use of [[noreturn]], because _Noreturn is used in places
dnl where [[noreturn]] works in C++. We need this in particular
dnl because of glr.cc which compiles code from glr.c in C++.
dnl And the C++ compiler chokes on _Noreturn. Also, we do not
dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings.
[#ifndef _Noreturn
# if (defined __cplusplus \
&& ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|| (defined _MSC_VER && 1900 <= _MSC_VER)))
# define _Noreturn [[noreturn]]
# elif ((!defined __cplusplus || defined __clang__) \
# elif (!defined __cplusplus \
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__)))
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|| (defined __apple_build_version__ \
? 6000000 <= __apple_build_version__ \
: 3 < __clang_major__ + (5 <= __clang_minor__))))
/* _Noreturn works as-is. */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
# define _Noreturn __attribute__ ((__noreturn__))
@@ -257,11 +391,11 @@ m4_define([b4_attribute_define],
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
@@ -273,9 +407,36 @@ m4_define([b4_attribute_define],
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END \
_Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif
]])
# b4_cast_define
# --------------
m4_define([b4_cast_define],
[# ifndef YY_CAST
# ifdef __cplusplus
# define YY_CAST(Type, Val) static_cast<Type> (Val)
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
# else
# define YY_CAST(Type, Val) ((Type) (Val))
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
# endif
# endif[]dnl
])
# b4_null_define
# --------------
# Portability issues: define a YY_NULLPTR appropriate for the current
@@ -321,9 +482,22 @@ static const b4_int_type_for([$2]) yy$1[[]] =
])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
## ------------- ##
## Token kinds. ##
## ------------- ##
# Because C enums are not scoped, because tokens are exposed in the
# header, and because these tokens are common to all the parsers, we
# need to make sure their names don't collide: use the api.prefix.
# YYEOF is special, since the user may give it a different name.
m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]])
m4_define([b4_symbol(-2, tag)], [[No symbol.]])
m4_if(b4_symbol(0, id), [YYEOF],
[m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])])
m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]])
m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]])
# b4_token_define(TOKEN-NUM)
# --------------------------
@@ -335,44 +509,92 @@ m4_define([b4_token_define],
# ----------------
# Output the definition of the tokens.
m4_define([b4_token_defines],
[b4_any_token_visible_if([/* Tokens. */
m4_join([
[[/* Token kinds. */
#define ]b4_symbol([-2], [id])[ -2
]m4_join([
], b4_symbol_map([b4_token_define]))
])])
])
# b4_token_enum(TOKEN-NUM)
# ------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
[b4_token_format([%s = %s], [$1])])
[b4_token_visible_if([$1],
[m4_format([ %-30s %s],
m4_format([[%s = %s%s%s]],
b4_symbol([$1], [id]),
b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])),
m4_if([$1], b4_last_enum_token, [], [[,]])),
[b4_symbol_tag_comment([$1])])])])
# b4_token_enums
# --------------
# Output the definition of the tokens (if there are) as enums.
# The definition of the token kinds.
m4_define([b4_token_enums],
[b4_any_token_visible_if([[/* Token type. */
[b4_any_token_visible_if([[/* Token kinds. */
#ifndef ]b4_api_PREFIX[TOKENTYPE
# define ]b4_api_PREFIX[TOKENTYPE
enum ]b4_api_prefix[tokentype
{
]m4_join([,
],
b4_symbol_map([b4_token_enum]))[
};
]b4_symbol([-2], [id])[ = -2,
]b4_symbol_foreach([b4_token_enum])dnl
[ };
typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t;
#endif
]])])
# b4_token_enums_defines
# ----------------------
# Output the definition of the tokens (if there are any) as enums and,
# The definition of the tokens (if there are any) as enums and,
# if POSIX Yacc is enabled, as #defines.
m4_define([b4_token_enums_defines],
[b4_token_enums[]b4_yacc_if([b4_token_defines])])
# b4_symbol_translate(STRING)
# ---------------------------
# Used by "bison" in the array of symbol names to mark those that
# require translation.
m4_define([b4_symbol_translate],
[[N_($1)]])
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-40s %s],
m4_format([[%s = %s%s%s]],
b4_symbol([$1], [kind_base]),
[$1],
m4_if([$1], b4_last_symbol, [], [[,]])),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[/* Symbol kind. */
enum yysymbol_kind_t
{
]b4_symbol([-2], kind_base)[ = -2,
]b4_symbol_foreach([b4_symbol_enum])dnl
[};
typedef enum yysymbol_kind_t yysymbol_kind_t;
]])])
## ----------------- ##
## Semantic Values. ##
## ----------------- ##
@@ -396,15 +618,6 @@ m4_define([b4_symbol_value],
## ---------------------- ##
# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
# -----------------------------------------------------------
# Declare the function NAME in C.
m4_define([b4_function_define],
[$2
$1 (b4_formals(m4_shift2($@)))[]dnl
])
# b4_formals([DECL1, NAME1], ...)
# -------------------------------
# The formal arguments of a C function definition.
@@ -418,21 +631,6 @@ m4_define([b4_formal],
## ----------------------- ##
## Declaring C functions. ##
## ----------------------- ##
# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
# ------------------------------------------------------------
# Declare the function NAME.
m4_define([b4_function_declare],
[$2 $1 (b4_formals(m4_shift2($@)));[]dnl
])
## --------------------- ##
## Calling C functions. ##
## --------------------- ##
@@ -469,10 +667,10 @@ m4_define([b4_sync_start], [[#]line $1 $2])
## User actions. ##
## -------------- ##
# b4_case(LABEL, STATEMENTS)
# --------------------------
# b4_case(LABEL, STATEMENTS, [COMMENTS])
# --------------------------------------
m4_define([b4_case],
[ case $1:
[ case $1:m4_ifval([$3], [ b4_comment([$3])])
$2
b4_syncline([@oline@], [@ofile@])dnl
break;])
@@ -496,18 +694,15 @@ m4_define_default([b4_yydestruct_define],
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
]b4_function_define([yydestruct],
[static void],
[[const char *yymsg], [yymsg]],
[[int yytype], [yytype]],
[[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
static void
yydestruct (const char *yymsg,
yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl
[[, YYLTYPE *yylocationp]])[]b4_user_formals[)
{
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
[ if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_symbol_actions([destructor])[
@@ -525,13 +720,10 @@ m4_define_default([b4_yy_symbol_print_define],
| Print this symbol's value on YYO. |
`-----------------------------------*/
]b4_function_define([yy_symbol_value_print],
[static void],
[[FILE *yyo], [yyo]],
[[int yytype], [yytype]],
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
static void
yy_symbol_value_print (FILE *yyo,
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
{
FILE *yyoutput = yyo;
]b4_parse_param_use([yyoutput], [yylocationp])dnl
@@ -540,12 +732,14 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
dnl glr.c does not feature yytoknum.
m4_if(b4_skeleton, ["yacc.c"],
[[# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
if (yykind < YYNTOKENS)
YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
# endif
]])dnl
b4_percent_code_get([[pre-printer]])dnl
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
b4_symbol_actions([printer])
YY_IGNORE_MAYBE_UNINITIALIZED_END
b4_percent_code_get([[post-printer]])dnl
[}
@@ -554,21 +748,18 @@ b4_percent_code_get([[post-printer]])dnl
| Print this symbol on YYO. |
`---------------------------*/
]b4_function_define([yy_symbol_print],
[static void],
[[FILE *yyo], [yyo]],
[[int yytype], [yytype]],
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
static void
yy_symbol_print (FILE *yyo,
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
{
YYFPRINTF (yyo, "%s %s (",
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
YYFPRINTF (yyo, ": ");
])dnl
[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl
[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl
b4_locations_if([, yylocationp])[]b4_user_args[);
YYFPRINTF (yyo, ")");
}]dnl
@@ -594,11 +785,11 @@ m4_define([b4_symbol_type_register],
[m4_define([b4_symbol($1, type_tag)],
[b4_symbol_if([$1], [has_id],
[b4_symbol([$1], [id])],
[yytype_[]b4_symbol([$1], [number])])])dnl
[yykind_[]b4_symbol([$1], [number])])])dnl
m4_append([b4_union_members],
m4_expand([
b4_symbol_tag_comment([$1])dnl
b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]))
m4_expand([m4_format([ %-40s %s],
m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]),
[b4_symbol_tag_comment([$1])])]))
])
@@ -831,16 +1022,14 @@ m4_define([b4_yy_location_print_define],
This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
# ifndef YY_LOCATION_PRINT
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
YY_ATTRIBUTE_UNUSED
]b4_function_define([yy_location_print_],
[static int],
[[FILE *yyo], [yyo]],
[[YYLTYPE const * const yylocp], [yylocp]])[
static int
yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
{
int res = 0;
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
@@ -864,17 +1053,17 @@ YY_ATTRIBUTE_UNUSED
return res;
}
# define YY_LOCATION_PRINT(File, Loc) \
# define YY_LOCATION_PRINT(File, Loc) \
yy_location_print_ (File, &(Loc))
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
#endif]],
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
# endif /* !defined YY_LOCATION_PRINT */]],
[[/* This macro is provided for backward compatibility. */
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif]])
# ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif]])
])
# b4_yyloc_default
+1 -1
View File
@@ -2,7 +2,7 @@
# D skeleton dispatching for Bison.
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# 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
+65 -25
View File
@@ -2,7 +2,7 @@
# D language support for Bison
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# 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
@@ -38,6 +38,11 @@ m4_define([b4_comment],
[_b4_comment([$1], [$2/* ], [$2 ], [ */])])
# b4_sync_start(LINE, FILE)
# -------------------------
m4_define([b4_sync_start], [[#]line $1 $2])
# b4_list2(LIST1, LIST2)
# ----------------------
# Join two lists with a comma if necessary.
@@ -95,21 +100,15 @@ m4_define([b4_location_type_if],
[b4_percent_define_ifdef([[location_type]], [$1], [$2])])
# b4_locations_if(TRUE, FALSE)
# ----------------------------
m4_define([b4_locations_if],
[m4_if(b4_locations_flag, 1, [$1], [$2])])
# 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[;
]])
## ------------ ##
@@ -149,9 +148,11 @@ private static immutable b4_int_type_for([$2])[[]] yy$1_ =
])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
## ------------- ##
## Token kinds. ##
## ------------- ##
m4_define([b4_symbol(-2, id)], [[YYEMPTY]])
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# ---------------------------------------
@@ -160,22 +161,61 @@ m4_define([b4_token_enum],
[b4_token_format([ %s = %s,
], [$1])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# b4_token_enums
# --------------
# Output the definition of the tokens as enums.
m4_define([b4_token_enums],
[/* Tokens. */
public enum YYTokenType {
/** Token returned by the scanner to signal the end of its input. */
EOF = 0,
b4_symbol_foreach([b4_token_enum])
[/* Token kinds. */
public enum TokenKind {
]b4_symbol_kind([-2])[ = -2,
b4_symbol_foreach([b4_token_enum])dnl
}
])
# b4-case(ID, CODE)
# -----------------
m4_define([b4_case], [ case $1:
## -------------- ##
## Symbol kinds. ##
## -------------- ##
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
# b4_symbol_kind(NUM)
# -------------------
m4_define([b4_symbol_kind],
[SymbolKind.b4_symbol_kind_base($@)])
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-30s %s],
m4_format([[%s = %s,]],
b4_symbol([$1], [kind_base]),
[$1]),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[ /* Symbol kinds. */
public enum SymbolKind
{
]b4_symbol(-2, kind_base)[ = -2, /* No symbol. */
]b4_symbol_foreach([b4_symbol_enum])dnl
[ };
]])])
# b4-case(ID, CODE, [COMMENTS])
# -----------------------------
m4_define([b4_case], [ case $1:m4_ifval([$3], [ b4_comment([$3])])
$2
break;])
+657 -521
View File
File diff suppressed because it is too large Load Diff
+103 -75
View File
@@ -1,6 +1,6 @@
# C++ GLR skeleton for Bison
# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -72,24 +72,17 @@ m4_defn([b4_parse_param]))],
# Bypass the default implementation to generate the "yy_symbol_print"
# and "yy_symbol_value_print" functions.
m4_define([b4_yy_symbol_print_define],
[[
/*--------------------.
[[/*--------------------.
| Print this symbol. |
`--------------------*/
]b4_function_define([yy_symbol_print],
[static void],
[[FILE *], []],
[[int yytype], [yytype]],
[[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep],
[yyvaluep]][]dnl
b4_locations_if([,
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
[yylocationp]]]),
b4_parse_param)[
static void
yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken,
const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[,
const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[)
{
]b4_parse_param_use[]dnl
[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
[ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[);
}
]])[
@@ -101,45 +94,24 @@ m4_defn([b4_initial_action])]))])[
# Hijack the post prologue to declare yyerror.
]m4_append([b4_post_prologue],
[b4_syncline([@oline@], [@ofile@])dnl
b4_function_declare([yyerror],
[static void],b4_locations_if([
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
[yylocationp]],])
b4_parse_param,
[[const char* msg], [msg]])])[
[static void
yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
])[const char* msg);]])[
#undef yynerrs
#undef yychar
#undef yylval]b4_locations_if([
#undef yylloc])
m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */
#define yyparse ]b4_prefix[parse
#define yylex ]b4_prefix[lex
#define yyerror ]b4_prefix[error
#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[
#define yylval ]b4_prefix[lval
#define yychar ]b4_prefix[char
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])]))
# Hijack the epilogue to define implementations (yyerror, parser member
# Inserted before the epilogue to define implementations (yyerror, parser member
# functions etc.).
m4_append([b4_epilogue],
]m4_define([b4_glr_cc_pre_epilogue],
[b4_syncline([@oline@], [@ofile@])dnl
[
/*------------------.
| Report an error. |
`------------------*/
]b4_function_define([yyerror],
[static void],b4_locations_if([
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
[yylocationp]],])
b4_parse_param,
[[const char* msg], [msg]])[
static void
yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
])[const char* msg)
{
]b4_parse_param_use[]dnl
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
@@ -181,9 +153,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
`--------------------*/
void
]b4_parser_class[::yy_symbol_value_print_ (int yytype,
]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[)
const location_type* yylocationp]])[) const
{]b4_locations_if([[
YYUSE (yylocationp);]])[
YYUSE (yyvaluep);
@@ -195,14 +167,14 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
void
]b4_parser_class[::yy_symbol_print_ (int yytype,
]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[)
const location_type* yylocationp]])[) const
{
*yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
<< ' ' << yytname[yytype] << " ("]b4_locations_if([[
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[
<< *yylocationp << ": "]])[;
yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[);
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
*yycdebug_ << ')';
}
@@ -238,6 +210,57 @@ b4_namespace_close[]dnl
])
m4_define([b4_define_symbol_kind],
[m4_format([#define %-15s %s],
b4_symbol($][1, kind_base),
b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base))
])
# b4_glr_cc_setup
# ---------------
# Setup redirections for glr.c: Map the names used in c.m4 to the ones used
# in c++.m4.
m4_define([b4_glr_cc_setup],
[[#undef ]b4_symbol(-2, [id])[
#define ]b4_symbol(-2, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(-2, [id])[
#undef ]b4_symbol(0, [id])[
#define ]b4_symbol(0, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[
#undef ]b4_symbol(1, [id])[
#define ]b4_symbol(1, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(1, [id])[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
// Expose C++ symbol kinds to C.
]b4_define_symbol_kind(-2)dnl
b4_symbol_foreach([b4_define_symbol_kind])])[
]])
m4_define([b4_undef_symbol_kind],
[[#undef ]b4_symbol($1, kind_base)[
]])
# b4_glr_cc_cleanup
# -----------------
# Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup],
[[#undef ]b4_symbol(-2, [id])[
#undef ]b4_symbol(0, [id])[
#undef ]b4_symbol(1, [id])[
]b4_undef_symbol_kind(-2)dnl
b4_symbol_foreach([b4_undef_symbol_kind])dnl
])
# b4_shared_declarations(hh|cc)
# -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh)
@@ -257,6 +280,21 @@ b4_percent_code_get([[requires]])[
]b4_attribute_define[
]b4_null_define[
// This skeleton is based on C, yet compiles it as C++.
// So expect warnings about C style casts.
#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's
// -pedantic reports as being a C++11 extension.
#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \
&& defined __clang__ && 4 <= __clang_major__
# pragma clang diagnostic ignored "-Wc++11-long-long"
#endif
// Whether we are compiled with exception support.
#ifndef YY_EXCEPTIONS
# if defined __GNUC__ && !defined __EXCEPTIONS
@@ -313,53 +351,43 @@ b4_percent_code_get([[requires]])[
# if ]b4_api_PREFIX[DEBUG
public:
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yykind The symbol kind.
/// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[
virtual void yy_symbol_value_print_ (int yytype,
virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[);
const location_type* yylocationp]])[) const;
/// \brief Report a symbol on the debug stream.
/// \param yytype The token type.
/// \param yykind The symbol kind.
/// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[
virtual void yy_symbol_print_ (int yytype,
virtual void yy_symbol_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[);
const location_type* yylocationp]])[) const;
private:
// Debugging.
/// Debug stream.
std::ostream* yycdebug_;
#endif
]b4_parse_param_vars[
};
]dnl Redirections for glr.c.
b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines])
[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
]b4_namespace_close[
]b4_percent_code_get([[provides]])[
]m4_popdef([b4_parse_param])dnl
])
])[
b4_defines_if(
]b4_defines_if(
[b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2019])[
[2002-2015, 2018-2020])[
// C++ GLR parser skeleton written by Akim Demaille.
]b4_disclaimer[
]b4_cpp_guard_open([b4_spec_header_file])[
]b4_cpp_guard_open([b4_spec_mapped_header_file])[
]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_header_file])[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[
]b4_output_end])
# Let glr.c (and b4_shared_declarations) believe that the user
+1 -1
View File
@@ -2,7 +2,7 @@
# Java skeleton dispatching for Bison.
# Copyright (C) 2007, 2009-2015, 2018-2019 Free Software Foundation,
# Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
+171 -22
View File
@@ -2,7 +2,7 @@
# Java language support for Bison
# Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -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[;
]])
## ------------ ##
@@ -106,10 +106,13 @@ m4_define([b4_null], [null])
# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
# -------------------------------------------------------
# We use intermediate functions (e.g., yypact_init) to work around the
# 64KB limit for JVM methods. See
# https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.
m4_define([b4_typed_parser_table_define],
[m4_ifval([$4], [b4_comment([$4])
])dnl
[private static final ]$1[ yy$2_[] = yy$2_init();
[private static final ]$1[[] yy$2_ = yy$2_init();
private static final ]$1[[] yy$2_init()
{
return new ]$1[[]
@@ -125,40 +128,158 @@ m4_define([b4_integral_parser_table_define],
[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
## ------------- ##
## Token kinds. ##
## ------------- ##
# b4_token_enum(TOKEN-NUM)
# ------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
[b4_token_format([ /** Token number, to be returned by the scanner. */
static final int %s = %s;
], [$1])])
[b4_token_visible_if([$1],
[m4_format([[ /** Token %s, to be returned by the scanner. */
static final int %s = %s%s;
]],
b4_symbol([$1], [tag]),
b4_symbol([$1], [id]),
b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])))])])
# b4_token_enums
# --------------
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
[b4_any_token_visible_if([/* Tokens. */
[b4_any_token_visible_if([ /* Token kinds. */
b4_symbol_foreach([b4_token_enum])])])
# b4-case(ID, CODE)
# -----------------
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_symbol_kind(NUM)
# -------------------
m4_define([b4_symbol_kind],
[SymbolKind.b4_symbol_kind_base($@)])
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-30s %s],
m4_format([[%s(%s)%s]],
b4_symbol([$1], [kind_base]),
[$1],
m4_if([$1], b4_last_symbol, [[;]], [[,]])),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
m4_define([b4_declare_symbol_enum],
[[ public enum SymbolKind
{
]b4_symbol_foreach([b4_symbol_enum])[
private final int yycode_;
SymbolKind (int n) {
this.yycode_ = n;
}
private static final SymbolKind[] values_ = {
]m4_map_args_sep([b4_symbol_kind(], [)], [,
], b4_symbol_numbers)[
};
static final SymbolKind get(int code) {
return values_[code];
}
public final int getCode() {
return this.yycode_;
}
]b4_parse_error_bmatch(
[simple\|verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
private static String yytnamerr_(String yystr)
{
if (yystr.charAt (0) == '"')
{
StringBuffer yyr = new StringBuffer();
strip_quotes: for (int i = 1; i < yystr.length(); i++)
switch (yystr.charAt(i))
{
case '\'':
case ',':
break strip_quotes;
case '\\':
if (yystr.charAt(++i) != '\\')
break strip_quotes;
/* Fall through. */
default:
yyr.append(yystr.charAt(i));
break;
case '"':
return yyr.toString();
}
}
return yystr;
}
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
/* The user-facing name of this symbol. */
public final String getName() {
return yytnamerr_(yytname_[yycode_]);
}
]],
[custom\|detailed],
[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[
/* The user-facing name of this symbol. */
public final String getName() {
return yynames_[yycode_];
}]])[
};
]])])
# b4_case(ID, CODE, [COMMENTS])
# -----------------------------
# We need to fool Java's stupid unreachable code detection.
m4_define([b4_case], [ case $1:
m4_define([b4_case],
[ case $1:m4_ifval([$3], [ b4_comment([$3])])
if (yyn == $1)
$2;
break;
])
])
# b4_predicate_case(LABEL, CONDITIONS)
# ------------------------------------
m4_define([b4_predicate_case], [ case $1:
m4_define([b4_predicate_case],
[ case $1:
if (! ($2)) YYERROR;
break;
])
])
## -------- ##
@@ -183,9 +304,21 @@ b4_percent_define_check_kind([[throws]], [code], [deprecated])
m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
b4_percent_define_default([[api.value.type]], [[Object]])
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
# %name-prefix
m4_define_default([b4_prefix], [[YY]])
# b4_api_prefix, b4_api_PREFIX
# ----------------------------
# Corresponds to %define api.prefix
b4_percent_define_default([[api.prefix]], [[YY]])
m4_define([b4_api_prefix],
[b4_percent_define_get([[api.prefix]])])
m4_define([b4_api_PREFIX],
[m4_toupper(b4_api_prefix)])
# b4_prefix
# ---------
# If the %name-prefix is not given, it is api.prefix.
m4_define_default([b4_prefix], [b4_api_prefix])
b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser])
m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])])
@@ -211,6 +344,22 @@ m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
## ----------------- ##
# b4_symbol_translate(STRING)
# ---------------------------
# Used by "bison" in the array of symbol names to mark those that
# require translation.
m4_define([b4_symbol_translate],
[[i18n($1)]])
# b4_trans(STRING)
# ----------------
# Translate a string if i18n is enabled. Avoid collision with b4_translate.
m4_define([b4_trans],
[b4_has_translations_if([i18n($1)], [$1])])
# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])
# ----------------------------------------------
# See README.
@@ -350,4 +499,4 @@ m4_define([b4_var_decl],
# -----------------------
# Expand to either an empty string or "throws THROWS".
m4_define([b4_maybe_throws],
[m4_ifval($1, [throws $1])])
[m4_ifval($1, [ throws $1])])
+601 -227
View File
File diff suppressed because it is too large Load Diff
+302 -275
View File
@@ -1,6 +1,6 @@
# Java skeleton for Bison -*- autoconf -*-
# D skeleton for Bison -*- autoconf -*-
# Copyright (C) 2007-2011, 2019 Free Software Foundation, Inc.
# Copyright (C) 2007-2012, 2019-2020 Free Software Foundation, Inc.
# 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
@@ -18,12 +18,11 @@
m4_include(b4_skeletonsdir/[d.m4])
m4_divert_push(0)dnl
@output(b4_parser_file_name@)@
b4_output_begin([b4_parser_file_name])
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in D],
[2007-2012, 2019])
b4_percent_define_ifdef([package], [module b4_percent_define_get([package]);
[2007-2012, 2019-2020])[
]b4_disclaimer[
]b4_percent_define_ifdef([package], [module b4_percent_define_get([package]);
])[
version(D_Version2) {
} else {
@@ -81,68 +80,14 @@ public interface Lexer
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[string s);
}
private final struct YYStackElement{
int state;
]b4_yystype[ value;]b4_locations_if(
b4_location_type[[] location;])[
}
private final struct YYStack {
private YYStackElement[] stack = [];
public final @@property ulong height()
{
return stack.length;
}
public final void push (int state, ]b4_yystype[ value]dnl
b4_locations_if([, ref ]b4_location_type[ loc])[)
{
stack ~= YYStackElement(state, value]b4_locations_if([, loc])[);
}
public final void pop ()
{
pop (1);
}
public final void pop (int num)
{
stack.length -= num;
}
public final int stateAt (int i)
{
return stack[$-i-1].state;
}
]b4_locations_if([[public final ref ]b4_location_type[ locationAt (int i)
{
return stack[$-i-1].location;
}
]])[public final ref ]b4_yystype[ valueAt (int i)
{
return stack[$-i-1].value;
}
// Print the state stack on the debug stream.
public final void print (File stream)
{
stream.write ("Stack now");
for (int i = 0; i < stack.length; i++)
stream.write (" %d", stack[i].state);
stream.writeln ();
}
}
]b4_locations_if(b4_position_type_if([[[
]b4_locations_if([b4_position_type_if([[
static assert(__traits(compiles,
(new ]b4_position_type[[1])[0]=(new ]b4_position_type[[1])[0]),
"struct/class ]b4_position_type[ must be default-constructible "
"and assignable");
static assert(__traits(compiles, (new string[1])[0]=(new ]b4_position_type[).toString()),
"error: struct/class ]b4_position_type[ must have toString method");
]]], [[
]], [[
/**
* A struct denoting a point in the input.*/
public struct ]b4_position_type[ {
@@ -152,15 +97,18 @@ public struct ]b4_position_type[ {
/** The line number within an input file. */
public int line = 1;
/** The name of the input file. */
public string filename = "(unspecified file)";
public string filename = null;
/**
* Return a string representation of the position. */
* A string representation of the position. */
public string toString() const {
return format("%s:%d.%d", filename, line, column);
if (filename)
return format("%s:%d.%d", filename, line, column);
else
return format("%d.%d", line, column);
}
}
]])b4_location_type_if([[[
]])b4_location_type_if([[
static assert(__traits(compiles, (new ]b4_location_type[((new ]b4_position_type[[1])[0]))) &&
__traits(compiles, (new ]b4_location_type[((new ]b4_position_type[[1])[0], (new ]b4_position_type[[1])[0]))),
"error: struct/class ]b4_location_type[ must have "
@@ -174,7 +122,7 @@ static assert(__traits(compiles, (new ]b4_location_type[[1])[0].begin=(new ]b4_l
static assert(__traits(compiles, (new string[1])[0]=(new ]b4_location_type[[1])[0].toString()),
"error: struct/class ]b4_location_type[ must have toString method.");
private immutable bool yy_location_is_class = !__traits(compiles, *(new ]b4_location_type[((new ]b4_position_type[[1])[0])));]]], [[
private immutable bool yy_location_is_class = !__traits(compiles, *(new ]b4_location_type[((new ]b4_position_type[[1])[0])));]], [[
/**
* A class defining a pair of positions. Positions, defined by the
* <code>]b4_position_type[</code> class, denote a point in the input.
@@ -196,6 +144,9 @@ public class ]b4_location_type[
this.begin = this.end = loc;
}
public this () {
}
/**
* Create a <code>]b4_location_type[</code> from the endpoints of the range.
* @@param begin The first position included in the range.
@@ -207,32 +158,36 @@ public class ]b4_location_type[
}
/**
* Return a representation of the location. For this to be correct,
* A representation of the location. For this to be correct,
* <code>]b4_position_type[</code> should override the <code>toString</code>
* method. */
public const string toString () const {
if (begin==end)
return begin.toString ();
else
return begin.toString () ~ "-" ~ end.toString ();
public override string toString () const {
auto end_col = 0 < end.column ? end.column - 1 : 0;
auto res = begin.toString ();
if (end.filename && begin.filename != end.filename)
res ~= "-" ~ format("%s:%d.%d", end.filename, end.line, end_col);
else if (begin.line < end.line)
res ~= "-" ~ format("%d.%d", end.line, end_col);
else if (begin.column < end_col)
res ~= "-" ~ format("%d", end_col);
return res;
}
}
private immutable bool yy_location_is_class = true;
]]))m4_ifdef([b4_user_union_members], [private union YYSemanticType
]])])m4_ifdef([b4_user_union_members], [private union YYSemanticType
{
b4_user_union_members
};],
[m4_if(b4_tag_seen_flag, 0,
[[private alias int YYSemanticType;]])])[
]b4_token_enums(b4_tokens)[
]b4_token_enums[
]b4_parser_class_declaration[
{
]b4_identification[
/** True if verbose error messages are enabled. */
public bool errorVerbose = ]b4_flag_value([error_verbose])[;
]b4_declare_symbol_enum[
]b4_locations_if([[
private final ]b4_location_type[ yylloc_from_stack (ref YYStack rhs, int n)
@@ -261,29 +216,27 @@ b4_user_union_members
]b4_lexer_if([[
/**
* Instantiates the Bison-generated parser.
* Instantiate the Bison-generated parser.
*/
public this] (b4_parse_param_decl([b4_lex_param_decl])[) {
this.yylexer = new YYLexer(]b4_lex_param_call[);
this.yyDebugStream = stderr;
]b4_parse_param_cons[
this (new YYLexer(]b4_lex_param_call[));
}
]])[
/**
* Instantiates the Bison-generated parser.
* Instantiate the Bison-generated parser.
* @@param yylexer The scanner that will supply tokens to the parser.
*/
]b4_lexer_if([[protected]], [[public]]) [this (]b4_parse_param_decl([[Lexer yylexer]])[) {
this.yylexer = yylexer;
this.yyDebugStream = stderr;
this.yylexer = yylexer;]b4_parse_trace_if([[
this.yyDebugStream = stderr;]])[
]b4_parse_param_cons[
}
]b4_parse_trace_if([[
private File yyDebugStream;
/**
* Return the <tt>File</tt> on which the debugging output is
* The <tt>File</tt> on which the debugging output is
* printed.
*/
public File getDebugStream () { return yyDebugStream; }
@@ -309,16 +262,22 @@ b4_user_union_members
*/
public final void setDebugLevel(int level) { yydebug = level; }
protected final void yycdebug (string s) {
if (0 < yydebug)
yyDebugStream.write (s);
}
protected final void yycdebugln (string s) {
if (0 < yydebug)
yyDebugStream.writeln (s);
}
]])[
private final int yylex () {
return yylexer.yylex ();
}
protected final void yyerror (]b4_locations_if(ref [b4_location_type[ loc, ]])[string s) {
yylexer.yyerror (]b4_locations_if([loc, ])[s);
}]
[protected final void yycdebug (string s) {
if (yydebug > 0)
yyDebugStream.writeln (s);
}
/**
@@ -345,11 +304,11 @@ b4_user_union_members
private static immutable int YYERRLAB1 = 7;
private static immutable int YYRETURN = 8;
]b4_locations_if([
private static immutable YYSemanticType yy_semantic_null = cast(YYSemanticType)null;])[
private static immutable YYSemanticType yy_semantic_null;])[
private int yyerrstatus_ = 0;
/**
* Return whether error recovery is being done. In this state, the parser
* Whether error recovery is being done. In this state, the parser
* reads token until it reaches a known state, and then restarts normal
* operation. */
public final bool recovering ()
@@ -373,7 +332,8 @@ b4_user_union_members
else
yyval = yystack.valueAt (0);
yy_reduce_print (yyn, yystack);
]b4_parse_trace_if([[
yy_reduce_print (yyn, yystack);]])[
switch (yyn)
{
@@ -381,7 +341,9 @@ b4_user_union_members
default: break;
}
yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
]b4_parse_trace_if([[
import std.conv : to;
yy_symbol_print ("-> $$ =", to!SymbolKind (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
yystack.pop (yylen);
yylen = 0;
@@ -429,33 +391,34 @@ b4_user_union_members
return yyr;
}
}
else if (yystr=="$end")
else if (yystr == "$end")
return "end of input";
return yystr;
}
]b4_parse_trace_if([[
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
private final void yy_symbol_print (string s, int yytype,
private final void yy_symbol_print (string s, SymbolKind yykind,
ref ]b4_yystype[ yyvaluep]dnl
b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
{
if (yydebug > 0) {
string message = s ~ (yytype < yyntokens_ ? " token " : " nterm ")
~ yytname_[yytype] ~ " ("]b4_locations_if([
if (0 < yydebug)
{
string message = s ~ (yykind < yyntokens_ ? " token " : " nterm ")
~ yytname_[yykind] ~ " ("]b4_locations_if([
~ yylocationp.toString() ~ ": "])[;
static if (__traits(compiles, message~=yyvaluep.toString ()))
static if (__traits(compiles, message ~= yyvaluep.toString ()))
message ~= yyvaluep.toString ();
else
message ~= format ("%s", &yyvaluep);
message ~= ")";
yycdebug (message);
yycdebugln (message);
}
}
]])[
/**
* Parse input from the scanner that was specified at object construction
* time. Return whether the end of the input was reached successfully.
@@ -465,9 +428,10 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
*/
public bool parse ()
{
/// Lookahead and lookahead in internal form.
int yychar = yyempty_;
int yytoken = 0;
// Lookahead token kind.
int yychar = TokenKind.YYEMPTY;
// Lookahead symbol kind.
SymbolKind yytoken = ]b4_symbol(-2, kind)[;
/* State. */
int yyn = 0;
@@ -490,9 +454,9 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
/// Semantic value of the lookahead.
]b4_yystype[ yylval;
int yyresult;
bool yyresult;]b4_parse_trace_if([[
yycdebug ("Starting parse\n");
yycdebugln ("Starting parse");]])[
yyerrstatus_ = 0;
]m4_ifdef([b4_initial_action], [
@@ -512,10 +476,10 @@ m4_popdef([b4_at_dollar])])dnl
{
/* New state. Unlike in the C/C++ skeletons, the state is already
pushed when we come here. */
case YYNEWSTATE:
yycdebug (format("Entering state %d\n", yystate));
if (yydebug > 0)
yystack.print (yyDebugStream);
case YYNEWSTATE:]b4_parse_trace_if([[
yycdebugln (format("Entering state %d", yystate));
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
/* Accept? */
if (yystate == yyfinal_)
@@ -530,9 +494,9 @@ m4_popdef([b4_at_dollar])])dnl
}
/* Read a lookahead token. */
if (yychar == yyempty_)
{
yycdebug ("Reading a token: ");
if (yychar == TokenKind.YYEMPTY)
{]b4_parse_trace_if([[
yycdebugln ("Reading a token");]])[
yychar = yylex ();]b4_locations_if([[
static if (yy_location_is_class) {
yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos);
@@ -543,53 +507,57 @@ m4_popdef([b4_at_dollar])])dnl
}
/* Convert token to internal form. */
if (yychar <= YYTokenType.EOF)
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
if (yytoken == ]b4_symbol(1, kind)[)
{
yychar = yytoken = YYTokenType.EOF;
yycdebug ("Now at end of input.\n");
// The scanner already issued an error message, process directly
// to error recovery. But do not keep the error token as
// lookahead, it is too special and may lead us to an endless
// loop in error recovery. */
yychar = TokenKind.]b4_symbol(2, id)[;
yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[
yyerrloc = yylloc;]])[
label = YYERRLAB1;
}
else
{
yytoken = yytranslate_ (yychar);
yy_symbol_print ("Next token is",
yytoken, yylval]b4_locations_if([, yylloc])[);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
label = YYDEFAULT;
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
label = YYDEFAULT;
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
if (yy_table_value_is_error_ (yyn))
label = YYERRLAB;
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
if (yy_table_value_is_error_ (yyn))
label = YYERRLAB;
else
{
yyn = -yyn;
label = YYREDUCE;
}
}
else
{
yyn = -yyn;
label = YYREDUCE;
/* Shift the lookahead token. */]b4_parse_trace_if([[
yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
/* Discard the token being shifted. */
yychar = TokenKind.YYEMPTY;
/* Count tokens shifted since error; after three, turn off error
* status. */
if (yyerrstatus_ > 0)
--yyerrstatus_;
yystate = yyn;
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
label = YYNEWSTATE;
}
}
else
{
/* Shift the lookahead token. */
yy_symbol_print ("Shifting", yytoken,
yylval]b4_locations_if([, yylloc])[);
/* Discard the token being shifted. */
yychar = yyempty_;
/* Count tokens shifted since error; after three, turn off error
* status. */
if (yyerrstatus_ > 0)
--yyerrstatus_;
yystate = yyn;
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
label = YYNEWSTATE;
}
break;
/*-----------------------------------------------------------.
@@ -612,33 +580,33 @@ m4_popdef([b4_at_dollar])])dnl
yystate = yystack.stateAt (0);
break;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
/*--------------------------------------.
| yyerrlab -- here on detecting error. |
`--------------------------------------*/
case YYERRLAB:
/* If not already recovering from an error, report this error. */
if (yyerrstatus_ == 0)
{
++yynerrs_;
if (yychar == yyempty_)
yytoken = yyempty_;
if (yychar == TokenKind.]b4_symbol(-2, id)[)
yytoken = ]b4_symbol(-2, kind)[;
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
}
]b4_locations_if([ yyerrloc = yylloc;])[
]b4_locations_if([
yyerrloc = yylloc;])[
if (yyerrstatus_ == 3)
{
/* If just tried and failed to reuse lookahead token after an
* error, discard it. */
if (yychar <= YYTokenType.EOF)
if (yychar <= TokenKind.]b4_symbol(0, [id])[)
{
/* Return failure if at end of input. */
if (yychar == YYTokenType.EOF)
if (yychar == TokenKind.]b4_symbol(0, [id])[)
return false;
}
else
yychar = yyempty_;
yychar = TokenKind.YYEMPTY;
}
/* Else will try to reuse lookahead token after shifting the error
@@ -665,13 +633,14 @@ m4_popdef([b4_at_dollar])])dnl
case YYERRLAB1:
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
// Pop stack until we find a state that shifts the error token.
for (;;)
{
yyn = yypact_[yystate];
if (!yy_pact_value_is_default_ (yyn))
{
yyn += yyterror_;
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
yyn += ]b4_symbol(1, kind)[;
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(1, kind)[)
{
yyn = yytable_[yyn];
if (0 < yyn)
@@ -685,9 +654,9 @@ m4_popdef([b4_at_dollar])])dnl
]b4_locations_if([ yyerrloc = yystack.locationAt (0);])[
yystack.pop ();
yystate = yystack.stateAt (0);
if (yydebug > 0)
yystack.print (yyDebugStream);
yystate = yystack.stateAt (0);]b4_parse_trace_if([[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
}
]b4_locations_if([
@@ -697,10 +666,9 @@ m4_popdef([b4_at_dollar])])dnl
yyloc = yylloc_from_stack (yystack, 2);
yystack.pop (2);])[
/* Shift the error token. */
yy_symbol_print ("Shifting", yystos_[yyn],
yylval]b4_locations_if([, yyloc])[);
/* Shift the error token. */]b4_parse_trace_if([[
import std.conv : to;
yy_symbol_print ("Shifting", to!SymbolKind (yystos_[yyn]), yylval]b4_locations_if([, yyloc])[);]])[
yystate = yyn;
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
label = YYNEWSTATE;
@@ -708,88 +676,93 @@ m4_popdef([b4_at_dollar])])dnl
/* Accept. */
case YYACCEPT:
return true;
yyresult = true;
label = YYRETURN;
break;
/* Abort. */
case YYABORT:
return false;
yyresult = false;
label = YYRETURN;
break;
case YYRETURN:]b4_parse_trace_if([[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
return yyresult;
}
}
// Generate an error message.
private final string yysyntax_error (int yystate, int tok)
{
if (errorVerbose)
private final string yysyntax_error (int yystate, SymbolKind tok)
{]b4_parse_error_case([verbose], [[
/* There are many possibilities here to consider:
- Assume YYFAIL is not used. It's too flawed to consider.
See
<http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
for details. YYERROR is fine as it does not invoke this
function.
- If this state is a consistent state with a default action,
then the only way this function was invoked is if the
default action is an error action. In that case, don't
check for expected tokens because there are none.
- The only way there can be no lookahead present (in tok) is
if this state is a consistent state with a default action.
Thus, detecting the absence of a lookahead is sufficient to
determine that there is no unexpected or expected token to
report. In that case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this
state is a consistent state with a default action. There
might have been a previous inconsistent state, consistent
state with a non-default action, or user semantic action
that manipulated yychar. (However, yychar is currently out
of scope during semantic actions.)
- Of course, the expected token list depends on states to
have correct lookahead information, and it depends on the
parser not to perform extra reductions after fetching a
lookahead from the scanner and before detecting a syntax
error. Thus, state merging (from LALR or IELR) and default
reductions corrupt the expected token list. However, the
list is correct for canonical LR with one exception: it
will still contain any token that will not be accepted due
to an error action in a later state.
*/
if (tok != ]b4_symbol(-2, kind)[)
{
/* There are many possibilities here to consider:
- Assume YYFAIL is not used. It's too flawed to consider.
See
<http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
for details. YYERROR is fine as it does not invoke this
function.
- If this state is a consistent state with a default action,
then the only way this function was invoked is if the
default action is an error action. In that case, don't
check for expected tokens because there are none.
- The only way there can be no lookahead present (in tok) is
if this state is a consistent state with a default action.
Thus, detecting the absence of a lookahead is sufficient to
determine that there is no unexpected or expected token to
report. In that case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this
state is a consistent state with a default action. There
might have been a previous inconsistent state, consistent
state with a non-default action, or user semantic action
that manipulated yychar. (However, yychar is currently out
of scope during semantic actions.)
- Of course, the expected token list depends on states to
have correct lookahead information, and it depends on the
parser not to perform extra reductions after fetching a
lookahead from the scanner and before detecting a syntax
error. Thus, state merging (from LALR or IELR) and default
reductions corrupt the expected token list. However, the
list is correct for canonical LR with one exception: it
will still contain any token that will not be accepted due
to an error action in a later state.
*/
if (tok != yyempty_)
// FIXME: This method of building the message is not compatible
// with internationalization.
string res = "syntax error, unexpected ";
res ~= yytnamerr_ (yytname_[tok]);
int yyn = yypact_[yystate];
if (!yy_pact_value_is_default_ (yyn))
{
// FIXME: This method of building the message is not compatible
// with internationalization.
string res = "syntax error, unexpected ";
res ~= yytnamerr_ (yytname_[tok]);
int yyn = yypact_[yystate];
if (!yy_pact_value_is_default_ (yyn))
{
/* Start YYX at -YYN if negative to avoid negative
indexes in YYCHECK. In other words, skip the first
-YYN actions for this state because they are default
actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
int count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
++count;
if (count < 5)
{
count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
{
res ~= count++ == 0 ? ", expecting " : " or ";
res ~= yytnamerr_ (yytname_[x]);
}
}
}
return res;
/* Start YYX at -YYN if negative to avoid negative
indexes in YYCHECK. In other words, skip the first
-YYN actions for this state because they are default
actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
int count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != ]b4_symbol(1, kind)[
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
++count;
if (count < 5)
{
count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != ]b4_symbol(1, kind)[
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
{
res ~= count++ == 0 ? ", expecting " : " or ";
res ~= yytnamerr_ (yytname_[x]);
}
}
}
}
return res;
}]])[
return "syntax error";
}
@@ -822,14 +795,6 @@ m4_popdef([b4_at_dollar])])dnl
]b4_parser_tables_define[
/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
to YYLEX-NUM. */
private static immutable ]b4_int_type_for([b4_toknum])[[]
yytoken_number_ =
@{
]b4_toknum[
@};
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
private static immutable string[] yytname_ =
@@ -837,6 +802,7 @@ m4_popdef([b4_at_dollar])])dnl
]b4_tname[
@};
]b4_parse_trace_if([[
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
private static immutable ]b4_int_type_for([b4_rline])[[] yyrline_ =
@{
@@ -852,45 +818,106 @@ m4_popdef([b4_at_dollar])])dnl
int yylno = yyrline_[yyrule];
int yynrhs = yyr2_[yyrule];
/* Print the symbols being reduced, and their result. */
yycdebug (format("Reducing stack by rule %d (line %d), ",
yyrule - 1, yylno));
yycdebugln (format("Reducing stack by rule %d (line %d):",
yyrule - 1, yylno));
/* The symbols being reduced. */
import std.conv : to;
for (int yyi = 0; yyi < yynrhs; yyi++)
yy_symbol_print (format(" $%d =", yyi + 1),
yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
to!SymbolKind (yystos_[yystack.stateAt(yynrhs - (yyi + 1))]),
]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
b4_rhs_location(yynrhs, yyi + 1)])[);
}
]])[
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
private static immutable ]b4_int_type_for([b4_translate])[[] yytranslate_table_ =
@{
]b4_translate[
@};
private static ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
private static SymbolKind yytranslate_ (int t)
{
if (t >= 0 && t <= yyuser_token_number_max_)
return yytranslate_table_[t];
]b4_api_token_raw_if(
[[ import std.conv : to;
return to!SymbolKind (t);]],
[[ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
immutable ]b4_int_type_for([b4_translate])[[] translate_table =
@{
]b4_translate[
@};
// Last valid token kind.
immutable int code_max = ]b4_code_max[;
if (t <= 0)
return ]b4_symbol(0, kind)[;
else if (t <= code_max)
{
import std.conv : to;
return to!SymbolKind (translate_table[t]);
}
else
return yyundef_token_;
return ]b4_symbol(2, kind)[;]])[
}
private static immutable int yylast_ = ]b4_last[;
private static immutable int yynnts_ = ]b4_nterms_number[;
private static immutable int yyempty_ = -2;
private static immutable int yyfinal_ = ]b4_final_state_number[;
private static immutable int yyterror_ = 1;
private static immutable int yyerrcode_ = 256;
private static immutable int yyntokens_ = ]b4_tokens_number[;
private static immutable int yyuser_token_number_max_ = ]b4_user_token_number_max[;
private static immutable int yyundef_token_ = ]b4_undef_token_number[;
private final struct YYStackElement {
int state;
]b4_yystype[ value;]b4_locations_if(
b4_location_type[[] location;])[
}
]/* User implementation code. */
b4_percent_code_get[]dnl
private final struct YYStack {
private YYStackElement[] stack = [];
public final @@property ulong height()
{
return stack.length;
}
public final void push (int state, ]b4_yystype[ value]dnl
b4_locations_if([, ref ]b4_location_type[ loc])[)
{
stack ~= YYStackElement(state, value]b4_locations_if([, loc])[);
}
public final void pop ()
{
pop (1);
}
public final void pop (int num)
{
stack.length -= num;
}
public final int stateAt (int i)
{
return stack[$-i-1].state;
}
]b4_locations_if([[
public final ref ]b4_location_type[ locationAt (int i)
{
return stack[$-i-1].location;
}]])[
public final ref ]b4_yystype[ valueAt (int i)
{
return stack[$-i-1].value;
}
]b4_parse_trace_if([[
// Print the state stack on the debug stream.
public final void print (File stream)
{
stream.write ("Stack now");
for (int i = 0; i < stack.length; i++)
stream.write (" ", stack[i].state);
stream.writeln ();
}]])[
}
]b4_percent_code_get[
}
]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
m4_divert_pop(0)dnl
b4_output_end
+447 -396
View File
File diff suppressed because it is too large Load Diff
+55 -41
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -16,13 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
m4_pushdef([b4_copyright_years],
[2002-2015, 2018-2019])
[2002-2015, 2018-2020])
# 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])])])])
@@ -48,7 +48,7 @@ m4_ifdef([b4_location_file],
["b4_location_file"])])
m4_define([b4_location_path],
b4_percent_define_get([[api.location.include]],
["b4_dir_prefix[]b4_location_file"]))
["b4_mapped_dir_prefix[]b4_location_file"]))
m4_define([b4_location_path],
m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2)))
])
@@ -62,11 +62,16 @@ m4_define([b4_location_define],
[[ /// A point in a source file.
class position
{
public:]m4_ifdef([b4_location_constructors], [[
public:
/// Type for file name.
typedef ]b4_percent_define_get([[api.filename.type]])[ filename_type;
/// Type for line and column numbers.
typedef int counter_type;
]m4_ifdef([b4_location_constructors], [[
/// Construct a position.
explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
explicit position (filename_type* f = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[)
: filename (f)
, line (l)
, column (c)
@@ -74,9 +79,9 @@ m4_define([b4_location_define],
]])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
void initialize (filename_type* fn = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[)
{
filename = fn;
line = l;
@@ -86,41 +91,40 @@ m4_define([b4_location_define],
/** \name Line and Column related manipulators
** \{ */
/// (line related) Advance to the COUNT next lines.
void lines (int count = 1)
void lines (counter_type count = 1)
{
if (count)
{
column = ]b4_location_initial_column[u;
column = ]b4_location_initial_column[;
line = add_ (line, count, ]b4_location_initial_line[);
}
}
/// (column related) Advance to the COUNT next columns.
void columns (int count = 1)
void columns (counter_type count = 1)
{
column = add_ (column, count, ]b4_location_initial_column[);
}
/** \} */
/// File name to which this position refers.
]b4_percent_define_get([[filename_type]])[* filename;
filename_type* filename;
/// Current line number.
unsigned line;
counter_type line;
/// Current column number.
unsigned column;
counter_type column;
private:
/// Compute max (min, lhs+rhs).
static unsigned add_ (unsigned lhs, int rhs, int min)
static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min)
{
return static_cast<unsigned> (std::max (min,
static_cast<int> (lhs) + rhs));
return lhs + rhs < min ? min : lhs + rhs;
}
};
/// Add \a width columns, in place.
inline position&
operator+= (position& res, int width)
operator+= (position& res, position::counter_type width)
{
res.columns (width);
return res;
@@ -128,21 +132,21 @@ m4_define([b4_location_define],
/// Add \a width columns.
inline position
operator+ (position res, int width)
operator+ (position res, position::counter_type width)
{
return res += width;
}
/// Subtract \a width columns, in place.
inline position&
operator-= (position& res, int width)
operator-= (position& res, position::counter_type width)
{
return res += -width;
}
/// Subtract \a width columns.
inline position
operator- (position res, int width)
operator- (position res, position::counter_type width)
{
return res -= width;
}
@@ -182,6 +186,10 @@ m4_define([b4_location_define],
class location
{
public:
/// Type for file name.
typedef position::filename_type filename_type;
/// Type for line and column numbers.
typedef position::counter_type counter_type;
]m4_ifdef([b4_location_constructors], [
/// Construct a location from \a b to \a e.
location (const position& b, const position& e)
@@ -196,18 +204,18 @@ m4_define([b4_location_define],
{}
/// Construct a 0-width location in \a f, \a l, \a c.
explicit location (]b4_percent_define_get([[filename_type]])[* f,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
explicit location (filename_type* f,
counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[)
: begin (f, l, c)
, end (f, l, c)
{}
])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
void initialize (filename_type* f = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[)
{
begin.initialize (f, l, c);
end = begin;
@@ -223,13 +231,13 @@ m4_define([b4_location_define],
}
/// Extend the current location to the COUNT next columns.
void columns (int count = 1)
void columns (counter_type count = 1)
{
end += count;
}
/// Extend the current location to the COUNT next lines.
void lines (int count = 1)
void lines (counter_type count = 1)
{
end.lines (count);
}
@@ -244,39 +252,45 @@ m4_define([b4_location_define],
};
/// Join two locations, in place.
inline location& operator+= (location& res, const location& end)
inline location&
operator+= (location& res, const location& end)
{
res.end = end.end;
return res;
}
/// Join two locations.
inline location operator+ (location res, const location& end)
inline location
operator+ (location res, const location& end)
{
return res += end;
}
/// Add \a width columns to the end position, in place.
inline location& operator+= (location& res, int width)
inline location&
operator+= (location& res, location::counter_type width)
{
res.columns (width);
return res;
}
/// Add \a width columns to the end position.
inline location operator+ (location res, int width)
inline location
operator+ (location res, location::counter_type width)
{
return res += width;
}
/// Subtract \a width columns to the end position, in place.
inline location& operator-= (location& res, int width)
inline location&
operator-= (location& res, location::counter_type width)
{
return res += -width;
}
/// Subtract \a width columns to the end position.
inline location operator- (location res, int width)
inline location
operator- (location res, location::counter_type width)
{
return res -= width;
}
@@ -305,7 +319,8 @@ m4_define([b4_location_define],
std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
unsigned end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
location::counter_type end_col
= 0 < loc.end.column ? loc.end.column - 1 : 0;
ostr << loc.begin;
if (loc.end.filename
&& (!loc.begin.filename
@@ -327,7 +342,7 @@ m4_ifdef([b4_position_file], [[
// used to define is now defined in "]b4_location_file[".
//
// To get rid of this file:
// 1. add 'require "3.2"' (or newer) to your grammar file
// 1. add '%require "3.2"' (or newer) to your grammar file
// 2. remove references to this file from your build system
// 3. if you used to include it, include "]b4_location_file[" instead.
@@ -346,7 +361,6 @@ m4_ifdef([b4_location_file], [[
]b4_cpp_guard_open([b4_location_path])[
# include <algorithm> // std::max
# include <iostream>
# include <string>
+30 -36
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -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])])])
@@ -32,48 +32,38 @@ m4_define([b4_stack_define],
{
public:
// Hide our reversed order.
typedef typename S::reverse_iterator iterator;
typedef typename S::const_reverse_iterator const_iterator;
typedef typename S::iterator iterator;
typedef typename S::const_iterator const_iterator;
typedef typename S::size_type size_type;
typedef typename std::ptrdiff_t index_type;
stack (size_type n = 200)
: seq_ (n)
{}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
stack (const stack&) = delete;
/// Non copyable.
stack& operator= (const stack&) = delete;
#endif
/// Random access.
///
/// Index 0 returns the topmost element.
T&
operator[] (size_type i)
const T&
operator[] (index_type i) const
{
return seq_[size () - 1 - i];
return seq_[size_type (size () - 1 - i)];
}
/// Random access.
///
/// Index 0 returns the topmost element.
T&
operator[] (int i)
operator[] (index_type i)
{
return operator[] (size_type (i));
}
/// Random access.
///
/// Index 0 returns the topmost element.
const T&
operator[] (size_type i) const
{
return seq_[size () - 1 - i];
}
/// Random access.
///
/// Index 0 returns the topmost element.
const T&
operator[] (int i) const
{
return operator[] (size_type (i));
return seq_[size_type (size () - 1 - i)];
}
/// Steal the contents of \a t.
@@ -88,7 +78,7 @@ m4_define([b4_stack_define],
/// Pop elements from the stack.
void
pop (int n = 1) YY_NOEXCEPT
pop (std::ptrdiff_t n = 1) YY_NOEXCEPT
{
for (; 0 < n; --n)
seq_.pop_back ();
@@ -102,49 +92,53 @@ m4_define([b4_stack_define],
}
/// Number of elements on the stack.
size_type
index_type
size () const YY_NOEXCEPT
{
return seq_.size ();
return index_type (seq_.size ());
}
/// Iterator on top of the stack (going downwards).
const_iterator
begin () const YY_NOEXCEPT
{
return seq_.rbegin ();
return seq_.begin ();
}
/// Bottom of the stack.
const_iterator
end () const YY_NOEXCEPT
{
return seq_.rend ();
return seq_.end ();
}
/// Present a slice of the top of a stack.
class slice
{
public:
slice (const stack& stack, int range)
slice (const stack& stack, index_type range)
: stack_ (stack)
, range_ (range)
{}
const T&
operator[] (int i) const
operator[] (index_type i) const
{
return stack_[range_ - i];
}
private:
const stack& stack_;
int range_;
index_type range_;
};
private:
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
stack (const stack&);
/// Non copyable.
stack& operator= (const stack&);
#endif
/// The wrapped container.
S seq_;
};
@@ -157,7 +151,7 @@ m4_ifdef([b4_stack_file],
// used to define is now defined with the parser itself.
//
// To get rid of this file:
// 1. add 'require "3.2"' (or newer) to your grammar file
// 1. add '%require "3.2"' (or newer) to your grammar file
// 2. remove references to this file from your build system.
]b4_output_end[
]])
+2
View File
@@ -0,0 +1,2 @@
dnl GNU M4 treats -dV in a position-independent manner.
m4_debugmode(V)m4_traceon()dnl
+114 -44
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# 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
@@ -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 YYASSERT
[b4_parse_assert_if([[#include <typeinfo>
#ifndef ]b4_assert[
# include <cassert>
# define YYASSERT assert
# define ]b4_assert[ assert
#endif
]])
]])])
@@ -110,15 +117,22 @@ m4_define([b4_value_type_declare],
template <typename T>
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([
: yytypeid_ (&typeid (T))])[
{
YYASSERT (sizeof (T) <= size);
{]b4_parse_assert_if([[
]b4_assert[ (sizeof (T) <= size);]])[
new (yyas_<T> ()) T (YY_MOVE (t));
}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
semantic_type (const self_type&) = delete;
/// Non copyable.
self_type& operator= (const self_type&) = delete;
#endif
/// Destruction, allowed only if empty.
~semantic_type () YY_NOEXCEPT
{]b4_parse_assert_if([
YYASSERT (!yytypeid_);
]b4_assert[ (!yytypeid_);
])[}
# if 201103L <= YY_CPLUSPLUS
@@ -126,10 +140,10 @@ m4_define([b4_value_type_declare],
template <typename T, typename... U>
T&
emplace (U&&... u)
{]b4_parse_assert_if([
YYASSERT (!yytypeid_);
YYASSERT (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
@@ -137,10 +151,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace ()
{]b4_parse_assert_if([
YYASSERT (!yytypeid_);
YYASSERT (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 ();
}
@@ -148,10 +162,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace (const T& t)
{]b4_parse_assert_if([
YYASSERT (!yytypeid_);
YYASSERT (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
@@ -178,10 +192,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
as () YY_NOEXCEPT
{]b4_parse_assert_if([
YYASSERT (yytypeid_);
YYASSERT (*yytypeid_ == typeid (T));
YYASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -189,10 +203,10 @@ m4_define([b4_value_type_declare],
template <typename T>
const T&
as () const YY_NOEXCEPT
{]b4_parse_assert_if([
YYASSERT (yytypeid_);
YYASSERT (*yytypeid_ == typeid (T));
YYASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -207,9 +221,9 @@ m4_define([b4_value_type_declare],
template <typename T>
void
swap (self_type& that) YY_NOEXCEPT
{]b4_parse_assert_if([
YYASSERT (yytypeid_);
YYASSERT (*yytypeid_ == *that.yytypeid_);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[
std::swap (as<T> (), that.as<T> ());
}
@@ -258,9 +272,12 @@ m4_define([b4_value_type_declare],
}
private:
/// Prohibit blind copies.
self_type& operator= (const self_type&);
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
semantic_type (const self_type&);
/// Non copyable.
self_type& operator= (const self_type&);
#endif
/// Accessor to raw memory as \a T.
template <typename T>
@@ -378,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], [user_number])])])])
# 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...)
@@ -400,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)]))[)
{
YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#else
symbol_type (]b4_join(
[int tok],
@@ -412,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]))[)
{
YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#endif
{]b4_parse_assert_if([[
]b4_assert[ (]b4_tok_in($@)[);
]])[}
]])])
+721 -576
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -3,7 +3,7 @@
<!--
bison.xsl - common templates for Bison XSLT.
Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+5 -5
View File
@@ -3,7 +3,7 @@
<!--
xml2dot.xsl - transform Bison XML Report into DOT.
Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -159,7 +159,7 @@
<xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@rule-number"/>
<xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="num" select="@rule-number"/>
<xsl:with-param name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
@@ -169,7 +169,7 @@
</xsl:template>
<xsl:template match="rule">
<xsl:param name="point"/>
<xsl:param name="dot"/>
<xsl:param name="num"/>
<xsl:param name="prev-lhs"/>
<xsl:text>&#10;</xsl:text>
@@ -198,14 +198,14 @@
<xsl:text>:</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$point = 0">
<xsl:if test="$dot = 0">
<xsl:text> .</xsl:text>
</xsl:if>
<!-- RHS -->
<xsl:for-each select="rhs/symbol|rhs/empty">
<xsl:apply-templates select="."/>
<xsl:if test="$point = position()">
<xsl:if test="$dot = position()">
<xsl:text> .</xsl:text>
</xsl:if>
</xsl:for-each>
+19 -11
View File
@@ -3,7 +3,7 @@
<!--
xml2text.xsl - transform Bison XML Report into plain text.
Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -52,7 +52,7 @@
<xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
<xsl:text>Nonterminals useless in grammar&#10;&#10;</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>&#10;</xsl:text>
</xsl:for-each>
@@ -65,7 +65,7 @@
<xsl:text>Terminals unused in grammar&#10;&#10;</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>&#10;</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(' &lt;', @type, '&gt;')"/>
</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(' &lt;', @type, '&gt;')"/>
</xsl:if>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text>&#10;</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>&#10; </xsl:text>
</xsl:if>
<xsl:text>on@right:</xsl:text>
<xsl:for-each select="key('bison:ruleByRhs', @name)">
@@ -300,7 +308,7 @@
name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
/>
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
</xsl:with-param>
@@ -311,7 +319,7 @@
<xsl:param name="itemset"/>
<xsl:param name="pad"/>
<xsl:param name="prev-lhs"/>
<xsl:param name="point"/>
<xsl:param name="dot"/>
<xsl:param name="lookaheads"/>
<xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
@@ -347,12 +355,12 @@
<!-- RHS -->
<xsl:for-each select="rhs/*">
<xsl:if test="position() = $point + 1">
<xsl:text> .</xsl:text>
<xsl:if test="position() = $dot + 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:apply-templates select="."/>
<xsl:if test="position() = last() and position() = $point">
<xsl:text> .</xsl:text>
<xsl:if test="position() = last() and position() = $dot">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:if test="$lookaheads">
+80 -56
View File
@@ -3,7 +3,7 @@
<!--
xml2html.xsl - transform Bison XML Report into XHTML.
Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -75,7 +75,7 @@
ol.lower-alpha {
list-style-type: lower-alpha;
}
.point {
.dot {
color: #cc0000;
}
#footer {
@@ -227,6 +227,7 @@
<xsl:text>&#10;</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>&#10;&#10;</xsl:text>
<p class="pre">
<ul>
<xsl:text>&#10;</xsl:text>
<xsl:apply-templates select="terminal"/>
</p>
</ul>
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
@@ -318,41 +322,64 @@
<xsl:text> Nonterminals, with rules where they appear</xsl:text>
</h3>
<xsl:text>&#10;&#10;</xsl:text>
<p class="pre">
<ul>
<xsl:text>&#10;</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(' &lt;', @type, '&gt;')"/>
</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>&#10;</xsl:text>
</xsl:template>
<xsl:template match="nonterminal">
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text>&#10; </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>&#10; </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(' &lt;', @type, '&gt;')"/>
</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>&#10; </xsl:text>
<ul>
<xsl:text>&#10;</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>&#10;</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>&#10;</xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
</ul>
<xsl:text>&#10; </xsl:text>
</li>
<xsl:text>&#10;</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>&#10;&#10;</xsl:text>
@@ -457,35 +484,44 @@
<xsl:with-param name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
/>
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
</xsl:with-param>
</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"/>
<xsl:param name="point"/>
<xsl:param name="dot"/>
<xsl:param name="lookaheads"/>
<xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
<xsl:text>&#10;</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"/>
@@ -529,14 +553,14 @@
<!-- RHS -->
<xsl:for-each select="rhs/*">
<xsl:if test="position() = $point + 1">
<xsl:if test="position() = $dot + 1">
<xsl:text> </xsl:text>
<span class="point">.</span>
<span class="dot">&#x2022;</span>
</xsl:if>
<xsl:apply-templates select="."/>
<xsl:if test="position() = last() and position() = $point">
<xsl:if test="position() = last() and position() = $dot">
<xsl:text> </xsl:text>
<span class="point">.</span>
<span class="dot">&#x2022;</span>
</xsl:if>
</xsl:for-each>
<xsl:if test="$lookaheads">
+3
View File
@@ -16,6 +16,7 @@
/bison.help
/bison.html
/bison.info
/bison.info.bak
/bison.log
/bison.pdf
/bison.ps
@@ -31,3 +32,5 @@
/version.texi
/yacc.1
/relocatable.texi
/figs/*.eps
/figs/*.svg
+380 -193
View File
File diff suppressed because it is too large Load Diff
+3242 -1685
View File
File diff suppressed because it is too large Load Diff
+23
View File
@@ -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;
+1 -1
View File
@@ -3,7 +3,7 @@ digraph "reduce.y"
node [fontname=courier shape=box]
edge [fontname=courier]
1 [label="State 1\n 3 a: \"0\" . [\".\"]\l 4 b: \"0\" . [\";\"]\l"]
1 [label="State 1\n 3 a: \"0\" [\".\"]\l 4 b: \"0\" [\";\"]\l"]
1 -> "1R3" [label="" style=solid]
"1R3" [style=filled shape=diamond fillcolor=yellowgreen label="R3"]
1 -> "1R4" [label="[\";\"]" style=solid]
+2 -2
View File
@@ -1,7 +1,7 @@
.------------------.
| State 1 |
| 3 a: "0" . [";"] |
| 4 b: "0" . ["."] |
| 3 a: "0" [";"] |
| 4 b: "0" ["."] |
`------------------'
/ \
/ \ ["."]
+2 -2
View File
@@ -3,7 +3,7 @@ digraph "shift.y"
node [fontname=courier shape=box]
edge [fontname=courier]
3 [label="State 3\n 1 exp: a . \".\"\l"]
3 [label="State 3\n 1 exp: a \".\"\l"]
3 -> 6 [style=solid label="\".\""]
6 [label="State 6\n 1 exp: a \".\" .\l"]
6 [label="State 6\n 1 exp: a \".\" \l"]
}
+2 -2
View File
@@ -1,6 +1,6 @@
.----------------.
| State 3 |
| 1 exp: a . ";" |
| 1 exp: a ";" |
`----------------'
|
| ";"
@@ -8,5 +8,5 @@
v
.----------------.
| State 6 |
| 1 exp: a ";" . |
| 1 exp: a ";" |
`----------------'
+9 -9
View File
@@ -2,34 +2,34 @@
// Report bugs to <[email protected]>.
// Home page: <http://www.gnu.org/software/bison/>.
digraph "/tmp/fo.y"
digraph "example.y"
{
node [fontname = courier, shape = box, colorscheme = paired6]
edge [fontname = courier]
0 [label="State 0\n\l 0 $accept: . exp $end\l 1 exp: . a \";\"\l 2 | . b \".\"\l 3 a: . \"0\"\l 4 b: . \"0\"\l"]
0 [label="State 0\n\l 0 $accept: exp $end\l 1 exp: a \";\"\l 2 | b \".\"\l 3 a: \"0\"\l 4 b: \"0\"\l"]
0 -> 1 [style=solid label="\"0\""]
0 -> 2 [style=dashed label="exp"]
0 -> 3 [style=dashed label="a"]
0 -> 4 [style=dashed label="b"]
1 [label="State 1\n\l 3 a: \"0\" . [\";\"]\l 4 b: \"0\" . [\".\"]\l"]
1 [label="State 1\n\l 3 a: \"0\" [\";\"]\l 4 b: \"0\" [\".\"]\l"]
1 -> "1R3" [style=solid]
"1R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
1 -> "1R4" [label="[\".\"]", style=solid]
"1R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
2 [label="State 2\n\l 0 $accept: exp . $end\l"]
2 [label="State 2\n\l 0 $accept: exp $end\l"]
2 -> 5 [style=solid label="$end"]
3 [label="State 3\n\l 1 exp: a . \";\"\l"]
3 [label="State 3\n\l 1 exp: a \";\"\l"]
3 -> 6 [style=solid label="\";\""]
4 [label="State 4\n\l 2 exp: b . \".\"\l"]
4 [label="State 4\n\l 2 exp: b \".\"\l"]
4 -> 7 [style=solid label="\".\""]
5 [label="State 5\n\l 0 $accept: exp $end .\l"]
5 [label="State 5\n\l 0 $accept: exp $end \l"]
5 -> "5R0" [style=solid]
"5R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
6 [label="State 6\n\l 1 exp: a \";\" .\l"]
6 [label="State 6\n\l 1 exp: a \";\" \l"]
6 -> "6R1" [style=solid]
"6R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
7 [label="State 7\n\l 2 exp: b \".\" .\l"]
7 [label="State 7\n\l 2 exp: b \".\" \l"]
7 -> "7R2" [style=solid]
"7R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
}
+5
View File
@@ -0,0 +1,5 @@
%token ID
%%
s: a ID
a: expr
expr: %empty | expr ID ','
+13
View File
@@ -0,0 +1,13 @@
%%
stmt:
expr
| if_stmt
;
if_stmt:
"if" expr "then" stmt
| "if" expr "then" stmt "else" stmt
;
expr:
"identifier"
+83 -51
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2001-2003, 2005-2015, 2018-2019 Free Software
## Copyright (C) 2001-2003, 2005-2015, 2018-2020 Free Software
## Foundation, Inc.
## This program is free software: you can redistribute it and/or modify
@@ -20,54 +20,71 @@ AM_MAKEINFOFLAGS = \
--set-customization-variable=AVOID_MENU_REDUNDANCY=true \
--set-customization-variable=ICONS=true
info_TEXINFOS = doc/bison.texi
doc_bison_TEXINFOS = \
info_TEXINFOS = %D%/bison.texi
%C%_bison_TEXINFOS = \
$(CROSS_OPTIONS_TEXI) \
doc/fdl.texi \
doc/gpl-3.0.texi \
doc/relocatable.texi
%D%/fdl.texi \
%D%/gpl-3.0.texi \
%D%/relocatable.texi
# Cannot express dependencies directly on file names because of Automake.
# Obfuscate with a variable.
doc_bison = doc/bison
$(doc_bison).dvi: $(FIGS_GV:.gv=.eps)
$(doc_bison).info: $(FIGS_GV:.gv=.txt)
$(doc_bison).pdf: $(FIGS_GV:.gv=.pdf)
$(doc_bison).html: $(FIGS_GV:.gv=.svg)
%C%_bison = %D%/bison
$(%C%_bison).dvi: $(FIGS_GV:.gv=.eps)
$(%C%_bison).info: $(FIGS_GV:.gv=.txt)
$(%C%_bison).pdf: $(FIGS_GV:.gv=.pdf)
$(%C%_bison).html: $(FIGS_GV:.gv=.svg)
TEXI2DVI = texi2dvi --build-dir=doc/bison.t2d -I doc
CLEANDIRS += doc/bison.t2d
TEXI2DVI = texi2dvi --build-dir=%D%/bison.t2d -I %D%
CLEANDIRS += %D%/bison.t2d
MOSTLYCLEANFILES += $(top_srcdir)/doc/*.tmp
MOSTLYCLEANFILES += $(top_srcdir)/%D%/*.tmp
CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl
CROSS_OPTIONS_TEXI = $(top_srcdir)/doc/cross-options.texi
$(CROSS_OPTIONS_TEXI): doc/bison.help $(CROSS_OPTIONS_PL)
CROSS_OPTIONS_TEXI = $(top_srcdir)/%D%/cross-options.texi
$(CROSS_OPTIONS_TEXI): %D%/bison.help $(CROSS_OPTIONS_PL)
# Create $@~ which is the previous contents. Don't use 'mv' here so
# that even if we are interrupted, the file is still available for
# diff in the next run. Note that $@ might not exist yet.
$(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~
$(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp
$(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \
<$(top_srcdir)/doc/bison.help >$@.tmp
<$(top_srcdir)/%D%/bison.help >$@.tmp
$(AM_V_at)diff -u $@~ $@.tmp || true
$(AM_V_at)mv $@.tmp $@
MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
# Fix Info's @code in @deftype
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html
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)*)}' \
-e '{' \
-e ' $$def = $$1;' \
-e ' $$def =~ s/|//g;' \
-e ' $$def;' \
-e '}gem;' $(srcdir)/$(%C%_bison).info
@ touch $@
EXTRA_DIST += $(srcdir)/$(%C%_bison).info.bak
MAINTAINERCLEANFILES += $(srcdir)/$(%C%_bison).info.bak
## ---------- ##
## Ref card. ##
## ---------- ##
EXTRA_DIST += doc/refcard.tex
CLEANFILES += doc/refcard.pdf
EXTRA_DIST += %D%/refcard.tex
CLEANFILES += %D%/refcard.pdf
doc/refcard.pdf: doc/refcard.tex
$(AM_V_GEN) cd doc && pdftex $(abs_top_srcdir)/doc/refcard.tex
%D%/refcard.pdf: %D%/refcard.tex
$(AM_V_GEN) cd %D% && pdftex $(abs_top_srcdir)/%D%/refcard.tex
## ---------------- ##
## doc/bison.help. ##
## %D%/bison.help. ##
## ---------------- ##
# Some of our targets (cross-options.texi, bison.1) use "bison --help".
@@ -89,18 +106,19 @@ doc/refcard.pdf: doc/refcard.tex
# compilations of cross-options.texi and bison.1. At the cost of
# repeated builds of bison.help.
EXTRA_DIST += $(top_srcdir)/doc/bison.help
EXTRA_DIST += $(top_srcdir)/%D%/bison.help
if ! CROSS_COMPILING
MAINTAINERCLEANFILES += $(top_srcdir)/doc/bison.help
$(top_srcdir)/doc/bison.help: src/bison$(EXEEXT)
$(AM_V_GEN)LC_ALL=C tests/bison --version >doc/bison.help.tmp
MAINTAINERCLEANFILES += $(top_srcdir)/%D%/bison.help
$(top_srcdir)/%D%/bison.help: src/bison$(EXEEXT)
$(AM_V_GEN)$(MKDIR_P) %D%
$(AM_V_at) LC_ALL=C tests/bison --version >%D%/bison.help.tmp
$(AM_V_at) LC_ALL=C tests/bison --help | \
## Avoid depending on the path to Bison.
sed -e 's,^Usage: .*/bison \[OPTION\],Usage: bison [OPTION],g' \
## Avoid variations in the output depending on whether we are
## on a glibc system.
-e '/translation bugs/d' >>doc/bison.help.tmp
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change doc/bison.help.tmp $@
-e '/translation bugs/d' >>%D%/bison.help.tmp
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change %D%/bison.help.tmp $@
endif ! CROSS_COMPILING
@@ -108,34 +126,48 @@ endif ! CROSS_COMPILING
## Man Pages. ##
## ----------- ##
dist_man_MANS = $(top_srcdir)/doc/bison.1
dist_man_MANS = $(top_srcdir)/%D%/bison.1
EXTRA_DIST += $(dist_man_MANS:.1=.x)
MAINTAINERCLEANFILES += $(dist_man_MANS)
# Differences to ignore when comparing the man page (the date).
# Differences to ignore when comparing man pages (the date).
remove_time_stamp = \
sed 's/^\(\.TH[^"]*"[^"]*"[^"]*\)"[^"]*"/\1/'
# Depend on configure to get version number changes.
if ! CROSS_COMPILING
MAN_DEPS = doc/bison.help doc/bison.x $(top_srcdir)/configure
MAN_DEPS = %D%/bison.help %D%/bison.x $(top_srcdir)/configure
endif
$(top_srcdir)/doc/bison.1: $(MAN_DEPS)
$(AM_V_GEN)$(HELP2MAN) \
--include=$(top_srcdir)/doc/bison.x \
--output=$@.tmp tests/bison
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \
touch $@; \
else \
mv $@.tmp $@; \
# If we don't have help2man, just touch the target. Maintainers must
# have the real thing, so if there's a .git directory, fail hard.
#
# We shouldn't need this, but on some OS the timestamps in the tarball
# leave us no choice. See
# https://lists.gnu.org/r/bug-bison/2020-05/msg00055.html.
$(top_srcdir)/%D%/bison.1: $(MAN_DEPS)
$(AM_V_GEN)if $(HELP2MAN) --version >/dev/null 2>&1; then \
$(HELP2MAN) \
--include=$(top_srcdir)/%D%/bison.x \
--output=$@.tmp tests/bison && \
{ $(remove_time_stamp) $@ >$@a.tmp || true; } && \
$(remove_time_stamp) $@.tmp >$@b.tmp && \
if diff $@a.tmp $@b.tmp >/dev/null 2>&1; then \
touch $@; \
else \
mv $@.tmp $@; \
fi && \
rm -f $@*.tmp; \
elif test -d $(srcdir)/.git; then \
echo >&2 "ERROR: $@: help2man is needed"; \
exit 1; \
else \
touch $@; \
fi
$(AM_V_at)rm -f $@*.tmp
if ENABLE_YACC
nodist_man_MANS = doc/yacc.1
nodist_man_MANS = %D%/yacc.1
endif
## ----------------------------- ##
@@ -144,8 +176,8 @@ endif
CLEANFILES += $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
FIGS_GV = \
doc/figs/example.gv \
doc/figs/example-reduce.gv doc/figs/example-shift.gv
%D%/figs/example.gv \
%D%/figs/example-reduce.gv %D%/figs/example-shift.gv
EXTRA_DIST += \
$(FIGS_GV) $(FIGS_GV:.gv=.txt) \
$(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
@@ -176,8 +208,8 @@ DOXYGEN = doxygen
doc: html
html-local: doc/Doxyfile
$(AM_V_GEN) $(DOXYGEN) doc/Doxyfile
html-local: %D%/Doxyfile
$(AM_V_GEN) $(DOXYGEN) %D%/Doxyfile
edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
-e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
@@ -185,11 +217,11 @@ edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
-e 's,@top_builddir\@,$(top_builddir),g' \
-e 's,@top_srcdir\@,$(top_srcdir),g'
EXTRA_DIST += doc/Doxyfile.in
CLEANFILES += doc/Doxyfile
EXTRA_DIST += %D%/Doxyfile.in
CLEANFILES += %D%/Doxyfile
# Sed is used to generate Doxyfile from Doxyfile.in instead of
# configure, because the former is way faster than the latter.
doc/Doxyfile: $(top_srcdir)/doc/Doxyfile.in
$(AM_V_GEN) $(edit) $(top_srcdir)/doc/Doxyfile.in >doc/Doxyfile
%D%/Doxyfile: $(top_srcdir)/%D%/Doxyfile.in
$(AM_V_GEN) $(edit) $(top_srcdir)/%D%/Doxyfile.in >%D%/Doxyfile
CLEANDIRS += doc/html
CLEANDIRS += %D%/html
+1 -1
View File
@@ -19,7 +19,7 @@
\def\finalout{\overfullrule=0pt}
%\finalout
% Copyright (c) 1998, 2001, 2009-2015, 2018-2019 Free Software
% Copyright (c) 1998, 2001, 2009--2015, 2018--2020 Free Software
% Foundation, Inc.
%
% This file is part of Bison.
+10
View File
@@ -0,0 +1,10 @@
%%
sequence:
%empty
| maybeword
| sequence "word"
;
maybeword:
%empty
| "word"
;
-38
View File
@@ -1,38 +0,0 @@
* bench.pl
A primitive Perl script to run benches. Currently its only bench is
the usual calculator: it has a lightweight processing part (but not
null), so it is really emphasizing the cost of the whole parsing
(including scanning and I/O).
Set the envvars BISON and CC to the programs and flags you want to
use. They default to bison and gcc. To run a non-installed bison
from a tarball built in _build, I suggest the following.
BISON=_build/tests/bison CC='gcc -O2' ./bench.pl
(The _build/tests/bison wrapper makes sure that _build/src/bison will
use the tarballs' skeletons, not those already installed as a
straightforward use of _build/src/bison would.)
--
Copyright (C) 2006, 2009-2015, 2018-2019 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/>.
Local Variables:
mode: outline
End:
+36
View File
@@ -0,0 +1,36 @@
# bench.pl
A primitive Perl script to run benches. Currently its only bench is the
usual calculator: it has a lightweight processing part (but not null), so it
is really emphasizing the cost of the whole parsing (including scanning and
I/O).
Set the envvars `BISON` and `CC` to the programs and flags you want to use.
They default to `bison` and `gcc`. To run a non-installed bison from a
tarball built in _build, I suggest the following.
BISON=_build/tests/bison CC='gcc -O2' ./bench.pl
(The `_build/tests/bison` wrapper makes sure that `_build/src/bison` will
use the tarballs' skeletons, not those already installed as a
straightforward use of `_build/src/bison` would.)
<!--
Local Variables:
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
-->
+369 -213
View File
File diff suppressed because one or more lines are too long
+3 -2
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2006, 2008-2015, 2018-2019 Free Software Foundation,
## Copyright (C) 2006, 2008-2015, 2018-2020 Free Software Foundation,
## Inc.
## This program is free software: you can redistribute it and/or modify
@@ -14,4 +14,5 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
nodist_noinst_SCRIPTS = etc/bench.pl
dist_noinst_DATA = %D%/README.md
nodist_noinst_SCRIPTS = %D%/bench.pl
+1 -1
View File
@@ -17,7 +17,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
+1
View File
@@ -0,0 +1 @@
/simple.yy
+7 -7
View File
@@ -8,13 +8,13 @@ afterwards.
## simple.yy - Simple example in C++14
A very simple example in C++, based on variants and symbol constructors.
Variants allow to use any C++ type as semantic value type, and symbol
constructors ensure consistency between declared token type and effective
constructors ensure consistency between declared token kind and effective
semantic value.
Run as `./simple`.
Extracted from the documentation: "A Simple C++ Example".
https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html
Extracted from the documentation: [A Simple C++
Example](https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html).
## variant.yy - Self-contained example in C++98
A variation of simple.yy, in C++98.
@@ -36,8 +36,8 @@ starting point for a clean parser in C++. The previous examples are better
introductory examples, and the C examples are also useful introductory
examples.
Extracted from the documentation: "A Complete C++ Example".
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
Extracted from the documentation: [A Complete C++
Example](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html).
<!---
@@ -46,7 +46,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -55,5 +55,5 @@ Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
# LocalWords: mfcalc calc parsers yy ispell american
LocalWords: mfcalc calc parsers yy ispell american
--->
+11 -19
View File
@@ -5,9 +5,9 @@ saw the traditional implementation in C, please first read
examples/c/lexcalc, which can be seen as a C precursor of this example.
Read the corresponding chapter in the documentation: "A Complete C++
Example". It is also available on line (maybe with a different version of
Bison):
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
Example". It is also available [on
line](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html)
(maybe with a different version of Bison).
To use it, copy this directory into some work directory, and run `make` to
compile the executable, and try it. It is a simple calculator which accepts
@@ -36,22 +36,14 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
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/>.
# LocalWords: calc parsers yy MERCHANTABILITY Ctrl ispell american
LocalWords: calc parsers yy MERCHANTABILITY Ctrl ispell american
--->
+9 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2005-2015, 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2005-2015, 2018-2020 Free Software Foundation, Inc.
#
# 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
@@ -44,11 +44,18 @@ EOF
run 0 9
cat >input <<EOF
1 +
EOF
run 1 'err: -:2.1: syntax error, unexpected end of file, expecting ( or identifier or number'
# LAC finds many more tokens.
cat >input <<EOF
a := 1
d := a + b * c
EOF
run 1 'err: -:3.1: syntax error, unexpected end of file, expecting ( or identifier or number'
run 1 'err: -:3.1: syntax error, unexpected end of file'
cat >input <<EOF
+1 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2005-2006, 2008-2015, 2018-2019 Free Software
## Copyright (C) 2005-2006, 2008-2015, 2018-2020 Free Software
## Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
+1 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2018-2019 Free Software Foundation, Inc.
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
##
## 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
+1 -1
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
#
# 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
+3 -3
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
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
@@ -117,7 +117,7 @@ namespace yy
static int count = 0;
const int stage = count;
++count;
auto loc = parser::location_type{nullptr, unsigned (stage + 1), unsigned (stage + 1)};
auto loc = parser::location_type{nullptr, stage + 1, stage + 1};
if (stage == 0)
return parser::make_TEXT (make_string_uptr ("I have numbers for you."), std::move (loc));
else if (stage < max)
@@ -139,7 +139,7 @@ namespace yy
int
main (int argc, const char *argv[])
{
if (2 <= argc && isdigit (*argv[1]))
if (2 <= argc && isdigit (static_cast<unsigned char> (*argv[1])))
{
auto maxl = strtol (argv[1], nullptr, 10);
max = INT_MIN <= maxl && maxl <= INT_MAX ? int(maxl) : 4;
+1 -1
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
#
# 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
+2 -2
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2015, 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
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
@@ -117,7 +117,7 @@ namespace yy
static int count = 0;
const int stage = count;
++count;
parser::location_type loc (NULLPTR, unsigned (stage + 1), unsigned (stage + 1));
parser::location_type loc (NULLPTR, stage + 1, stage + 1);
switch (stage)
{
case 0:
+53 -13
View File
@@ -10,8 +10,8 @@ The first example is that of a simple double-precision Reverse Polish
Notation calculator (a calculator using postfix operators). This example
provides a good starting point, since operator precedence is not an issue.
Extracted from the documentation: "Reverse Polish Notation Calculator"
https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html
Extracted from the documentation: [Reverse Polish Notation
Calculator](https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html).
## calc - Simple Calculator
This example is slightly more complex than rpcalc: it features infix
@@ -24,19 +24,55 @@ A more complete C example: a multi-function calculator. More complex than
the previous example. Using precedence directives to support infix
operators.
Extracted from the documentation: "Multi-Function Calculator: mfcalc".
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
Extracted from the documentation: [Multi-Function Calculator:
mfcalc](https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html).
## lexcalc - calculator with Flex and Bison
The calculator, redux. This time using a scanner generated by Flex.
The calculator with precedence directives and location tracking. It uses
Flex to generate the scanner.
## reccalc - recursive calculator with Flex and Bison
The example builds on top of the previous one to provide a reentrant parser.
Such parsers can be called concurrently in different threads, or even
recursively. To demonstrate this feature, expressions in parentheses are
tokenized as strings, and then recursively parsed from the parser. So
This example builds on top of the previous one to provide a reentrant
parser. Such parsers can be called concurrently in different threads, or
even recursively. To demonstrate this feature, expressions in parentheses
are tokenized as strings, and then recursively parsed from the parser. So
`(((1)+(2))*((3)+(4)))` uses eight parsers, with a depth of four.
## pushcalc - calculator implemented with a push parser
All the previous examples are so called "pull parsers": the user invokes the
parser once, which repeatedly calls the scanner until the input is drained.
This example demonstrates the "push parsers": the user calls the scanner to
fetch the next token, passes it to the parser, and repeats the operation
until the input is drained.
This example is a straightforward conversion of the 'calc' example to the
push-parser model.
## bistromathic - all the bells and whistles
This example demonstrates best practices when using Bison.
- Its hand-written scanner tracks locations.
- Its interface is pure.
- 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
parser state, based on `yyexpected_tokens`.
- It uses Bison's standard catalogue for internationalization of generated
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.
<!---
@@ -45,7 +81,9 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2018-2020 Free Software Foundation, Inc.
This file is part of GNU bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -54,6 +92,8 @@ Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
# LocalWords: mfcalc calc parsers yy rpcalc lexcalc redux reccalc ispell
# LocalWords: reentrant tokenized american postfix
--->
LocalWords: mfcalc calc parsers yy rpcalc lexcalc redux reccalc ispell
LocalWords: reentrant tokenized american postfix pushcalc bistromathic
LocalWords: lookahead
-->
+40
View File
@@ -0,0 +1,40 @@
# This Makefile is designed to be simple and readable. It does not
# aim at portability. It requires GNU Make.
BASE = bistromathic
BISON = bison
XSLTPROC = xsltproc
# We need to find the headers and libs for readline (and possibly intl).
# You probably need to customize this for your own environment.
CPPFLAGS = -I/opt/local/include
LDFLAGS = -L/opt/local/lib
# Find the translation catalogue for Bison's generated messagess.
BISON_LOCALEDIR = $(shell $(BISON) $(BISON_FLAGS) --print-localedir)
CPPFLAGS += -DENABLE_NLS -DBISON_LOCALEDIR='"$(BISON_LOCALEDIR)"'
LIBS = -lreadline -lm # In some environments, -lintl is needed.
all: $(BASE)
%.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
$(BASE): parse.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
run: $(BASE)
@echo "Type bistromathic expressions. Quit with ctrl-d."
./$<
html: $(BASE).html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \
$(BASE) *.o \
parse.[ch] parse.output parse.xml parse.html parse.gv
clean:
rm -f $(CLEANFILES)
+49
View File
@@ -0,0 +1,49 @@
# bistromathic - all the bells and whistles
This example demonstrates best practices when using Bison.
- Its hand-written scanner tracks locations.
- Its interface is pure.
- 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
parser state, based on `yyexpected_tokens`.
- It uses Bison's standard catalogue for internationalization of generated
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.
To customize the interaction with bistromathic, see the GNU Readline user
manual (see `info rluserman`).
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
LocalWords: bistromathic yyexpected lookahead ispell american
LocalWords: MERCHANTABILITY
--->
+361
View File
@@ -0,0 +1,361 @@
#! /bin/sh
# Copyright (C) 2020 Free Software Foundation, Inc.
#
# 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/>.
# Users may customize the behavior of readline, which might break our
# expected results.
INPUTRC=/dev/null
export INPUTRC
# Beware of portability issues of readline when not feeding it from a
# terminal.
#
# With recent versions of GNU Readline, input "1+2*3\n" gives
# "> 1+2*3\n7\n> \n"
#
# macOS' version does not display the prompt and does not repeat stdin
# on stdout, so input "1+2*3\n" gives "7\n" as output. Let's try to
# cope with this.
#
# On OpenBSD 6.5 the prompt is displayed, but the input is not
# repeated (!). So input "1+2*3\n" gives "> 7\n> \n" as output.
#
# On AIX, you get some escaping sequence before the prompt:
# "<ESC>[?1034h> 1+2*3". It appears to pass the terminfo capability
# "smm", to put the terminal in "meta mode": as if the user had hit
# META.
echo >perfect '> 0
0
> '
echo >ok '0'
echo '0' | prog >effective
echo "checking for readline output..."
if diff perfect effective; then
# Alles ist gut.
strip_prompt=false
elif diff ok effective; then
strip_prompt=true
else
skip "this is not the GNU Readline we expect"
fi
cat >input <<EOF
1+2*3
EOF
run 0 '> 1+2*3
7
> '
cat >input <<EOF
(1+2) * 3
EOF
run 0 '> (1+2) * 3
9
> '
run -noerr 0 '> (1+2) * 3
9
> ' -p
cat >input <<EOF
a = 256
sqrt (a)
EOF
run 0 '> a = 256
256
> sqrt (a)
16
> '
cat >input <<EOF
a = .16
b = 10 ^ 2
sqrt (a * b)
EOF
run 0 '> a = .16
0.16
> b = 10 ^ 2
100
> sqrt (a * b)
4
> '
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 | *
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 | 1 + 2 * * 3
err: | ^'
cat >input <<EOF
1 / 0
EOF
run 0 '> 1 / 0
> ''
err: 1.1-5: error: division by zero'
## ---------------- ##
## Error recovery. ##
## ---------------- ##
cat >input <<EOF
((1 ++ 2) ** 3)
(1 ++ 2) + (3 ** 4)
EOF
run 0 '> ((1 ++ 2) ** 3)
666
> (1 ++ 2) + (3 ** 4)
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 | (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
()
EOF
run 0 '> ()
666
> ''
err: 1.2: syntax error: expected - or ( or number or function or variable before )
err: 1 | ()
err: | ^'
cat >input <<EOF
100% + 10
EOF
run 0 '> 100% + 10
> ''
err: 1.4: syntax error: invalid character: %'
# Traces. This allows to check the location of the error. If we
# forget to map YYerror to YYUNDEF, error recovery enters an endless
# loop with this input.
cat >input <<EOF
(+_)
EOF
run 0 '> (+_)
666
> ''
err: Starting parse
err: Entering state 0
err: Stack now 0
err: Reading a token
err: Next token is token ( (1.1: )
err: Shifting token ( (1.1: )
err: Entering state 2
err: Stack now 0 2
err: Return for a new token:
err: Reading a token
err: Next token is token + (1.2: )
err: LAC: initial context established for +
err: LAC: checking lookahead +: Err
err: LAC: checking lookahead end of file: Err
err: LAC: checking lookahead +: Err
err: LAC: checking lookahead -: S1
err: LAC: checking lookahead *: Err
err: LAC: checking lookahead /: Err
err: LAC: checking lookahead ^: Err
err: LAC: checking lookahead (: S2
err: LAC: checking lookahead ): Err
err: LAC: checking lookahead =: Err
err: LAC: checking lookahead exit: Err
err: LAC: checking lookahead number: S4
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
err: Stack now 0 2 10
err: Next token is token + (1.2: )
err: LAC: initial context established for +
err: LAC: checking lookahead +: Err
err: Error: discarding token + (1.2: )
err: Error: popping token error (1.2: )
err: Stack now 0 2
err: LAC: initial context discarded due to error recovery
err: Shifting token error (1.2: )
err: Entering state 10
err: Stack now 0 2 10
err: Return for a new token:
err: 1.3: syntax error: invalid character: _
err: Reading a token
err: Error: popping token error (1.2: )
err: Stack now 0 2
err: Shifting token error (1.2-3: )
err: Entering state 10
err: Stack now 0 2 10
err: Next token is token invalid token (1.3: )
err: LAC: initial context established for invalid token
err: LAC: checking lookahead invalid token: Always Err
err: Error: discarding token invalid token (1.3: )
err: Error: popping token error (1.2-3: )
err: Stack now 0 2
err: LAC: initial context discarded due to error recovery
err: Shifting token error (1.2-3: )
err: Entering state 10
err: Stack now 0 2 10
err: Return for a new token:
err: Reading a token
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 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 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 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 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 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
## ------------ ##
## Completion. ##
## ------------ ##
# From now on, the differences between versions of GNU Readline are
# too painful to try to cope with.
if $strip_prompt; then
echo "SKIP: this is not the GNU Readline we expect"
exit $status
fi
# On Windows10/MSYS2 the ^G coming from <tab> completion is not
# emitted the same way
# (https://lists.gnu.org/r/bug-bison/2020-05/msg00076.html).
echo "checking for kernel name... $(uname -s)"
case $(uname -s) in
(MSYS*)
echo "SKIP: this is Windows/MSYS"
exit $status
;;
esac
# Check completion after an operator.
sed -e 's/\\t/ /g' >input <<EOF
(1+\t\t
EOF
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 | (1+
err: | ^'
# Check the completion of a word.
sed -e 's/\\t/ /g' >input <<EOF
(at\t\t
EOF
run 0 '> (atan ( ''
> ''
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
e\t\t
EOF
run -n 0 '> e
end of file exit exp ''
> e
0
> ''
err: '
# Check that completion prints valid locations even when there is an error.
sed -e 's/\\t/ /g' >input <<EOF
1++\t
EOF
run -n 0 '> 1++ ''
> ''
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.
sed -e 's/\\t/ /g' >input <<EOF
(1++2) + 3 +\t\t
EOF
run -n 0 '> (1++2) + 3 + ''
> ''
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: | ^
'
+41
View File
@@ -0,0 +1,41 @@
## Copyright (C) 2020 Free Software Foundation, Inc.
##
## 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/>.
bistromathicdir = $(docdir)/%D%
## --------------- ##
## Bistromathics. ##
## --------------- ##
%D%/parse.c: $(dependencies)
if ENABLE_BISTROMATHIC
check_PROGRAMS += %D%/bistromathic
TESTS += %D%/bistromathic.test
nodist_%C%_bistromathic_SOURCES = %D%/parse.y
# Don't use gnulib's system headers.
%C%_bistromathic_CPPFLAGS = \
-DBISON_LOCALEDIR='"$(localdir)"' \
-DLOCALEDIR='"$(localdir)"' \
-I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_bistromathic_CFLAGS = $(TEST_CFLAGS)
%C%_bistromathic_LDADD = -lm $(LIBREADLINE) $(LIBINTL)
endif
EXTRA_DIST += %D%/bistromathic.test
dist_bistromathic_DATA = %D%/parse.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/parse.[ch] %D%/parse.output
CLEANDIRS += %D%/*.dSYM
+670
View File
@@ -0,0 +1,670 @@
/* Parser and scanner for bistromathic. -*- C -*-
Copyright (C) 2019-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/>. */
%require "3.7"
// Emitted on top of the implementation file.
%code top {
#include <ctype.h> // isdigit
#include <locale.h> // LC_ALL
#include <math.h> // cos, sin, etc.
#include <stdarg.h> // va_start
#include <stdio.h> // printf
#include <stdlib.h> // calloc
#include <string.h> // strcmp
#include <readline/readline.h>
#include <readline/history.h>
#if defined ENABLE_NLS && ENABLE_NLS
// Unable the translation of Bison's generated messages.
# define YYENABLE_NLS 1
# include <libintl.h>
// Unless specified otherwise, we expect bistromathic's own
// catalogue to be installed in the same tree as Bison's catalogue.
# ifndef LOCALEDIR
# define LOCALEDIR BISON_LOCALEDIR
# endif
#endif
}
// Emitted in the header file, before the definition of YYSTYPE.
%code requires {
// Function type.
typedef double (func_t) (double);
// Data type for links in the chain of symbols.
typedef struct symrec symrec;
struct symrec
{
char *name; // name of symbol
int type; // type of symbol: either VAR or FUN
union
{
double var; // value of a VAR
func_t *fun; // value of a FUN
} value;
symrec *next; // link field
};
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.
%code provides {
# ifndef __attribute__
# ifndef __GNUC__
# define __attribute__(Spec) /* empty */
# endif
# endif
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.
%code {
#if defined ENABLE_NLS && ENABLE_NLS
# define _(Msgid) gettext (Msgid)
#else
# define _(Msgid) (Msgid)
#endif
// Whether to quit.
int done = 0;
}
// Include the header in the implementation rather than duplicating it.
%define api.header.include {"parse.h"}
// Don't share global variables between the scanner and the parser.
%define api.pure full
// Generate a push parser.
%define api.push-pull push
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
// with TOK_ (e.g., TOK_EOF).
%define api.token.prefix {TOK_}
// Customized syntax error messages (see yyreport_syntax_error).
%define parse.error custom
// with locations.
%locations
// and accurate list of expected tokens.
%define parse.lac full
// 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
PLUS "+"
MINUS "-"
STAR "*"
SLASH "/"
CARET "^"
LPAREN "("
RPAREN ")"
EQUAL "="
EXIT "exit"
<double>
NUM _("number")
<symrec*>
FUN _("function")
VAR _("variable")
%nterm <double> exp
// Enable run-time traces (yydebug).
%define parse.trace
// Formatting semantic values in debug traces.
%printer { fprintf (yyo, "%s", $$->name); } VAR;
%printer { fprintf (yyo, "%s()", $$->name); } FUN;
%printer { fprintf (yyo, "%g", $$); } <double>;
// Precedence (from lowest to highest) and associativity.
%precedence "="
%left "+" "-"
%left "*" "/"
%precedence NEG // negation--unary minus
%right "^" // exponentiation
%% // The grammar follows.
input:
%empty
| exp { printf ("%.10g\n", $exp); }
| "exit" { done = 1; }
;
exp:
NUM
| VAR { $$ = $VAR->value.var; }
| VAR "=" exp { $$ = $3; $VAR->value.var = $3; }
| FUN "(" exp ")" { $$ = $FUN->value.fun ($3); }
| exp[l] "+" exp[r] { $$ = $l + $r; }
| exp[l] "-" exp[r] { $$ = $l - $r; }
| exp[l] "*" exp[r] { $$ = $l * $r; }
| exp[l] "/" exp[r]
{
if ($r == 0)
{
yyerror (&@$, uctx, "error: division by zero");
YYERROR;
}
else
$$ = $l / $r;
}
| "-" exp %prec NEG { $$ = -$2; }
| exp[l] "^" exp[r] { $$ = pow ($l, $r); }
| "(" exp ")" { $$ = $2; }
| "(" error ")" { $$ = 666; }
;
// End of grammar.
%%
/*------------.
| Functions. |
`------------*/
struct init
{
char const *name;
func_t *fun;
};
static struct init const funs[] =
{
{ "atan", atan },
{ "cos", cos },
{ "exp", exp },
{ "ln", log },
{ "sin", sin },
{ "sqrt", sqrt },
{ 0, 0 },
};
// The symbol table: a chain of 'struct symrec'.
static symrec *sym_table;
// Put functions in table.
static void
init_table (void)
{
for (int i = 0; funs[i].name; i++)
{
symrec *ptr = putsym (funs[i].name, TOK_FUN);
ptr->value.fun = funs[i].fun;
}
}
symrec *
putsym (char const *name, int sym_type)
{
symrec *res = (symrec *) malloc (sizeof (symrec));
res->name = strdup (name);
res->type = sym_type;
res->value.var = 0; // Set value to 0 even if fun.
res->next = sym_table;
sym_table = res;
return res;
}
symrec *
getsym (char const *name)
{
for (symrec *p = sym_table; p; p = p->next)
if (strcmp (p->name, name) == 0)
return p;
return NULL;
}
// How many symbols are registered.
static int
symbol_count (void)
{
int res = 0;
for (symrec *p = sym_table; p; p = p->next)
++res;
return res;
}
/*----------.
| Scanner. |
`----------*/
yytoken_kind_t
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
const user_context *uctx)
{
int c;
// Ignore white space, get first nonwhite character.
do {
// Move the first position onto the last.
yylloc->first_line = yylloc->last_line;
yylloc->first_column = yylloc->last_column;
yylloc->last_column += 1;
c = *((*line)++);
} while (c == ' ' || c == '\t');
switch (c)
{
case '+': return TOK_PLUS;
case '-': return TOK_MINUS;
case '*': return TOK_STAR;
case '/': return TOK_SLASH;
case '^': return TOK_CARET;
case '=': return TOK_EQUAL;
case '(': return TOK_LPAREN;
case ')': return TOK_RPAREN;
case '!': return TOK_YYUNDEF;
case '\0': return TOK_YYEOF;
// Numbers.
case '.':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
int nchars = 0;
if (sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars) != 1)
abort ();
*line += nchars - 1;
yylloc->last_column += nchars - 1;
return TOK_NUM;
}
// Identifiers.
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
{
int nchars = 0;
char buf[100];
if (sscanf (*line - 1, "%99[a-z]%n", buf, &nchars) != 1)
abort ();
*line += nchars - 1;
yylloc->last_column += nchars - 1;
if (strcmp (buf, "exit") == 0)
return TOK_EXIT;
else
{
symrec *s = getsym (buf);
if (!s)
s = putsym (buf, TOK_VAR);
yylval->TOK_VAR = s;
return s->type;
}
}
// Stray characters.
default:
yyerror (yylloc, uctx, "syntax error: invalid character: %c", c);
return TOK_YYerror;
}
}
/*---------.
| Parser. |
`---------*/
static const char *
error_format_string (int argc)
{
switch (argc)
{
default: // Avoid compiler warnings.
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
// "unexpected token", and '%0e', '%1e'... are expected tokens
// at this point.
//
// For instance on the expression "1 + * 2", you'd get
//
// 1.5: syntax error: expected - or ( or number or function or variable before *
case 2: return _("%@: syntax error: expected %0e before %u");
case 3: return _("%@: syntax error: expected %0e or %1e before %u");
case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e etc., before %u");
}
}
int
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);
if (argsize < 0)
return argsize;
const int too_many_expected_tokens = argsize == 0 && arg[0] != YYSYMBOL_YYEMPTY;
if (too_many_expected_tokens)
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, *loc);
format += 2;
}
// %u: unexpected token.
else if (format[0] == '%' && format[1] == 'u')
{
fputs (yysymbol_name (yypcontext_token (ctx)), stderr);
format += 2;
}
// %0e, %1e...: expected token.
else if (format[0] == '%'
&& isdigit ((unsigned char) format[1])
&& format[2] == 'e'
&& (format[1] - '0') < argsize)
{
int i = format[1] - '0';
fputs (yysymbol_name (arg[i]), stderr);
format += 3;
}
else
{
fputc (*format, stderr);
++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, const user_context *uctx, char const *format, ...)
{
if (uctx->silent)
return;
YY_LOCATION_PRINT (stderr, *loc);
fputs (": ", stderr);
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
putc ('\n', stderr);
}
// Return a newly allocated copy of at most N bytes of STRING. In
// other words, return a copy of the initial segment of length N of
// STRING.
static char *
xstrndup (const char *string, size_t n)
{
// len = strnlen (string, n), portably.
const char *end = memchr (string, '\0', n);
size_t len = end ? (size_t) (end - string) : n;
char *new = malloc (len + 1);
if (!new)
abort ();
new[len] = '\0';
return memcpy (new, string, len);
}
/*-----------.
| Readline. |
`-----------*/
// Parse (and execute) this line.
static int
process_line (YYLTYPE *lloc, const char *line)
{
user_context uctx = {0, line};
yypstate *ps = yypstate_new ();
int status = 0;
do {
YYSTYPE lval;
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++;
lloc->last_column = 1;
return status;
}
// Get the list of possible tokens after INPUT was read.
// Returns a nonnegative.
static int
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 {
YYSTYPE lval;
yytoken_kind_t token = yylex (&input, &lval, &lloc, &uctx);
// Don't let the parse know when we reach the end of input.
if (token == TOK_YYEOF)
break;
status = yypush_parse (ps, token, &lval, &lloc, &uctx);
} while (status == YYPUSH_MORE);
int res = 0;
// If there were parse errors, don't propose completions.
if (!ps->yynerrs)
{
// Then query for the accepted tokens at this point.
res = yypstate_expected_tokens (ps, tokens, ntokens);
if (res < 0)
abort ();
}
yypstate_delete (ps);
return res;
}
// Attempt to complete on the contents of TEXT. START and END bound
// the region of rl_line_buffer that contains the word to complete.
// TEXT is the word to complete. We can use the entire contents of
// rl_line_buffer in case we want to do some simple parsing. Return
// the array of matches, or NULL if there aren't any.
static char **
completion (const char *text, int start, int end)
{
YYDPRINTF ((stderr, "completion (\"%.*s[%.*s]%s\")\n",
start, rl_line_buffer,
end - start, rl_line_buffer + start,
rl_line_buffer + end));
// Get list of token numbers.
int tokens[YYNTOKENS];
char *line = xstrndup (rl_line_buffer, (size_t) start);
int ntokens = expected_tokens (line, tokens, YYNTOKENS);
free (line);
// Build MATCHES, the list of possible completions.
const size_t len = strlen (text);
// Need initial prefix and final NULL.
char **matches
= calloc ((size_t) ntokens + (size_t) symbol_count () + 2, sizeof *matches);
if (!matches)
abort ();
int match = 1;
for (int i = 0; i < ntokens; ++i)
switch (tokens[i])
{
case YYSYMBOL_FUN:
for (symrec *s = sym_table; s; s = s->next)
if (s->type == TOK_FUN && strncmp (text, s->name, len) == 0)
matches[match++] = strdup (s->name);
break;
case YYSYMBOL_VAR:
for (symrec *s = sym_table; s; s = s->next)
if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0)
matches[match++] = strdup (s->name);
break;
default:
{
const char* token = yysymbol_name (tokens[i]);
if (strncmp (text, token, len) == 0)
matches[match++] = strdup (token);
break;
}
}
// Find the longest common prefix, and install it in matches[0], as
// required by readline.
if (match == 1)
matches[0] = strdup (text);
else
{
size_t lcplen = strlen (matches[1]);
for (int i = 2; i < match && lcplen; ++i)
for (size_t j = 0; j < lcplen; ++j)
if (matches[1][j] != matches[i][j])
lcplen = j;
matches[0] = xstrndup (matches[1], lcplen);
}
if (yydebug)
{
fprintf (stderr, "completion (\"%.*s[%.*s]%s\") = ",
start, rl_line_buffer,
end - start, rl_line_buffer + start,
rl_line_buffer + end);
for (int i = 1; matches[i]; ++i)
fprintf (stderr, "%s%s",
i == 1 ? "{" : ", ",
matches[i]);
fprintf (stderr, "}\n");
}
// Don't fall back to proposing file names.
rl_attempted_completion_over = 1;
return matches;
}
static void
init_readline (void)
{
// Allow conditional parsing of the ~/.inputrc file.
rl_readline_name = "bistromathic";
// Tell the completer that we want a crack first.
rl_attempted_completion_function = completion;
// The basic list of characters that signal a break between words
// for the completer routine.
rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(+-*/^)";
}
/*-------.
| Main. |
`-------*/
int
main (int argc, char const* argv[])
{
#if defined ENABLE_NLS && ENABLE_NLS
// Set up internationalization.
setlocale (LC_ALL, "");
// Use Bison's standard translation catalogue for error messages
// (the generated messages).
bindtextdomain ("bison-runtime", BISON_LOCALEDIR);
// The translation catalogue of bistromathic is actually included in
// Bison's. In your own project, use the name of your project.
bindtextdomain ("bison", LOCALEDIR);
textdomain ("bison");
#endif
// Enable parse traces on option -p.
if (1 < argc && strcmp (argv[1], "-p") == 0)
yydebug = 1;
init_table ();
init_readline ();
YYLTYPE lloc = {1, 1, 1, 1};
while (!done)
{
char *line = readline ("> ");
if (!line)
{
// Finish the line started by the prompt.
putchar ('\n');
break;
}
if (*line)
add_history (line);
process_line (&lloc, line);
free (line);
}
}
+7 -12
View File
@@ -9,20 +9,15 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2019 Free Software Foundation, Inc.
Copyright (C) 2019-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.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
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/>.
--->
+7 -1
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2019 Free Software Foundation, Inc.
# Copyright (C) 2019-2020 Free Software Foundation, Inc.
#
# 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
@@ -34,4 +34,10 @@ cat >input <<EOF
(1+2) * 3
EOF
run 0 9
# Check the traces.
run -noerr 0 9 -p
cat >input <<EOF
1++2
EOF
run 0 "err: syntax error, unexpected '+', expecting number or '('"
+14 -5
View File
@@ -1,6 +1,8 @@
%code top {
#include <assert.h>
#include <ctype.h> /* isdigit. */
#include <stdio.h> /* For printf, etc. */
#include <stdio.h> /* printf. */
#include <stdlib.h> /* abort. */
#include <string.h> /* strcmp. */
int yylex (void);
@@ -8,16 +10,22 @@
}
%define api.header.include {"calc.h"}
%define api.value.type union /* Generate YYSTYPE from these types: */
/* Generate YYSTYPE from the types used in %token and %type. */
%define api.value.type union
%token <double> NUM "number"
%type <double> expr term fact
/* Generate the parser description file. */
/* Generate the parser description file (calc.output). */
%verbose
/* Nice error messages with details. */
%define parse.error detailed
/* Enable run-time traces (yydebug). */
%define parse.trace
/* Formatting semantic values. */
/* Formatting semantic values in debug traces. */
%printer { fprintf (yyo, "%g", $$); } <double>;
%% /* The grammar follows. */
@@ -67,7 +75,8 @@ yylex (void)
if (c == '.' || isdigit (c))
{
ungetc (c, stdin);
scanf ("%lf", &yylval.NUM);
if (scanf ("%lf", &yylval.NUM) != 1)
abort ();
return NUM;
}
+2 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2019 Free Software Foundation, Inc.
## Copyright (C) 2019-2020 Free Software Foundation, Inc.
##
## 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
@@ -27,6 +27,7 @@ nodist_%C%_calc_SOURCES = %D%/calc.y
# Don't use gnulib's system headers.
%C%_calc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_calc_CFLAGS = $(TEST_CFLAGS)
dist_calc_DATA = %D%/calc.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/calc.[ch] %D%/calc.output %D%/scan.c
+9 -13
View File
@@ -3,26 +3,22 @@
This directory contains lexcalc, the traditional example of using Flex and
Bison to build a simple calculator.
It features detailed syntax errors with locations.
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2019 Free Software Foundation, Inc.
Copyright (C) 2018-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/>.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
--->
+7 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
#
# 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
@@ -29,4 +29,9 @@ run -noerr 0 9 -p
cat >input <<EOF
(1+2) *
EOF
run 1 'err: syntax error, unexpected end-of-line, expecting ( or number'
run 1 'err: 1.8-2.0: syntax error, unexpected end of line, expecting ( or number'
cat >input <<EOF
1 / (2 - 2)
EOF
run 1 'err: 1.1-11: error: division by zero'
+13 -4
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2018-2019 Free Software Foundation, Inc.
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
##
## 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
@@ -15,9 +15,9 @@
lexcalcdir = $(docdir)/%D%
## ------ ##
## Calc. ##
## ------ ##
## --------- ##
## LexCalc. ##
## --------- ##
if FLEX_WORKS
check_PROGRAMS += %D%/lexcalc
@@ -25,10 +25,19 @@ if FLEX_WORKS
nodist_%C%_lexcalc_SOURCES = %D%/parse.y %D%/parse.h %D%/scan.l
# Don't use gnulib's system headers.
%C%_lexcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
# Fighting warnings triggered by Flex is just too painful.
# %C%_lexcalc_CFLAGS = $(TEST_CFLAGS)
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
+47 -9
View File
@@ -1,3 +1,22 @@
/* Parser for lexcalc. -*- C -*-
Copyright (C) 2018-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/>. */
// Prologue (directives).
%expect 0
@@ -6,10 +25,10 @@
{
// Tell Flex the expected prototype of yylex.
#define YY_DECL \
enum yytokentype yylex (YYSTYPE* yylval, int *nerrs)
yytoken_kind_t yylex (YYSTYPE* yylval, YYLTYPE *yylloc, int *nerrs)
YY_DECL;
void yyerror (int *nerrs, const char *msg);
void yyerror (YYLTYPE *loc, int *nerrs, const char *msg);
}
// Emitted on top of the implementation file.
@@ -19,12 +38,30 @@
#include <stdlib.h> // getenv.
}
// Include the header in the implementation rather than duplicating it.
%define api.header.include {"parse.h"}
// Don't share global variables between the scanner and the parser.
%define api.pure full
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
// with TOK_ (e.g., TOK_EOF).
%define api.token.prefix {TOK_}
// %token and %type use genuine types (e.g., "%token <int>"). Let
// %bison define YYSTYPE as a union of all these types.
%define api.value.type union
%define parse.error verbose
// Generate detailed error messages.
%define parse.error detailed
// with locations.
%locations
// Enable debug traces (see yydebug in main).
%define parse.trace
// Error count, exchanged between main, yyparse and yylex.
// Error count, exchanged between main, yyparse and yylex.
%param {int *nerrs}
%token
@@ -34,8 +71,7 @@
SLASH "/"
LPAREN "("
RPAREN ")"
EOL "end-of-line"
EOF 0 "end-of-file"
EOL "end of line"
;
%token <int> NUM "number"
@@ -66,7 +102,7 @@ exp:
{
if ($3 == 0)
{
yyerror (nerrs, "invalid division by zero");
yyerror (&@$, nerrs, "error: division by zero");
YYERROR;
}
else
@@ -77,9 +113,11 @@ exp:
;
%%
// Epilogue (C code).
void yyerror (int *nerrs, const char *msg)
void yyerror (YYLTYPE *loc, int *nerrs, const char *msg)
{
fprintf (stderr, "%s\n", msg);
YY_LOCATION_PRINT (stderr, *loc);
fprintf (stderr, ": %s\n", msg);
++*nerrs;
}
+42 -7
View File
@@ -1,16 +1,51 @@
/* Prologue (directives). -*- C++ -*- */
/* Scanner for lexcalc. -*- C -*-
Copyright (C) 2018-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/>. */
/* Prologue (directives). */
/* Disable Flex features we don't need, to avoid warnings. */
%option nodefault noinput nounput noyywrap
%{
#include <errno.h> /* errno, ERANGE */
#include <limits.h> /* INT_MIN */
#include <stdlib.h> /* strtol */
#include "parse.h"
// Each time a rule is matched, advance the end cursor/position.
#define YY_USER_ACTION \
yylloc->last_column += (int) yyleng;
// Move the first position onto the last.
#define LOCATION_STEP() \
do { \
yylloc->first_line = yylloc->last_line; \
yylloc->first_column = yylloc->last_column; \
} while (0)
%}
%%
%{
// Each time yylex is called, move the head position to the end one.
LOCATION_STEP ();
%}
/* Rules. */
"+" return TOK_PLUS;
@@ -26,18 +61,18 @@
errno = 0;
long n = strtol (yytext, NULL, 10);
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
yyerror (nerrs, "integer is out of range");
yyerror (yylloc, nerrs, "integer is out of range");
yylval->TOK_NUM = (int) n;
return TOK_NUM;
}
"\n" yylloc->last_line++; yylloc->last_column = 1; return TOK_EOL;
/* Ignore white spaces. */
[ \t]+ continue;
[ \t]+ LOCATION_STEP (); continue;
"\n" return TOK_EOL;
. yyerror (yylloc, nerrs, "syntax error, invalid character"); continue;
. yyerror (nerrs, "syntax error, invalid character");
<<EOF>> return TOK_EOF;
<<EOF>> return TOK_YYEOF;
%%
/* Epilogue (C code). */
+3 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2018-2019 Free Software Foundation, Inc.
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
##
## 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
@@ -16,8 +16,10 @@
cdir = $(docdir)/%D%
dist_c_DATA = %D%/README.md
include %D%/bistromathic/local.mk
include %D%/calc/local.mk
include %D%/lexcalc/local.mk
include %D%/mfcalc/local.mk
include %D%/pushcalc/local.mk
include %D%/reccalc/local.mk
include %D%/rpcalc/local.mk
+2 -1
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2005-2006, 2008-2015, 2018-2019 Free Software
## Copyright (C) 2005-2006, 2008-2015, 2018-2020 Free Software
## Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
@@ -31,6 +31,7 @@ nodist_%C%_mfcalc_SOURCES = $(mfcalc_sources)
%D%/mfcalc.c: $(dependencies)
# Don't use gnulib's system headers.
%C%_mfcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_mfcalc_CFLAGS = $(TEST_CFLAGS)
%C%_mfcalc_LDADD = -lm
dist_TESTS += %D%/mfcalc.test

Some files were not shown because too many files have changed in this diff Show More