Commit Graph

1831 Commits

Author SHA1 Message Date
Akim Demaille
024f00fd11 tests: fix incorrect test case
In c2ba260487 ("glr.c: fix signature
when using custom error messages"), I meant to add a test case for C,
not C++.  It does not work in C++.

* tests/calc.at: Run for glr.c, not glr.cc.
2021-08-12 10:13:38 +02:00
Akim Demaille
15ba35a51b build: check for C++ 20 and 2b
C++20 is released.

* configure.ac, m4/bison-cxx-std.m4, tests/atlocal.in,
* tests/local.at: Replace 2a with 20, and add support for 2b.
2021-08-12 09:07:36 +02:00
Akim Demaille
db66acc5d0 tests: remove obsolete checks
* tests/atlocal.in: It was an error for tests to depend on gnulib:
they must not, as gnulib would hide portability issues that we want to
catch.  So this piece of code is no longer useful, and must not be
useful.
2021-08-12 08:24:13 +02:00
Akim Demaille
3477ced42b tests: be robust to old versions of xlstproc
Reported by Christopher Nielsen <mascguy@github.com>.
<https://trac.macports.org/raw-attachment/ticket/59927/bison-test-results-20210811-95b72.log.xz>

* tests/report.at (AT_CHECK_HTML): New.
Use it.
2021-08-12 08:16:08 +02:00
Akim Demaille
c2ba260487 glr.c: fix signature when using custom error messages
Reported by Tom Shields <thomas.evans.shields@icloud.com>.

* data/skeletons/glr.c (yypcontext_location): Fix return type.
* tests/calc.at: Check the case pure, location, custom error messages.
2021-08-11 18:01:12 +02:00
Akim Demaille
e4e3cbce77 tests: check symbol/token renumbering
In some extreme situations, with lots of useless tokens, Bison was
numbering them incorrectly, which resulted in a broken grammar.
<https://lists.gnu.org/r/bison-patches/2021-03/msg00001.html>
commit a774839ca8.

* tests/regression.at (Useless Tokens): New.
2021-08-11 18:00:38 +02:00
Akim Demaille
3c5f73fe51 yacc: comply with recent POSIX updates: declare yyerror and yylex
In POSIX Yacc mode, declare yyerror and yylex unless already #defined,
or if YYERROR_IS_DECLARED/YYLEX_IS_DECLARED are defined (for
consistency with Bison's YYSTYPE_IS_DECLARED/YYLTYPE_IS_DECLARED).
See <https://austingroupbugs.net/view.php?id=1388#c5220>.

* data/skeletons/c.m4 (b4_function_declare): Resurect.
(b4_lex_formals): Since we will possibly expose this prototype
in the header, take the prefix into account.
* data/skeletons/yacc.c (b4_declare_yyerror_and_yylex): New.
(b4_shared_declarations): Use it.

* tests/local.at (AT_YACC_IF): New.
When in Yacc mode, set the `yacc` Autotest keyword.
(AT_YYERROR_DECLARE(c)): Don't declare in Yacc mode,
to avoid clashes (since this signature is static).
(AT_YYERROR_DEFINE(c)): Don't define as static in Yacc mode.
* tests/regression.at (Early token definitions with --yacc): Specify
that we are in Yacc mode.
2021-08-09 07:17:19 +02:00
Akim Demaille
7f1e9249d0 d: prepare to be able to run LAC tests
Unfortunately it seems to be quite difficult to have "LAC: Exploratory
stack" run for D.

* data/skeletons/lalr1.d: We need File when traces are enabled.
* tests/local.at (AT_YYLEX_DEFINE(d)): New.
* tests/regression.at: Prepare for D, but don't run it, it does not
work.
2021-08-07 12:53:19 +02:00
Akim Demaille
6d86d26b33 tests: factor iterating over skeletons
* tests/local.at (AT_FOR_EACH_SKEL): New.
Use where appropriate.
* data/skeletons/lalr1.d: Reject -d.
* tests/input.at, tests/scanner.at: Also check D.
2021-08-07 12:53:19 +02:00
Akim Demaille
80db1029e6 m4: catch suspicions of unevaluated macros
Check in m4's output if there are sequences such as m4_foo or b4_foo,
which are probably resulting from incorrect m4 processing.

It actually already is useful:

- it caught a leaking b4_lac_if leaking from glr.c, where LAC is not
  supported, hence b4_lac_if is not defined.

- it also caught references to location.hh in position.hh when
  location.hh does not exist.

- while making "Code injection" robust to these new warnings (it is
  its very purpose to let b4_canary pass unevaluated), I saw that it
  did not check lalr1.d, and when adding lalr1.d, it revealed it did
  underquote ocurrences of token value types.

* src/scan-skel.l (macro): New abbreviation.
Use it.
* data/skeletons/glr.c: Don't use b4_lac_if, we don't have it.
* data/skeletons/location.cc: Don't generate position.hh when we don't
generate location.hh.
* data/skeletons/d.m4 (b4_basic_symbol_constructor_define): Fix
underquotation.
* data/skeletons/bison.m4 (b4_canary): New.
* tests/input.at (Code injection): Use it, and check lalr1.d too.
2021-08-07 12:53:19 +02:00
Akim Demaille
9de593aba7 tests: extract AT_LOCATION_PRINT_DECLARE and AT_LOCATION_PRINT_DEFINE
* tests/local.at (AT_LOCATION_PRINT_DECLARE)
(AT_LOCATION_PRINT_DEFINE): New.
2021-08-06 18:02:23 +02:00
Akim Demaille
6fc9f13aef tests: rename AT_YACC_IF as AT_YACC_C_IF
In data/, b4_yacc_if refers to %yacc, not yacc.c.

* tests/local.at (AT_YACC_IF): Rename as...
(AT_YACC_C_IF): this.
2021-08-06 18:02:23 +02:00
Akim Demaille
cb7bdc251d style: tests: rebox comments
* tests/glr-regression.at: here.
2021-08-04 09:14:49 +02:00
Akim Demaille
952479fca7 scan: fix typo in UTF-8 escape
We had:

```
-mbchar    ...|\xF0[\x\90-\xBF]([\x80-\xBF]{2})|...
+mbchar    ...|\xF0[\x90-\xBF]([\x80-\xBF]{2})|...
```

so a precise sequence that matches the incorrect regex can let NUL
bytes pass through, which triggers an assertion violation downstream.
It is a pity that Flex does not report an error for such input.

Reported by Ahcheong Lee <ahcheong.lee@gmail.com>.
<https://lists.gnu.org/r/bug-bison/2021-04/msg00003.html>

* src/scan-gram.l (mbchar): Fix the bad regex.
* tests/input.at (Invalid inputs): Check that case.
2021-08-03 12:22:52 +02:00
Adela Vais
9ba3c5ceb9 d: add push parser support
Support the push-pull directive with the options pull, push and both.
Pull remains the default option.

* data/skeletons/d.m4: Add user aliases for the push parser's return
values: PUSH_MORE, ABORT, ACCEPT.
* data/skeletons/lalr1.d: Add push parser support.
* tests/calc.at: Test it.
2021-04-11 07:41:39 +02:00
Adela Vais
4bd4cdf377 d: add token constructors support
The user can return from yylex() by calling the Symbol method of the
same name as the TokenKind reported, and adding the parameters for
value and location if necessary.  These methods generate compile-time
errors if the parameters are not correlated.  Token constructors work
with both %union and api.value.type union.

* data/skeletons/d.m4: Here.
* tests/calc.at: Test it.
2021-03-26 07:01:55 +01:00
Akim Demaille
ae0889d805 d: add api.value.type union support
The union of the values is handled by the backend.
In D, unions can hold classes, structs, etc., so this is more similar
to the C++ api.value.type variant.

* data/skeletons/d.m4, data/skeletons/lalr1.d: Here.
* tests/calc.at, tests/local.at: Test it.
2021-03-26 07:01:48 +01:00
Akim Demaille
e1caae6b48 Merge 3.7.6 into master
* maint:
  maint: post-release administrivia
  version 3.7.6
  yacc: fix push parser
  tables: fix again the handling of useless tokens
2021-03-10 06:41:59 +01:00
Akim Demaille
cf899f7a7c yacc: fix push parser
When a pstate is used for multiple successive parses, some state may
leak from one run into the following one.  That was introduced in
330552ea49 "yacc.c: push: don't clear
the parser state when accepting/rejecting".

Reported by Ryan <dev@splintermail.com>
https://lists.gnu.org/r/bug-bison/2021-03/msg00000.html

* data/skeletons/yacc.c (yypush_parse): We reusing a pstate from a
previous run, do behave as if it were the first run.
* tests/push.at (Pstate reuse): Check this.
2021-03-07 18:41:38 +01:00
Akim Demaille
d50a3e450e graph: output foo.gv by default, instead of *.dot
That change was started in Bison 3.4.  The announcement for 3.7 stated
that in Bison 3.8 we would use *.gv by default.

* src/files.c (compute_output_file_names): spec_graph_file defaults
too *.gv.
* doc/bison.texi, examples/c++/calc++/local.mk, tests/output.at:
Adjust.
2021-02-02 06:51:39 +01:00
Akim Demaille
47186ec460 tests: adjust to the removal of YYPRINT
* tests/regression.at: here.
2021-02-01 08:34:49 +01:00
Akim Demaille
9acc9d2aee c++: issue a compile-time warning when #define YYSTYPE is used
Using #define YYSTYPE has always been strongly discouraged in C++.
Macros are dangerous and can result in subtle bugs.
https://lists.gnu.org/r/bug-bison/2020-12/msg00007.html

Maybe some people are currently using #define YYSTYPE.  Instead of
dropping support right now, first issue a warning.  Bison can "see" if
YYDEBUG is defined (it could even be on the command line), only the
compiler knows.  Unfortunately `#warning` is non-portable, and
actually GCC even dies on it when `-pedantic` is enabled.  So we need
to use `#pragma message`.  We must make it conditional as some
compilers might not support it, but it doesn't matter if only _some_
compilers emit the warning: it should be enough to catch the attention
of the developers.

* data/skeletons/c++.m4: Issue a warning when the user defined
YYSTYPE.
* tests/actions.at: Don't #define YYSTYPE.
* tests/headers.at (Several parsers): Ignore the YYSTYPE in the
warning.
2021-02-01 05:54:06 +01:00
Akim Demaille
6dc09317fb m4: provide macros for api.value.type=union
* data/skeletons/bison.m4 (b4_union_if): New.
Remove support for "%define variant", which was deprecated long ago.
* tests/local.at (AT_UNION_IF): New.
2021-01-31 07:27:41 +01:00
Akim Demaille
fc0dbb3bba traces: display the Bison version
* src/main.c (main): When traces are enabled, display the Bison
version.
* tests/conflicts.at, tests/report.at, tests/sets.at:
Use AT_PACKAGE_VERSION (for package.m4) instead of post-processing the
output.
2021-01-30 14:32:00 +01:00
Akim Demaille
de93a0728b tests: run the main test suite on "make check"
Automake appears to not recognize "check-local" when it is not a
isolated target.  Fixes 77a8b84fc8.

* tests/local.mk (check-local): Make it visible to Automake.
2021-01-30 09:06:36 +01:00
Adela Vais
689b184983 d: tests: various style fixes
* tests/calc.at, tests/scanner.at: Here.
(yylex): Report values directly, without storing them to the union
first.
2021-01-30 08:49:22 +01:00
Paul Eggert
ef3adfa0fb Update URLs to prefer https: to http:
Also, fix a few http: URLs that were no longer working.
2021-01-30 07:32:03 +01:00
Paul Eggert
b4582f1918 Update URLs to prefer https: to http:
Also, fix a few http: URLs that were no longer working.
2021-01-29 13:48:43 -08:00
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
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
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
0317055bb0 %merge: clearer tests on diagnostics
* tests/glr-regression.at: Use caret errors.
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
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
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
d7e8aaa271 package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-16 16:11:17 +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
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
3a9529eaed tests: check YYACCEPT and YYABORT
There are some tests that cover them, but nothing for all the
skeletons.  Let's do that in the calculator tests.

* tests/calc.at: Check YYACCEPT and YYABORT.
2021-01-16 09:16:06 +01:00
Akim Demaille
4aa731d110 glr2.cc: introduce the yytranslate_ member function
* data/skeletons/c++.m4 (b4_yytranslate_define): Use static_cast
rather than the YY_CAST macro.
Avoids the need to define YY_CAST in the header.
* data/skeletons/glr2.cc: Fix calls to b4_shared_declarations: pass
the type of file we are in.
Don't define YYTRANSLATE.
(parser::yytranslate_): New, as in lalr1.cc.
Adjust to use it.

* tests/glr-regression.at: Adjust.
2021-01-10 17:04:06 +01:00
Akim Demaille
3ad6d862b7 glr2.cc: tests: simplify
* tests/glr-regression.at: Remove useless qualification for tokens.
2021-01-10 17:04:06 +01:00
Akim Demaille
3fa59c32fc glr2.cc: rely on symbol kinds rather than token kinds
Instead of tracking the lookahead with yychar, use yytoken.  This is
consistent with lalr1.cc, saves us from calls to YYTRANSLATE (except
when calling yylex), and makes it easier to migrate to using
symbol_type.

* data/skeletons/glr2.cc: Replace all uses of `int yychar` with
`symbol_kind_type yytoken`.
(yygetToken): Don't take/return the lookahead's token-kind and
symbol-kind, just work directly on yystack's `yytoken` member.

* tests/glr-regression.at (AT_PRINT_LOOKAHEAD_DECLARE)
(AT_PRINT_LOOKAHEAD_DEFINE): New.
Adjust to the fact that we have yytoken, not yychar, in glr2.cc.
2021-01-10 17:04:06 +01:00
Akim Demaille
3bcc090758 glr: examples: fix locations
The locations are actually false: they should include the location of
the semicolon (we print statements), but they don't.

* examples/c++/glr/c++-types.test, examples/c++/glr/c++-types.yy,
* examples/c/glr/c++-types.test, examples/c/glr/c++-types.y,
* tests/cxx-type.at:
Fix locations and adjust expectations.
2021-01-10 17:02:54 +01:00
Akim Demaille
5433b0a84b glr: tests: more macros
This will be useful to support changes in glr2.cc.

tests/glr-regression.at
(Incorrect lookahead during deterministic GLR)
(Incorrect lookahead during nondeterministc GLR):
Introduce and use PRINT_LOOKAHEAD.
2021-01-10 17:02:54 +01:00
Akim Demaille
21c812e2f0 glr: tests: formatting changes
* tests/glr-regression.at: here.
Use %empty where applicable.
2021-01-10 17:02:46 +01:00
Akim Demaille
442c8d85aa tests: fix definition for parser class name
* tests/local.at (AT_PARSER_CLASS): Fix it.
And use it.
2021-01-10 12:14:47 +01:00
Akim Demaille
b52a2172a1 tests: remove some redundant tests
* tests/calc.at: Cut the CI some slack.
2021-01-07 18:51:48 +01:00
Adela Vais
c13b3c02d3 d: remove support for parse.error verbose
Without the history, D should not support this option. Before the
removal, 'detailed' and 'verbose' options generated the same code.

* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Adapt tests to use 'detailed' instead of 'verbose'.
* tests/calc.at: Document it.
2021-01-07 18:51:48 +01:00
Akim Demaille
f859462658 d: add support for %printer
Currently we display the addresses of the semantic values.  Instead,
print the values.

Add support for YY_USE across languages.

* data/skeletons/c.m4, data/skeletons/d.m4 (b4_use): New.
* data/skeletons/bison.m4 (b4_symbol_actions): Use b4_use to be
portable to D.

Add support for %printer, and use it.

* data/skeletons/d.m4: Instead of duplicating what's already in
c-like.m4, include it.
(b4_symbol_action): New.
Differs from the one in bison.m4 in that it uses yyval/yyloc instead
of *yyvaluep and *yylocationp.

* data/skeletons/lalr1.d (yy_symbol_print): Avoid calls to formatting,
just call write directly.
Use the %printer.
* examples/d/calc/calc.y: Specify a printer.
Enable traces when $YYDEBUG is set.
* tests/calc.at: Fix the use of %printer with D.
2021-01-07 06:31:28 +01:00