38 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
07e18e7fb4 package: bump copyrights to 2022
Run "make update-copyright".
2022-01-15 11:16:30 -08: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
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
d7e8aaa271 package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-16 16:11:17 +01:00
Akim Demaille
b327f38832 deprecate %defines in favor of %header
This is consistent with --defines being deprecated in favor of
--header.  The directive %defines is also too similar to %define.
And %header matches nicely with api.header.name.

* src/scan-gram.l (%defines): Deprecate to %header.
(%header): Scan it.
* src/parse-gram.y (PERCENT_DEFINES): Replace with...
(PERCENT_HEADER): this.
* data/skeletons/lalr1.java
* doc/bison.texi
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/java.at, tests/local.at, tests/output.at,
* tests/synclines.at, tests/types.at:
Convert most tests to check %header instead of %defines.
2020-09-19 17:49:03 +02:00
Valentin Tolmer
ef09bf065a glr2.cc: fork glr.cc to a c++ version
This is a fork of glr.cc to be c++-first instead of a wrapper around
glr.c.

* data/skeletons/glr2.cc: New.
* data/skeletons/bison.m4, data/skeletons/c++.m4: Adjust.
* data/skeletons/c.m4 (b4_user_args_no_comma): New.
* src/reader.c (grammar_rule_check_and_complete): glr2.cc is C++.
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/local.at, tests/regression.at, tests/scanner.at,
* tests/synclines.at, tests/types.at: Also check glr2.cc.
2020-08-30 10:45:21 +02:00
Akim Demaille
e7aff57122 style: rename user_token_number as code
This should have been done in 3.6, but I wanted to avoid introducing
conflicts into Vincent's work on counterexamples.  It turns out it's
completely orthogonal.

* data/README.md, data/skeletons/bison.m4, data/skeletons/c++.m4,
* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/java.m4,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/variant.hh, data/skeletons/yacc.c, src/conflicts.c,
* src/derives.c, src/gram.c, src/gram.h, src/output.c,
* src/parse-gram.c, src/parse-gram.y, src/print-xml.c, src/print.c,
* src/reader.c, src/symtab.c, src/symtab.h, tests/input.at,
* tests/types.at:
s/user_token_number/code/g.
Plus minor changes.
2020-05-23 08:43:58 +02:00
Akim Demaille
8036635251 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-05 10:26:35 +01:00
Akim Demaille
3398b0fa90 c++: fix old cast warnings
We still have a few old C casts in lalr1.cc, let's get rid of them.
Reported by Frank Heckenbach.

Actually, let's monitor all our casts using easy to grep macros.
Let's use these macros to use the C++ standard casts when we are in
C++.

* data/skeletons/c.m4 (b4_cast_define): New.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/yacc.c:
Use it and/or its casts.

* tests/actions.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/headers.at, tests/torture.at,
* tests/types.at:
Use YY_CAST instead of C casts.

* configure.ac (warn_cxx): Add -Wold-style-cast.
* doc/bison.texi: Disable it.
2019-11-02 16:40:50 +01:00
Akim Demaille
a11c144609 tests: simplify AT_PARSER_CHECK usage
Currently the caller must specify the ./ prefix to its command.  Let's
avoid that: it will be nicer to read, make it easier to have a version
that works for Java and C/C++.

* tests/local.at (AT_PARSER_CHECK): Prefix the command with ./.
Adjust callers.
2019-02-21 17:46:11 +01:00
Akim Demaille
79e79be298 diagnostics: improve accuracy for deprecated %define variables
* src/parse-gram.y: Use the location of the whole definition to record
the location of a %define variable, instead of just the name of the
variable.
Adjust tests.
2019-01-14 19:57:37 +01:00
Akim Demaille
2471733f1a package: bump copyrights to 2019 2019-01-05 14:58:05 +01:00
Akim Demaille
e5780041b9 c++: exhibit a safe symbol_type
Instead of introducing make_symbol (whose name, btw, somewhat
infringes on the user's "name space", if she defines a token named
"symbol"), let's make the construction of symbol_type safer, using
assertions.

For instance with:

    %token ':' <std::string> ID <int> INT;

generate:

    symbol_type (int token, const std::string&);
    symbol_type (int token, const int&);
    symbol_type (int token);

It does mean that now named token constructors (make_ID, make_INT,
etc.) go through a useless assert, but I think we can ignore this: I
assume any decent compiler will inline the symbol_type ctor inside the
make_TOKEN functions, which will show that the assert is trivially
verified, hence I expect no code will be emitted for it.  And anyway,
that's an assert, NDEBUG controls it.

* data/c++.m4 (symbol_type): Turn into a subclass of
basic_symbol<by_type>.
Declare symbol constructors when variants are enabled.
* data/variant.hh (_b4_type_constructor_declare)
(_b4_type_constructor_define): Replace with...
(_b4_symbol_constructor_declare, _b4_symbol_constructor_def): these.
Generate symbol_type constructors.
* doc/bison.texi (Complete Symbols): Document.
* tests/types.at: Check.
2018-12-22 14:55:07 +01:00
Akim Demaille
1f4dd2671a c++: provide symbol constructors per type
On

    %token <int> FOO BAR

we currently generate make_FOO(int) and make_BAR(int).  However, in
order to factor their scanners, some users would also like to have
make_symbol(tok, int), where tok is FOO or BAR.  To ensure type
safety, add assertions that do check that value type and token type
match.  Bind this assertion to the parse.assert %define variable.

Suggested by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00034.html
Should also match expectations from Аскар Сафин.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00023.html

* data/variant.hh: Use b4_token_visible_if where applicable.
(_b4_type_constructor_declare, _b4_type_constructor_define): New.
Use them.
2018-12-22 13:05:28 +01:00
Akim Demaille
34c52d10ac c++: style changes
* data/c++.m4, data/variant.hh: Improve layout of the generated code.
Avoid casts.
(_b4_symbol_constructor_declare, _b4_symbol_constructor_define): Rename
as...
(_b4_token_maker_declare, _b4_token_maker_define): these.
* tests/types.at: Improve pair printing.
2018-12-22 13:05:28 +01:00
Akim Demaille
a8e66fc010 style: simplify tests
* tests/types.at: Simplify C++ instantiations.
2018-12-22 11:28:59 +01:00
Akim Demaille
98d199ccc8 c++: fix token constructors for types with commas
Bitten by macros, again.
See 680b715518.

* data/variant.hh (_b4_symbol_constructor_declare)
(_b4_symbol_constructor_define): Do not use user types, which can
include commas as in `std::pair<int, int>`, to macros.

* tests/local.at: Adjust the lex related macros to support the
case of token constructors.
* tests/types.at: Also check token constructors on types with commas.
2018-12-19 06:40:28 +01:00
Akim Demaille
81dbd0d82e C++: support variadic emplace
Suggested by Askar Safin.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00006.html

* data/variant.hh: Implement.
* tests/types.at: Check.
* doc/bison.texi: Document.
2018-12-10 17:50:12 +01:00
Akim Demaille
4e510c69b1 c++: using macros around user types breaks when they include comma
We may generate code such as

    basic_symbol (typename Base::kind_type t, YY_RVREF (std::pair<int,int>) v);

which, of course, breaks, because YY_RVREF sees two arguments.  Let's
not play tricks with _VA_ARGS__, I'm unsure about it portability.
Anyway, I plan to change more things in this area.

Reported by Sébastien Villemot.
http://lists.gnu.org/archive/html/bug-bison/2018-11/msg00014.html

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Don't use macro on user types.
* tests/types.at: Check that we support pairs.
2018-11-20 20:01:50 +01:00
Akim Demaille
8eb1d79333 tests: run the api.value.type tests for all C++ standards
* tests/local.at (AT_LANG_FOR_EACH_STD): New.
(AT_REQUIRE_CXX_VERSION): Rename as...
(AT_REQUIRE_CXX_STD): this.
Accept an argument for what to do when the requirement is not met.
* tests/types.at (api.value.type): Check all the C++ stds.
2018-11-16 17:37:47 +01:00
Akim Demaille
b4b8666e4a tests: be strict about types
* tests/actions.at, tests/c++.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/local.at, tests/torture.at,
* tests/types.at:
Pay stricter attention to types to avoid warnings.
2018-10-22 17:49:06 +02:00
Akim Demaille
098f5084a0 tests: rename AT_SKEL_CC_IF/AT_SKEL_JAVA_IF as AT_CXX_IF/AT_JAVA_IF
The previous name is too obscure, and the other macros for C++ use
CXX, not CC.

* tests/local.at (AT_SKEL_CC_IF, AT_SKEL_JAVA_IF): Rename as...
(AT_CXX_IF, AT_JAVA_IF): these.
Adjust callers.
2018-10-21 08:28:47 +02:00
Akim Demaille
07a4b32f4d c++: check that emplace for rvalues works
See the previous commit.

* tests/local.at (AT_REQUIRE_CXX_VERSION): New.
* tests/types.at (api.value.type): Check emplace in C++14.
2018-10-21 08:02:52 +02:00
Akim Demaille
e7b709ab0b %printer: promote yyo rather than yyoutput
* doc/bison.texi: Promote yyo rather than yyoutput.

* data/c.m4, data/glr.cc, tests/types.at, tests/calc.at,
tests/regression.at: Adjust.
2018-10-20 19:03:01 +02:00
Akim Demaille
6537a59c98 tests: fix a memory leak
This has been bugging me for while.  I was hard to reproduce: it
worked only on GNU/Linux, probably because libc++ implements the small
string optimization, while libstdc++ did not and actually allocated on
the heap for this small string.

See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00110.html.

* tests/types.at (api.value.type): Do not provide a semantic value to
EOF.
2018-09-23 11:50:58 +02:00
Akim Demaille
8da0cef821 tests: fix memory leak
This was reported by ASAN on the CI.

* tests/types.at (api.value.type): Don't set a semantic value to EOF.
2018-09-18 13:21:38 +02:00
Akim Demaille
2e9e591889 Update copyright years
Run `make update-copyright`.
2018-05-12 18:18:41 +02:00
Akim Demaille
dbd1609311 style: don't use std::endl
* data/lalr1.cc, doc/bison.texi, etc/bench.pl.in, examples/variant.yy,
* tests/actions.at, tests/atlocal.in, tests/c++.at, tests/headers.at,
* tests/local.at, tests/types.at:
Don't use std::endl, it flushes uselessly, and is considered bad
style.
2018-05-08 12:35:06 +02:00
Akim Demaille
827bc59ca1 %union: fix the support for named %union
Bison supports a union tag, for obscure reasons.  But it does a poor
job at it, especially since Bison 3.0.
Reported by Stephen Cameron and Tobias Frost.

It did not ensure that the name was not given several times.  An easy
way to do this is to make the %union tag be handled as a %define
variable, as they cannot be defined several times.

Since Bison 3.0, the synclines were wrongly placed, resulting in
invalid code.  Addressing this issue, because of the way the union tag
was stored (as a code muscle), would have been tedious.  Unless we
rather define the %union tag as a %percent variable, whose synclines
are easier to manipulate.

So replace the b4_union_name muscle by the api.value.union.name
%define variable, document, and check.

* data/bison.m4: Make sure that api.value.union.name has a keyword value.
* data/c++.m4: Make sure that api.value.union.name is not defined.
* data/c.m4 (b4_union_name): No longer use it, use api.value.union.name.
* doc/bison.texi (%define Summary): Document it.
* src/parse-gram.y (union_name): No longer define b4_uion_name, but
api.value.union.name.
* tests/input.at (Redefined %union name): New.
* tests/synclines.at (%union name syncline): New.
* tests/types.at: Check named %unions.
2015-01-04 18:00:51 +01:00
Akim Demaille
3209eb1c4c package: bump to 2015
Which also requires:

* gnulib: Update.
2015-01-04 17:49:13 +01:00
Akim Demaille
8d4dc896cb yacc.c: fix broken union when api.value.type=union and %defines are used
Reported by Rich Wilson.

* data/c.m4 (b4_symbol_type_register): Append to b4_union_members,
not b4_user_union_members.
The latter invokes the former, but it is the former which is reinitialized
to empty by b4_value_type_setup_union.
* tests/types.at: Check it.

This reveals another bug, this time in the case of glr.c parsers.

* data/glr.c: Generate the header file before the implementation file,
to be sure that the setup is run before what depends on it.
2014-12-31 14:39:05 +01:00
Akim Demaille
fc51acddb4 package: bump to 2014
* AUTHORS, ChangeLog-2012, Makefile.am, NEWS, PACKAGING, README,
* README-alpha, README-hacking, THANKS, TODO, bootstrap.conf,
* build-aux/darwin11.4.0.valgrind, build-aux/local.mk,
* build-aux/update-b4-copyright,
* build-aux/update-package-copyright-year, cfg.mk, configure.ac,
* data/README, data/bison.m4, data/c++-skel.m4, data/c++.m4,
* data/c-like.m4, data/c-skel.m4, data/c.m4, data/glr.c, data/glr.cc,
* data/java-skel.m4, data/java.m4, data/lalr1.cc, data/lalr1.java,
* data/local.mk, data/location.cc, data/stack.hh, data/variant.hh,
* data/xslt/bison.xsl, data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, data/yacc.c, djgpp/Makefile.maint,
* djgpp/README.in, djgpp/config.bat, djgpp/config.sed,
* djgpp/config.site, djgpp/config_h.sed, djgpp/djunpack.bat,
* djgpp/local.mk, djgpp/subpipe.c, djgpp/subpipe.h,
* djgpp/testsuite.sed, doc/bison.texi, doc/local.mk, doc/refcard.tex,
* etc/README, etc/bench.pl.in, etc/local.mk,
* examples/calc++/calc++.test, examples/calc++/local.mk,
* examples/extexi, examples/local.mk, examples/mfcalc/local.mk,
* examples/mfcalc/mfcalc.test, examples/rpcalc/local.mk,
* examples/rpcalc/rpcalc.test, examples/test, examples/variant.yy,
* lib/abitset.c, lib/abitset.h, lib/bbitset.h, lib/bitset.c,
* lib/bitset.h, lib/bitset_stats.c, lib/bitset_stats.h,
* lib/bitsetv-print.c, lib/bitsetv-print.h, lib/bitsetv.c,
* lib/bitsetv.h, lib/ebitset.c, lib/ebitset.h, lib/get-errno.c,
* lib/get-errno.h, lib/lbitset.c, lib/lbitset.h, lib/libiberty.h,
* lib/local.mk, lib/main.c, lib/timevar.c, lib/timevar.def,
* lib/timevar.h, lib/vbitset.c, lib/vbitset.h, lib/yyerror.c,
* m4/bison-i18n.m4, m4/c-working.m4, m4/cxx.m4, m4/flex.m4,
* m4/timevar.m4, src/AnnotationList.c, src/AnnotationList.h,
* src/InadequacyList.c, src/InadequacyList.h, src/LR0.c, src/LR0.h,
* src/Sbitset.c, src/Sbitset.h, src/assoc.c, src/assoc.h,
* src/closure.c, src/closure.h, src/complain.c, src/complain.h,
* src/conflicts.c, src/conflicts.h, src/derives.c, src/derives.h,
* src/files.c, src/files.h, src/flex-scanner.h, src/getargs.c,
* src/getargs.h, src/gram.c, src/gram.h, src/graphviz.c,
* src/graphviz.h, src/ielr.c, src/ielr.h, src/lalr.c, src/lalr.h,
* src/local.mk, src/location.c, src/location.h, src/main.c,
* src/muscle-tab.c, src/muscle-tab.h, src/named-ref.c,
* src/named-ref.h, src/nullable.c, src/nullable.h, src/output.c,
* src/output.h, src/parse-gram.c, src/parse-gram.y, src/print-xml.c,
* src/print-xml.h, src/print.c, src/print.h, src/print_graph.c,
* src/print_graph.h, src/reader.c, src/reader.h, src/reduce.c,
* src/reduce.h, src/relation.c, src/relation.h, src/scan-code.h,
* src/scan-code.l, src/scan-gram.h, src/scan-gram.l, src/scan-skel.h,
* src/scan-skel.l, src/state.c, src/state.h, src/symlist.c,
* src/symlist.h, src/symtab.c, src/symtab.h, src/system.h,
* src/tables.c, src/tables.h, src/uniqstr.c, src/uniqstr.h,
* tests/actions.at, tests/atlocal.in, tests/bison.in, tests/c++.at,
* tests/calc.at, tests/conflicts.at, tests/cxx-type.at,
* tests/existing.at, tests/glr-regression.at, tests/headers.at,
* tests/input.at, tests/java.at, tests/javapush.at, tests/local.at,
* tests/local.mk, tests/named-refs.at, tests/output.at, tests/push.at,
* tests/reduce.at, tests/regression.at, tests/sets.at,
* tests/skeletons.at, tests/synclines.at, tests/testsuite.at,
* tests/torture.at, tests/types.at:
here.
2014-02-03 15:27:02 +01:00
Akim Demaille
435575cb5e api.value.type: use keyword/brace values
Suggested by Joel E. Denny.
http://lists.gnu.org/archive/html/bison-patches/2013-03/msg00016.html

* data/bison.m4 (b4_percent_define_get_kind): New.
(b4_variant_flag): Check that api.value.type is defined as the 'variant'
keyword value.
* data/c.m4 (_b4_value_type_setup_keyword): New.
(b4_value_type_setup): Use it to simplify reading.
Use b4_define_silent.
Decode api.value.type, including its type.
(b4_value_type_define): Likewise.
* data/c++.m4 (b4_value_type_declare): Adjust the decoding of api.value.type,
taking its kind into account.
* doc/bison.texi: Adjust all the examples to the new syntax.
* NEWS: Ditto.
* tests/types.at: Adjust
2013-04-09 16:59:06 +02:00
Akim Demaille
1fa19a7697 api.value.type: diagnose guaranteed failure with --yacc
Instead of generating invalid C code, generate an error when --yacc and
'%define api.value.type union' are used together.

* data/bison.m4: Issue an error in this case.
* tests/types.at (%yacc vs. %define api.value.type union): New, check this
error.
* doc/bison.texi (Type Generation): Document it.
* tests/output.at: Check that '-o y.tab.c' and '-y' behave equally
wrt generated file names.
* NEWS (Use of YACC='bison -y'): New.
Promote the use of 'bison -o y.tab.c'.
2013-04-09 14:07:52 +02:00
Akim Demaille
cb8d8bb9b6 value type: accept "->" in type tags
Provide a means to dereference pointers when defining tags.  One
example could be:

  %code requires
  {
    typedef struct ListElementType
    {
      union value
      {
        int intVal;
        float floatVal;
        char* charptrVal;
      } value;

      struct ListElementType* next;
    } ListElementType;
  }

  %union
  {
    ListElementType* list;
  }

  %token <list->value.charptrVal> STRING
  %token <list->value.intVal> INTEGER
  %token <list->value.floatVal> REAL
  %type <list> ElementList LiteralType

* src/scan-code.l, src/scan-gram.l: Accept "->" in tags.
* tests/types.at: Add more test cases to cover this case.
2013-04-09 14:07:51 +02:00
Akim Demaille
6574576cfb api.value.type: implement proper support, check, and document
* data/c.m4 (b4_symbol_type_register, b4_type_define_tag)
(b4_symbol_value_union, b4_value_type_setup_union)
(b4_value_type_setup_variant, b4_value_type_setup):
New.
(b4_value_type_define): Use it to set up properly the type.
Handle the various possible values of api.value.type.
* data/c++.m4 (b4_value_type_declare): Likewise.
* data/lalr1.cc (b4_value_type_setup_variant): Redefine.

* tests/types.at: New.
Exercise all the C/C++ skeletons with different types of
api.value.type values.
* tests/local.mk, tests/testsuite.at: Use it.

* doc/bison.texi (%define Summary): Document api.value.type.
* NEWS: Advertise it, together with api.token.constructor.
2013-04-09 14:07:51 +02:00