Commit Graph

1816 Commits

Author SHA1 Message Date
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
Adela Vais
594cae57ca d: add internationalisation support
The D parser implements this feature similarly to the C parser,
by using Gettext. Functions gettext() and dgettext() are
imported using extern(C). The internationalisation uses yysymbol_name
to report the name of the SymbolKinds.

* data/skeletons/d.m4 (SymbolKind.toString.yytranslatable,
SymbolKind.toString.yysymbol_name: New), data/skeletons/lalr1.d: Here.
* doc/bison.texi: Document it.
* tests/calc.at: Test it.
2021-01-06 18:33:41 +01:00
Akim Demaille
c2a06bf791 glr: strengthen the tests
On some experimentation I was running, the test suite was passing, yet
the example crashed when run in verbose mode.  Let's add this case to
the test suite.

* tests/cxx-type.at: Run all these tests in verbose mode too.
2021-01-05 07:23:44 +01:00
Akim Demaille
e2199d0fb2 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/glr2.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-03 19:57:10 +01:00
Akim Demaille
ab1208e263 glr: consistently use the same wording in traces
* data/skeletons/glr.c, data/skeletons/glr2.cc (yyglrReduce): Traces
refer to "state 42", not to "state #42".
2021-01-03 08:14:22 +01:00
Akim Demaille
3911aba39a %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.
2020-12-31 08:07:34 +01:00
Akim Demaille
8bc45673d5 %merge: test support for api.value.type=union
* tests/glr-regression.at: here.
2020-12-31 08:07:34 +01:00
Akim Demaille
edfcca8481 %merge: clearer tests on diagnostics
* tests/glr-regression.at: Use caret errors.
2020-12-31 08:07:11 +01:00
Akim Demaille
94701b4e5e style: rename semanticVal as value
* data/skeletons/README-D.txt: Remove, now useless and obsolete.
* data/skeletons/glr2.cc, examples/d/calc/calc.y,
* tests/calc.at, tests/d.at, tests/scanner.at (semanticVal): Replace
with...
(value): this.
2020-12-26 14:26:23 +01:00
Akim Demaille
8db99c54f4 tests: don't require YYSTYPE/YYLTYPE to be defined in C++
* tests/glr-regression.at: Use AT_YYSTYPE/AT_YYLTYPE to generate
yy::parser::value_type and yy::parser::location_type in C++.
2020-12-26 11:55:01 +01:00
Adela Vais
32bb53870b d: remove unnecessary methods from the Lexer interface
The complete symbol approach in yylex removes the need for the methods
semanticVal, startPos and endPos, which were used when the values were
reported separately.

* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Remove sections about the three methods.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Remove the unused methods.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
2020-12-21 15:53:32 +01:00
Akim Demaille
c0f3b55b25 style: address syntax-check diagnostics
* examples/c/glr/c++-types.y: Formatting changes.
* po/POTFILES.in: Add missing files.
* src/reader.c: Remove useless include.
* tests/calc.at: Avoid magic values for exit.
Obfuscate calls to error.
2020-12-21 07:51:02 +01:00
Adela Vais
20d657c1dd d: create alias Position for YYPosition
* data/skeletons/d.m4 (b4_public_types_declare): Here.
* data/skeletons/lalr1.d: Adjust.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Use it.
* tests/calc.at: Test it.
2020-12-21 07:16:25 +01:00
Adela Vais
b00fa62e95 d: create alias Value for YYSemanticType
* data/skeletons/d.m4: Here.
* data/skeletons/lalr1.d, examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
2020-12-21 07:13:48 +01:00
Adela Vais
8e44b24ba8 d: create alias Location for YYLocation
* data/skeletons/d.m4: Here.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Adjust.
* tests/calc.at: Test it.
2020-12-21 07:13:17 +01:00
Adela Vais
cc04459cfe d: reduce verbosity for returning the location from yylex()
* examples/d/calc/calc.y (start, end): Replace by this...
(location): new member variable in the Lexer class.
Use it.
* tests/calc.at: Use the defined location variable.
2020-12-21 06:54:35 +01:00