617 Commits

Author SHA1 Message Date
Paul Eggert
dcf16ff191 maint: make update-copyright 2026-01-18 09:45:29 -08:00
Paul Eggert
4ff0741f58 maint: make update-copyright 2025-03-17 17:48:06 -07:00
Paul Eggert
6a4b3240cf maint: pacify gcc 14.2 -Wmaybe-uninitialized
* data/skeletons/lalr1.cc:
* data/skeletons/yacc.c:
Add YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN and
YY_IGNORE_MAYBE_UNINITIALIZED_END to pacify GCC 14,
apparently after inlining.
2025-03-13 13:39:45 -07:00
Adela Vais
0faf371992 d: fix syntax error on SymbolKind.toString method
Reported by ledaniel2.
<https://github.com/akimd/bison/issues/88>

* data/skeletons/d.m4: Here.
2022-09-20 07:07:12 +02:00
Adela Vais
be4528096e d: fix interface syntax error
Fix syntax error regarding interface inheritance of the Lexer. It
appeared when the `%code lexer` option was used.

Reported by ledaniel2.
<https://github.com/akimd/bison/issues/84>

* data/skeletons/lalr1.d: Fix syntax.
* tests/d.at: Test it.
2022-09-20 06:39:05 +02:00
Anthony Heading
eb83487606 c++: enable C++11 assignment operators for lalr1.cc
<https://github.com/akimd/bison/pull/85>
<https://lists.gnu.org/r/bug-bison/2022-04/msg00000.html>

* data/skeletons/c++.m4: Enable C++11 assignment operators for
all C++ skeletons.
2022-09-03 09:37:07 +02:00
Akim Demaille
a166d5450e yacc.c, lalr1.cc: fix warnings about yynerrs
Most often yynerrs is not used.  Clang 15 now complains about such
variables.  Bison itself does not compile:

```
src/parse-gram.c:1797:9: error: variable 'gram_nerrs' set but not used [-Werror,-Wunused-but-set-variable]
    int yynerrs = 0;
        ^
src/parse-gram.c:79:25: note: expanded from macro 'yynerrs'
                        ^
1 error generated.
```

Reported by Nikita Popov.
Fixes https://github.com/akimd/bison/issues/89.

* data/skeletons/yacc.c (yynerrs): Flag with YY_ATTRIBUTE_UNUSED.
* data/skeletons/lalr1.cc (yynerrs_): Likewise.
2022-08-02 09:07:31 +02:00
Akim Demaille
b7bdf78c18 glr2.cc: fix -Wnoexcept issues
440-453 and 685 failed with GCC 12.1:

```
test.cc:1814:21:   required from here
/opt/local/include/gcc12/c++/bits/stl_construct.h:95:14: error: noexcept-expression evaluates to 'false' because of a call to '{anonymous}::glr_stack_item::glr_stack_item(bool)' [-Werror=noexcept]
   95 |     noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...)))
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:1486:5: note: but '{anonymous}::glr_stack_item::glr_stack_item(bool)' does not throw; perhaps it should be declared 'noexcept'
 1486 |     glr_stack_item (bool state = true)
      |     ^~~~~~~~~~~~~~
```

Reported by Paul Eggert.
<https://lists.gnu.org/r/bison-patches/2022-07/msg00008.html>

* data/skeletons/glr2.cc (glr_state, glr_stack_item): Declare the
default ctors noexcept.
2022-08-01 08:02:20 +02:00
Akim Demaille
722070124e lalr1.cc: declare stack_symbol_type as noexcept
Many C++ tests (400-25, 440-53, 664-5, 667-76, 679-80, 682-3, 685-9,
692) failed with GCC 12.1:

```
test.cc:843:28:   required from here
/opt/local/include/gcc12/c++/bits/stl_construct.h:95:14: error: noexcept-expression evaluates to 'false' because of a call to 'yy::parser::stack_symbol_type::stack_symbol_type()' [-Werror=noexcept]
   95 |     noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...)))
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:990:3: note: but 'yy::parser::stack_symbol_type::stack_symbol_type()' does not throw; perhaps it should be declared 'noexcept'
  990 |   parser::stack_symbol_type::stack_symbol_type ()
      |   ^~~~~~
```

Reported by Paul Eggert.
<https://lists.gnu.org/r/bison-patches/2022-07/msg00008.html>

* data/skeletons/lalr1.cc (stack_symbol_type::stack_symbol_type()):
Declare noexcept.
2022-08-01 07:08:52 +02:00
Paul Eggert
07e18e7fb4 package: bump copyrights to 2022
Run "make update-copyright".
2022-01-15 11:16:30 -08:00
Akim Demaille
3fc3ef658e c++: use YY_NOEXCEPT where it helps
Suggested by Don Macpherson.
<https://github.com/akimd/bison/issues/80>

* data/skeletons/c++.m4, data/skeletons/glr2.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh: Use YY_NOEXCEPT
where it helps constructors.
2021-09-18 08:07:22 +02:00
Akim Demaille
eeb5d6f11b glr2.cc: semantic_option: use a symbol
* data/skeletons/c++.m4 (basic_symbol): Add assignment operators.
* data/skeletons/glr2.cc (semantic_option): Replace yytoken, yyvalue
and yylocation by yyla.
2021-09-13 06:20:40 +02:00
Akim Demaille
70441b5ab1 glr2.cc: don't publish move ctor to lalr1.cc
These operators were introduced in "c++: add move assignments to the
symbol type" (fdaedc780a) for glr2.cc.

* data/skeletons/c++.m4: Define them for glr2.cc only.
2021-09-13 06:18:57 +02:00
Akim Demaille
7538d8dc1a glr2.cc: simplify semantic_option
* data/skeletons/glr2.cc (semantic_option): Simplify the rule-based
constructor.  This shows that it should be easy to use a symbol_kind,
instead of the kind/value/location triple.
2021-09-12 20:04:54 +02:00
Akim Demaille
b07b5ce423 glr2.cc: we require C++11
* data/skeletons/glr2.cc: So no need for C++98 compatibility.
2021-09-12 20:04:54 +02:00
Akim Demaille
157e91dcc6 glr2.cc: introduse b4_glr2_cc_if
* data/skeletons/bison.m4 (b4_glr2_cc_if): Intro.
* data/skeletons/c++.m4: use.
2021-09-12 20:04:44 +02:00
Akim Demaille
b820718adf glr2.cc: don't pass %parse-param to destroy
I regret that %destructor and %printer give access to the %parse-param
in lalr1.cc, since that prevents them from being implemented as a
simple destructor and operator<<.  Let's not repeat the mistake in
glr2.cc.  In addition, fixes a name conflict we have currently in
tests 566 568 570 657:

     calc.cc:1395:85: error: declaration shadows a field of 'calc::parser' [-Werror,-Wshadow]
     void glr_state::destroy (char const* yymsg, calc::parser& yyparser, semantic_value *result, int *count, int *nerrs)
                                                                                         ^
     calc.hh:441:21: note: previous declaration is here
         semantic_value *result;
                         ^

With this commit, the whole test suite passes for glr2.cc.

* data/skeletons/glr2.cc (glr_state::destroy): Don't take the user
arguments.
2021-09-12 14:00:55 +02:00
Akim Demaille
6e6e11795c glr2.cc: kill trailing white spaces
Fixes several calc tests.

Tests 566 568 570 657 still fail because of a name clash when using
%parse-param:

    calc.cc:1395:85: error: declaration shadows a field of 'calc::parser' [-Werror,-Wshadow]
    void glr_state::destroy (char const* yymsg, calc::parser& yyparser, semantic_value *result, int *count, int *nerrs)
                                                                                        ^
    calc.hh:441:21: note: previous declaration is here
        semantic_value *result;
                        ^

* data/skeletons/glr2.cc: Fix indentation/trailing spaces.
2021-09-12 14:00:55 +02:00
Akim Demaille
d432079f8a glr2.cc: move strong_index_alias into the unnamed namespace
* data/skeletons/glr2.cc: here.
2021-09-12 14:00:55 +02:00
Akim Demaille
b6ac175a1c glr2.cc: use only symbol_kind_type, not yysymbol_kind_t
* data/skeletons/glr2.cc: here.
And prefer the unnamed namespace to static.
2021-09-12 14:00:55 +02:00
Akim Demaille
5f90ef59a4 glr2.cc: prefer using, and remove useless type aliases
* data/skeletons/glr2.cc: here.
2021-09-12 14:00:55 +02:00
Akim Demaille
10ee04479f glr2.cc: put glr_state_set and glr_stack_item in unnamed namespace
* data/skeletons/glr2.cc: here.
2021-09-12 14:00:55 +02:00
Akim Demaille
c09524cf8f glr2.cc: move state_stack into the unnamed namespace
* data/skeletons/glr2.cc: here.
Prefer `using` to `typedef`, this is C++11.
Use the type alias we introduced.
2021-09-12 14:00:55 +02:00
Akim Demaille
28152fc10a glr2.cc: style: clarify control flow
* data/skeletons/glr2.cc (yypreference): Be more functional-style.
2021-09-12 14:00:55 +02:00
Akim Demaille
9babd05a90 glr2.cc: move glr_stack and glr_state into the parser class
In order to be able to link several glr2.cc parser together, we cannot
have glr_stack and glr_state be in no namespace.  Putting them in the
unnamed namespace is not doable, since we need to fwd declare them in
the parser.  Putting them in the specified namespace is not enough
either, since some users would like to be able to put several parsers
in the same name, only differing by the class name.

* data/skeletons/glr2.cc (glr_state, glr_stack): Move into yy::parser.
2021-09-12 14:00:55 +02:00
Akim Demaille
3e94b12ddd glr2.cc: put create_state_set_index in unnamed namespace
* data/skeletons/glr2.cc: here.
2021-09-12 14:00:55 +02:00
Akim Demaille
7cb6de2533 glr2.cc: prefer unnamed namespace to 'static'
* data/skeletons/glr2.cc: here.
2021-09-12 14:00:55 +02:00
Akim Demaille
4ec4309cce glr2.cc: put semantic_option into an unnamed namespace
If we link several glr2.cc parsers together, we get linking failures
because of duplicate symbols.

* data/skeletons/glr2.cc (semantic_option::indexIn)
(semantic_option::next): Remove the useless overloads.
2021-09-12 14:00:50 +02:00
Akim Demaille
ca96df89b2 glr2.cc: don't publish YY_EXCEPTIONS
We don't need them in the header file.

* data/skeletons/glr2.cc (YY_EXCEPTIONS): Define only in the
implementation file.
* tests/headers.at (Several Parsers): Also check glr2.cc.
2021-09-12 12:03:58 +02:00
Akim Demaille
a75072476e glr2.cc: custom error messages
Reported by Tom Shields <thomas.evans.shields@icloud.com>.
<https://lists.gnu.org/r/bug-bison/2021-08/msg00003.html>

* data/skeletons/glr2.cc (context): New.
Use it to generate the error messages.
Add support for custom error messages.
* tests/calc.at: Check support for custom error messages.
2021-09-12 12:03:58 +02:00
Akim Demaille
7c47598d4f glr2.cc: start the transition to using symbol_type
Currently glr2.cc uses three variables/struct members to denote the
symbols' kind (or state), value and location.  lalr1.cc has two types
for "complete" symbols: symbol_type and stack_symbol_type.  Let's use
that model in glr2.cc too.

For a start use yyla (a symbol_type) to denote the lookahead, instead
of the triple yytoken, yylval and yylloc.  This will make easier the
introduction of the "context" subclass, used in parse.error=custom.

It simplifies the code in several places.  For instance from:

    symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
    value_type yylval_current;
    ]b4_symbol_variant([this->yytoken],
                       [yylval_current], [move], [this->yylval])], [[
    value_type yylval_current = this->yylval;]])[]b4_locations_if([
    location_type yylloc_current = this->yylloc;])[

to:

    symbol_type yyla_current = std::move (this->yyla);

* data/skeletons/glr2.cc (yytoken, yylval, yylloc): Replace by...
(yyla): this.
Adjust all dependencies.
(yyloc_default): Remove, unused.
* tests/c++.at, tests/glr-regression.at, tests/types.at: C++11 is
required for glr2.cc.
Adjust to changes in glr2.cc.
2021-09-12 12:03:58 +02:00
Akim Demaille
fdaedc780a c++: add move assignments to the symbol type
This will be used in glr2.cc, which requires C++11.

* data/skeletons/c++.m4 (basic_symbol, by_kind): Add move assignment.
2021-09-12 12:03:58 +02:00
Akim Demaille
85f5e3b9d5 c++: avoid using the obsolete names
* data/skeletons/c++.m4: Don't define obsolete identifiers in the case
of glr2.cc.  Let's not start with technical debt.
* data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/variant.hh: Use token_kind_type, not token_type.
* tests/c++.at, tests/local.at: Use value_type, not semantic_type.
2021-09-12 12:03:58 +02:00
Akim Demaille
5d9ccd5a87 yacc: declare yyerror/yylex only when POSIXLY_CORRECT
The recent changes to comply with POSIX are breaking Automake's test
suite.
Reported by Kiyoshi Kanazawa.
<https://lists.gnu.org/r/bug-bison/2021-09/msg00005.html>

To limit the impact of POSIX changes, bind them to $POSIXLY_CORRECT.
Suggested by Karl Berry.
<https://lists.gnu.org/r/bug-bison/2021-09/msg00009.html>

The existing `maintainer-check-posix` Make target checks these
changes.

* src/getargs.h, src/getargs.c (set_yacc): New.
Use it.
* data/skeletons/bison.m4 (b4_posix_if): New.
* data/skeletons/yacc.c (b4_declare_yyerror_and_yylex): Use it.
* doc/bison.texi, tests/local.at: Adjust.
2021-09-11 08:26:10 +02:00
Akim Demaille
075a879052 style: c++: formatting changes
* data/skeletons/variant.hh, data/skeletons/glr2.cc: Fix space before
paren issue.
2021-08-29 18:36:07 +02:00
Akim Demaille
a5c55bb758 c++: beware of Visual C++ limitations
Contrary to what commit d8cc6b073e "c++:
shorten the assertions that check whether tokens are correct"
believed, MS Visual C++'s preprocessor limitation is not on the input
line length, but on the size of the line holding the full C++
statement.

Reported by Vince Huffaker <vince@vincejulie.com>
<https://lists.gnu.org/r/help-bison/2021-08/msg00003.html>

* data/skeletons/variant.hh (_b4_symbol_constructor_define): Hide the
assertion from Visual C++.
2021-08-29 10:10:56 +02:00
Akim Demaille
36f37568ba glr2.cc: require C++11
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2021-08/msg00006.html

* m4/bison-cxx-std.m4 (_BISON_CXXSTD_98_snippet): We don't need
vector::data, it was only for glr2.cc, which is C++11 anyway.
(_BISON_CXXSTD_11_snippet): We need vector::data and std::swap on
arrays.
* m4/cxx.m4 (BISON_TEST_FOR_WORKING_CXX_COMPILER): We don't need
vector::data.
* tests/local.at (AT_COMPILE_CXX): Skip when glr2.cc and no support
for C++11.
2021-08-19 08:21:22 +02:00
Akim Demaille
348b5039fd c: fix _Noreturn support detection
Reported by Christopher Nielsen <mascguy@github.com>.
<https://trac.macports.org/ticket/59927#comment:59> and
<https://trac.macports.org/ticket/59927#comment:62>.

* data/skeletons/c.m4: Fix typo.
2021-08-11 18:01:12 +02:00
Akim Demaille
07cdeda9f8 lalr1.cc: style changes
* data/skeletons/lalr1.cc: Formatting changes.
Use more `const`, as in glr2.cc.
2021-08-11 18:01:12 +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
b2a00ed5dd style: rename b4_lex as b4_yylex
For consistency with b4_yyerror_formals, etc.

* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/d.m4,
* data/skeletons/glr.c, data/skeletons/glr2.cc,
* data/skeletons/java.m4, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c
(b4_lex, b4_lex_formals): Rename as...
(b4_yylex, b4_yylex_formals): these.
2021-08-09 07:17:19 +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
9b6065303b all: fix confusion between token ctor and symbol ctor
The symbol constructors are genuine constructors.  Token constructors
are plain functions that construct tokens.
2021-08-01 09:55:39 +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
Adela Vais
a9c2549c27 d: rewrite Symbol's constructors in M4
The D code was becoming too complex.
M4 is easier to maintain in the long run.

* data/skeletons/d.m4: Here.
2021-03-26 06:49:32 +01:00