Commit Graph

7791 Commits

Author SHA1 Message Date
Akim Demaille
77a8b84fc8 tests: provide check-examples and check-tests
* examples/local.mk (check-examples): New.
* tests/local.mk (check-tests): New.
* README-hacking.md: Document them.
2021-01-27 20:48:38 +01:00
Akim Demaille
b27bba5ced bistromathic: use gettext for all the messages
* examples/c/bistromathic/parse.y: Add missing calls to _.
2021-01-27 20:48:38 +01:00
Adela Vais
7a525fa06f d: tests: avoid mixing output from reportSyntaxError and getExpectedTokens
Function reportSyntaxError buffers and prints the message at the end.

* tests/local.at: Here.
2021-01-24 10:27:17 +01:00
Akim Demaille
c7037bfcb0 glr2.cc: fix destructor support
Currently glr2.cc does not use 'symbol's everywhere, in various places
it also uses yykind, yyval and yyloc "by hand".  So we need two
different calls for user-defined constructors: once for ~symbol,
another for yy_destroy_.  Both need to call the user destructors with
different calling conventions.

* data/skeletons/glr2.cc (b4_symbol_action): Rename as...
(b4_symbol_action_for_yyval): this.
(b4_symbol_action): New, taken from lalr1.cc.
(yy_destroy_, yy_symbol_value_print_): Use b4_symbol_action_for_yyval.
2021-01-24 09:56:07 +01:00
Akim Demaille
874e75975b glr2.cc: beware of types with angle brackets
For C++98, avoid "yyval.as<std::list<int>>".

* data/skeletons/glr2.cc (b4_call_merger): Add spaces within "<...>".
2021-01-24 09:56:02 +01:00
Akim Demaille
51f12cffd2 package: fix details after merge with 3.7.5
* TODO, cfg.mk: Update.
* src/parse-gram.c, src/parse-gram.h: Regen.
2021-01-24 09:30:02 +01:00
Akim Demaille
c94456986d Merge tag 'v3.7.5'
Three new commits:

commit 8358090292
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Wed Jan 20 18:30:16 2021 -0800

    c: port to HP-UX 11.23

commit 2c294c1325
Author: Vincent Imbimbo <vmi6@cornell.edu>
Date:   Sat Jan 23 13:25:18 2021 -0500

    cex: fix state-item pruning

commit c22902e360
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Jan 23 18:40:15 2021 +0100

    tables: fix handling for useless tokens
2021-01-24 09:22:49 +01:00
Akim Demaille
2fac23b9dd version 3.7.5
* NEWS: Record release date.
v3.7.5
2021-01-24 08:30:41 +01:00
Akim Demaille
c22902e360 tables: fix handling for useless tokens
In some rare conditions, the generated parser can be wrong when there
are useless tokens.

Reported by Balázs Scheidler.
https://github.com/akimd/bison/issues/72

Balázs managed to prove that the bug was introduced in

    commit af1c6f973a
    Author: Theophile Ranquet <ranquet@lrde.epita.fr>
    Date:   Tue Nov 13 10:38:49 2012 +0000

    tables: use bitsets for a performance boost

    Suggested by Yuri at
    <http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00000.html>.

    The improvement is marginal for most grammars, but notable for large
    grammars (e.g., PosgreSQL's postgre.y), and very large for the
    sample.y grammar submitted by Yuri in
    http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00012.html.
    Measured with --trace=time -fsyntax-only.

    parser action tables    postgre.y     sample.y
    Before                 0,129 (44%)  37,095 (99%)
    After                  0,117 (42%)   5,046 (93%)

    * src/tables.c (pos): Replace this set of integer coded as an unsorted
    array of integers with...
    (pos_set): this bitset.

which was implemented long ago, but that I installed only recently
(March 2019), first published in v3.3.90.

That patch introduces a bitset to represent a set of integers.  It
managed negative integers by using a (fixed) base (the smallest
integer to represent).  It avoided negative accesses into the bitset
by ignoring integers smaller than the base, under the asumption that
these cases correspond to useless tokens that are ignored anyway.
While it turns out to be true for all the test cases in the test suite
(!), Balázs' use case demonstrates that it is not always the case.

So we need to be able to accept negative integers that are smaller
than the current base.

"Amusingly" enough, the aforementioned patch was visibly unsure about
itself:

    /* Store PLACE into POS_SET.  PLACE might not belong to the set
       of possible values for instance with useless tokens.  It
       would be more satisfying to eliminate the need for this
       'if'.  */

This commit needs several improvements in the future:
- support from bitset for bit assignment and shifts
- amortized resizing of pos_set
- test cases

* src/tables.c (pos_set_base, pos_set_dump, pos_set_set, pos_set_test):
New.
Use them instead of using bitset_set and bitset_test directly.
2021-01-24 08:28:45 +01:00
Vincent Imbimbo
2c294c1325 cex: fix state-item pruning
There were several bugs in pruning that would leave the state-item
graph in an inconsistent state which could cause crashes later on:

- Pruning now happens in one pass instead of two.

- Disabled state-items no longer prune the state-items they transition
  to if that state-item has other states that transition to it.

- State-items that transition to disabled state-items are always
  pruned even if they have productions.

Reported by Michal Bartkowiak <michal.bartkowiak@nokia.com>
https://lists.gnu.org/r/bug-bison/2021-01/msg00000.html
and Zartaj Majeed
https://github.com/akimd/bison/issues/71

* src/state-item.c (prune_forward, prune_backward): Fuse into...
(prune_state_item): this.
Adjust callers.
2021-01-24 08:24:56 +01:00
Akim Demaille
236b85dd28 package: pacify syntax-check
* cfg.mk: Currently we cannot update gnulib because of portability
issues with ancient versions of clang
(https://lists.gnu.org/r/bug-gnulib/2021-01/msg00241.html).  So skip
the check about copyright date for gnulib.
2021-01-23 15:08:48 +01:00
Akim Demaille
4109d56aa9 news: update 2021-01-23 15:02:49 +01:00
Akim Demaille
003ca0498d package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-23 15:02:49 +01:00
Akim Demaille
3abad26a2d %merge: associate it to its first definition, not the latest
Currently each time we meet %merge we record this location as the
defining location (and symbol).  Instead, record the first definition.

In the generated code we go from

    yy0->A = merge (*yy0, *yy1);

to

    yy0->S = merge (*yy0, *yy1);

where S was indeed the first symbol, and in the diagnostics we go from

    glr-regr18.y:30.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
       30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~
    glr-regr18.y:29.18-24: note: previous declaration
       29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~
    glr-regr18.y:31.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
       31 | sym3: %merge<merge> { $$ = 0; } ;
          |             ^~~~~~~
    glr-regr18.y:30.18-24: note: previous declaration
       30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~

to

    glr-regr18.y:30.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
       30 | sym2: sym3 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~
    glr-regr18.y:29.18-24: note: previous declaration
       29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~
    glr-regr18.y:31.13-19: error: result type clash on merge function 'merge': <type3> != <type1>
       31 | sym3: %merge<merge> { $$ = 0; } ;
          |             ^~~~~~~
    glr-regr18.y:29.18-24: note: previous declaration
       29 | sym1: sym2 %merge<merge> { $$ = $1; } ;
          |                  ^~~~~~~

where both duplicates are reported against definition 1, rather than
using definition 1 as a reference when diagnosing about definition 2,
and then 2 as a reference for 3.

* src/reader.c (record_merge_function_type): Keep the first definition.
* tests/glr-regression.at: Adjust.
2021-01-23 15:02:49 +01:00
Akim Demaille
1bac4ecc44 %merge: fix compatibility with api.value.type=union
Reported by Jot Dot.
https://lists.gnu.org/r/help-bison/2020-12/msg00014.html

* data/skeletons/glr.c, data/skeletons/glr2.cc (b4_call_merger): Use
the symbol's slot, not its type.
* examples/c/glr/c++-types.y: Use explicit per-symbol typing together
with api.value.type=union.
(yylex): Use yytoken_kind_t.
2021-01-23 15:02:49 +01:00
Akim Demaille
84b00b6bf0 %merge: delegate the generation of calls to mergers to m4
Don't generate C code from bison, leave that to the skeletons.

* src/output.c (merger_output): Emit invocations to b4_call_merger.
* data/skeletons/glr.c (b4_call_merger): New.
2021-01-23 15:02:49 +01:00
Akim Demaille
a26f7cf98f %merge: let mergers record a typing-symbol, rather than a type
Symbols are richer than types, and in M4 it is my simpler (and more
common) to deal with symbols rather than types.  So let's associate
mergers to a symbol rather than a type name.

* src/reader.h (merger_list): Replace the 'type' member by a symbol
member.
* src/reader.c (record_merge_function_type): Take a symbol as
argument, rather than a type name.
* src/output.c (merger_output): Adjust.
2021-01-23 10:43:25 +01:00
Akim Demaille
0317055bb0 %merge: clearer tests on diagnostics
* tests/glr-regression.at: Use caret errors.
2021-01-23 10:43:25 +01:00
Akim Demaille
c73dcd6958 skeletons: introduce "slot"s for symbols
Extracted from d9cf99b6a5, in the master
branch.

* data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics
than type and type_tag.
2021-01-23 10:43:25 +01:00
Akim Demaille
11f6839645 style: YYUSE is private, make it YY_USE
This macro is not exposed to users, make start it with 'YY_'.

* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* src/parse-gram.c, tests/actions.at, tests/c++.at, tests/headers.at,
* tests/local.at (YYUSE): Rename as...
(YY_USE): this.
2021-01-23 10:43:25 +01:00
Akim Demaille
4910c02579 package: codespell
* src/parse-gram.y: Fix spelling.
2021-01-23 10:43:25 +01:00
Akim Demaille
83bc889536 cex: fix traces: fix display of disabled items
The display of disabled state items is incorrect.  The item is
stuttered, and lacks on end-of-line.

From

    State 7:
        1 exp: exp • "⊕" exp
        ->     1 exp: exp "⊕" • exp
        <-     1 exp: • exp "⊕" exp

        2 exp: exp • "+" exp    2 exp: exp • "+" exp DISABLED
        2 exp: exp "+" exp •
        <-     2 exp: exp "+" • exp

        3 exp: exp • "+" exp    3 exp: exp • "+" exp DISABLED
        3 exp: exp "+" exp •
        <-     3 exp: exp "+" • exp

to

    State 7:
        1 exp: exp • "⊕" exp
        ->     1 exp: exp "⊕" • exp
        <-     1 exp: • exp "⊕" exp

        2 exp: exp • "+" exp  DISABLED

        2 exp: exp "+" exp •
        <-     2 exp: exp "+" • exp

        3 exp: exp • "+" exp  DISABLED

        3 exp: exp "+" exp •
        <-     3 exp: exp "+" • exp

* src/state-item.c (state_items_report): Don't issue disabled items
twice, and issue two '\n' at their end.
* tests/conflicts.at: Check it.
2021-01-23 10:43:04 +01:00
Akim Demaille
2f554e6260 cex: fix traces: add missing end-of-lines
In 430ca0fc63, I completely forgot that
`puts` adds a `\n`.

* src/lssi.c, src/state-item.c: Restore missing end-of-lines in the
output.
2021-01-23 10:42:52 +01:00
Akim Demaille
7a31b6bb7f cex: add support for $TIME_LIMIT
* src/counterexample.c (TIME_LIMIT): Replace with...
(time_limit): this.
(counterexample_init): Check $TIME_LIMIT.
* src/scan-gram.l: Reorder includes.
2021-01-23 09:40:32 +01:00
Akim Demaille
8320691a63 cex: send traces to stderr, not stdout
When comparing traces from different machines, the mixture of
stdout/stderr in the output are making things uselessly difficult.

* src/lssi.c, src/state-item.c: Output debug traces on stderr.
2021-01-23 09:39:27 +01:00
Akim Demaille
3b03c62e49 c++: I'm tired of Flex's warnings
* doc/bison.texi: Disable another warning I'm tired to see.
New releases would be most welcome.
2021-01-23 09:39:15 +01:00
Akim Demaille
a700a13822 glr.cc: don't "leak" yyparse
When using glr.cc, the C function yyparse is an internal detail that
should not be exposed.  Users might call it by accident (I did).

* data/skeletons/glr.c (yyparse): When used for glr.cc, rename as yy_parse_impl.
* data/skeletons/glr.cc: Adjust.
2021-01-23 09:37:05 +01:00
Akim Demaille
1d3df34671 tables: avoid warnings and save bits
The yydefgoto table uses -1 as an invalid for an impossible case (we
never use yydefgoto[0], since it corresponds to the reduction to
$accept, which never happens).  Since yydefgoto is a table of state
numbers, this -1 forces a signed type uselessly, which (1) might
trigger compiler warnings when storing a value from yydefgoto into a
state number (nonnegative), and (2) wastes bits which might result in
using a int16 where a uint8 suffices.

Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00027.html

* src/tables.c (default_goto): Use 0 rather than -1 as invalid value.
* tests/regression.at: Adjust.
2021-01-23 09:36:24 +01:00
Akim Demaille
89d2b69c1b c++: use noexcept where appropriate
Reported by Don Macpherson.
https://github.com/akimd/bison/issues/63
https://github.com/akimd/bison/issues/64

* data/skeletons/c++.m4, data/skeletons/lalr1.cc: here.
2021-01-23 09:28:01 +01:00
Martin Rehak
1e0b087244 examples: avoid "unbound variable" errors
When the shell option `nounset` is set, we may get "unbound variable"
errors.
https://lists.gnu.org/r/bug-bison/2020-11/msg00013.html

* examples/test (diff_opts): Be sure to initialize it.
2021-01-23 09:27:30 +01:00
Akim Demaille
4744faf205 autoconf: update 2021-01-23 09:24:11 +01:00
Akim Demaille
1ac973aa56 c: adjust _Noreturn to pedantic clang
Reported by Joe Nelson <joe@begriffs.com>.
https://lists.gnu.org/r/help-bison/2021-01/msg00004.html
Fixed by Paul Eggert in gnulib.
https://lists.gnu.org/r/bug-gnulib/2021-01/msg00156.html

* data/skeletons/c.m4 (b4_attribute_define): Adjust _Noreturn to
pedantic clang.
2021-01-23 09:24:01 +01:00
Paul Eggert
8358090292 c: port to HP-UX 11.23
Problem reported by Albert Chin in:
https://lists.gnu.org/r/bug-bison/2021-01/msg00029.html
* data/skeletons/c.m4 (b4_c99_int_type_define):
Work around HP-UX bug.
2021-01-21 11:45:34 -08:00
Akim Demaille
fb144c021c d: examples: reduce scopes
* data/skeletons/lalr1.d (YYLocation.step): New.
* examples/d/calc/calc.y (Lexer): Reduce scopes to avoid uninitialized
varibles.
Factor the handling of locations.
We don't need lenChars.
2021-01-17 08:38:51 +01:00
Adela Vais
5aaa93ae72 d: examples: calc: remove Value from Lexer
The Symbol constructor does not use it, so it is easier to not use
Value at all.

* examples/d/calc/calc.y: Here.
2021-01-17 08:38:51 +01:00
Adela Vais
cd99a1a923 d: examples: calc: use of std.conv.parse for location
From Dlang v2.095.0 onwards, std.conv.parse reports the number of
consumed characters.

* examples/d/calc/calc.y: Here.
2021-01-17 08:38:51 +01:00
Adela Vais
d53bbd5f06 d: examples: simple: fix style
* examples/d/simple/calc.y: Formatting changes.
2021-01-17 08:38:35 +01:00
Akim Demaille
615bad4186 CI: run D tests
* .travis.yml: here.
2021-01-17 08:37:09 +01:00
Akim Demaille
4f6d1f5fdc package: codespell
* data/skeletons/glr2.cc, src/parse-gram.y: Fix spelling.
2021-01-16 18:05:57 +01:00
Akim Demaille
4fd2e5c22a package: fixes
* examples/c++/glr/local.mk, examples/c/glr/local.mk (CLEANFILES):
Complete to fix distcheck.
* src/output.c (merger_output): Obfuscate to pacify syntax-check's
sc_space_before_open_paren.
2021-01-16 17:30:17 +01:00
Akim Demaille
7e0b792d12 regen 2021-01-16 16:11:17 +01:00
Akim Demaille
d7e8aaa271 package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-16 16:11:17 +01:00
Akim Demaille
30a8d580fa gnulib: update
* src/output.c, src/print-xml.c: Adjust.
2021-01-16 16:11:04 +01:00
Akim Demaille
119dedb591 autoconf: update 2021-01-16 15:37:19 +01:00
Akim Demaille
d85ea95d6f cex: fix traces
The display of disabled state items is incorrect.  The item is
stuttered, and lacks on end-of-line.

From

    State 7:
        1 exp: exp • "⊕" exp
        ->     1 exp: exp "⊕" • exp
        <-     1 exp: • exp "⊕" exp

        2 exp: exp • "+" exp    2 exp: exp • "+" exp DISABLED
        2 exp: exp "+" exp •
        <-     2 exp: exp "+" • exp

        3 exp: exp • "+" exp    3 exp: exp • "+" exp DISABLED
        3 exp: exp "+" exp •
        <-     3 exp: exp "+" • exp

to

    State 7:
        1 exp: exp • "⊕" exp
        ->     1 exp: exp "⊕" • exp
        <-     1 exp: • exp "⊕" exp

        2 exp: exp • "+" exp  DISABLED

        2 exp: exp "+" exp •
        <-     2 exp: exp "+" • exp

        3 exp: exp • "+" exp  DISABLED

        3 exp: exp "+" exp •
        <-     3 exp: exp "+" • exp

* src/state-item.c (state_items_report): Don't issue disabled items
twice, and issue two '\n' at their end.
* tests/conflicts.at: Check it.
2021-01-16 15:19:15 +01:00
Akim Demaille
a9911528e0 cex: fix traces
In 430ca0fc63, I completely forgot that
`puts` adds a `\n`.

* src/lssi.c, src/state-item.c: Restore missing end-of-lines in the
output.
2021-01-16 14:40:54 +01:00
Akim Demaille
17fb1d0377 c: add support for YYNOMEM
Suggested by Joe Nelson <joe@begriffs.com>.
https://lists.gnu.org/r/help-bison/2020-12/msg00020.html

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): New.
Use it.
(yyexhaustedlab): Rename as...
(yynomemlab): this.
* tests/calc.at: Check it.
* doc/bison.texi: Document it.
Fix incorrect statements about non-existing constants for YYERROR etc.
2021-01-16 09:37:09 +01:00
Akim Demaille
a9f9f317b5 doc: spell check
Gettext uses "catalog", not "catalogue".

* doc/bison.texi, examples/c/README.md,
* examples/c/bistromathic/Makefile,
* examples/c/bistromathic/README.md,
* examples/c/bistromathic/parse.y:
Spell check.
2021-01-16 09:37:09 +01:00
Akim Demaille
4524e17616 yacc.c, glr.c: style: rename yyreturn and yyreturnlab
* data/skeletons/glr.c, data/skeletons/yacc.c: here.
2021-01-16 09:24:28 +01:00
Akim Demaille
c93aec904a glr.c: style: formatting changes
* data/skeletons/glr.c (YYCHK1): here.
2021-01-16 09:21:24 +01:00