Commit Graph

1862 Commits

Author SHA1 Message Date
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
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
Joshua Watt
f08110cb50 doc: fix documented function name
* data/README.md: Fix the name of a referenced function to match the
name in code.
2021-02-25 06:55:22 +01:00
Akim Demaille
c80b404dfa c: rename YY_LOCATION_PRINT as YYLOCATION_PRINT and make it public
It is very helpful to be able to look at the locations in the debug
traces, let's provide the users with (i) a means to do that for their
location types, and (ii) a public macro to print locations when debug
traces are enabled.

* data/skeletons/c.m4 (b4_yy_location_print_define): Rename as...
(b4_yylocation_print_define): this.
Define YYLOCATION_PRINT instead of YY_LOCATION_PRINT.
Ensure backward compatibility for those who might have defined/used
YY_LOCATION_PRINT in spite the warnings.
Adjust dependencies.
* data/skeletons/glr2.cc: We don't use YYLOCATION_PRINT here.
2021-02-09 06:48:02 +01:00
Akim Demaille
fdba54a961 c: stop defining YY_LOCATION_PRINT when locations are not enabled
* data/skeletons/c.m4 (b4_yy_location_print_define): here.
2021-02-02 06:53:53 +01:00
Akim Demaille
1efe31185f yacc: remove support for YYPRINT
Its removal was annonced several times in NEWS (for Bison 3.5, 3.6, 3.7).

* data/skeletons/c.m4, data/skeletons/yacc.c: Remove support for YYPRINT.
* NEWS: Fix the mess introduced by the merge.
Document the removal of YYPRINT.
* doc/bison.texi (The YYPRINT Macro): Remove.
2021-02-01 06:51:15 +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
a70e21215a c++: stop referring to YYSTYPE in yylex
* data/skeletons/glr2.cc, data/skeletons/lalr1.cc (b4_lex): Don't
refer to YYSTYPE, but to value_type.
Note that this is "symbolic" in the sense that these values are never
used by b4_function_call.
2021-02-01 05:54:06 +01:00
Akim Demaille
0dc20612c0 glr2.cc: no longer be part of b4_glr_cc_if
We are fully independant of glr.c/glr.cc, we no longer need to pretend
we are glr.cc.

* data/skeletons/bison.m4: here.
2021-01-31 18:44:30 +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
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
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
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
003ca0498d package: bump copyrights to 2021
Run 'make update-copyright'.
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
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
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
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
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
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
d7e8aaa271 package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-16 16:11:17 +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
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
Akim Demaille
c1494a7871 glr2.cc: don't prepare for subclassing
I am not aware of people subclassing the parser class, and I fail to
see how this could be useful.  Rather than leaving a badly baked
feature (as in glr.cc currently), let's not support it at all, until
someone comes and explains why and how it would be useful.

* data/skeletons/glr2.cc (parser): We need no virtual function members.
2021-01-16 07:14:50 +01:00
Akim Demaille
0923da74e8 glr2.cc: formatting changes
* data/skeletons/glr2.cc: here.
2021-01-16 07:14:47 +01:00
Akim Demaille
0a4a7178c8 glr2.cc: move strong_index_alias into implementation file
* data/skeletons/glr2.cc: here.
Fix coding style issues.
2021-01-16 07:14:35 +01:00
Akim Demaille
da4d38f830 glr2.cc: remove some useless qualifications
* data/skeletons/glr2.cc: Rely on the type-aliases provided by
glr_stack.
2021-01-16 07:14:23 +01:00
Akim Demaille
769322e01e glr2.cc: more free functions about the automaton into glr_stack
* data/skeletons/glr2.cc (yypact_value_is_default)
(yytable_value_is_error, yyisShiftAction, yyisErrorAction)
(yyisDefaultedState, yydefaultAction):
Move into...
(glr_stack): here.
Fix naming conventions.
2021-01-16 07:14:00 +01:00
Akim Demaille
19418cfc75 glr2.cc: move free-functions into glr_stack
* data/skeletons/glr2.cc (yypreference, yyLRgotoState): Move into...
(glr_stack): here.
2021-01-16 07:13:50 +01:00
Akim Demaille
42d5a16f8d glr2.cc: make yygetToken a member of glr_stack
It's on purpose that I keep the `this->` now.  We'll see later if we
want to remove them.

* data/skeletons/glr2.cc (yygetToken): Move into...
(glr_stack::yyget_token): this.
(b4_lex): Adjust.
2021-01-16 07:13:27 +01:00
Akim Demaille
118c4bd3a1 glr2.cc: move parser::parse into glr_stack
Currently we have two classes that actually should be fused together:
parser and glr_stack.  Both carry part of the parsing: (i) parser
contains `parse`, which is the top-level of the parsing process, it
uses yygetToken, etc., and (ii) glr_stack takes care of all the
details (dealing with the stack), and also calls yygetToken.

However if we fuse them together, we would get a large parser class,
in the header file.  So it is probably better to split this large
class using the pimpl idiom.  But then it appears that glr_stack is
very close from being the impl of parser.

Let's improve this.

For a start...

* data/skeletons/glr2.cc (parser::parse): Move to...
(glr_stack::parse): here.
(parser::parse): Use it.
2021-01-16 07:11:05 +01:00
Akim Demaille
cca770a156 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-13 08:03:45 +01:00
Akim Demaille
983364d76a glr2.cc: remove remains from glr.cc
* data/skeletons/glr2.cc: We no longer play dirty tricks with
parse-params, remove the now useless dance around them.
We now have genuine objects for locations, leave the initial action
alone.
2021-01-10 21:30:34 +01:00
Akim Demaille
6833b1be47 glr2.cc: add support for api.token.constructor
* data/skeletons/glr2.cc: Add support for api.token.constructor.
* examples/c++/glr/c++-types.yy: Use it.
* examples/c++/glr/c++-types.test: Adjust expectations for error
messages.
2021-01-10 17:12:50 +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
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
3a98be5284 glr2.cc: use references to print symbols
* data/skeletons/glr2.cc (b4_symbol_action): New, so that we use
`yyval` and `yyloc` rather than the `yyvaluep` and `yylocationp`
pointers.
(yy_symbol_value_print_, yy_symbol_print_, yy_destroy_): Use
references rather than pointers.
Drop support for the undocumented, obsolete, `yyoutput` variable.
Adjust callers.
(glr_state::destroy): Don't use yy_symbol_print_ when we don't have a
symbol.  Rather, write dedicated code.
2021-01-10 17:02:54 +01:00