Compare commits

...
1246 Commits
Author SHA1 Message Date
Paul Eggert a47fb7838a build: update gnulib submodule to latest 2026-07-30 08:36:29 -07:00
Paul Eggert 089c39aab2 bison: allow trivially copyable C++ YYLTYPE
Problem reported by James K. Lowden in:
https://lists.gnu.org/r/bison-patches/2026-07/msg00000.html
* data/skeletons/yacc.c: In C++, check that YYLTYPE is
trivially copyable if this is not already known.
But skip the check in older compilers.
2026-07-21 12:52:53 -07:00
Paul Eggert 3841fe9de4 maint: update .gitignore 2026-07-21 12:52:53 -07:00
Paul Eggert 7024830c72 maint: propagate gnulib changes 2026-07-21 12:52:53 -07:00
Paul Eggert 720943cff0 maint: prefer mcel
* bootstrap.conf (gnulib_modules): Add mcel-prefer.
(gnulib_tool_option_extras): Avoid mbiterf.
This simplifies Bison a bit, which does not need
the more-complex mbiterf.
2026-07-21 12:52:53 -07:00
Paul Eggert 706ebd0fa5 bison: port to GCC 16.1.1 -Wclobbered
* data/skeletons/glr.c, data/skeletons/glr2.cc:
Ignore -Wclobbered if GCC 4.6 or later.
2026-07-21 12:52:53 -07:00
Paul Eggert ff9eee58c3 bison: port to GCC 16.1.1 -Wmaybe-uninitialized
* data/skeletons/lalr1.cc: Increase the scope of
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN.
Needed for GCC 16.1.1 20260515 (Red Hat 16.1.1-2).
2026-07-21 12:52:53 -07:00
Paul Eggert 4f6785aee9 build: update gnulib and autoconf submodules to latest 2026-07-21 12:52:53 -07:00
Paul Eggert c3f856a430 bison: port to recent glibc / Gnulib
* src/muscle-tab.c (muscle_grow, muscle_syncline_grow)
(muscle_pair_list_grow, muscle_boundary_grow, string_decode)
(define_directive): Use char *, not char const *, for
pointers that are passed to obstack_free or are stored through.
This avoids undefined behavior in C.
2026-07-21 12:52:53 -07:00
Paul Eggert 8d101c19d4 bison: tighten up output file names
Problem reported by Michał Majchrowicz.
* src/parse-gram.y: Do not allow '/' in %header and %output directives.
2026-04-23 12:49:06 -07:00
Paul Eggert 3169c1e7a2 html: use xsltproc from PATH
* src/print-xml.c (print_html):
* src/reader.c (prepare_percent_define_front_end_variables):
Drop undocumented support for lines like ‘%define tool.xsltproc
"whatever"’, as this can cause more trouble than it cures.
2026-04-23 09:21:37 -07:00
Paul Eggert 39c1239ed5 doc: improve yacc man page fonts
Problem reported by Helge Kreutzmann in:
https://lists.gnu.org/r/bug-bison/2025-12/msg00000.html
* doc/yacc.1.in: Fix fonts.
2026-01-18 10:16:18 -08:00
Paul Eggert dcf16ff191 maint: make update-copyright 2026-01-18 09:45:29 -08:00
Paul Eggert c6d1f65185 doc: improve man page (mostly fonts)
Problems reported by Helge Kreutzmann in:
https://lists.gnu.org/r/bug-bison/2026-01/msg00000.html
* doc/bison.x: Refontify, mostly.
* src/getargs.c (usage): Clarify usage message.
2026-01-18 09:39:28 -08:00
Bruno HaibleandPaul Eggert c1144a5076 tests: Fix test failures of Java tests on Cygwin.
Fix suggested by Paul Eggert.

* tests/atlocal.in (lf): New variable.
* tests/local.at (AT_JAVA_PARSER_CHECK): Pass a Windows-agnostic value
of line.separator to the Java runtime.
2025-08-09 13:58:50 -07:00
Paul Eggert 5d2c34b48c maint: pacify -Wunterminated-string-initialization
* src/symtab.c (is_identifier):
Pacify GCC 15.1 -Wunterminated-string-initialization.
2025-08-03 23:09:33 -07:00
Bruno HaibleandPaul Eggert 5209a67035 build: Avoid failure of the Java tests in Cygwin-based environments.
* examples/test (prog): In Cygwin-based environments, convert the class path
element to native Windows syntax.
2025-08-03 22:51:19 -07:00
Bruno HaibleandPaul Eggert df2ed793af build: Fix "make dvi" and "make distcheck" error.
* bootstrap.conf (gnulib_extra_files): Add build-aux/epsf.tex.
* build-aux/local.mk (EXTRA_DIST): Add build-aux/epsf.tex.
2025-08-03 20:29:41 -07:00
Paul Eggert 84119fd53e build: update gnulib and autoconf submodules to latest 2025-08-03 20:29:41 -07:00
Bruno HaibleandPaul Eggert f8793e27f0 build: Don't hardcode the location of the gnulib directory.
* build-aux/move-if-change: Remove symlink.
* bootstrap.conf (gnulib_extra_files): Add build-aux/move-if-change.
2025-08-03 20:18:29 -07:00
Paul Eggert 2ceaf03d69 maint: update .gitignore files 2025-07-10 18:34:10 -07:00
Paul Eggert 5d0d1b4965 ./bootstrap 2025-07-10 18:34:10 -07:00
Paul Eggert 42a5f17b8f build: update gnulib and autoconf submodules to latest 2025-07-10 18:34:10 -07:00
Paul Eggert 4ff0741f58 maint: make update-copyright 2025-03-17 17:48:06 -07:00
Paul Eggert d7527048a8 maint: port to strict C function type checking
Violation of C standard detected by clang -fsanitize=undefined
with clang 19.1.7 on Fedora 41 x86-64.
* src/counterexample.c (si_bfs_free):
* src/files.c (prefix_map_free, add_prefix_map):
* src/fixits.c (fixit_cmp, fixit_free, fixits_register):
(expand_to_conflict, nonunifying_shift_path)
(search_state_free_children, search_state_free, ssb_free)
(ssb_hasher, ssb_comp, ssb_equals, visited_hasher)
(visited_comparator, ssb_append, unifying_example):
* src/lssi.c (lssi_free, lssi_hasher, lssi_comparator)
(shortest_path_from_start):
* src/parse-simulation.c (free_parse_state)
(parse_state_list_new, parser_pop):
* src/state-item.c (hash_pair_hasher, hash_pair_comparator)
(hash_pair_free, hash_pair_table_create):
Avoid undefined behavior in C, which does not allow you to cast a
function pointer to some other function type and then call it via
that other type.  Instead, use functions with correct types
according to the C standard, and cast their parameters.
* src/getargs.c (xargmatch_fn): Return int const, not int, to
match what ARGMATCH_DEFINE_GROUP does.  In all uses of
ARGMATCH_DEFINE_GROUP, say that they return int, to match
xargmatch_fn.
(FLAGS_ARGMATCH): Do not cast function pointer.
* src/parse-simulation.c (vc_derivation_list_append): New function.
* src/system.h (deconst): New static function.
2025-03-13 13:39:45 -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
Paul Eggert aa0c96bf14 maint: adjust to Gnulib API changes
* src/output.c (output_skeleton):
* src/print-xml.c (print_html):
Adjust to Gnulib API changes.
2025-03-13 13:39:45 -07:00
Paul Eggert 3ad31c23f1 doc: pacify texinfo 7.1
* doc/bison.texi: Don’t put @anchor inside @item,
as texinfo 7.1 complains.
2025-03-13 13:39:45 -07:00
Paul Eggert 41a939eece maint: ./bootstrap 2025-03-13 13:39:45 -07:00
Paul Eggert 8b3df1a443 build: update gnulib and autoconf submodules to latest 2025-03-13 13:39:44 -07:00
FutureandPaul Eggert 97852f39f4 maint: remove unnecessary casts before using gnulib functions
* src/parse-gram.y, src/scan-gram.l: Do not cast c-ctype.h function
args to unsigned char unnecessarily.
* src/parse-gram.c: Regenerate.

Copyright-paperwork-exempt: yes
2022-11-04 11:53:52 -07:00
Akim Demaille 25b3d0e1a3 cex: check -Dcex.timeout
* src/counterexample.c (counterexample_init): Remove stray debug
trace.
Complain about invalid values.
* tests/input.at (-Dcex.timeout): New.
2022-09-20 08:25:06 +02:00
Akim Demaille de3041b69a news: update
* NEWS: update.
2022-09-20 07:16:25 +02:00
Adela VaisandAkim Demaille 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 VaisandAkim Demaille 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
Akim Demaille c025891547 cex: provide the user with a means to change the timeout
Reported by Frank Heckenbach.
https://lists.gnu.org/r/bug-bison/2022-07/msg00011.html

* bootstrap.conf: Use c_strtod, so that even in French locales "1.5"
is accepted, instead of "1,5".
* src/counterexample.c, src/state-item.c: Use xtime_t instead of
time_t, so that accuracy goes from seconds to nanoseconds.
( counterexample_init): Depend on cex.timeout rather than
$TIME_LIMIT.
* doc/bison.texi (%define Summary): Document cex.timeout.
2022-09-16 06:03:28 +02:00
Akim Demaille 15b97a0a6a doc: define the syntax of named references
Reported by Arthur Schwarz.
https://lists.gnu.org/r/help-bison/2022-06/msg00007.html

* doc/bison.texi (Named References): Define the syntax of named
references.
2022-09-12 07:24:21 +02:00
Akim Demaille 290d3d09d4 cex: clarify message
Reported by Frank Heckenbach.
https://lists.gnu.org/r/bug-bison/2022-07/msg00007.html

src/counterexample.c (unifying_example): Prefer "searching for" to
"finding", which is somewhat confusing.
2022-09-10 14:53:39 +02:00
Akim Demaille 374cf8bbaf doc: fix the description of the syntax of %token and %left
Reported by Frank Heckenbach.
https://lists.gnu.org/r/bug-bison/2022-07/msg00007.html

* doc/bison.texi (Symbol Decls): here.
2022-09-10 14:48:24 +02:00
Akim Demaille dd6ca19927 reader: reject rules on YYEOF
We crashed when rules were given on YYEOF.
Reported by Han Zheng.
Fixes https://github.com/akimd/bison/issues/92.

* src/reader.c (check_and_convert_grammar): Make sure YYEOF is not
an nterm.
* tests/input.at (Rule for YYEOF): New.
2022-09-10 14:09:02 +02:00
Akim Demaille 3661ebbb2c gnulib: update 2022-09-10 09:14:10 +02:00
Akim Demaille 6376364120 muscles: fix handling of the "@'" escape
When we use `b4_` or `m4_` somewhere in the input, it is escaped as
`b4@'_`/`m4@'_` so that the warning about unexpanded b4_foo/m4_foo
macros does not fire.

But in the case of muscles, the `@'` escape was not recognized, and an
assertion was triggered.

Reported by Han Zheng.
<https://github.com/akimd/bison/issues/91>

* src/muscle-tab.c (COMMON_DECODE): Handle `@'`.
* tests/skeletons.at (Suspicious sequences): Check that case.
2022-09-04 08:51:53 +02:00
Anthony HeadingandAkim Demaille 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 ec9c5556d9 tests: ignore messages from the JVM
Reported by Giorgos Pap.
<https://lists.gnu.org/r/bug-bison/2022-08/msg00002.html>

* examples/test: Discard "Picked up _JAVA_OPTIONS:" messages.
2022-09-03 09:13:48 +02:00
Akim Demaille cfef21f5b0 diagnostics: Windows compatibility issues
Suggested by Bruno Haible
<https://lists.gnu.org/r/bug-bison/2022-08/msg00006.html>
following a report from Andrei Malashkin
<https://lists.gnu.org/r/bug-bison/2022-08/msg00003.html>

* src/location.c (caret_set_file): Read the file in binary.
We already deal with CRLF in caret_getc_internal.
2022-09-03 08:58:49 +02:00
Akim Demaille 5555f4d051 regen 2022-08-02 09:07:31 +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 657dbff05c maint: update .gitignore for Gnulib 2022-07-31 13:28:52 -07:00
Paul Eggert 6d58f297cc maint: don’t use \] in BREs and EREs
* .travis.yml (jobs):
* doc/local.mk ($(top_srcdir)/%D%/bison.help):
* tests/regression.at (Web2c Actions, Useless Tokens):
* tests/scanner.at (Token numbers: $1):
Use plain ], not \], in a POSIX regular expression,
as POSIX says the interpretation of \] is undefined.
2022-07-31 13:28:52 -07:00
Paul Eggert d95df5028d maint: improve Gnulib checking
* configure.ac: With --enable-gcc-warnings, #define lint,
_FORTIFY_SOURCE, and GNULIB_PORT_CHECK, to better check Gnulib.
2022-07-31 12:00:28 -07:00
Paul Eggert 4e89da6e5d maint: don’t get fdl.texi from Gnulib
This reverses the 2012-01-13T09:39:[email protected] patch,
as Gnulib’s fdl.texi module now says “Don't use this module!”
* bootstrap.conf (gnulib_modules): Remove fdl.
* doc/.gitignore: Don’t ignore fdl.texi.
* doc/fdl.texi: New file, copied from Gnulib.
2022-07-31 12:00:28 -07:00
Paul Eggert aa58acb76e gnulib: update 2022-07-31 12:00:28 -07:00
Akim Demaille db8c1bbbfd style: enforce GNU-style variable names
* examples/c/glr/c++-types.y, tests/cxx-type.at (lineNum, colNum):
Rename as...
(line_num, col_num): these.
2022-07-31 12:58:16 +02:00
Akim Demaille cf686be382 tests: avoid useless variables
Reported by clang's -Wunused-but-set-variable warning.

* configure.ac (warn_common): Add -Wunused-but-set-variable.
* tests/cxx-type.at: Don't emit location track code when we don't use
locations.
2022-07-31 12:56:59 +02:00
Akim Demaille c70b68c60d gnulib: update
We now build cleanly even if libtextstyle is not available.
See https://lists.gnu.org/r/bug-bison/2022-07/msg00002.html.
2022-07-31 11:14:42 +02:00
Akim Demaille 78b767d3eb gnulib: update
There are now new files to track.  See
<https://lists.gnu.org/r/bug-gnulib/2022-07/msg00053.html>.
2022-07-31 10:52:47 +02:00
Akim Demaille cb679b2a09 address unused variables
Reported by recent versions of clang.

* src/counterexample.c (search_state_prepend): Use complexity_cost.
* src/print.c: Remove useless variable.
2022-07-31 09:35:05 +02:00
Akim Demaille 6ee1494d6e doc: explain why location's "column" are defined vaguely
Suuggested by Frank Heckenbach.
<https://lists.gnu.org/r/bug-bison/2022-01/msg00000.html>

* doc/bison.texi (Location Type): Explain why location's "column" are
defined vaguely.
Show tab handling in ltcalc and calc++.
* examples/c/bistromathic/parse.y: Show tab handling.
* examples/c++/calc++/calc++.test,
* examples/c/bistromathic/bistromathic.test:
Check tab handling.
2022-06-15 07:55:13 +02:00
Akim Demaille a475c4d5c1 gnulib: update 2022-06-15 07:55:11 +02:00
Akim Demaille 1183d5ebfe gnulib: update 2022-01-23 18:43:16 +01:00
Paul Eggert 8b96c82b05 doc: improve calling-convention doc
* doc/bison.texi (Calling Convention, Error Reporting Function):
Suggest ‘%code provides’ to declare yylex and yyerror.
Prompted by this email thread:
https://lists.gnu.org/r/bug-bison/2022-01/msg00002.html
2022-01-15 11:16:30 -08:00
Paul Eggert 07e18e7fb4 package: bump copyrights to 2022
Run "make update-copyright".
2022-01-15 11:16:30 -08:00
Bruno HaibleandAkim Demaille 013d598219 gnulib: make use of gnulib-tool's --automake-subdir option
Starting this week, Gnulib supports generating a "non-recursive" Automake
Makefile.am snippet https://lists.gnu.org/r/bug-gnulib/2021-12/msg00085.html.

* bootstrap.conf: Use gnulib-tool's --automake-subdir.
2021-12-19 17:11:30 +01:00
Akim Demaille 83a8f8b707 gnulib: update
To get native non-recursive make support.
2021-12-19 16:49:45 +01:00
Akim Demaille f8e8f57e9f doc: add indexes
* doc/bison.texi (Special Tokens): here.
2021-12-19 16:41:05 +01:00
Akim Demaille 6571c2d1b1 warnings: don't complain about m4_foo and b4_foo when from the user
Currently, occurrences of these identifiers in the user's input yield
spurious warnings.

To tell the difference between a legitimate m4_foo from the user, and
a bad m4_foo coming from a non-evaluated macro of a skeleton, escape
the user's identifiers as m4@'_foo.  We already use @' as a special
sequence to be stripped from the skeleton's output.

See <https://lists.gnu.org/r/bug-bison/2021-10/msg00026.html> and
previous commit ("warnings: be less picky about occurrences of m4_/b4_
in the output").

* src/flex-scanner.h (OBSTACK_SGROW): New.
* src/output.c (output_escaped): Escape m4_ and b4_.
* src/scan-code.l: Likewise.
* src/system.h (obstack_escape): Likewise.
And rewrite as a function.
* tests/skeletons.at (Suspicious sequences): Make sure the user can
use m4_foo/b4_foo without spurious warnings.
2021-11-07 09:52:05 +01:00
Akim Demaille c95d0dd5f5 warnings: be less picky about occurrences of m4_/b4_ in the output
Reported by Marko Mäkelä.
<https://lists.gnu.org/r/bug-bison/2021-10/msg00026.html>

* src/scan-skel.l: It is ok to have foob4_ or foom4_.
* tests/skeletons.at (Suspicious sequences): New.
2021-11-06 19:30:06 +01:00
Akim Demaille 76301e7399 gnulib: update 2021-11-06 09:11:29 +01:00
Akim Demaille c83425ef4e tests: address portability issues about strdup
Reported by Dennis Clarke
<https://lists.gnu.org/r/bug-bison/2021-10/msg00005.html>.
In particular
<https://lists.gnu.org/r/bug-bison/2021-10/msg00023.html>.

* doc/bison.texi, examples/c/glr/c++-types.y,
* examples/c/bistromathic/parse.y tests/testsuite.h:
Define _XOPEN_SOURCE to 600, to get a strdup that works on Solaris.

* tests/glr-regression.at: Use strdup freely.
2021-11-06 09:00:58 +01:00
Akim Demaille c9b5b46d74 tests: fix coding style
* tests/cxx-type.at, tests/glr-regression.at:
Prefer strdup to malloc+strcpy.
Use snake_case.
2021-11-06 08:29:59 +01:00
Akim Demaille 7558cbf373 examples: fix coding style
* examples/c/glr/c++-types.y: Use snake_case identifiers.
Prefer strdup to malloc+strcpy.
2021-11-06 08:29:59 +01:00
Akim Demaille 6e6950fbbc build: check -Wsubobject-linkage in C++
* configure.ac (warn_cxx): here.
2021-10-11 07:14:57 +02:00
Akim Demaille 4fe5a375fa tests: make it easier to spot failures
* examples/c/glr/c++-types.test: Split in several small test cases.
2021-10-09 10:39:22 +02:00
Akim Demaille 7c90a28f17 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-09-25 11:11:06 +02:00
Akim Demaille 9beba1919c version 3.8.2
* NEWS: Record release date.
2021-09-25 10:43:40 +02:00
Akim Demaille 80ebbe7330 tests: Apple clang issues warning on C++11 features
$ cat /tmp/foo.cc
using foo = int;
foo f;
$ clang++ -Wc++11-extensions -c /tmp/foo.cc
/tmp/foo.cc:1:13: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using foo = int;
            ^
1 warning generated.
$ clang++ --version
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

* tests/local.at (AT_COMPILE_CXX): Make sure -std=c++11 is passed when
running glr2.cc.  It may be overridden by another flag in CXXFLAGS
afterwards.
2021-09-25 10:42:46 +02:00
Akim Demaille 028df02a9f avoid using atoi
* cfg.mk: Disable sc_indent as auto indent is too invasive for now.
Enable sc_prohibit_atoi_atof, except where we don't care.
* src/location.c, src/muscle-tab.c: Use strtol instead of atoi.
2021-09-25 08:03:22 +02:00
Akim Demaille 71dfc86d58 news: update 2021-09-24 05:38:58 +02:00
Akim Demaille 5c1069c7d8 gnulib: update
To get

commit 7818455627c5e54813ac89924b8b67d0bc869146
Author: Bruno Haible <[email protected]>
Date:   Fri Sep 17 22:22:50 2021 +0200

    threadlib: Avoid crashes in thread-related functions on Cygwin 3.2.0.

    Reported by Brian Inglis via Akim Demaille in
    <https://lists.gnu.org/archive/html/bug-gnulib/2021-09/msg00063.html>.

    * m4/threadlib.m4 (gl_WEAK_SYMBOLS): Force a "guessing no" result on
    Cygwin.
2021-09-18 16:25:57 +02: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 dd6e78360a gnulib: update 2021-09-13 08:36:37 +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 6bfdf22c50 glr2.cc: check linking conflicts
* tests/headers.at (Several Headers): Link two glr2.cc parsers.
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 2142e59155 c++: demonstrate custom error messages in the examples
Let's use c++/glr to demonstrate custom error messages in C++ (not
just in glr2.cc).

* examples/c++/glr/c++-types.yy (report_syntax_error): New.
* examples/c++/glr/c++-types.test: Adjust.
* examples/c/bistromathic/parse.y: Comment changes.
* tests/local.at (AT_YYERROR_DEFINE(c++)): Use a nicer way to print
the lookakead's name.
2021-09-12 12:03:58 +02:00
Akim Demaille a75072476e glr2.cc: custom error messages
Reported by Tom Shields <[email protected]>.
<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 c3a4686a03 regen 2021-09-12 12:03:58 +02:00
Akim Demaille 9cdfd86cbb maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-09-11 08:55:22 +02:00
Akim Demaille 659376b590 version 3.8.1
* NEWS: Record release date.
2021-09-11 08:26:40 +02:00
Akim Demaille 0343acbe89 portability: don't use strtof
It is not available on HP-UX 11i.
Reported by Larkin Nickle <[email protected]>.
<https://lists.gnu.org/r/bug-bison/2021-09/msg00012.html>

Gnulib provides no replacement, but anyway we should be using doubles,
since difftime uses doubles.

* bootstrap.conf: We want portability on stdtod.
* src/counterexample.c: Use double, not float, for time measurements.
2021-09-11 08:26:10 +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 ad9b8a069f maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-09-07 20:56:23 +02:00
Akim Demaille ec3375ab4e version 3.8
* NEWS: Record release date.
2021-09-07 20:28:49 +02:00
Akim Demaille 12c8e427c7 news: update 2021-09-07 20:28:36 +02:00
Akim Demaille 9f8f3d2e77 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-09-02 07:56:44 +02:00
Akim Demaille 108724c2e7 version 3.7.91
* NEWS: Record release date.
2021-09-02 07:31:20 +02:00
Akim Demaille da0f993fb9 tests: disable "Multistart reports"
For some reason this test fails on Solaris/x86.  But multistart is not
part of 3.8, so we can postpone the debugging of this issue.
Reported by Dagobert Michelsen.
<https://lists.gnu.org/r/bug-bison/2021-08/msg00027.html>

* tests/report.at (Multistart reports): Comment out.
2021-09-02 07:27:42 +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 a7ded4284e style: rename stmtMerge as stmt_merge
Follow the GNU Coding Style.

* doc/bison.texi, examples/c++/glr/c++-types.yy,
* examples/c/glr/c++-types.y, tests/cxx-type.at: s/stmtMerge/stmt_merge/g.
2021-08-29 16:25:38 +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 <[email protected]>
<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 bc5aa8e274 tests: don't postprocess stderr with sed
On Solaris, sed throws away the NUL bytes from the stream, even in C
locale.  So instead of postprocessing bison's stderr to neutralize
changes in value of `argv[0]`, use an envvar to actually neutralize
variations of `argv[0]` during tests.

Reported by Dagobert Michelsen.
<https://lists.gnu.org/r/bug-bison/2021-08/msg00025.html>

* src/main.c (main): Change `argv[0]` if BISON_PROGRAM_NAME is
defined.
* tests/bison.in: No longer mess with stderr, just pass
the expected BISON_PROGRAM_NAME value.
2021-08-29 09:50:02 +02:00
Akim Demaille 0a82bf5c07 CI: don't require Autoconf 2.71 2021-08-19 10:07:51 +02:00
Akim Demaille a70e75b8a4 examples: don't demonstrate multistart, which is not part of 3.8
Besides, for mysterious reasons, this fails on some environment.
Reported by Dagobert Michelsen.
<https://lists.gnu.org/archive/html/bug-bison/2021-08/msg00008.html>

* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Revert to a single-start example.
2021-08-19 09:19:07 +02:00
Akim Demaille 3afa9757da tests: grep -E is not portable
Reported by Dagobert Michelsen.
<https://lists.gnu.org/r/bug-bison/2021-08/msg00008.html>

* tests/calc.at: Use $EGREP.
2021-08-19 08:21:23 +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 f2c568d3ef readme: add D 2021-08-13 09:06:34 +02:00
Akim Demaille bb7860d208 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-08-13 08:47:37 +02:00
Akim Demaille 8bb81e2048 version 3.7.90
* NEWS: Record release date.
2021-08-13 08:20:06 +02:00
Akim Demaille 84059ea508 build: ignore syntax-check's file_system check on Doxyfile
* cfg.mk: Here.
2021-08-13 08:15:31 +02:00
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 0af06e091b gnulib: update 2021-08-12 10:13:38 +02:00
Akim Demaille 1d291901b4 news: be clear that glr2.cc is C++11 2021-08-12 10:13:38 +02:00
Akim Demaille f387ffc1d3 build: modernize to newer Autoconf releases
* configure.ac: here.
2021-08-12 10:13:38 +02:00
Akim Demaille 9307c173c7 build: reject C++ compilers that don't support std::vector::data
GCC 4.2 on macOS claims to support C++98, but does not feature it.

input.cc: In member function 'void state_stack::yycompressStack()':
input.cc:1774: error: 'class std::vector<glr_stack_item, std::allocator<glr_stack_item> >' has no member named 'data'

Reported by Christopher Nielsen <[email protected]>.
<https://trac.macports.org/raw-attachment/ticket/59927/bison-test-results-20210811-95b72.log.xz>.

* m4/bison-cxx-std.m4 (_BISON_CXXSTD_98_snippet): Check for it.
* m4/cxx.m4 (BISON_TEST_FOR_WORKING_CXX_COMPILER): Ditto.
2021-08-12 10:13:26 +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 <[email protected]>.
<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 348b5039fd c: fix _Noreturn support detection
Reported by Christopher Nielsen <[email protected]>.
<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 <[email protected]>.

* 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 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 dabde7c560 build: enable -Wmismatched-dealloc
* configure.ac (warn_common): Here.
2021-08-09 07:17:19 +02:00
Akim Demaille 272da17cfd gnulib: update 2021-08-09 07:17:19 +02:00
Akim Demaille 4b802d6417 bistromathic: beware of portability issues with readline
In some cases readline emits a trailing spaces after the last
suggestion, which results in errors such as:

```
-(       -       atan    cos     exp     ln      number  sin     sqrt$
+(       -       atan    cos     exp     ln      number  sin     sqrt    $
```

Reported by Christopher Nielsen <[email protected]>.
<https://trac.macports.org/ticket/59927#comment:48>
<https://trac.macports.org/attachment/ticket/59927/bison-3.7.6-test-10.13.test-suite.log>

* examples/test (run): Add support for -t.
* examples/c/bistromathic/bistromathic.test: Use it.
2021-08-08 08:08:04 +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 6118406c3e style: formatting changes in scan-code.l
* src/scan-code.l: Fix indentation.
2021-08-07 12:53:15 +02:00
Akim Demaille a83202a436 doc: avoid #define YYDEBUG in C++
* doc/bison.texi (Enabling Traces): here.
2021-08-07 07:57:58 +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 d4b195ece6 doc: more pointers to the examples
* doc/bison.texi (Infix Calc): Here.
2021-08-06 18:02:23 +02:00
Akim Demaille 85032e9630 git: add diff patterns for Autotest and Texinfo 2021-08-06 18:02:19 +02:00
Akim Demaille 7e16706f7b CI: fix the GCC 9 build 2021-08-06 18:01:15 +02:00
Akim Demaille b7d2b854be todo: d: push and token ctors are done 2021-08-04 21:42:31 +02:00
Akim Demaille 93f9e527ca doc: refer to the examples
* doc/bison.texi: Point to rpcalc, mfcalc, simple.y, calc++, c/glr and
c++/glr.
2021-08-04 21:36:41 +02:00
Akim Demaille 0c0cf6f5a4 examples: modernize the example Makefiles
* examples/c++/Makefile, examples/c++/calc++/Makefile,
* examples/c++/glr/Makefile, examples/c/bistromathic/Makefile,
* examples/c/calc/Makefile, examples/c/glr/Makefile,
* examples/c/lexcalc/Makefile, examples/c/mfcalc/Makefile,
* examples/c/pushcalc/Makefile, examples/c/reccalc/Makefile,
* examples/c/rpcalc/Makefile, examples/d/calc/Makefile,
* examples/d/simple/Makefile, examples/java/calc/Makefile,
* examples/java/simple/Makefile:
Use --html to generate *.html directly.
No longer demonstrate --xml.
No longer show rules for xml to html.
Use --header, not --defines.
Use --graph without specifying the output file now that we
generate *.gv by default.
2021-08-04 10:07:48 +02:00
Akim Demaille 413d318940 doc: glr: document typed mergers
See <https://lists.gnu.org/r/help-bison/2020-12/msg00016.html>.

* doc/bison.texi (Merging GLR Parses): document typed mergers.
And avoid #define YYSTYPE.
2021-08-04 09:14:49 +02:00
Akim Demaille cb7bdc251d style: tests: rebox comments
* tests/glr-regression.at: here.
2021-08-04 09:14:49 +02:00
Akim Demaille e814ddc92f news: update
In particular, announce lalr1.d.
2021-08-04 07:01:07 +02:00
Akim Demaille b293d4fbca doc: fix spello
* doc/bison.texi (Multiple start-symbols): here.
2021-08-03 12:22:52 +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 <[email protected]>.
<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
Akim Demaille e14825ecb7 todo: POSIX yacc and prototypes 2021-08-03 09:04:15 +02:00
Akim Demaille 98823ea402 doc: update Doxygen template file
* doc/Doxyfile.in: here.
2021-08-03 09:04:15 +02:00
Akim Demaille ad40c80a03 doc: a bit of editing
* doc/bison.texi: Use @samp{...}, not "..." for pieces of code.
Use @samp{...}, not @command{...} for command lines.
Promote %header/--header over %defines/--defines.
Spellcheck.
2021-08-03 08:57:35 +02:00
Akim Demaille 3c7cc7dc4f gnulib: update 2021-08-03 08:08:24 +02:00
Alyssa RossandAkim Demaille 410d37b994 getargs: don't translate first line of --version
<https://lists.gnu.org/r/bison-patches/2021-06/msg00002.html>

* src/getargs.c (version): here.
2021-08-01 10:04:24 +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
Akim Demaille 5325292e5d d: minor clean up
* doc/bison.texi: Use @samp, not "...", around pieces of code.
* examples/d/calc/calc.y: Don't promote %union.
2021-07-25 18:21:12 +02:00
Akim Demaille ca403f672c gnulib: update 2021-06-23 07:18:30 +02:00
Adela VaisandAkim Demaille 5c554ea8a3 d: demonstrate the token constructors
* examples/d/calc/calc.y: Use the token constructors in the 'calc' example.
2021-06-06 08:10:46 +02:00
Adela VaisandAkim Demaille 7eee2ccbd2 d: update documentation
* doc/bison.texi: Various fixes.
(D Push Parser Interface, D Complete Symbols): New sections.
2021-04-11 07:57:50 +02:00
Adela VaisandAkim Demaille f99314765b d: demonstrate the push parser
* examples/d/calc/calc.y: Use a parser of type 'push' in the calc
example.
2021-04-11 07:41:39 +02:00
Adela VaisandAkim Demaille 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 VaisandAkim Demaille 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 VaisandAkim Demaille 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 fb032a28df gnulib: update 2021-03-26 06:42:17 +01:00
Akim Demaille 59a2053c83 files: please syntax-check
* src/files.c (string_free): syntax-check does not want us to cast
arguments to free.
2021-03-10 06:43:00 +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 c4cf4cc2f5 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-03-08 06:36:36 +01:00
Akim Demaille b458b34f94 version 3.7.6
* NEWS: Record release date.
2021-03-08 06:15:53 +01:00
Akim Demaille 09a22da8c8 doc: don't mention YY_LOCATION_PRINT
* doc/bison.texi (Syntax Error Reporting Function): Don't refer to
YY_LOCATION_PRINT, it is a private internal detail.
2021-03-07 18:41:38 +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 <[email protected]>
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 a774839ca8 tables: fix again the handling of useless tokens
The right-shift added in c22902e360
("tables: fix handling for useless tokens") is incorrect.  In
particular, we need to reset the "new" bits.

Reported by Balázs Scheidler.
https://github.com/akimd/bison/issues/74

* src/tables.c (pos_set_set): Fix the right-shift.
2021-03-07 11:56:30 +01:00
Akim Demaille 15c61fb712 html: fix memory leak
* src/print-xml.c (print_html): Free allocated memory.
2021-02-26 07:36:11 +01:00
Akim Demaille f6eb1ac87b output: cache the mapped file names
Don't repeatedly call malloc/free for each call to map_file_name.

* bootstrap.conf: We need hash-map.
* src/files.h, src/files.c (map_file_name): The caller must not free
the result.
Adjust callers.
(mapped_dir_prefix, spec_mapped_header_file): Remove.
* src/files.c
(map_file_name): Rename as...
(map_file_name_alloc): this.
(mapped_files, map_file_name, string_equals, string_hash, string_free):
New.
2021-02-26 07:16:57 +01:00
Joshua WattandAkim Demaille b96528b48c output: use mapped file name for symbols
Applies the file name mapping before exporting it as a symbol. This
allows the symbols to correctly respect the --file-prefix-map command
line option.

Signed-off-by: Joshua Watt <[email protected]>
2021-02-26 07:16:57 +01:00
Akim Demaille 4511e43245 style: formatting changes
* src/files.c, src/files.h: Save horizontal space.
Prefer `res` for returned values.
Put the doc into the header.
2021-02-26 07:16:35 +01:00
Akim Demaille 306fc3ec00 gnulib: update 2021-02-26 07:04:43 +01:00
Joshua WattandAkim Demaille 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 c61b282d77 regen 2021-02-25 06:55:08 +01:00
Akim Demaille 2d1d2f87f9 doc: printing locations
Document YYLOCATION_PRINT.

* doc/bison.texi (Printing Locations): New node.
2021-02-09 07:05:08 +01:00
Akim Demaille f50fff58d1 examples: improve some function prototypes
* examples/c/bistromathic/parse.y, examples/c/glr/c++-types.y,
* examples/c/lexcalc/parse.y: Use const where appropriate.
Avoid `yy` prefixes where it does not make sense.
Avoid the `p` prefix for pointers.
2021-02-09 07:04:05 +01:00
Akim Demaille e0ab5c324a examples: use YYLOCATION_PRINT
* examples/c/bistromathic/parse.y, examples/c/glr/c++-types.y,
* examples/c/lexcalc/parse.y: Don't use the private internal detail
`YY_LOCATION_PRINT`, use `YYLOCATION_PRINT`.
2021-02-09 06:59:50 +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 96b881094b examples: do not rely on YY_LOCATION_PRINT
* examples/c/bistromathic/parse.y (location_print): New.
Use it.
2021-02-09 06:48:00 +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 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 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 dc8fe0678a c++: make it clear that #define YYSTYPE is not supported
We have been accepting this for years, but it is deprecated: people
are expecting to define api.value.type instead.

* doc/bison.texi: Make it clear that YYSTYPE and YYLTYPE are for C
only.
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 638de51289 CI: try GCC 11 and Clang 11 2021-02-01 05:54:06 +01:00
Akim Demaille b46afca5be gnulib: update 2021-02-01 05:34:53 +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
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 VaisandAkim Demaille 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 EggertandAkim Demaille 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
Akim Demaille b27bba5ced bistromathic: use gettext for all the messages
* examples/c/bistromathic/parse.y: Add missing calls to _.
2021-01-27 20:48:38 +01:00
Adela VaisandAkim Demaille 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 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 51f12cffd2 package: fix details after merge with 3.7.5
* TODO, cfg.mk: Update.
* src/parse-gram.c, src/parse-gram.h: Regen.
2021-01-24 09:30:02 +01:00
Akim Demaille c94456986d Merge tag 'v3.7.5'
Three new commits:

commit 8358090292
Author: Paul Eggert <[email protected]>
Date:   Wed Jan 20 18:30:16 2021 -0800

    c: port to HP-UX 11.23

commit 2c294c1325
Author: Vincent Imbimbo <[email protected]>
Date:   Sat Jan 23 13:25:18 2021 -0500

    cex: fix state-item pruning

commit c22902e360
Author: Akim Demaille <[email protected]>
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 4083ee52b5 doc: fix typo
Reported by Kaz Kylheku.
https://lists.gnu.org/r/bison-patches/2020-11/msg00019.html

* doc/bison.texi (Versioning): here.
2021-01-24 08:55:42 +01:00
Kaz KylhekuandAkim Demaille 3c47ed0fe6 doc: document best deployment practices.
* doc/bison.texi (Versioning): New node about practices
regarding dealing with multiple versions of Bison.
2021-01-24 08:55:30 +01:00
Akim Demaille 1ff6bcb2f1 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-01-24 08:53:16 +01:00
Akim Demaille 2fac23b9dd version 3.7.5
* NEWS: Record release date.
2021-01-24 08:30:41 +01:00
Akim Demaille c22902e360 tables: fix handling for useless tokens
In some rare conditions, the generated parser can be wrong when there
are useless tokens.

Reported by Balázs Scheidler.
https://github.com/akimd/bison/issues/72

Balázs managed to prove that the bug was introduced in

    commit af1c6f973a
    Author: Theophile Ranquet <[email protected]>
    Date:   Tue Nov 13 10:38:49 2012 +0000

    tables: use bitsets for a performance boost

    Suggested by Yuri at
    <http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00000.html>.

    The improvement is marginal for most grammars, but notable for large
    grammars (e.g., PosgreSQL's postgre.y), and very large for the
    sample.y grammar submitted by Yuri in
    http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00012.html.
    Measured with --trace=time -fsyntax-only.

    parser action tables    postgre.y     sample.y
    Before                 0,129 (44%)  37,095 (99%)
    After                  0,117 (42%)   5,046 (93%)

    * src/tables.c (pos): Replace this set of integer coded as an unsorted
    array of integers with...
    (pos_set): this bitset.

which was implemented long ago, but that I installed only recently
(March 2019), first published in v3.3.90.

That patch introduces a bitset to represent a set of integers.  It
managed negative integers by using a (fixed) base (the smallest
integer to represent).  It avoided negative accesses into the bitset
by ignoring integers smaller than the base, under the asumption that
these cases correspond to useless tokens that are ignored anyway.
While it turns out to be true for all the test cases in the test suite
(!), Balázs' use case demonstrates that it is not always the case.

So we need to be able to accept negative integers that are smaller
than the current base.

"Amusingly" enough, the aforementioned patch was visibly unsure about
itself:

    /* Store PLACE into POS_SET.  PLACE might not belong to the set
       of possible values for instance with useless tokens.  It
       would be more satisfying to eliminate the need for this
       'if'.  */

This commit needs several improvements in the future:
- support from bitset for bit assignment and shifts
- amortized resizing of pos_set
- test cases

* src/tables.c (pos_set_base, pos_set_dump, pos_set_set, pos_set_test):
New.
Use them instead of using bitset_set and bitset_test directly.
2021-01-24 08:28:45 +01:00
Vincent ImbimboandAkim Demaille 2c294c1325 cex: fix state-item pruning
There were several bugs in pruning that would leave the state-item
graph in an inconsistent state which could cause crashes later on:

- Pruning now happens in one pass instead of two.

- Disabled state-items no longer prune the state-items they transition
  to if that state-item has other states that transition to it.

- State-items that transition to disabled state-items are always
  pruned even if they have productions.

Reported by Michal Bartkowiak <[email protected]>
https://lists.gnu.org/r/bug-bison/2021-01/msg00000.html
and Zartaj Majeed
https://github.com/akimd/bison/issues/71

* src/state-item.c (prune_forward, prune_backward): Fuse into...
(prune_state_item): this.
Adjust callers.
2021-01-24 08:24:56 +01:00
Akim Demaille 236b85dd28 package: pacify syntax-check
* cfg.mk: Currently we cannot update gnulib because of portability
issues with ancient versions of clang
(https://lists.gnu.org/r/bug-gnulib/2021-01/msg00241.html).  So skip
the check about copyright date for gnulib.
2021-01-23 15:08:48 +01:00
Akim Demaille 4109d56aa9 news: update 2021-01-23 15:02: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 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 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 a26f7cf98f %merge: let mergers record a typing-symbol, rather than a type
Symbols are richer than types, and in M4 it is my simpler (and more
common) to deal with symbols rather than types.  So let's associate
mergers to a symbol rather than a type name.

* src/reader.h (merger_list): Replace the 'type' member by a symbol
member.
* src/reader.c (record_merge_function_type): Take a symbol as
argument, rather than a type name.
* src/output.c (merger_output): Adjust.
2021-01-23 10:43:25 +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 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 4910c02579 package: codespell
* src/parse-gram.y: Fix spelling.
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 2f554e6260 cex: fix traces: add missing end-of-lines
In 430ca0fc63, I completely forgot that
`puts` adds a `\n`.

* src/lssi.c, src/state-item.c: Restore missing end-of-lines in the
output.
2021-01-23 10:42:52 +01:00
Akim Demaille 7a31b6bb7f cex: add support for $TIME_LIMIT
* src/counterexample.c (TIME_LIMIT): Replace with...
(time_limit): this.
(counterexample_init): Check $TIME_LIMIT.
* src/scan-gram.l: Reorder includes.
2021-01-23 09:40:32 +01:00
Akim Demaille 8320691a63 cex: send traces to stderr, not stdout
When comparing traces from different machines, the mixture of
stdout/stderr in the output are making things uselessly difficult.

* src/lssi.c, src/state-item.c: Output debug traces on stderr.
2021-01-23 09:39:27 +01:00
Akim Demaille 3b03c62e49 c++: I'm tired of Flex's warnings
* doc/bison.texi: Disable another warning I'm tired to see.
New releases would be most welcome.
2021-01-23 09:39:15 +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 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 <[email protected]>.
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 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
Martin RehakandAkim Demaille 1e0b087244 examples: avoid "unbound variable" errors
When the shell option `nounset` is set, we may get "unbound variable"
errors.
https://lists.gnu.org/r/bug-bison/2020-11/msg00013.html

* examples/test (diff_opts): Be sure to initialize it.
2021-01-23 09:27:30 +01:00
Akim Demaille 4744faf205 autoconf: update 2021-01-23 09:24:11 +01:00
Akim Demaille 1ac973aa56 c: adjust _Noreturn to pedantic clang
Reported by Joe Nelson <[email protected]>.
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
Adela VaisandAkim Demaille 5aaa93ae72 d: examples: calc: remove Value from Lexer
The Symbol constructor does not use it, so it is easier to not use
Value at all.

* examples/d/calc/calc.y: Here.
2021-01-17 08:38:51 +01:00
Adela VaisandAkim Demaille cd99a1a923 d: examples: calc: use of std.conv.parse for location
From Dlang v2.095.0 onwards, std.conv.parse reports the number of
consumed characters.

* examples/d/calc/calc.y: Here.
2021-01-17 08:38:51 +01:00
Adela VaisandAkim Demaille d53bbd5f06 d: examples: simple: fix style
* examples/d/simple/calc.y: Formatting changes.
2021-01-17 08:38:35 +01:00
Akim Demaille 615bad4186 CI: run D tests
* .travis.yml: here.
2021-01-17 08:37:09 +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 4fd2e5c22a package: fixes
* examples/c++/glr/local.mk, examples/c/glr/local.mk (CLEANFILES):
Complete to fix distcheck.
* src/output.c (merger_output): Obfuscate to pacify syntax-check's
sc_space_before_open_paren.
2021-01-16 17:30:17 +01:00
Akim Demaille 7e0b792d12 regen 2021-01-16 16:11:17 +01:00
Akim Demaille d7e8aaa271 package: bump copyrights to 2021
Run 'make update-copyright'.
2021-01-16 16:11:17 +01:00
Akim Demaille 30a8d580fa gnulib: update
* src/output.c, src/print-xml.c: Adjust.
2021-01-16 16:11:04 +01:00
Akim Demaille 119dedb591 autoconf: update 2021-01-16 15:37:19 +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 a9911528e0 cex: fix traces
In 430ca0fc63, I completely forgot that
`puts` adds a `\n`.

* src/lssi.c, src/state-item.c: Restore missing end-of-lines in the
output.
2021-01-16 14:40:54 +01:00
Akim Demaille 17fb1d0377 c: add support for YYNOMEM
Suggested by Joe Nelson <[email protected]>.
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 a9f9f317b5 doc: spell check
Gettext uses "catalog", not "catalogue".

* doc/bison.texi, examples/c/README.md,
* examples/c/bistromathic/Makefile,
* examples/c/bistromathic/README.md,
* examples/c/bistromathic/parse.y:
Spell check.
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 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 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 82133a6103 cex: add support for $TIME_LIMIT
* src/counterexample.c (TIME_LIMIT): Replace with...
(time_limit): this.
(counterexample_init): Check $TIME_LIMIT.
* src/scan-gram.l: Reorder includes.
2021-01-14 06:35:09 +01:00
Akim Demaille cca770a156 c: adjust _Noreturn to pedantic clang
Reported by Joe Nelson <[email protected]>.
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 430ca0fc63 cex: send traces to stderr, not stdout
When comparing traces from different machines, the mixture of
stdout/stderr in the output are making things uselessly difficult.

* src/lssi.c, src/state-item.c: Output debug traces on stderr.
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 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 47612d987b glr2.cc: example: style changes
* examples/c++/glr/c++-types.yy: We need C++ 11 (we use shared_ptr).
2021-01-10 17:04:04 +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
Akim Demaille fbdff2bc38 glr2.cc: fix memory leak
* data/skeletons/glr2.cc (glr_stack_item::setState): Free the previous
state before installing the new one.
2021-01-10 17:02:54 +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 428999c117 CI: disable the installation of dmd
Currently all the builds fail:

    $ mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
    --2021-01-10 06:05:39--  https://dlang.org/install.sh
    Resolving dlang.org (dlang.org)... 162.217.114.56, 2607:fc50:1:ff02::5:0
    Connecting to dlang.org (dlang.org)|162.217.114.56|:443... connected.
    ERROR: cannot verify dlang.org's certificate, issued by ‘CN=R3,O=Let's Encrypt,C=US’:
      Unable to locally verify the issuer's authority.
    To connect to dlang.org insecurely, use `--no-check-certificate'.

* .travis.yml: Disable dmd.
2021-01-10 12:14:43 +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 VaisandAkim Demaille 8d01c60e9c d: create getter for the number of errors from the parser
* data/skeletons/lalr1.d: Here.
2021-01-07 18:51:48 +01:00
Adela VaisandAkim Demaille 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 VaisandAkim Demaille dc8b16424a d: remove unnecessary imports
* data/skeletons/lalr1.d: Here.
2021-01-06 18:33:41 +01:00
Adela VaisandAkim Demaille 5bac3ddcee d: remove yytnamerr usage
It is a backwards-compatible feature for the other parsers.
D should not support this option.

* data/skeletons/d.m4: Here.
2021-01-06 18:33:41 +01:00
Adela VaisandAkim Demaille 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 e51e89856a glr2.cc: add support for variants
(Bison) Variants are extremely picky, which makes them both
annoying (lots of micro-details must be taken care of) and
precious (all the micro-details must be taken care of, in particular
object lifetime).

So (i) each time a semantic value is stored, it must be stored in a
place that exists, and (ii) each time a semantic value is discarded,
its place must have been emptied.

Example of (i)

    - new (&yys.value ()) value_type (s->value ());
    + {]b4_variant_if([[
    +   new (&yys.value ()) value_type ();
    +   ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)],
    +                      [yys.value ()], [copy], [s->value ()])], [[
    +   new (&yys.value ()) value_type (s->value ());]])[
    + }

Example of (ii)

      yyparser.yy_destroy_ ("Error: discarding",
    -                       yytoken, &yylval]b4_locations_if([, &yylloc])[);
    +                       yytoken, &yylval]b4_locations_if([, &yylloc])[);]b4_variant_if([[
    + // Value type destructor.
    + ]b4_symbol_variant([[YYTRANSLATE (this->yychar)]], [[yylval]], [[template destroy]])])[
      this->yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[;

However, in some places we must not be "pure".  In particular:

    glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW
      : is_state_ (other.is_state_)
    {
      std::memcpy (raw_, other.raw_, union_size);
    }

still must use memcpy, because the constructor would change pred, and
it must not.  This constructor is used only when resizing the stack,
in which case pred (which is relative) must not be "adjusted".

The result works, but is messy.  Its verbosity comes from at least two
factors:

- we don't have support for complete symbols (binding kind, value and
  location), and we should at least try to have it.  That simplified
  lalr1.cc a lot.

- I have not tried to be smart and use 'move' when possible.  As a
  consequence many places have 'copy' and then 'destroy'.  That kind
  of clean up can be done once everything appears to be solid.

* data/skeletons/glr2.cc: Be more rigorous in object lifetime.
In particular, don't forget to discard the lookahead when we're done
with it.
Call variant routines where needed.
Deal with plenty of details.
(b4_call_merger): Add support for variants.
Use references in mergers, rather than pointers.

* examples/c++/glr/c++-types.yy: Exercise variants.
2021-01-05 09:28:20 +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 8733959954 c++: I'm tired of Flex's warnings
* doc/bison.texi: Disable another warning I'm tired to see.
New releases would be most welcome.
2021-01-03 20:11:48 +01:00
Akim Demaille 31b8b8f179 glr: example: flush the output
* examples/c/glr/c++-types.y: Flush stdout so that the logs (on
stderr) and the effective output (on stdout) mix correctly.
While at it, be a bit more const-correct.
2021-01-03 19:58:23 +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 c1884d3002 glr.c: example: use a printer
* examples/c++/glr/c++-types.yy: Here.
2021-01-03 08:14:22 +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 74d1e881a7 glr2.cc: also equip semantic_option with self check
* data/skeletons/glr2.cc (semantic_option): Add MAGIC_, magic_ and
check_ members.
Use it.
2021-01-02 13:02:34 +01:00
Akim Demaille f30067ed51 glr2.cc: log the execution of deferred actions
See "glr.c: log the execution of deferred actions".

* data/skeletons/glr2.cc (yyuserAction): Take yyk as a new argument.
Rename argument yyn as yyrule for clarity.
Log before and after the user action.
Adjust callers to not call YY_REDUCE_PRINT and YY_SYMBOL_PRINT.
2021-01-02 13:02:19 +01:00
Akim Demaille 630448ba6b glr2.cc: minor clean up
* data/skeletons/glr2.cc (YYUNDEFTOK): Now useless.
Formatting/coding style changes.
2021-01-02 08:28:26 +01:00
Akim Demaille 1283dc7243 glr.c: log the execution of deferred actions
Currently deferred reductions are not "verbose" at all: only immediate
reductions are displayed in the YYDEBUG traces.  I don't understand
why.  Besides it seems actually simpler the install the reduction
traces right around the user action inside yyuserAction rather that
around calls to yyuserAction.

This only trouble is that yyuserAction does not know the stack number
it works on, so we have to pass it.  And pass -1 when we are actually
running on a temporary stack.

The glr example, on "T(x) + y;" as input, adds these logs, which
allow to see when the `<cast>` is built:

     Stack 0 Entering state 26
     Reduced stack 0 by rule 7 (line 108); action deferred.  Now in state 7.
     Stack 0 Entering state 7
     Reading a token
     Next token is token '+' (1.6: )
     Stack 1 Entering state 27
     Reduced stack 1 by rule 13 (line 123); action deferred.  Now in state 12.
     Stack 1 Entering state 12
     Next token is token '+' (1.6: )
     Stack 1 dies.
     Removing dead stacks.
     On stack 0, shifting token '+' (1.6: )
     Stack 0 now in state #14
    +Reducing stack -1 by rule 6 (line 107):
    +   $1 = token identifier (1.3: x)
    +-> $$ = nterm expr (1.3: x)
    +Reducing stack -1 by rule 7 (line 108):
    +   $1 = token typename (1.0: T)
    +   $2 = token '(' (1.2: )
    +   $3 = nterm expr (1.3: x)
    +   $4 = token ')' (1.4: )
    +-> $$ = nterm expr (1.0-3: <cast>(x,T))
     Returning to deterministic operation.

* data/skeletons/glr.c (yyuserAction): Take yyk as a new argument.
Rename argument yyn as yyrule for clarity.
Log before and after the user action.
Adjust callers to not call YY_REDUCE_PRINT and YY_SYMBOL_PRINT.
2021-01-02 07:37:00 +01:00
Akim Demaille e3d4b42f58 glr.c: reorder routines
The next commit wants to use YY_REDUCE_PRINT above its current
definition.  Move it higher.

* data/skeletons/glr.c (yylhsNonterm, YY_REDUCE_PRINT): Make available
earlier.
2021-01-02 07:37:00 +01:00
Akim Demaille f67c1ce937 glr.c: example: use the exact same display as in the C++ example
* examples/c/glr/c++-types.y: Add a space after the commas.
* examples/c/glr/c++-types.test: Adjust expectations.
2021-01-02 07:37:00 +01:00
Akim Demaille 5a4e606275 glr.c: example: several improvements
* examples/c/glr/c++-types.y (node_print): New.
Use YY_LOCATION_PRINT instead of duplicating it.
And actually use it in the action instead of badly duplicating it.
(main): Add proper option support.
* examples/c/glr/c++-types.test: Adjust expectations on locations.
* examples/c++/glr/c++-types.yy: Fix bad iteration.
2021-01-02 07:36:35 +01:00
Akim Demaille 83f2eb3737 glr2.cc: the example requires Bison 3.8
This will save us from generating the position.hh file.

* src/parse-gram.y: Claim we are 3.8.
* examples/c++/glr/c++-types.yy: Require 3.8.
2020-12-31 08:21:25 +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 fbe5abd23d %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.
2020-12-31 08:07:25 +01:00
Akim Demaille c09f2e4c7b %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, data/skeletons/glr2.cc (b4_call_merger): New.
2020-12-31 08:07:11 +01:00
Akim Demaille ac3d5b76f7 %merge: let mergers record a typing-symbol, rather than a type
Symbols are richer than types, and in M4 it is my simpler (and more
common) to deal with symbols rather than types.  So let's associate
mergers to a symbol rather than a type name.

* src/reader.h (merger_list): Replace the 'type' member by a symbol
member.
* src/reader.c (record_merge_function_type): Take a symbol as
argument, rather than a type name.
* src/output.c (merger_output): Adjust.
2020-12-31 08:07:11 +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 92e943bd24 glr2.cc: style: quoting changes
* data/skeletons/glr2.cc: Use stricter quoting rules.
2020-12-28 08:20:22 +01:00
Akim Demaille e40da7b6b3 lalr1.cc: style: quoting changes
* data/skeletons/lalr1.cc: here.
2020-12-28 08:20:16 +01:00
Akim Demaille 70b3c8fb20 glr2.cc: use references to the stack rather than pointers
Now that the lookahead macros (that used yystackp) are out of the way,
there is no reason to continue using a pointer.

* data/skeletons/glr2.cc: Use yystack, a reference, rather that
yystackp, a pointer.
Fix tons of const-correctness issues.
2020-12-27 08:50:10 +01:00
Akim Demaille e9b7641cca glr2.cc: simplify names
Now that we no longer play dangerous games with macros, we can give
the lookahead's token kind its proper name.  The content of yychar
_is_ raw (as opposed to yytoken), there's no reason to pleonasmicate
it (and thus to neologize).

* data/skeletons/glr2.cc (glr_stack::yyrawchar): Rename as...
(glr_stack::yychar): this.
2020-12-27 08:36:20 +01:00
Akim Demaille 321fac2193 glr2.cc: get rid of the macros wrapping the lookahead
In glr.c, the macros yychar, yylval and yylloc allow to deal with
api.pure: sometimes they point to global variables (impure), sometimes
they point to the member variables (pure).

There's no room for globals in glr2.cc.  Besides, they map yychar to
yyrawchar, yylval to yyval, etc. which obfuscates what is actually
going on.

* data/skeletons/glr2.cc (glr_stack::yyval, glr_stack::yyloc): Rename
as...
(glr_stack::yylval, glr_stack::yylloc): these, for clarity.
(yynerrs, yychar, yylval, yylloc, yystackp): Remove these macros.
(b4_yygetToken_call): Remove.
2020-12-27 08:34:49 +01:00
Akim Demaille 2777b73166 glr2.cc: reorganize the skeleton
Restore a more natural order: first define the macros and then use
them.  Currently, some macros were defined between the moment the
header is issued, and then the implementation file.  As a result, it
was possible for the header and the implementation to not use the same
versions of the macros.

* data/skeletons/glr2.cc: Define the macros first, then use them.
* data/skeletons/lalr1.cc: Minor comment and quoting changes.
2020-12-26 18:06:02 +01:00
Akim Demaille 89296e3962 glr2.cc: example: simplify
* examples/c++/glr/c++-types.yy: Formatting changes.
Remove unused support for '@'.
* examples/c/glr/c++-types.y: Ditto.
2020-12-26 17:40:18 +01:00
Akim Demaille bb97a2a37b glr2.cc: make yyreportTree a member function of semantic_option
* data/skeletons/glr2.cc (yy_accessing_symbol, yylhsNonterm): Define
ealier.
(state_stack::yyreportTree): Move to...
(semantic_option::yyreportTree): here.
Adjust dependencies.
2020-12-26 15:40:36 +01:00
Akim Demaille 8a22b557b9 glr2.cc: pass references to yyreportAmbiguity
* data/skeletons/glr2.cc (yyreportAmbiguity): Use references.
2020-12-26 15:40:33 +01:00
Akim Demaille 92dc8bf23b style: use yyval only, not yysval
* data/skeletons/glr.c, data/skeletons/glr2.cc: Use yyval, as in
the other skeletons.
2020-12-26 14:26:23 +01:00
Akim Demaille c18dbfcb06 glr2.cc: pass location by const ref to yyglrShift
* data/skeletons/glr2.cc (glr_state.yyglrShift): Take the location by
const&.
Remove useless `inline`.
2020-12-26 14:26:23 +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 3e6826aff1 glr2.cc: remove dead comments
* data/skeletons/glr2.cc: We no longer wrap glr.c here.
2020-12-26 14:26:23 +01:00
Akim Demaille 9466c734c5 glr2.cc: use YYCDEBUG, not YY_DEBUG_STREAM
* data/skeletons/glr2.cc (YY_DEBUG_STREAM): Rename as...
(YYCDEBUG): this, as in lalr1.cc.
2020-12-26 14:26:22 +01:00
Akim Demaille b9a533d63e glr2.cc: formatting changes
* data/skeletons/glr2.cc: here.
Remove useless `inline`.
2020-12-26 14:26:22 +01:00
Akim Demaille d0e44162b5 glr2.cc: don't use YYSTYPE/YYLTYPE at all
* data/skeletons/glr2.cc: Define value_type and location_type where
needed, and use them only.
(yyuserMerge): Make it a member function of the glr_state class.
2020-12-26 11:55:01 +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
Akim Demaille 2157ced3dd c++: rename semantic_type as value_type
We always refer to the triplet "kind, value, location".  All of them
are nouns, and we support api.value.type and api.location.type.  On
this regard, "semantic_type" was a poor choice.  Make it "value_type".

The test suite was not updated to use value_type, on purpose, to
enforce backward compatibility.

* data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/glr2.cc,
* data/skeletons/variant.hh, doc/bison.texi: Define value_type rather
than semantic_type.
Add a backward compatibility typedef.
* examples/c++/glr/c++-types.yy: Migrate.
2020-12-26 09:05:45 +01:00
Akim Demaille 59653c8efd doc: more about sanitizers
* README-hacking.md: here.
2020-12-26 08:08:06 +01:00
Akim Demaille 2a07cb0f2d glr2.cc: simplify
* data/skeletons/glr2.cc (glr_state_set::yyremoveDeletes): Use
vector::resize rather than vector::erase.
(glr_state::copyFrom): Merge into...
(glr_state::operator=): here.
Valentin wanted each assignment to be explicit, hence copyFrom rather
that operator=.  But in 0a82316e54
(glr2.cc: example: use objects (not pointers) to represent the AST),
in order to get real objects to be processed correctly, we had to
introduce the assignment operator.  Afterward, we also introduced a
full implementation of the copy-ctor, independent of copyFrom.  As a
result, today the only invocation of copyFrom is from the assignment
operator.  Simplify this.
2020-12-26 07:54:44 +01:00
Akim Demaille 734ce73bf2 glr2.cc: fix warnings about uninitialized locations
With GCC10, the CI shows tons of warnings such as
(327. actions.at:374: testing Initial location: glr2.cc):

    input.cc: In member function 'YYRESULTTAG glr_stack::yyglrReduce(state_set_index, rule_num, bool)':
    input.cc:1357:11: error: '<anonymous>.glr_state::yyloc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1357 |     yyloc = other.yyloc;
          |     ~~~~~~^~~~~~~~~~~~~

This is because we don't have the constructors for locations.  But we
should have them!  That's only because of glr.cc that ctors were not
enabled by default.  In glr2.cc, they should.

That fixes all the warnings when Bison's locations are used.  However,
when user-defined locations without constructor are used, we still
have:

    550. calc.at:1409: testing Calculator glr2.cc %locations api.location.type={Span}  ...
    calc.cc: In member function 'YYRESULTTAG glr_stack::yyglrReduce(state_set_index, rule_num, bool)':
    calc.cc:1261:11: error: '<anonymous>.glr_state::yyloc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1261 |     yyloc = other.yyloc;
          |     ~~~~~~^~~~~~~~~~~~~

To address this case, we need glr_state to explicily initialize its
yyloc member.

* data/skeletons/glr2.cc: Use genuine objects, with ctors, for position
and location.
(glr_state): Explicitly initialize yyloc in the constructors.
2020-12-26 07:54:05 +01:00
Akim Demaille baea8cf9fa glr2.cc: provide glr_state with a genuine copy-constructor
The copy constructor was (lazily) implemented by a call to copyFrom.
Unfortunately copyFrom reads yyresolved from the destination (and
source), and in the case of the copy-ctor this is random garbagge,
which UBSAN catches:

    glr-regr2a.cc:1072:10: runtime error: load of value 7, which is not a valid value for type 'bool'

Rather than defining yyresolved before calling copyFrom, let's just
provide a genuine cpy-ctor for glr_state.

* data/skeletons/glr2.cc (glr_state::glr_state): Implement properly.
2020-12-25 11:04:53 +01:00
Akim Demaille 636c9a8042 glr2.cc: beware of self-assignment
In yycompressStack:

    while (yyr != YY_NULLPTR)
      {
        nextFreeItem->check_ ();
        yyr->check_();
        nextFreeItem->setState(*yyr);
        glr_state& nextFreeState = nextFreeItem->getState();
        yyr = yyr->pred();
        nextFreeState.setPred(&(nextFreeItem - 1)->getState());
        setFirstTop(&nextFreeState);
        ++nextFreeItem;
      }

it is possible that nextFreeItem and yyr are actually the same state.
In which case `nextFreeItem->setState(*yyr)` does really bad things.

* data/skeletons/glr2.cc (glr_stack_item::setState): Beware of
self-assignment.
2020-12-25 11:04:53 +01:00
Akim Demaille 7dc942dca3 glr: comment changes
* data/skeletons/glr.c: A bit more doc.
(yypstates): Rename yyst (only occurrence) to yys (commonly used for
yyGLRState).
* data/skeletons/glr2.cc: Ditto.
Prefer '\n' to "\n".
2020-12-25 11:04:33 +01:00
Adela VaisandAkim Demaille 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
Adela VaisandAkim Demaille 27109d9d4a d: use Location and Position aliases in the backend
* data/skeletons/lalr1.d: Here.
2020-12-21 15:53:27 +01:00
Adela VaisandAkim Demaille 2b4451c4af d: remove unnecessary comparison from YYParser.parse()
* data/skeletons/lalr1.d: Here.
2020-12-21 15:51:57 +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 VaisandAkim Demaille 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 VaisandAkim Demaille 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 VaisandAkim Demaille 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 VaisandAkim Demaille 6692df8992 d: remove yychar from YYParse.parse()
The yychar variable was keeping the external form of the token (the
TokenKind).  As the D parser translates the token to its internal
form (the SymbolKind) inside the struct Symbol, there is no need for
yychar anymore.

* data/examples/lalr1.d (yychar): Remove.
Use only yytoken.
2020-12-21 06:56:00 +01:00
Adela VaisandAkim Demaille 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
Adela VaisandAkim Demaille ee4ec08513 d: m4 style consistency fix
* data/skeletons/lalr1.d: Here.
2020-12-21 06:49:13 +01:00
Adela VaisandAkim Demaille 13bb2b78b3 d: create alias Symbol for YYParse.Symbol
* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Document it.
* 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 06:47:57 +01:00
Adela VaisandAkim Demaille 848a17fa33 d: change name of YYParser.Symbol's semanticValue() to value()
Member value was renamed to value_ to avoid the name clash.

* data/skeletons/d.m4: Change member names.
* data/skeletons/lalr1.d: Adjust.
2020-12-21 06:46:09 +01:00
Akim Demaille c6a39f8409 glr2.cc: formatting changes
* data/skeletons/glr2.cc (glr_state): here.
(glr_state::MAGIC): Make it easier to recognize in decimal.
2020-12-20 18:49:06 +01:00
Akim Demaille df34ad7c6e glr2.cc: call the destructor in a way that complies with clang
examples/c++/glr/c++-types.cc:721:24: error:
      expected the class name after '~' to name a destructor
    yysval.YYSTYPE::~semantic_type ();
                    ^

Using a local typedef, for some reaon, result in clang complaining
about a useless local typedef.  Since anyway we don't want to keep on
using YYSTYPE and YYLTYPE, it is time to introduce proper typedefs to
reach these guys.  And to be slightly in advance of the other
skeletons: use value_type, not semantic_type.  This is much more
consistent with our use of the (kind, value, location) triplet.

* data/skeletons/glr2.cc (glr_state::value_type)
(glr_state::location_type): New.
(glr_state::~glr_state): Use value_type to name the dtor.
2020-12-20 18:46:17 +01:00
Akim Demaille 0a82316e54 glr2.cc: example: use objects (not pointers) to represent the AST
Currently we are using pointers.  The whole point of
glr2.cc (vs. glr.cc) is precisely to allow genuine C++ objects to be
semantic values.  Let's make that work.

* data/skeletons/glr2.cc (glr_state::glr_state): Be sure to initialize
yysval.
(glr_state): Add copy-ctor, assignment and dtor.
(glr_state::copyFrom): Be sure to initialize the destination if it was
not.
(glr_state::~glr_state): Destroy the semantic value.
* examples/c++/glr/ast.hh: Rewrite so that we use genuine objects,
rather than a traditional OOP hierarchy that requires to deal with
pointers.
With help from Bruno Belanyi <[email protected]>.
* examples/c++/glr/c++-types.yy: Remove memory management.
Use true objects.
(main): Don't reach yydebug directly.

* examples/c++/glr/local.mk: We need C++11.
2020-12-20 18:41:42 +01:00
Akim Demaille 611348e67b glr2.cc: more checks
* data/skeletons/glr2.cc: Clarify use of magic numbers.
(glr_stack_item::getState): Check the returned state.
2020-12-20 15:56:22 +01:00
Akim Demaille fe0102d4d5 glr2.cc: fix GLR stack expansion
When expanding the GLR stack, none of the pointers were updated to
reflect the new location of the displaced objects.

This fixes

    748: Incorrect lookahead during nondeterministic GLR: glr2.cc

* data/skeletons/glr2.cc (yyexpandGLRStack): Update the split point
and the stack tops.
(reduceToOneStack): Factor a bit.
2020-12-20 14:54:47 +01:00
Akim Demaille 718cb1ab38 glr2.cc: factor the computation of the accessing symbol
* data/skeletons/glr2.cc (yy_accessing_symbol): New, as in glr.c.
Use it.
2020-12-20 14:54:46 +01:00
Akim Demaille 08f657f4a4 glr2.cc: fix calling conventions for yyexpandGLRStackIfNeeded
This test fails:

748: Incorrect lookahead during nondeterministic GLR: glr2.cc

It consumes lots of stack space, so at some point we need to expand
it.  Because of Boolean logic mistakes, we then claim
memory-exhausted (first error).  Hence we jump to cleaning the
stack (popall_), calling all the destructors, and at some point we
crash with heap-use-after-free (second error).

This commit fixes the first error.  Unfortunately, even though we now
do expand the stack, we crash again with (another)
heap-use-after-free, not addressed here.

Eventually, we should make sure popall_() properly works.

* data/skeletons/glr2.cc (yyexpandGLRStackIfNeeded): Return true iff
success (i.e., memory not exhausted).
2020-12-20 14:54:46 +01:00
Akim Demaille 7292ed6e64 glr2.cc: example: use streams and accept arguments
From a debugger, it is easier to pass a file name than working on
stdin.

* examples/c++/glr/c++-types.yy: Reduce scopes.
Avoid YYSTYPE/YYLTYPE: use the C++ types.
(input, process): New.
(main): Use them.
2020-12-20 14:54:46 +01:00
Akim Demaille 3f473dd2d7 glr: formatting changes
* data/skeletons/glr.c: Formatting changes.
* data/skeletons/glr2.cc: Ditto.
(glr_state_set::INITIAL_NUMBER_STATES): Remove, unused (and useless:
let std::vector deal with that).
2020-12-20 14:54:46 +01:00
Akim Demaille 03d33fd3a4 skeletons: better comments for some tables
And also, remove the incorrect indentation of these comments:

    -  /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
    +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
     static const yytype_int8 yyr2[] =
     {
            0,     2,     4,     0,     2,     1,     1,     1,     3,     2,

I don't remember why this indentation was added (in
0991e29b75), but it seems wrong,
at least for yacc.c.  I suspect this was done with lalr1.cc (where
this is embeded in the class definition, so it should be indented),
but today lalr1.cc uses other routines to output these comments.

* data/skeletons/bison.m4 (b4_integral_parser_tables_map): Improve the
wording of the comments of some tables.
* data/skeletons/c.m4 (b4_integral_parser_table_define): Remove
indentation.
2020-12-20 14:54:46 +01:00
Akim Demaille 0a6c2e6400 glr2.cc: fix glr_stack_item::setState
A glr_stack_item has "raw" memory to store either a glr_state or a
semantic_option.  glr_stack_item::setState stores a state using a copy
assignment.  However, this is more like a construction: we are
starting from "raw" memory, so use the placement new operator instead.
While it probably makes no difference when parse.assert is disabled,
it does make one when it is: the constructor properly initialize the
magic number, the assignment does not.  So without these changes, the
next commit (which stores genuine objects in semantic values) fails
tests 712 and 730 because of incorrect magic numbers.

* data/skeletons/glr2.cc (glr_stack_item::setState): Build the state,
don't just copy it.
2020-12-19 07:29:37 +01:00
Akim Demaille 640b1313d7 glr2.cc: more self checks
* data/skeletons/glr2.cc: here.
2020-12-19 07:29:37 +01:00
Akim Demaille 66706a7c19 glr2.cc: style: s/Type/Kind/g
* data/skeletons/glr2.cc (YY_SYMBOL_PRINT): Use Kind, not Type.
As in the other skeletons.
2020-12-19 07:29:37 +01:00
Akim Demaille 80664353b2 glr2.cc: example: style: add missing copyright headers
* examples/c++/glr/ast.hh, examples/c++/glr/c++-types.yy: here.
* examples/c++/glr/local.mk: Fix distribution of ast.hh.
2020-12-19 07:29:30 +01:00
Akim Demaille d6fbeb2798 glr2.cc: example: address Clang warnings
ast.hh:24:7: error: 'Node' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Node
          ^
    ast.hh:57:7: error: 'Nterm' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Nterm : public Node
          ^
    ast.hh:102:7: error: 'Term' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Term : public Node
          ^

* examples/c++/glr/ast.hh: Define the destructors out of the class
definition.
This does not change anything, it is still in the header, but that
does pacify clang.
2020-12-19 07:29:29 +01:00
Akim Demaille b33817f8bb glr: tests: add support for the YYDEBUG envvar
When debugging these parsers, we really need debug traces.
Enable them, and bind them to $YYDEBUG.

* tests/glr-regression.at: Support the YYDEBUG envvar.
As a consequence, now that syntactic ambiguities are reported, adjust
the expected output.
(No users destructors if stack 0 deleted): Don't return 0 on memory
exhaustion, really return the parser's status, and adust expectations.
2020-12-16 07:38:59 +01:00
Akim Demaille c97dbc46af glr.c: comment changes
* data/skeletons/glr.c (yycompressStack): Reduce scope, and import some
nice comments from glr2.cc.
2020-12-14 06:33:22 +01:00
Akim Demaille b2d35f5cb8 glr2.cc: make the example more C++
Currently the example really looks like C.  Instead of a union of
structs to implement the AST, use a hierarchy.  It would be nice to
feature a C++17 version with std variants.

* examples/c++/glr/c++-types.yy (Node, free_node, new_nterm)
(new_term): Move into...
* examples/c++/glr/ast.hh: here, a proper C++ hierarchy.
2020-12-14 06:33:22 +01:00
Akim Demaille 855d46678a glr2.cc: make yyparse a member function
Amusingly enough, glr2.cc still had its core function, yyparse, being
a free function instead of a member function.

* data/skeletons/glr2.cc (yyparse): Remove this free function called
from yyparser::parse.  Inline its body into...
(yyparser::parse): this member function.
This requires moving a bit the yychar, etc. macros.
Access to token can be simplified (the
b4_namespace_ref::b4_parser_class prefix is no longer needed).
2020-12-14 06:33:22 +01:00
Akim Demaille 178a033e8b glr2.cc: being pure is not an option
Remove the useless conditional b4_pure_if: the skeleton is, of course,
pure (no global variables).  Make glr2.cc intrinsically pure.

* data/skeletons/glr2.cc (b4_pure_if): Remove definition and uses.
(b4_lex): New.
Stolen from lalr1.cc to avoid needing to use the one from c.m4.
2020-12-14 06:33:22 +01:00
Akim Demaille c8006f4637 glr2.cc: fix yycompressStack
Currently, yycompressStack expects the free items to be states only.
That's not the case.

Fixes 712 and 730 pass.  748 still fails, but later and
differently (heap-use-after-free).

* data/skeletons/glr2.cc (glr_stack_item::setState): New.
(glr_stack_item::yycompressStack): Use it.
* tests/glr-regression.at: Adjust.
2020-12-14 06:33:22 +01:00
Akim Demaille 5b65b3d543 glr2.cc: fix pointer arithmethics
A glr_state keeps tracks of its predecessor using an offset relative
to itself (i.e., pointer subtraction).  Unfortunately we sometimes
have to compute offsets for pointers that live in different
containers, in particular in yyfillin.  In that case there is no
reason for the distance between the two objects to be a multiple of
the object size (0x40 on my machine), and the resulting ptrdiff_t may
be "wrong", i.e., it does allow to recover one from the other.  We
cannot use "typed" pointer arithmetics here, the Euclidean division
has it wrong.  So use "plain" char* pointers.

Fixes 718 (Duplicate representation of merged trees: glr2.cc) and
examples/c++/glr/c++-types.

Still XFAIL:

    712: Improper handling of embedded actions and dollar(-N) in GLR parsers: glr2.cc
    730: Incorrectly initialized location for empty right-hand side in GLR: glr2.cc
    748: Incorrect lookahead during nondeterministic GLR: glr2.cc

* data/skeletons/glr2.cc (glr_state::as_pointer_): New.
(glr_state::pred): Use it.
* examples/c++/glr/c++-types.test: The test passes.
* tests/glr-regression.at (Duplicate representation of merged trees:
glr2.cc): Passes.
2020-12-14 06:33:21 +01:00
Akim Demaille 2b52bd1644 glr2.cc: style fixes
* data/skeletons/glr2.cc: Formatting changes.
2020-12-14 06:33:12 +01:00
Akim Demaille 9ee51ece65 glr2.cc: add sanity check in glr_state
The use of YY_IGNORE_NULL_DEREFERENCE_BEGIN/END in `check_` is to
please GCC 10:

    glr-regr8.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state&)':
    glr-regr8.cc:1433:21: error: potential null pointer dereference [-Werror=null-dereference]
     1433 |     YYASSERT (this->magic_ == MAGIC);
          |               ~~~~~~^~~~~~
    glr-regr8.cc:905:40: note: in definition of macro 'YYASSERT'
      905 | # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
          |                                        ^~~~~~~~~

* data/skeletons/glr2.cc (glr_state::check_): New.
Use it in the member functions.
2020-12-13 06:59:04 +01:00
Akim Demaille 2313f891bd glr2.cc: add sanity checks in glr_stack_item
We obviously have broken pointer arithmetics that hands us
glr_stack_items that are not glr_stack_items.  Have a simple check for
this, to have earlier failures.

* data/skeletons/glr2.cc (glr_stack_item::check_): New.
Use it.
(glr_stack_item::contents): Avoid the useless struct.
Fix minor stylistic issues.
2020-12-13 06:31:41 +01:00
Akim Demaille 42fe808292 glr2.cc: run the glr-regression tests
When installed on master as of 2020-12-05 (on top of "glr2.cc: fix
when the stack is not expandable", almost all the GLR regression tests
fail (with a SEGV):

    709: Badly Collapsed GLR States: glr2.cc             FAILED (glr-regression.at:130)
    712: Improper handling of embedded actions and dollar(-N) in GLR parsers: glr2.cc FAILED (glr-regression.at:275)
    715: Improper merging of GLR delayed action sets: glr2.cc FAILED (glr-regression.at:404)
    718: Duplicate representation of merged trees: glr2.cc FAILED (glr-regression.at:502)
    721: User destructor for unresolved GLR semantic value: glr2.cc FAILED (glr-regression.at:566)
    724: User destructor after an error during a split parse: glr2.cc FAILED (glr-regression.at:624)
    727: Duplicated user destructor for lookahead: glr2.cc FAILED (glr-regression.at:724)
    730: Incorrectly initialized location for empty right-hand side in GLR: glr2.cc FAILED (glr-regression.at:823)
    733: No users destructors if stack 0 deleted: glr2.cc FAILED (glr-regression.at:911)
    736: Corrupted semantic options if user action cuts parse: glr2.cc FAILED (glr-regression.at:974)
    739: Undesirable destructors if user action cuts parse: glr2.cc FAILED (glr-regression.at:1042)
    742: Leaked semantic values if user action cuts parse: glr2.cc FAILED (glr-regression.at:1173)
    748: Incorrect lookahead during nondeterministic GLR: glr2.cc FAILED (glr-regression.at:1546)
    751: Leaked semantic values when reporting ambiguity: glr2.cc FAILED (glr-regression.at:1639)
    754: Leaked lookahead after nondeterministic parse syntax error: glr2.cc FAILED (glr-regression.at:1710)
    757: Uninitialized location when reporting ambiguity: glr2.cc FAILED (glr-regression.at:1794)
    766: Predicates: glr2.cc                             FAILED (glr-regression.at:2045)

These pass:

    745: Incorrect lookahead during deterministic GLR: glr2.cc ok
    760: Missed %merge type warnings when LHS type is declared later: glr2.cc ok
    763: Ambiguity reports: glr2.cc ok

With Valentin Tolmer's "glr2.cc: Fix memory corruption bug" commit,
these test fail "gracefully":

    712: Improper handling of embedded actions and dollar(-N) in GLR parsers: glr2.cc FAILED (glr-regression.at:268)
    730: Incorrectly initialized location for empty right-hand side in GLR: glr2.cc FAILED (glr-regression.at:816)
    748: Incorrect lookahead during nondeterministic GLR: glr2.cc FAILED (glr-regression.at:1539)

And these do not end:

    709: Badly Collapsed GLR States: glr2.cc             FAILED (glr-regression.at:123)
    715: Improper merging of GLR delayed action sets: glr2.cc FAILED (glr-regression.at:397)
    718: Duplicate representation of merged trees: glr2.cc FAILED (glr-regression.at:495)
    751: Leaked semantic values when reporting ambiguity: glr2.cc FAILED (glr-regression.at:1632)

With "tests: glr2.cc: run the glr-regression tests", none loop, and
709, 715, and 751 pass.  Only 718 still fails.

* tests/glr-regression.at: Run all the tests with glr2.cc.
* tests/local.at (AT_GLR2_CC_IF): New.
2020-12-06 15:11:33 +01:00
Akim Demaille 4beefee4bf glr2.cc: use the same format for traces as glr.c
* data/skeletons/glr2.cc: here.
This allows to share the same expected output.
2020-12-06 14:02:38 +01:00
Akim Demaille 3301849f0f glr2.cc: add support for parse.assert
* data/skeletons/glr2.cc: Fake support of parse.assert, so that the
tests can use it without failing.
2020-12-06 14:02:38 +01:00
Akim Demaille 349ea900f5 glr2.cc: fix yyresolveValue
When "tests: glr2.cc: run the glr-regression tests" tests are run,
before this commit the following tests used to loop endlessly:

    709: Badly Collapsed GLR States: glr2.cc             FAILED (glr-regression.at:123)
    715: Improper merging of GLR delayed action sets: glr2.cc FAILED (glr-regression.at:397)
    718: Duplicate representation of merged trees: glr2.cc FAILED (glr-regression.at:495)
    751: Leaked semantic values when reporting ambiguity: glr2.cc FAILED (glr-regression.at:1632)

After this commit, no test loops and 709, 715, and 751 pass.  Only 718
still fails.

* data/skeletons/glr2.cc (yyresolveValue): Add missing incrementation
of the iteration variable.
2020-12-06 14:02:38 +01:00
Valentin TolmerandAkim Demaille 1b85ac4586 glr2.cc: misc cleanups
* data/skeletons/glr2.cc: Use 'const' on variables and applicable
member functions.
Improve comments.
Use references where applicable.
Enforce names_like_this, notLikeThis.
Reduce scopes.
2020-12-06 14:02:38 +01:00
Valentin TolmerandAkim Demaille 2ec6df3b07 glr2.cc: fix memory corruption bug
* data/skeletons/glr2.cc (yyremoveDeletes): Remove double-increment in
the loop.
(glr_state::copyFrom): Handle gracefully when other is resolved.
2020-12-06 14:02:38 +01:00
Akim Demaille e72eda7aee glr2.cc: turn some pointers into references
* data/skeletons/glr2.cc: Prefer references to pointers.
Add a few more const.
2020-12-06 14:02:38 +01:00
Valentin TolmerandAkim Demaille 4f24f5f304 glr2.cc: use 'const' for some constant local variables
* data/skeletons/glr2.cc: here.
2020-12-06 13:54:45 +01:00
Akim Demaille 12b5924939 glr2.cc: fix when the stack is not expandable
* data/skeletons/glr2.cc (yyexpandGLRStackIfNeeded): Fix the
implementation when !YYSTACKEXPANDABLE.
2020-12-06 13:54:45 +01:00
Akim Demaille d4188398f1 glr.c: fix line numbers in logs
* data/skeletons/glr.c (yyglrReduce): Fix line numbers.
* tests/glr-regression.at: Fix expectations.
2020-12-06 13:54:45 +01:00
Akim Demaille 8ab625e517 tests: glr: run the glr regression tests with glr.cc
* tests/glr-regression.at: Adjust the tests to be more independent of
the language, and run them with glr.cc.
Some tests relied on yychar, yylval and yylloc being global variables:
pass arguments instead.
2020-12-05 12:39:59 +01:00
Akim Demaille edf6aa7d3b tests: glr: prepare for more languages
* tests/glr-regression.at: Wrap each test in an AT_TEST.
Call it with glr.c.
2020-12-05 12:39:59 +01:00
Akim Demaille 4aec17af93 tests: glr: use AT_FULL_COMPILE
* tests/glr-regression.at: Instead of using AT_BISON_CHECK and
AT_COMPILE, use AT_FULL_COMPILE.  This is shorter, and makes it easier
to add support for other programming languages.
2020-12-05 11:22:20 +01:00
Akim Demaille c98b8856e6 tests: glr: prefer directives to warnings
* tests/glr-regression.at: Use %expect and %expect-rr in the grammar
files, rather than accepting diagnostics.
This will make it easier to support other programming languages.
2020-12-05 11:22:20 +01:00
Akim Demaille 4ec49a8585 tests: factor the access to token kinds
* tests/local.at (AT_BISON_OPTION_PUSHDEFS): Define AT_TOKEN.
(AT_BISON_OPTION_POPDEFS): Undefine it.
* tests/actions.at, tests/c++.at, tests/calc.at: Use AT_TOKEN.
2020-12-05 11:22:20 +01:00
Akim Demaille 627d275a3a tests: formatting changes
* tests/local.at: here.
2020-12-05 11:22:20 +01:00
Akim Demaille 84a84560c3 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.
2020-12-05 07:36:01 +01:00
Akim Demaille 0e78a9028e portability: beware of GCC 4.6
src/reader.c: In function 'grammar_start_symbols_add':
    src/reader.c:67:24: error: declaration of 'dup' shadows a global declaration [-Werror=shadow]

* src/reader.c (grammar_start_symbols_add): Rename dup as dupl.
2020-12-03 19:46:20 +01:00
Akim Demaille 24233748ec 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 <[email protected]>.
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.
2020-12-03 06:21:53 +01:00
Akim Demaille 9840e5b621 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.
2020-12-03 06:19:17 +01:00
Akim Demaille 8eede447db gnulib: update 2020-11-30 16:48:04 +01:00
Akim Demaille 5b19f91ccf multistart: check duplicates
* src/symlist.h, src/symlist.c (symbol_list_find_symbol)
(symbol_list_last): New.
(symbol_list_append): Use symbol_list_last.
* src/reader.c (grammar_start_symbols_add): Check and discard duplicates.
* tests/input.at (Duplicate %start symbol): New.
* tests/reduce.at (Bad start symbols): Add the multistart keyword.
2020-11-30 16:48:03 +01:00
Akim Demaille 7fe9205b9f style: change the format of a debugging function
* src/symlist.c (symbol_list_syms_print): Use braces to make traces
easier to read.
2020-11-22 16:01:05 +01:00
Akim Demaille d798851e48 style: rename grammar_start_symbols_set as grammar_start_symbols_add
* src/reader.h, src/reader.c (grammar_start_symbols_set): Rename as...
(grammar_start_symbols_add): this.
Adjust dependencies.
2020-11-22 11:18:20 +01:00
Akim Demaille 5af04b99dd TODO: update 2020-11-22 09:57:17 +01:00
Akim Demaille 38cdb2aba2 multistart: also use the api.prefix in the implementation
We were declaring foo_parse_expr but implementing yyparse_expr.

* data/skeletons/yacc.c (_b4_define_sub_yyparse): Use api.prefix for
the parse function name.
2020-11-21 14:57:29 +01:00
Akim Demaille 5629305131 doc: using stow to set up a bison herd
* README-hacking.md (Stow): New.
2020-11-20 22:09:31 +01:00
Adela VaisandAkim Demaille e5854bbddd d: change YYLocation's type from class to struct
This avoids heap allocation and gives minimal costs for the
creation and destruction of the YYParser.Symbol struct if
the location tracking is active.

Suggested by H. S. Teoh.

* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Adjust.
* tests/calc.at: Test it.
2020-11-20 22:09:31 +01:00
Adela VaisandAkim Demaille 10305f3e94 d: change the return value of yylex from TokenKind to YYParser.Symbol
The complete symbol approach was deemed to be the right approach for Dlang.
Now, the user can return from yylex() an instance of YYParser.Symbol structure,
which binds together the TokenKind, the semantic value and the location. Before,
the last two were reported separately to the parser.
Only the user API is changed, Bisons's internal structure is kept the same.

* data/skeletons/d.m4 (struct YYParser.Symbol): New.
* data/skeletons/lalr1.d: Change the return value.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Demonstrate it.
* tests/calc.at, tests/scanner.at: Test it.
2020-11-20 22:09:31 +01:00
Martin RehakandAkim Demaille 2ca158c893 examples: avoid "unbound variable" errors
When the shell option `nounset` is set, we may get "unbound variable"
errors.
https://lists.gnu.org/r/bug-bison/2020-11/msg00013.html

* examples/test (diff_opts): Be sure to initialize it.
2020-11-20 06:42:39 +01:00
Akim Demaille 336089123f gnulib: update
* Makefile.am (gitsort): New.
Use it.
2020-11-20 06:28:42 +01:00
Adela VaisandAkim Demaille 593724366f d: add support for lookahead correction
When using lookahead correction, the method YYParser.Context.getExpectedTokens
is not annotated with const, because the method calls yylacCheck, which is not
const. Also, because of yylacStack and yylacEstablished, yylacCheck needs to
be called from the context of the parser class, which is sent as parameter to
the Context's constructor.

* data/skeletons/lalr1.d (yylacCheck, yylacEstablish, yylacDiscard,
yylacStack, yylacEstablished): New.
(Context): Use it.
* doc/bison.texi: Document it.
* tests/calc.at: Check it.
2020-11-18 08:14:43 +01:00
Adela VaisandAkim Demaille 0e51f6146a d: change the name of the custom error message function to reportSyntaxError
Changed from syntax_error to reportSyntaxError to be similar to the Java parser.

* data/skeletons/lalr1.d: Change the function name.
* doc/bison.texi: Document it.
* tests/local.at: Adjust.
2020-11-18 08:14:21 +01:00
Akim Demaille 5945da031e Merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.7.4
2020-11-14 12:42:36 +01:00
Akim Demaille 0364dbacbf maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-11-14 12:26:42 +01:00
Akim Demaille 7a11a9308c version 3.7.4
* NEWS: Record release date.
2020-11-14 12:04:26 +01:00
Akim Demaille b9b13602ed style: prefer b4_symbol(empty, ...) to b4_symbol(-2, ...)
* data/skeletons/c.m4: here.
2020-11-13 07:01:36 +01:00
Akim Demaille 23472033ee Merge branch 'maint'
* maint:
  c++: shorten the assertions that check whether tokens are correct
  c++: don't glue functions together
  lalr1.cc: YY_ASSERT should use api.prefix
  c++: don't use YY_ASSERT at all if parse.assert is disabled
  c++: style: follow the Bison m4 quoting pattern
  yacc.c: provide the Bison version as an integral macro
  regen
  style: make conversion of version string to int public
  %require: accept version numbers with three parts ("3.7.4")
  yacc.c: fix #definition of YYEMPTY
  gnulib: update
  doc: fix incorrect section title
  doc: minor grammar fixes in counterexamples section
2020-11-13 07:01:19 +01:00
Akim Demaille d8cc6b073e c++: shorten the assertions that check whether tokens are correct
Before:

    YY_ASSERT (tok == token::YYEOF || tok == token::YYerror || tok == token::YYUNDEF || tok == 120 || tok == 49 || tok == 50 || tok == 51 || tok == 52 || tok == 53 || tok == 54 || tok == 55 || tok == 56 || tok == 57 || tok == 97 || tok == 98);

After:

    YY_ASSERT (tok == token::YYEOF
               || (token::YYerror <= tok && tok <= token::YYUNDEF)
               || tok == 120
               || (49 <= tok && tok <= 57)
               || (97 <= tok && tok <= 98));

Clauses are now also wrapped on several lines.  This is nicer to read
and diff, but also avoids pushing Visual C++ to its arbitrary
limits (640K and lines of 16380 bytes ought to be enough for anybody,
otherwise make an C2026 error).

The useless parens are there for the dummy warnings about
precedence (in the future, will we also have to put parens in
`1+2*3`?).

* data/skeletons/variant.hh (_b4_filter_tokens, b4_tok_in, b4_tok_in):
New.
(_b4_token_constructor_define): Use them.
2020-11-13 06:17:52 +01:00
Akim Demaille 0264b4bca0 c++: don't glue functions together
* data/skeletons/bison.m4 (b4_type_foreach): Accept a separator.
* data/skeletons/c++.m4: Use it.
And fix an incorrect comment.
2020-11-13 06:17:52 +01:00
Akim Demaille 8b424b865e lalr1.cc: YY_ASSERT should use api.prefix
Working on the previous commit I realized that YY_ASSERT was used in
the generated headers, so must follow api.prefix to avoid clashes when
multiple C++ parser with variants are used.

Actually many more macros should obey api.prefix (YY_CPLUSPLUS,
YY_COPY, etc.).  There was no complaint so far, so it's not urgent
enough for 3.7.4, but it should be addressed in 3.8.

* data/skeletons/variant.hh (b4_assert): New.
Use it.
* tests/local.at (AT_YYLEX_RETURN): Fix.
* tests/headers.at: Make sure variant-based C++ parsers are checked
too.
This test did find that YY_ASSERT escaped renaming (before the fix in
this commit).
2020-11-13 06:17:52 +01:00
Akim Demaille f4431ea115 c++: don't use YY_ASSERT at all if parse.assert is disabled
In some extreme situations (about 800 tokens), we generate a
single-line assertion long enough for Visual C++ to discard the end of
the line, thus falling into parse ends for the missing `);`.  On a
shorter example:

    YY_ASSERT (tok == token::TOK_YYEOF || tok == token::TOK_YYerror || tok == token::TOK_YYUNDEF || tok == token::TOK_ASSIGN || tok == token::TOK_MINUS || tok == token::TOK_PLUS || tok == token::TOK_STAR || tok == token::TOK_SLASH || tok == token::TOK_LPAREN || tok == token::TOK_RPAREN);

Whether NDEBUG is used or not is irrelevant, the parser dies anyway.

Reported by Jot Dot <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00002.html

We should avoid emitting lines so long.

We probably should also use a range-based assertion (with extraneous
parens to pacify fascist compilers):

    YY_ASSERT ((token::TOK_YYEOF <= tok && tok <= token::TOK_YYUNDEF)
               || (token::TOK_ASSIGN <= tok && ...)

But anyway, we should simply not emit this assertion at all when not
asked for.

* data/skeletons/variant.hh: Do not define, nor use, YY_ASSERT when it
is not enabled.
2020-11-13 06:17:52 +01:00
Akim Demaille fe8c36ddca c++: style: follow the Bison m4 quoting pattern
* data/skeletons/variant.hh: here.
2020-11-13 06:17:24 +01:00
Akim Demaille d0ea78ca47 todo: more 2020-11-11 16:57:10 +01:00
Akim Demaille 21c147b6e5 yacc.c: provide the Bison version as an integral macro
Suggested by Balazs Scheidler.
https://github.com/akimd/bison/issues/55

* src/muscle-tab.c (muscle_init): Move/rename `b4_version` to/as...
* src/output.c (prepare): `b4_version_string`.
Also define `b4_version`.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/d.m4,
* data/skeletons/java.m4: Adjust.
* doc/bison.texi: Document it.
2020-11-11 09:08:57 +01:00
Akim Demaille d3c575a6c6 regen 2020-11-11 08:47:23 +01:00
Akim Demaille d8b49e2b73 style: make conversion of version string to int public
* src/parse-gram.y (str_to_version): Rename as/move to...
* src/strversion.h, src/strversion.c (strversion_to_int): these new
files.
2020-11-11 08:47:23 +01:00
Akim Demaille 14c65a35f0 %require: accept version numbers with three parts ("3.7.4")
* src/parse-gram.y (str_to_version): Support three parts.
* data/skeletons/location.cc, data/skeletons/stack.hh:
Adjust.
2020-11-11 08:47:23 +01:00
Todd C. MillerandAkim Demaille c47bb87f9f yacc.c: fix #definition of YYEMPTY
When generating a C parser, YYEMPTY is present in enum yytokentype but
there is no corresponding #define like there is for the other values.
There is a special case for YYEMPTY in b4_token_enums but no
corresponding case in b4_token_defines.

* data/skeletons/c.m4 (b4_token_defines): Do define YYEMPTY.
2020-11-11 08:47:21 +01:00
Akim Demaille 98c35e0025 gnulib: update 2020-11-10 07:56:13 +01:00
Akim Demaille 7cc9107053 style: enforce java coding style
* tests/scanner.at: here.
2020-11-10 07:55:36 +01:00
Akim Demaille 25ded505a3 ielr: fix incorrect function call
* src/ielr.c: s/rule_is_accepting/rule_is_initial/.
2020-11-10 07:15:43 +01:00
Akim Demaille 6c0ba6089a ielr: more comments and logs
* src/ielr.c: More comments.
(state_list_print): New.
2020-11-10 07:08:07 +01:00
Akim Demaille 70ee8c77a8 multistart: fix IELR computations
IELR needs to rule out the successors of the kernel items of the
initial state (`$accept: input • $end`).  In the case of multistart,
this condition must be expressed differently: the mere item index does
not suffice.

* src/ielr.c (ielr_item_has_lookahead, ielr_compute_lookaheads): Don't
rely on the item index to check whether is_successor_of_initial_item.
It is certainly more costly than just checking the item index, but (i)
we need to compute the rule anyway, so it's not very much more costly,
and (ii) in ielr_item_has_lookahead, this situation is actually
impossible, so an optimizing compiler reading the assertions should
actually avoid this computation.
2020-11-10 07:08:07 +01:00
Akim Demaille e9a43ed4ae ielr: make some conditions about items easier to understand
Checking that an item index is > 1 means ruling out `$accept: • input
$end` and `$accept: input • $end`.  But actually only the latter is
possible there, i.e., we're checking whether this item is about a
successor of a (kernel) item of the initial state ($accept: input •
$end).

* src/ielr.c (is_successor_of_initial_item): Use a variable to name
this condition.
2020-11-10 07:08:07 +01:00
Akim Demaille a38d0b9145 multistart: introduce and use rule_is_initial
* src/gram.h (rule_is_initial): New.
* src/graphviz.c, src/print-xml.c, src/print.c, src/lalr.c: Use it.
Some of these occurrences were incorrect (checking whether this is
rule 0), and not behaving properly in the case of multistart.
2020-11-10 07:08:03 +01:00
Akim Demaille 4b0cd01fb7 style: comment and formatting changes, and fixes
* examples/c/lexcalc/parse.y: Fix option handling.
* src/gram.h: Clarify comments.
* src/ielr.c: Fix indentation.
* src/print.c, src/state.h: More comments.
2020-11-08 13:42:15 +01:00
Akim Demaille 0328cbad64 lalr: add assertions
* src/lalr.c: Remove incorrect comment (subsumed anyway by the
(correct) one in the header.
(set_goto_map): More debug traces.
(map_goto): Add an assertion.
2020-11-08 08:25:20 +01:00
Akim Demaille 3b80811cfa glr2.cc: remove scaffolding for glr.c
* data/skeletons/glr2.cc (b4_glr_cc_setup, b4_glr_cc_cleanup): Remove.
2020-11-07 17:28:25 +01:00
Akim Demaille 10eb13007e d: remove dead comment
* data/skeletons/lalr1.d (reportSyntaxError): here.
2020-11-07 17:12:21 +01:00
Adela VaisandAkim Demaille dc15b62a7c d: add the custom error message feature
Parser.Context class returns a const YYLocation, so Lexer's method
yyerror() needs to receive the location as a const parameter.

Internal error reporting flow is changed to be similar to that of
the other skeletons. Before, case YYERRLAB was calling yyerror()
with the result of yysyntax_error() as the string parameter. As the
custom error message lets the user decide if they want to use
yyerror() or not, this flow needed to be changed. Now, case YYERRLAB
calls yyreportSyntaxError(), that builds the error message using
yysyntaxErrorArguments(). Then yyreportSyntaxError() passes the
error message to the user defined syntax_error() in case of a custom
message, or to yyerror() otherwise.

In the tests in tests/calc.at, the order of the tokens needs to be
changed in order of precedence, so that the D program outputs the
expected tokens in the same order as the other parsers.

* data/skeletons/lalr1.d: Add the custom error message feature.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Adjust.
* tests/calc.at, tests/local.at: Test it.
2020-11-07 17:03:23 +01:00
Adela VaisandAkim Demaille 4252134ba4 d: examples: fix coding style
* examples/d/calc/calc.y, examples/d/simple/calc.y: Fix whitespace issues
and remove the @property attribute.
2020-11-07 17:03:04 +01:00
Akim Demaille 5a31cda4c3 style: avoid explicit symbol numbers
This should have been part of commit "symbols: stop dealing with YYEMPTY
as b4_symbol(-2, ...)" (cd40ec9526).
Give names to all the special symbols: "eof", "error" and "undef".

* data/skeletons/bison.m4 (b4_symbol): Let `b4_symbol(eof, ...)` mean
`b4_symbol(0, ...)`, `b4_symbol(error, ...)` mean `b4_symbol(1, ...)`,
and , `b4_symbol(undef, ...)` mean `b4_symbol(2, ...)`..

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c:
Prefer symbols to numbers.
2020-11-07 16:58:47 +01:00
Adela VaisandAkim Demaille 34e6e8815a d: fix Context class
All methods are now declared as const. Method getExpectedTokens() has now the
functionality of reporting only the number of expected tokens.

* data/skeletons/lalr1.d: Fix Context class.
2020-11-07 07:55:12 +01:00
Akim Demaille b5aee13b82 doc: fix typo
Reported by Kaz Kylheku.
https://lists.gnu.org/r/bison-patches/2020-11/msg00019.html

* doc/bison.texi (Versioning): here.
2020-11-07 07:55:12 +01:00
Adela VaisandAkim Demaille 660f3d4732 d: doc: add D Action Features section
* doc/bison.texi (D Action Features section): New.
2020-11-07 07:55:12 +01:00
Adela VaisandAkim Demaille abf5f7f90e d: add yyerrok
In D's case, yyerrok() is a private method of the Parser class.
It can be called directly as `yyerrok()` from the grammar rules section.

* data/skeletons/lalr1.d: Add yyerrok().
* examples/d/calc/calc.y, examples/d/simple/calc.y: Demonstrate yyerrok().
* tests/calc.at: Update D tests to use yyerrok().
2020-11-07 07:14:52 +01:00
Akim Demaille d49da0101a java: lac: a stronger test for the exploratory stack
* tests/local.at (AT_YYLEX_DEFINE(java)): Fix overquoting issue.
Style changes.
* tests/regression.at (LAC: Exploratory stack): Run for lalr1.java too.
2020-11-06 07:37:15 +01:00
Kaz KylhekuandAkim Demaille fa8aca1ed4 doc: document best deployment practices.
* doc/bison.texi (Versioning): New node about practices
regarding dealing with multiple versions of Bison.
2020-11-05 06:04:23 +01:00
Akim Demaille 829ac9caed java: lac: more tests, and some doc
* doc/bison.texi: C++ and Java support LAC.
* tests/input.at (LAC: Errors for %define): Generalize the test, and
apply it to Java.
2020-11-04 07:28:13 +01:00
Akim Demaille f7a7310433 java: avoid Integer(String), use parseInt
examples/java/calc/Calc.java:1531: warning: [deprecation] Integer(String) in Integer has been deprecated
          yylval = new Integer(st.sval);
                   ^

* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/scanner.at: Use Integer.parseInt.
2020-11-03 08:46:54 +01:00
Akim Demaille d156910453 java: prefer ArrayList to Vector
Vector is synchronized, which is completely useless in our case (and
not even relevant when concurrency matters).  No seasoned Java
programmer would use it.
Reported by Uxio Prego.

* data/skeletons/lalr1.java: Replace Vector with ArrayList.
Unfortunately its API is not as rich, and lacks lastElement and
setSize.
2020-11-03 08:46:54 +01:00
Akim Demaille 1995d9e2f2 java: lac: check it
* tests/calc.at: Add tests for LAC in pull and push parsers.
Skip LAC: line from the logs.
* tests/local.at (reportSyntaxError): Output the error message in a
single call, to avoid having the error message on stderr be
interrupted by the debug traces of LAC in getExpectedTokens.
2020-11-03 08:46:54 +01:00
Akim Demaille c223baee63 java: add support for lookahead correction
Shamelessly stolen from Adrian Vogelsgesang's implementation in
lalr1.cc.

* data/skeletons/lalr1.java (yycdebugNnl, yyLacCheck, yyLacEstablish)
(yyLacDiscard, yylacStack, yylacEstablished): New.
(Context): Use it.
* examples/java/calc/Calc.y: Enable LAC.
2020-11-03 08:46:54 +01:00
Akim Demaille 787052f074 style: java: more style fixes
* data/skeletons/lalr1.java, tests/java.at: Avoid space before paren.
And use braces as is customary in the Java.
2020-11-03 08:46:54 +01:00
Akim Demaille 042b916c0e style: comment changes in the skeletons
* data/skeletons/lalr1.cc: Prepare for Java's LAC.
* data/skeletons/lalr1.java: Style fixes.
2020-11-03 08:46:54 +01:00
Akim Demaille 57848d9262 doc: fix incorrect section title
Reported by Gaurav Singh <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:15:24 +01:00
Akim Demaille bd6b046ce7 doc: fix incorrect section title
Reported by Gaurav Singh <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:12:27 +01:00
Nick GassonandAkim Demaille 7c6e7bd300 doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:36:43 +01:00
Nick GassonandAkim Demaille 8d7cd5e84d doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:33:40 +01:00
Adela VaisandAkim Demaille 0cd16ae964 d: create the Parser.Context class
This will provide the user an interface for creating custom error messages.

* data/skeletons/lalr1.d: Add the Context class.
* doc/bison.texi: Document it.
2020-10-27 07:39:00 +01:00
Akim Demaille 98691fcd2d Merge branch 'maint'
* upstream/maint:
  doc: fix typo
  maint: post-release administrivia
  version 3.7.3
  build: don't link bison against libreadline
  gnulib: update
  glr.cc: fix: use symbol_name
  build: fix a concurrent build issue in examples
2020-10-14 21:12:45 +02:00
Akim Demaille 3cba59dd7f doc: fix typo
* README: here.
2020-10-14 21:12:04 +02:00
Akim Demaille a15879c623 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-10-13 07:23:28 +02:00
Akim Demaille 5d501ee728 version 3.7.3
* NEWS: Record release date.
2020-10-13 07:01:24 +02:00
Akim Demaille bc5e4541da build: don't link bison against libreadline
Reported by Paul Smith <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-10/msg00001.html

* src/local.mk (src_bison_LDADD): here.
2020-10-13 06:57:33 +02:00
Akim Demaille 567d1eaa19 gnulib: update 2020-10-13 06:46:06 +02:00
Akim Demaille 2347e959d4 doc: D comes before Java in alphabetical order
* doc/bison.texi: Keep languages sorted.
2020-10-07 06:29:24 +02:00
Akim Demaille 36143b5ecc report: put the dot after %empty in items
When printing items, it is clearer to put the dot after %emtpy rather
than before:

     0 $accept: . unit "end of file"
     1 unit: . assignments exp
-    2 assignments: . %empty
+    2 assignments: %empty .
     3            | . assignments assignment

Also, use the Unicode characters if they are supported.

* src/gram.c (item_print): Put the dot after %emtpy.
* tests/conflicts.at, tests/reduce.at, tests/report.at: Adjust.
2020-10-07 06:28:52 +02:00
Adela VaisandAkim Demaille 7cd195b30a d: change api.token.raw default value to true
Generate consecutive values for enum TokenKind, as D's yylex()
returns TokenKind and collisions can't happen.

* data/skeletons/d.m4: Change default value.
* tests/scanner.at, tests/d.at: Check it.
2020-10-03 17:17:32 +02:00
Akim Demaille e66673aa64 m4: have b4_percent_define_if_define apply default values lazily
Currently `b4_percent_define_ifdef([foo])` assigns a default value to
`foo` when invoked.  As a consequence, skeletons such as lalr1.d
cannot specify their specific default values: `foo` was defined in
bison.m4.

Instead, provide `foo` with a default value when `b4_foo_if` is
invoked.

I could not measure a runtime difference between both cases.

* data/skeletons/bison.m4 (_b4_percent_define_define): New.
Helps getting rid of spurious indentation that resulted in spurious
white space in the output.
(b4_percent_define_if_define): Move the definition to...
(_b4_percent_define_if_define): when the defined macros is called.
2020-10-03 09:17:53 +02:00
Adela VaisandAkim Demaille 3829bd6262 d: don't trigger GC in void toString
* data/skeletons/d.m4 (b4_declare_symbol_enum): Here.
2020-10-02 06:48:11 +02:00
Adela VaisandAkim Demaille 72360b51a5 d: document support
* doc/bison.texi: Various fixes.
(D Parsers): New section.
2020-10-02 06:46:32 +02:00
Adela VaisandAkim Demaille 4bbda69f1e d: remove the default prefix for SymbolKind's enum elements
This is not needed in D, since the kinds are "scoped".

* data/skeletons/d.m4: Remove the default prefix.
* doc/bison.text: Document it.
2020-10-02 06:46:32 +02:00
Adela VaisandAkim Demaille 4855b98554 d: remove the @property attribute from interface Lexer
D best practices is to not use it.

* data/skeletons/lalr1.d: Remove attribute.
2020-10-02 06:35:17 +02:00
Akim Demaille cd40ec9526 symbols: stop dealing with YYEMPTY as b4_symbol(-2, ...)
* data/skeletons/bison.m4 (b4_symbol): Redirect `b4_symbol(empty,
...)` to `b4_symbol(-2, ...)`.
Change all uses of the latter to the former.
2020-09-29 06:49:31 +02:00
Akim Demaille a7daa63cb7 tests: remove useless prefix for EOF in D
* tests/calc.at (CALC_EOF): Rename as...
(EOF): this.
Since there is no risk of a clash with #define EOF here...
2020-09-29 06:49:31 +02:00
Adela VaisandAkim Demaille 2e5592b3ab d: support api.symbol.prefix and api.token.prefix
The D skeleton was not properly supporting them.

* data/skeletons/d.m4, data/skeletons/lalr1.d: Fix it.
* tests/calc.at: Check it.
2020-09-28 19:27:19 +02:00
Akim Demaille 9b18cac96b multistart: start more thorough testing
* tests/local.at (AT_MULTISTART_IF): New.
* tests/calc.at: Adjust to check multiple start symbols.
* data/skeletons/yacc.c (yy_parse_impl): Fix.
2020-09-28 19:26:53 +02:00
Akim Demaille c19c1e7ec5 tests: style: reorder the calculator test macros
* tests/local.at (AT_TOKEN_TRANSLATE_IF): New, moved from...
* tests/calc.at: here.
Instead of sorting per feature (main, yylex, calc.y) and then by
language, do the converse, so that C bits are together, etc.
2020-09-27 19:29:29 +02:00
Akim Demaille 15cf0095d3 tests: shorten the generated file
* tests/synclines.at (_AT_SYNCLINES_COMPILE): Pull the comments out.
2020-09-27 19:29:29 +02:00
Akim Demaille 3ff7db34a2 gnulib: update 2020-09-27 11:58:28 +02:00
Akim Demaille d441a34791 multistart: also give access to yynerrs
This is something that has always bothered me: with pure parsers (and
they all should be) the user does not have an (easy) access to yynerrs
at the end of the parse.  In the case of error recovery, that's the
only direct means to know if there were errors.  The usual approach
being having the user maintain a counter incremented each time yyerror
is called.

So here, also capture yynerrs in the return value of the start-symbol
parsing functions.

* data/skeletons/yacc.c (yy_parse_impl_t): New.
(yy_parse_impl): Use it.
(b4_accept): Fill it.
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l: No longer
pass nerrs as lex- and parse-param, just use the resulting yynerrs.
bistromathic and reccalc both demonstrate %param.
2020-09-27 11:58:28 +02:00
Akim Demaille f4d33ff4b4 yacc.c: also count calls to YYERROR in yynerrs
* data/skeletons/yacc.c: here.
2020-09-27 11:58:27 +02:00
Akim Demaille 683040b324 multistart: allow tokens as start symbols
After all, why not?

* src/reader.c (switching_token): Use symbol_id_get.
(check_start_symbols): Require that the start symbol is a token only
if it's the only one.
* examples/c/lexcalc/parse.y: Let NUM be a start symbol.
2020-09-27 09:44:23 +02:00
Akim Demaille d9cf99b6a5 multistart: use b4_accept instead of action post-processing
For each start symbol, generate a parsing function with a richer
return value than the usual of yyparse.  Reserve a place for the
returned semantic value, in order to avoid having to pass a pointer as
argument to "return" that value.  This also makes the call to the
parsing function independent of whether a given start-symbol is typed.

For instance, if the grammar file contains:

    %type <int> expression
    %start input expression

(so "input" is valueless) we get

    typedef struct
    {
      int yystatus;
    } yyparse_input_t;

    yyparse_input_t yyparse_input (void);

    typedef struct
    {
      int yyvalue;
      int yystatus;
    } yyparse_expression_t;

    yyparse_expression_t yyparse_expression (void);

This commit also changes the implementation of the parser termination:
when there are multiple start symbols, it is the initial rules that
explicitly YYACCEPT.  They do that after having exported the
start-symbol's value (if it is typed):

  switch (yyn)
    {
  case 1: /* $accept: YY_EXPRESSION expression $end  */
  { ((*yyvalue).TOK_expression) = (yyvsp[-1].TOK_expression); YYACCEPT; }
    break;

  case 2: /* $accept: YY_INPUT input $end  */
  { YYACCEPT; }
    break;

I have tried several ways to deal with termination, and this is the
one that appears the best one to me.  It is also the most natural.

* src/scan-code.h, src/scan-code.l (obstack_for_actions): New.
* src/reader.c (grammar_rule_check_and_complete): Generate the actions
of the rules for each start symbol.

* data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics
than type and type_tag.
* data/skeletons/yacc.c (b4_accept): New.
Generates the body of the action of the start rules.
(_b4_declare_sub_yyparse): For each start symbol define a dedicated
return type for its parsing function.
Adjust the declaration of its parsing function.
(_b4_define_sub_yyparse): Adjust the definition of the function.

* examples/c/lexcalc/parse.y: Check the case of valueless symbols.
* examples/c/lexcalc/lexcalc.test: Check start symbols.
2020-09-27 09:44:18 +02:00
Akim Demaille a6805bb8d9 multistart: adjust reader checks for generated rules
So far we were not checking the generated rule 0 at all.  Now there
can be several of them.  Instead of not checking at all, let's be more
selective on the check to run on them.

* src/reader.c (grammar_rule_check_and_complete): Don't check for
value usage for generated rules, it is ok to have a valued start
symbol, in which case it is ok for the generated rule ("accept: start
$end {}") to not use $1.
(packgram): Call grammar_rule_check_and_complete for all the rules.
2020-09-27 09:23:51 +02:00
Akim Demaille a0b044186b todo: more 2020-09-27 09:23:51 +02:00
Akim Demaille 01af4ad9c3 multistart: toy with it in lexcalc
* examples/c/lexcalc/parse.y: Define several start symbols.
* examples/c/lexcalc/lexcalc.test: Check support.
2020-09-27 09:23:51 +02:00
Akim Demaille ed324578a2 multistart: equip yacc.c
* data/skeletons/yacc.c: Add support for multiple start symbols.
2020-09-27 09:23:51 +02:00
Akim Demaille 05d6b54703 multistart: pass the list of start symbols to the backend
* src/output.c (start_symbols_output): New.
(muscles_output): Use it.
2020-09-27 09:23:51 +02:00
Akim Demaille 78d0e5e671 multistart: also check the HTML report
We don't actually have checks for HTML, so let's do it for multistart.

* tests/report.at: here.
2020-09-27 09:23:51 +02:00
Akim Demaille 85ccc1bab3 multistart: adjust computation of initial core and adjust reports
Currently the core of the initial state is limited to the single rule
on $accept.

* src/lr0.c (generate_states): There may now be several rules on
$accept.

* src/graphviz.c (conclude_red): Recognize "final" transitions by the
fact that we reduce to "$accept".
* src/print.c (print_reduction): Likewise.
* src/print-xml.c (print_reduction): Likewise.
2020-09-27 09:23:51 +02:00
Akim Demaille 4646be7db4 regen 2020-09-27 09:23:51 +02:00
Akim Demaille 8eaddf326b multistart: turn start symbols into rules on $accept
Now that the parser can read several start symbols, let's process
them, and create the corresponding rules.

* src/parse-gram.y (grammar_declaration): Accept a list of start symbols.
* src/reader.h, src/reader.c (grammar_start_symbol_set): Rename as...
(grammar_start_symbols_set): this.

* src/reader.h, src/reader.c (start_flag): Replace with...
(start_symbols): this.
* src/reader.c (grammar_start_symbols_set): Build a list of start
symbols.
(switching_token, create_start_rules): New.
(check_and_convert_grammar): Use them to turn the list of start
symbols into a set of rules.
* src/reduce.c (nonterminals_reduce): Don't complain about $accept,
it's an internal detail.
(reduce_grammar): Complain about all the start symbols that don't
derive sentences.

* src/symtab.c (startsymbol, startsymbol_loc): Remove, replaced by
start_symbols.
symbols_pack): Move the check about the start symbols
to...
* src/symlist.c (check_start_symbols): here.
Adjust to multiple start symbols.
* tests/reduce.at (Empty Language): Generalize into...
(Bad start symbols): this.
2020-09-27 09:23:51 +02:00
Akim Demaille db68f61595 regen 2020-09-27 09:23:51 +02:00
Akim Demaille 7eca26e87b parser: expose a list of symbols
* src/parse-gram.y (%type): Also use current_class.
(symbol_decl.1): Rename as...
(symbols.1): this.
2020-09-27 09:23:51 +02:00
Akim Demaille e50ec28153 reader: get ready to create several initial rules
* src/reader.c (create_start_rule): New.
Use it.
2020-09-27 09:23:50 +02:00
Akim Demaille f7f2c99c28 gram: more debugging information
* src/gram.c (ritem_print): Show indices in ritem.
2020-09-27 09:23:50 +02:00
Akim Demaille c08e0863be glr.cc: fix: use symbol_name
* data/skeletons/glr.cc: here.
2020-09-27 09:22:02 +02:00
Akim Demaille f9b360663b glr2.cc: add an example
Currently this example crashes on input such as "T (x) + y;".
The same example with glr.c works properly.

* examples/c++/glr/Makefile, examples/c++/glr/README.md,
* examples/c++/glr/c++-types.test, examples/c++/glr/c++-types.yy,
* examples/c++/glr/local.mk, examples/c++/local.mk: New.
Based on examples/c/glr/c++-types.y.
2020-09-26 18:33:48 +02:00
Akim Demaille 3add9ffbde glr.cc: fix: use symbol_name
* data/skeletons/glr.cc: here.
2020-09-26 14:33:09 +02:00
Adela VaisandAkim Demaille f296669c0f d: change the return value of yylex from int to TokenKind
* data/skeletons/lalr1.d: Change the return value.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust.
* tests/scanner.at: Adjust.
* tests/calc.at (_AT_DATA_CALC_Y(d)): New, extracted from...
(_AT_DATA_CALC_Y(c)): here.
The two grammars have been sufficiently different to be separated.
Still trying to be them together results in a maintenance burden.  For
the same reason, instead of specifying the results for D and for the
rest, compute the expected results with D from the regular case.
2020-09-26 08:08:25 +02:00
Adela VaisandAkim Demaille de638df104 d: support api.parser.extends and api.parser.implements
The D skeleton was not properly supporting them.

* data/skeletons/d.m4: Fix it.
* tests/d.at: Check it.
* tests/local.mk, tests/testsuite.at: Adjust.
2020-09-24 09:29:45 +02:00
Akim Demaille 8dc60543c8 glr2.cc: also run all the calculator tests
This revealed issues with yy_symbol_print and yy_reduce_print.
These changes, in turn, reactivated GCC10 warnings:

    559. calc.at:1258: testing Calculator glr2.cc %locations %header parse.error=verbose %debug api.prefix={calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}  ...
    tests/calc.at:1258: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    tests/calc.at:1258: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    calc.cc: In function 'void glr_stack::yyresolveLocations(glr_state*, int)':
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:1177:10: error: potential null pointer dereference [-Werror=null-dereference]
     1177 |   return yypred ? &(asItem (this) - yypred)->getState () : YY_NULLPTR;
          |          ^~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

* tests/calc.at (AT_CHECK_CALC_GLR_CC): Also check glr2.cc.
* data/skeletons/glr2.cc: Don't pass the user arguments to
yy_symbol_print and yy_reduce_print, since they have it in the parser
object.
(b4_user_formals_no_comma, b4_pure_args, b4_lpure_args)
(b4_locuser_formals, b4_locuser_args): Remove, useless.
(YY_IGNORE_NULL_DEREFERENCE_BEGIN): Enable for GCC >= 10 too.
2020-09-21 06:43:10 +02:00
Akim Demaille f8cd049ecc tests: check the location of the right-hand side symbols
The D skeleton was not properly supporting @1 etc.
Reported by Adela Vais.
https://lists.gnu.org/r/bison-patches/2020-09/msg00049.html

* data/skeletons/d.m4 (b4_rhs_location): Fix it.
* tests/calc.at: Check the support of @n for all the skeletons.
2020-09-20 17:24:06 +02:00
Akim Demaille 72946549ed style: formatting changes
* src/scan-code.l: here.
2020-09-20 08:23:28 +02:00
Akim Demaille bad4fc09a7 style: introduce parse_positional_ref
* src/scan-code.l: here.
2020-09-20 08:23:28 +02:00
Akim Demaille aac79ca103 style: clarify the way state kernels (aka cores) are built
Use state_list_append in a more natural way.

* src/lr0.c (generate_states): Here.
2020-09-20 08:23:28 +02:00
Akim Demaille 843f99886c style: reorder and comment
* src/reader.h: here.
2020-09-20 08:23:28 +02:00
Akim Demaille 647453a614 examples: add a demonstration of GLR parsers in C
Based on the test case 668 (cxx-type.at:437) "GLR: Merge conflicting
parses, pure, locations".

* examples/c/glr/Makefile, examples/c/glr/README.md,
* examples/c/glr/c++-types.test, examples/c/glr/c++-types.y,
* examples/c/glr/local.mk: New.
2020-09-19 18:05:15 +02:00
Akim Demaille d4ffb69424 glr: support api.header.include
* data/skeletons/glr.c: here.
2020-09-19 17:50:28 +02:00
Akim Demaille 0711dca9d9 add support for --html
* bootstrap.conf: We need the "execute" module.
* src/files.h, src/files.c (spec_html_file, html_flag): New.
* src/getargs.h, src/getargs.c (--html): New.
* src/print-xml.h, src/print-xml.c (print_html): New.
* src/main.c: Use them.
* tests/output.at, tests/report.at: Check --html.
2020-09-19 17:49:03 +02:00
Akim Demaille f5d4b64909 regen 2020-09-19 17:49:03 +02: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
Akim Demaille 75c3746ce2 options: rename --defines as --header
The name "defines" is incorrect, the generated file contains far more
than just #defines.

* src/getargs.h, src/getargs.c (-H, --header): New option.
With optional argument, just like --defines, --xml, etc.
(defines_flag): Rename as...
(header_flag): this.
Adjust dependencies.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c:
Adjust.
* examples, doc/bison.texi: Adjust.
* tests/headers.at, tests/local.at, tests/output.at: Convert most
tests from using --defines to using --header.
2020-09-19 08:31:49 +02:00
Akim Demaille b329f0b5df CI: beware of time limits
* .travis.yml (GCC 8): Run only the part 1 of the tests.
2020-09-17 19:42:46 +02:00
Valentin TolmerandAkim Demaille 12a5cc07e0 glr2.cc: replace refs to parser::symbol_kind_type with yysymbol_kind_t
* data/skeletons/glr2.cc: here.
2020-09-17 19:37:05 +02:00
Valentin TolmerandAkim Demaille 27b5d92563 glr2.cc: fix container out-of-bounds access
Clang 10 with ASAN enabled reported errors in glr2.cc.

* data/skeletons/glr2.cc: here.
2020-09-17 19:35:47 +02:00
Akim Demaille 34476c449a glr2.cc: disable GCC 4.6 warning
231. conflicts.at:1096: testing Syntax error in consistent error state: glr2.cc ...
    tests/conflicts.at:1096: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:2674:36: error: 'yysval' may be used uninitialized in this function [-Werror=uninitialized]

Do not initialize the variable: this way ASAN can really make sure we
do set it to a proper value.
If we initialize it, ASAN would report nothing.

* data/skeletons/c.m4 (YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN): Disable
GCC 4.6's -Wuninitialized.
* data/skeletons/glr2.cc: Disable the warning locally.
2020-09-15 07:27:00 +02:00
Akim Demaille 795a59aba4 glr2.cc: fix warning with GCC 4.7 and 4.8
231. conflicts.at:1096: testing Syntax error in consistent error state: glr2.cc ...
    tests/conflicts.at:1096: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    input.cc: In function 'int yyparse(yy::parser&)':
    input.cc:3147:41: error: 'yyarg' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         return yytnamerr_ (yytname_[yysymbol]);
                                             ^
    input.cc:2058:34: note: 'yyarg' was declared here
         yy::parser::symbol_kind_type yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
                                      ^

* data/skeletons/glr2.cc (yyreportSyntaxError): Initialize yyarg.
2020-09-14 19:53:01 +02:00
Akim Demaille 243fa94ce2 glr2.cc: simplify symbol kinds
We emit code like

    if (yytoken != yy::parser::symbol_kind::symbol_kind::S_YYEMPTY)

* data/skeletons/glr2.cc: Use b4_symbol correctly.
2020-09-14 19:30:48 +02:00
Akim Demaille 11995fec50 glr2.cc: fix warning about local variable vs. member
Fix a warning triggered in GCC (at least from 4.6 to 4.9):

    input.cc: In constructor 'glr_stack_item::glr_stack_item(bool)':
    input.cc:1371:5: error: declaration of 'is_state' shadows a member of 'this' [-Werror=shadow]
         : is_state_(is_state)
         ^

* data/skeletons/glr2.cc (glr_stack_item): Alpha-convert.
2020-09-14 06:34:07 +02:00
Akim Demaille c654eb481c c++: variants: minor simplification
Do as Valentin Tolmer did in glr2.cc.

* data/skeletons/variant.hh: The union does not need to be named.
2020-09-13 13:47:25 +02:00
Akim Demaille 5c37f5994d glr2.cc: avoid type-punning issues
On the CI, tests fail with GCC 4.6 to GCC 6 as follows:

    tests/synclines.at:440: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o \"\\\"\".cc \"\\\"\".y
    tests/synclines.at:440: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o \"\\\"\" \"\\\"\".cc $LIBS
    stderr:
    "\"".cc: In member function 'glr_state& glr_stack_item::getState()':
    "\"".cc:1404:47: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<glr_state*>(&raw_);
                                                   ^
    "\"".cc: In member function 'const glr_state& glr_stack_item::getState() const':
    "\"".cc:1408:53: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<const glr_state*>(&raw_);
                                                         ^
    "\"".cc: In member function 'semantic_option& glr_stack_item::getOption()':
    "\"".cc:1413:53: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<semantic_option*>(&raw_);
                                                         ^
    "\"".cc: In member function 'const semantic_option& glr_stack_item::getOption() const':
    "\"".cc:1417:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<const semantic_option*>(&raw_);
                                                           ^

See also be6fa942ac.

* data/skeletons/glr2.cc (glr_stack_item): Use a temporary void*
variable to avoid type-punning issues with reinterpret_cast.
2020-09-13 13:45:17 +02:00
Akim Demaille 952a61b62e glr.cc, glr2.cc: don't publish compiler pragmas
Currently the compiler attributes are defined in
b4_shared_declarations (that can in the header if it exists, otherwise
in the implementation file).  This is not needed, only the
implementation file needs them.

Besides, glr2.cc was also defining these macros in the implementation
file, so we had two definitions.

* data/skeletons/glr.cc, data/skeletons/glr2.cc: Define the compiler
attribute macros only in the implementation files.
* tests/regression.at (Lex and parse params): Generate a header, to
make it easy to check that the header is self-sufficient.
2020-09-13 12:23:13 +02:00
Akim Demaille cf8f805d36 glr2.cc: disable incorrect warnings from GCC6 to 9
For instance with GCC8:

    616. regression.at:1560: testing Lex and parse params: glr2.cc ...
    tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o input.cc input.y
    tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    stderr:
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
       return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
              ^~~~~~
    input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
       return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
              ^~~~~~
    cc1plus: all warnings being treated as errors

It complains that the implicit this in yypred might be null.  It fears
it because of loops such as

    for (glr_state* yys = firstTopState();
         yys != yystateStack.yysplitPoint;
         yys = yys->pred())
      yyn += 1;

that could possibly set yys to null, since yys->pred might return
null.  However, the warning is incorrect, since in C++ `this` cannot
be null.  GCC 10 no longer emits this warning.

GCC 7 also complains many times about glr_stack::yyresolveLocations
when NDEBUG is enabled (when it is not, YYASSERT (yyoption !=
YY_NULLPTR) is probably enough to pacify GCC):

    616. regression.at:1560: testing Lex and parse params: glr2.cc ...
    tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o input.cc input.y
    tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    stderr:
    input.cc: In member function 'void glr_stack::yyresolveLocations(glr_state*, int)':
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

* data/skeletons/glr2.cc (YY_IGNORE_NULL_DEREFERENCE_BEGIN)
(YY_IGNORE_NULL_DEREFERENCE_BEGIN): New.
(glr_state::pred, glr_stack::yyresolveLocations): Use them.
2020-09-13 12:08:28 +02:00
Adela VaisandAkim Demaille 2bc886dc02 d: make enum SymbolKind idiomatic D
Taking into account comments from H. S. Teoh.
https://lists.gnu.org/r/bison-patches/2020-09/msg00021.html

* data/skeletons/d.m4, data/skeletons/lalr1.d (SymbolKind): Wrap the
enum in a structure that contains its string representation.
2020-09-12 17:09:32 +02:00
Akim Demaille b5e6d9c4ca glr2.cc: address warnings with G++ 4.8
input.cc: In constructor 'glr_stack_item::glr_stack_item(bool)':
input.cc:1423:5: error: declaration of 'isState' shadows a member of 'this' [-Werror=shadow]
     : isState_(isState) {
     ^
test.cc:1165:45: error: declaration of 'begin' shadows a member of 'this' [-Werror=shadow]
test.cc:1167:45: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

* data/skeletons/glr2.cc (isState): Rename as...
(is_state): this.
Formatting changes.
(reduceToOneStack): Rename variables to avoid name clashes.
2020-09-12 15:23:19 +02:00
Akim Demaille 3ae2a22a05 glr2.cc: get rid of the C indirection for yy_symbol_print
* data/skeletons/glr2.cc (yy_symbol_print): Remove.
Just use yyparser.yy_symbol_print_ directly.
2020-09-12 14:49:05 +02:00
Akim Demaille 146a8eb101 glr2.cc: formatting changes
* data/skeletons/glr2.cc: here.
2020-09-12 14:44:29 +02:00
Akim Demaille 4428e8e8b3 glr2.cc: fix GCC10 warning
For instance on test 433: "glr2.cc api.value.type={double}"

    tests/types.at:138: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    In file included from /opt/local/include/gcc10/c++/bits/stl_tempbuf.h:60,
                     from /opt/local/include/gcc10/c++/bits/stl_algo.h:62,
                     from /opt/local/include/gcc10/c++/algorithm:62,
                     from test.cc:82:
    /opt/local/include/gcc10/c++/bits/stl_construct.h: In instantiation of 'constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = glr_stack_item; _Args = {glr_stack_item}; decltype (::new(void*(0)) _Tp) = glr_stack_item*]':
    /opt/local/include/gcc10/c++/bits/alloc_traits.h:514:21:   required from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = glr_stack_item; _Args = {glr_stack_item}; _Tp = glr_stack_item; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<glr_stack_item>]'
    /opt/local/include/gcc10/c++/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {glr_stack_item}; _Tp = glr_stack_item; _Alloc = std::allocator<glr_stack_item>; std::vector<_Tp, _Alloc>::reference = glr_stack_item&]'
    /opt/local/include/gcc10/c++/bits/stl_vector.h:1204:21:   required from 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = glr_stack_item; _Alloc = std::allocator<glr_stack_item>; std::vector<_Tp, _Alloc>::value_type = glr_stack_item]'
    test.cc:1949:48:   required from here
    /opt/local/include/gcc10/c++/bits/stl_construct.h:95:14: error: noexcept-expression evaluates to 'false' because of a call to 'glr_stack_item::glr_stack_item(const glr_stack_item&)' [-Werror=noexcept]
       95 |     noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...)))
          |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    test.cc:1436:3: note: but 'glr_stack_item::glr_stack_item(const glr_stack_item&)' does not throw; perhaps it should be declared 'noexcept'
     1436 |   glr_stack_item(const glr_stack_item& other)
          |   ^~~~~~~~~~~~~~
    cc1plus: all warnings being treated as errors
    stdout:
    tests/types.at:138: exit code was 1, expected 0
    433. types.at:138: 433. glr2.cc api.value.type={double} (types.at:138): FAILED (types.at:138)

* data/skeletons/glr2.cc (glr_stack_item): Use YY_NOEXCEPT/YY_NOTHROW.
2020-09-12 14:44:27 +02:00
Valentin TolmerandAkim Demaille 00e47b11d2 glr2.cc: coding style changes
* data/skeletons/glr2.cc: Change some CamlCase to snake_case, and
remove some yy prefixes for classes inside the namespace.
2020-09-12 14:11:58 +02:00
Valentin TolmerandAkim Demaille cf8723de0d glr2.cc: move StrongIndexAlias into the namespace
* data/skeletons/glr2.cc: here.
2020-09-12 14:11:40 +02:00
Valentin TolmerandAkim Demaille 8bfc319f8e glr2.cc: remove usage of PTRDIFF_MAX
* data/skeletons/glr2.cc: Use std::ptrdiff_t and numeric_limits.
2020-09-12 14:11:00 +02:00
Valentin TolmerandAkim Demaille 1c5b05ad31 glr2.cc: remove C-style casts
* data/skeletons/glr2.cc: here.
2020-09-12 14:10:21 +02:00
Valentin TolmerandAkim Demaille b7e2cac2aa glr2.cc: add copy constructor to yyGLRStackItem
This silences the clang warning -Wdeprecated-copy.

* data/skeletons/glr2.cc: here.
2020-09-12 14:10:02 +02:00
Akim Demaille 93d6a5ba4d examples: d: remove unused token
* examples/d/calc/calc.y, examples/d/simple/calc.y: Remove "=".
2020-09-07 06:46:50 +02:00
Akim Demaille 5d711972b8 Merge branch 'maint' (i.e., Bison 3.7.2)
* upstream/maint:
  maint: post-release administrivia
  version 3.7.2
  build: disable syntax-check warning
  gnulib: update
  build: fix incorrect dependencies
  doc: updates
  gnulib: update
  tests: beware of sed portability issues
2020-09-06 13:19:03 +02:00
Akim Demaille 541943ee04 build: fix a concurrent build issue in examples
Reported by Thomas Deutschmann <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00010.html

* examples/c/lexcalc/local.mk: scan.o depends on parse.[ch].
2020-09-06 10:08:22 +02:00
Akim Demaille dcdd119f69 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-09-05 18:31:25 +02:00
Akim Demaille a0bc06b703 version 3.7.2
* NEWS: Record release date.
2020-09-05 18:06:16 +02:00
Akim Demaille 5e33dfe59d build: disable syntax-check warning
error_message_uppercase
etc/bench.pl.in-419-static int yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]});

* cfg.mk: here.
2020-09-05 17:59:56 +02:00
Akim Demaille 2a4e9a358f gnulib: update 2020-09-05 17:44:38 +02:00
Akim Demaille f7b642cff7 build: fix incorrect dependencies
Commit af000bab11 ("doc: work around
Texinfo 6.7 bug"), published in 3.4.91, added a dependency on the
"all" target.

This is a super bad idea, since "make all" will run this
target *before* "all", which builds bison.  It turns out that this new
dependency actually needed bison to be built.  So all the regular
process (i) build $(BUILT_SOURCES) and then (ii) build bison, was
wrecked since some of the $(BUILT_SOURCES) depended on bison...

It was "easy" to see in the logs of "make V=1" because we were
building bison files (such as src/files.o) *before* displaying the
banner for "all-recursive".  With this fix, we finally get again the
proper sequence:

    rm -f examples/c/reccalc/scan.stamp examples/c/reccalc/scan.stamp.tmp
    /opt/local/libexec/gnubin/mkdir -p examples/c/reccalc
    touch examples/c/reccalc/scan.stamp.tmp
    flex   -oexamples/c/reccalc/scan.c --header=examples/c/reccalc/scan.h ./examples/c/reccalc/scan.l
    mv examples/c/reccalc/scan.stamp.tmp examples/c/reccalc/scan.stamp
    rm -f lib/fcntl.h-t lib/fcntl.h && \
    { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
      ...
    } > lib/fcntl.h-t && \
    mv lib/fcntl.h-t lib/fcntl.h
    ...
    mv -f lib/alloca.h-t lib/alloca.h
    make  all-recursive

Reported by Mingli Yu <[email protected]>.
https://github.com/akimd/bison/issues/31
https://lists.gnu.org/r/bison-patches/2020-05/msg00055.html

Reported by Claudio Calvelli <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00001.html
https://bugs.gentoo.org/716516

* doc/local.mk (all): Rename as...
(all-local): this.
So that we don't compete with BUILT_SOURCES.
2020-09-05 17:42:20 +02:00
Akim Demaille 0d8407440c doc: simplify the extraction of example snippets
* doc/bison.texi: Use qualified paths.
* examples/extexi: Comment changes.
2020-09-05 09:19:39 +02:00
Akim Demaille 1df4b746da glr2.cc: style changes
* data/skeletons/glr2.cc: Remove stray comment.
2020-09-05 07:47:21 +02:00
Akim Demaille f3f7f6e1dc glr2.cc: get rid of the yyerror scaffolding
The yyerror stand-alone function was used to bounce from glr.c's call
to yyerror to glr.cc's parser.error.  Now that glr.c is out of the
way, just directly use parser.error.

* data/skeletons/glr2.cc (yyerror): Remove.
Adjust callers.
(b4_yyerror_args, b4_lyyerror_args, b4_pure_formals): Remove.
Now unused.
2020-09-05 07:44:23 +02:00
Valentin TolmerandAkim Demaille 38abe1e1b7 glr2.cc: avoid warnings about printf and shadowing
* data/skeletons/glr2.cc: Migrate from using printf to std::cerr & co.
Since the yyGLRStack has the user params, no need to pass them around.
2020-09-04 06:47:10 +02:00
Adela VaisandAkim Demaille 6e1d83c8a8 examples: d: demonstrate location tracking
* examples/d/calc/calc.y: Track locations.
* examples/d/calc/calc.test: Check locations.
2020-09-03 08:44:42 +02:00
Adela VaisandAkim Demaille 8032dde383 examples: d: duplicate the example as "simple" and "calc"
* examples/d/Makefile, examples/d/calc.d, examples/d/calc.test,
examples/d/calc/local.mk: Move into...
* examples/d/calc, examples/d/simple: these new directories.
2020-09-03 08:20:41 +02:00
Akim Demaille 3da17724ad doc: updates
* NEWS, TODO: here.
2020-09-02 21:37:23 +02:00
Adela VaisandAkim Demaille f3bcb3de0e examples: d: fix the handling of unary +
It was interpreting "+exp" as "-exp".

* examples/d/calc.y: Fix.
* examples/d/calc.test: Check it.
2020-09-02 07:38:42 +02:00
Akim Demaille 325ec7d324 cex: always show ε/%empty in counterexamples
On a case such as
    %%
    exp
    : empty "a"
    | "a" empty

    empty
    : %empty

we used to display

    warning: shift/reduce conflict on token "a" [-Wcounterexamples]
    Example: • "a"
    Shift derivation
      exp
      ↳ 2: • "a" empty
                 ↳ 2: ε
    Example: • "a"
    Reduce derivation
      exp
      ↳ 1: empty  "a"
           ↳ 3: •

where the shift derivation shows an item "2: empty → ε", with an
explicit "ε", but the reduce derivation shows "3: empty → •", without
"ε".

For consistency, let's always show ε/%empty in rules with an empty
rhs:

    Reduce derivation
      exp
      ↳ 1: empty    "a"
           ↳ 3: ε •

* src/derivation.c (derivation_width, derivation_print_tree_impl):
Always show ε/%empty in counterexamples.
* tests/diagnostics.at: Check that case.
* tests/conflicts.at, tests/counterexample.at: Adjust.
2020-09-02 07:31:55 +02:00
Akim Demaille 82d913741b glr2.cc: avoid warnings about long long
* data/skeletons/glr2.cc: Disable the warning before triggering it.
2020-08-30 20:05:34 +02:00
Akim Demaille 3c36d871fa cex: display the rule numbers
From

    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Shift derivation
      if_stmt
      ↳ "if" expr "then" stmt
                         ↳ if_stmt
                           ↳ "if" expr "then" stmt • "else" stmt
    Reduce derivation
      if_stmt
      ↳ "if" expr "then" stmt                        "else" stmt
                         ↳ if_stmt
                           ↳ "if" expr "then" stmt •

to

    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Shift derivation
      if_stmt
      ↳ 3: "if" expr "then" stmt
                            ↳ 2: if_stmt
                                 ↳ 4: "if" expr "then" stmt • "else" stmt
    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Reduce derivation
      if_stmt
      ↳ 4: "if" expr "then" stmt                              "else" stmt
                            ↳ 2: if_stmt
                                 ↳ 3: "if" expr "then" stmt •

* src/state-item.h, src/state-item.c (state_item_rule): New.
* src/derivation.h, src/derivation.c (struct derivation): Add a rule
member.
Adjust dependencies.
* src/counterexample.c, src/parse-simulation.c: Pass the rule to
derivation_new.
* src/derivation.c (fprintf_if): New.
(derivation_width, derivation_print_tree_impl): Take the rule number
into account.

* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.

* doc/bison.texi: Adjust.
2020-08-30 19:20:49 +02:00
Akim Demaille 2becdace96 gnulib: update 2020-08-30 18:34:35 +02:00
Akim Demaille 115a947f08 tests: beware of sed portability issues
Reported by David Laxer <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00027.html

* tests/output.at: Don't use + with sed.
While at it, fix a quotation problem hidden by the use of '#'.
2020-08-30 18:34:35 +02:00
Akim Demaille 68e3e442f9 gnulib: update 2020-08-30 17:32:43 +02:00
Akim Demaille e432619d11 tests: beware of sed portability issues
Reported by David Laxer <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00027.html

* tests/output.at: Don't use + with sed.
While at it, fix a quotation problem hidden by the use of '#'.
2020-08-30 17:16:18 +02:00
Akim Demaille b63e3a3352 glr2.cc: fix a few warnings
* data/skeletons/glr2.cc: Fix some documentation.
Be consistent between class/struct.
(yydoAction, yyresolveAction): Avoid passing yyparser where useless.
2020-08-30 12:58:27 +02:00
Valentin TolmerandAkim Demaille 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 a1b7fef045 c: always use YYMALLOC/YYFREE
Reported by Kovalex <[email protected]>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00015.html

* data/skeletons/yacc.c: Don't make direct calls to malloc/free.
* tests/calc.at: Check it.
2020-08-30 10:05:18 +02:00
Akim Demaille 067e35a8be build: beware of POSIX mode
Reported by Dennis Clarke.
https://lists.gnu.org/r/bug-bison/2020-08/msg00013.html

* examples/d/local.mk, examples/java/calc/local.mk,
* examples/java/simple/local.mk: Pass bison's options before its
argument, in case we're in POSIX mode.
2020-08-30 09:38:05 +02:00
Akim Demaille 0522047c96 doc: history of api.prefix
Reported by Matthew Fernandez <[email protected]>.
https://lists.gnu.org/r/help-bison/2020-08/msg00015.html

* doc/bison.texi (api.prefix): We move to {} in 3.0.
2020-08-30 09:29:00 +02:00
Akim Demaille 3724b50ef9 CI: intel moved the script for ICC
* .travis.yml: Adjust.
2020-08-11 07:18:48 +02:00
Akim Demaille b801b7b670 fix: unterminated \-escape
An assertion failed when the last character is a '\' and we're in a
character or a string.
Reported by Agency for Defense Development.
https://lists.gnu.org/r/bug-bison/2020-08/msg00009.html

* src/scan-gram.l: Catch unterminated escapes.
* tests/input.at (Unexpected end of file): New.
2020-08-08 07:53:33 +02:00
Akim Demaille b7aab2dbad fix: crash when redefining the EOF token
Reported by Agency for Defense Development.
https://lists.gnu.org/r/bug-bison/2020-08/msg00008.html

On an empty such as

    %token FOO
           BAR
           FOO 0
    %%
    input: %empty

we crash because when we find FOO 0, we decrement ntokens (since FOO
was discovered to be EOF, which is already known to be a token, so we
increment ntokens for it, and need to cancel this).  This "works well"
when EOF is properly defined in one go, but here it is first defined
and later only assign token code 0.  In the meanwhile BAR was given
the token number that we just decremented.

To fix this, assign symbol numbers after parsing, not during parsing,
so that we also saw all the explicit token codes.  To maintain the
current numbers (I'd like to keep no difference in the output, not
just equivalence), we need to make sure the symbols are numbered in
the same order: that of appearance in the source file.  So we need the
locations to be correct, which was almost the case, except for nterms
that appeared several times as LHS (i.e., several times as "foo:
...").  Fixing the use of location_of_lhs sufficed (it appears it was
intended for this use, but its implementation was unfinished: it was
always set to "false" only).

* src/symtab.c (symbol_location_as_lhs_set): Update location_of_lhs.
(symbol_code_set): Remove broken hack that decremented ntokens.
(symbol_class_set, dummy_symbol_get): Don't set number, ntokens and
nnterms.
(symbol_check_defined): Do it.
(symbols): Don't count nsyms here.
Actually, don't count nsyms at all: let it be done in...
* src/reader.c (check_and_convert_grammar): here.  Define nsyms from
ntokens and nnterms after parsing.
* tests/input.at (EOF redeclared): New.

* examples/c/bistromathic/bistromathic.test: Adjust the traces: in
"%nterm <double> exp %% input: ...", exp used to be numbered before
input.
2020-08-07 07:30:06 +02:00
Akim Demaille 89e42ffb4b style: fix missing space before paren
* cfg.mk (_space_before_paren_exempt): Be less laxist.
* src/output.c, src/reader.c: Fix space before paren issues.
Pacify the warnings where applicable.
2020-08-07 07:30:06 +02:00
Akim Demaille 6aae4a7378 style: fix comments and more debug trace
* src/location.c, src/symtab.h, src/symtab.c: here.
2020-08-07 07:30:06 +02:00
Akim Demaille 7d4a4300c2 style: more uses of const
* src/symtab.c: here.
2020-08-07 07:30:06 +02:00
Akim Demaille 31d4ec28bd bench: fix support for pure parser
* etc/bench.pl.in (is_pure): New.
(generate_grammar_calc): Use code provides where needed.
Use is_pure to call yylex properly.
Coding style fixes.
2020-08-07 07:29:16 +02:00
Akim Demaille 0a5bfb4fda portability: multiple typedefs
Older versions of GCC (4.1.2 here) don't like repeated typedefs.

      CC       src/bison-parse-simulation.o
    src/parse-simulation.c:61: error: redefinition of typedef 'parse_state'
    src/parse-simulation.h:74: error: previous declaration of 'parse_state' was here
    make: *** [Makefile:7876: src/bison-parse-simulation.o] Error 1

Reported by Nelson H. F. Beebe.

* src/parse-simulation.c (parse_state): Don't typedef,
parse-simulation.h did it already.
2020-08-03 07:30:35 +02:00
Akim Demaille 12d0b15679 style: revert "avoid warnings with GCC 4.6"
This reverts commit d0bec3175f (which
should have read "We have a clash...", not "With have a clash...").
Now that `max()` was renamed `max_int()`, we can use `max` again, as
elsewhere in the code.

* src/counterexample.c (visited_hasher): Alpha reconversion.
2020-08-02 10:20:23 +02:00
Akim Demaille cb7dcb011e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-08-02 09:32:34 +02:00
Akim Demaille 71579c7219 version 3.7.1
* NEWS: Record release date.
2020-08-02 09:10:02 +02:00
Akim Demaille 2f8a874215 portability: we use termios.h and sys/ioctl.h
Reported by Maarten De Braekeleer.
https://lists.gnu.org/r/bison-patches/2020-07/msg00079.html

* bootstrap.conf (gnulib_modules): Add termios and sys_ioctl.
2020-08-02 08:36:49 +02:00
Maarten De BraekeleerandAkim Demaille ad6f600bb1 portability: rename accept to acceptsymbol because of MSVC
MSVC already defines this symbol.

* src/symtab.h, src/symtab.c (accept): Rename as...
(acceptsymbol): this.
Adjust dependencies.
2020-08-02 08:32:57 +02:00
Akim Demaille de4f41eab7 regen 2020-08-02 08:32:57 +02:00
Maarten De BraekeleerandAkim Demaille e73f086b0d portability: use CHAR_LITERAL instead of CHAR because MSVC defines CHAR
* src/parse-gram.y, src/scan-gram.l: here.
2020-08-02 08:32:57 +02:00
Maarten De BraekeleerandAkim Demaille 8cf098415e portability: use INT_LITERAL instead of INT because MSVC defines INT
It is defined as a typedef, not a macro.
https://lists.gnu.org/r/bison-patches/2020-08/msg00001.html

* src/parse-gram.y, src/scan-gram.l: here.
2020-08-02 08:32:30 +02:00
Akim Demaille 977e19840d portability: beware of max () with MSVC
Reported by Maarten De Braekeleer.
https://lists.gnu.org/r/bison-patches/2020-07/msg00080.html

We don't want to use gnulib's min and max macros, since we use
function calls in min/max arguments.

* src/location.c (max_int, min_int): Move to...
* src/system.h: here.
* src/counterexample.c, src/derivation.c: Use max_int instead of max.
2020-08-02 08:19:35 +02:00
Akim Demaille d975c2f76e libtextstyle: be sure to have ostream_printf and hyperlink support
Older versions of libtextstyle do not support them, rule them out.

Reported by Lars Wendler
https://lists.gnu.org/r/bug-bison/2020-07/msg00030.html

and by Arnold Robbins
https://lists.gnu.org/r/bug-bison/2020-07/msg00041.html and
https://lists.gnu.org/mailman/private/gawk-devel/2020-July/003988.html

and by Nelson H. F. Beebe
https://lists.gnu.org/mailman/private/gawk-devel/2020-July/003993.html

With support from Bruno Haible in gnulib
https://lists.gnu.org/r/bug-gnulib/2020-08/msg00000.html
thread starting at
https://lists.gnu.org/r/bug-gnulib/2020-07/msg00148.html

* configure.ac: Require libtextstyle 0.20.5.
* gnulib: Update.
2020-08-02 08:19:35 +02:00
Akim Demaille 0676801b8c CI: comment changes 2020-08-01 10:02:44 +02:00
Akim Demaille 82aa96e9b1 regen 2020-08-01 08:54:46 +02:00
Akim Demaille cb65553449 diagnostics: better location for type redeclarations
From

    foo.y:1.7-11: error: %type redeclaration for bar
        1 | %type <foo> bar bar
          |       ^~~~~
    foo.y:1.7-11: note: previous declaration
        1 | %type <foo> bar bar
          |       ^~~~~

to

    foo.y:1.17-19: error: %type redeclaration for bar
        1 | %type <foo> bar bar
          |                 ^~~
    foo.y:1.13-15: note: previous declaration
        1 | %type <foo> bar bar
          |             ^~~

* src/symlist.h, src/symlist.c (symbol_list_type_set): There's no need
for the tag's location, use that of the symbol.
* src/parse-gram.y: Adjust.
* tests/input.at: Adjust.
2020-08-01 08:54:46 +02:00
Akim Demaille f47a1bd622 todo: updates for D 2020-07-30 07:14:57 +02:00
Akim Demaille 205d372c68 cex: style: comment changes
* src/parse-simulation.c: here.
2020-07-29 20:00:59 +02:00
Akim Demaille 07a1243b40 cex: style: prefer "res" for the returned value
* src/derivation.c (derivation_new): here.
2020-07-29 20:00:59 +02:00
Akim Demaille ece343d2c2 cex: style: prefer FOO_print to print_FOO
* src/state-item.h, src/state-item.c (print_state_item): Rename as...
(state_item_print): this.
* src/counterexample.c (print_counterexample): Rename as...
(counterexample_print): this.
2020-07-29 20:00:27 +02:00
Akim Demaille be95a4fe29 scanner: don't crash on strings containing a NUL byte
We crash if the input contains a string containing a NUL byte.
Reported by Suhwan Song.
https://lists.gnu.org/r/bug-bison/2020-07/msg00051.html

* src/flex-scanner.h (STRING_FREE): Avoid accidental use of
last_string.
* src/scan-gram.l: Don't call STRING_FREE without calling
STRING_FINISH first.
* tests/input.at (Invalid inputs): Check that case.
2020-07-28 19:01:48 +02:00
Akim Demaille 6accee7716 doc: refer to cex from sections dealing with conflicts
The documentation about -Wcex should be put forward.

* doc/bison.texi: Refer to -Wcex from the sections about conflicts.
2020-07-28 07:45:07 +02:00
Akim Demaille e63f22703e doc: factor ifnottex/iftex examples
* doc/bison.texi: Factor the common bits out of ifnottex/iftex.
2020-07-28 07:45:07 +02:00
Akim Demaille fa390dc311 doc: fix colors
The original Texinfo macros introducing colors were made for
diagnostics, which are printed in bold.  So by copy-paste accident the
styles we introduced for counterexamples were also in bold.  They
should not.

* doc/bison.texi: Separate the styling of diagnostics from the styling
for counterexamples.
Don't use bold in the latter case.
2020-07-28 07:45:07 +02:00
Akim Demaille 17fdf5eca2 doc: fixes
* doc/bison.texi: Fix spello.
Fix missing colors, and factor.
2020-07-28 07:45:07 +02:00
Akim Demaille 72b3c1a673 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-23 20:15:38 +02:00
Akim Demaille 6675d36e25 version 3.7
* NEWS: Record release date.
2020-07-23 19:58:16 +02:00
Akim Demaille d0bec3175f style: avoid warnings with GCC 4.6
With have a clash with the "max" function.

    src/counterexample.c: In function 'visited_hasher':
    src/counterexample.c:720:48: error: declaration of 'max' shadows a global declaration [-Werror=shadow]
    src/counterexample.c:116:12: error: shadowed declaration is here [-Werror=shadow]

* src/counterexample.c (visited_hasher): Alpha conversion.
2020-07-23 19:55:24 +02:00
Akim Demaille 79e68b6c4d doc: fix definition of -Wall
* doc/bison.texi (Diagnostics): here.
2020-07-23 09:17:18 +02:00
Akim Demaille 5cb74cacd8 gnulib: update
* bootstrap.conf: We need stpncpy.
2020-07-23 06:56:25 +02:00
Akim Demaille 9c8e6e05b6 tests: fixes
Fix 6b78e50cef, "cex: make "rerun with
'-Wcex'" a note instead of a warning"

* tests/conflicts.at (-W versus %expect and %expect-rr): Fix
expectations.
2020-07-23 06:33:30 +02:00
Akim Demaille 431774d1f6 cex: update NEWS for 3.7
* NEWS: Update to the current style of cex display.
2020-07-22 07:36:02 +02:00
Akim Demaille 7d5474e979 doc: catch up with the current display of cex
Unfortunately I found no way to use the ↳ glyph in Texinfo, so I used
@arrow{} instead, which has a different width, so we have to have all
the examples doubled, once for TeX, another for the rest of the world.

* doc/bison.texi: Use the current display in the examples.
* doc/calc.y, doc/ids.y, doc/if-then-else.y, doc/sequence.y: New.
2020-07-22 07:36:02 +02:00
Akim Demaille 6b78e50cef cex: make "rerun with '-Wcex'" a note instead of a warning
Currently the suggestion to rerun is a -Wother warning:

    warning: 2 shift/reduce conflicts [-Wconflicts-sr]
    warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]

Instead, let's attach it as a subnote of the diagnostic (in the
current case, -Wconflicts-sr):

    warning: 2 shift/reduce conflicts [-Wconflicts-sr]
    note: rerun with option '-Wcounterexamples' to generate conflict counterexamples

* src/conflicts.c (conflicts_print): Do that.
Adjust the test suite.
2020-07-21 18:57:56 +02:00
Akim Demaille 28769d608e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-20 07:58:03 +02:00
Akim Demaille a22588bcb9 version 3.6.93
* NEWS: Record release date.
2020-07-20 07:37:47 +02:00
Akim Demaille b8c5e5609f cex: label all the derivations by their initial action
From

    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example: A b .
      First derivation
        a
        `-> A b .
      Second derivation
        a
        `-> A b
              `-> b .

to

    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example: A b .
      First reduce derivation
        a
        `-> A b .
      Second reduce derivation
        a
        `-> A b
              `-> b .

* src/counterexample.c (print_counterexample): here.
Compute the width of the labels to properly align the values.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-20 07:36:38 +02:00
Akim Demaille b81229e1f9 cex: improve readability of the subsections
Now that the derivation is no longer printed on one line, aligning the
example and the derivation is no longer useful.  It can actually be
harmful, as it makes the overall structure less clear.

* src/derivation.h, src/derivation.c (derivation_print_leaves): Remove
the `prefix` argument.
* src/counterexample.c (print_counterexample): Put the example next to
its label.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-20 07:09:31 +02:00
Akim Demaille 815a76f558 cex: don't issue an empty line between counterexamples
Now that we use complain, the "sections" are clearer.

* src/counterexample.c (print_counterexample): Use the empty line only
in reports.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust.
2020-07-20 06:45:31 +02:00
Akim Demaille ea138cd1f1 cex: use usual routines for diagnostics about S/R conflicts
See previous commit.  We go from

    input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
    Shift/reduce conflict on token "⊕":
      Example              exp "+" exp • "⊕" exp
      Shift derivation
        exp
        ↳ exp "+" exp
                  ↳ exp • "⊕" exp

to

    input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr]
    input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples]
      Example              exp "+" exp • "⊕" exp
      Shift derivation
        exp
        ↳ exp "+" exp
                  ↳ exp • "⊕" exp

with an hyperlink on -Wcounterexamples.

* src/counterexample.c (counterexample_report_shift_reduce):
Use complain.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at:
Adjust.
2020-07-20 06:45:27 +02:00
Akim Demaille 9922f1f877 cex: use usual routines for diagnostics about R/R conflicts
This is more consistent, and brings benefits: users know that these
diagnostics are attached to -Wcounterexamples, and they can also click
on the hyperlink if permitted by their terminal.

We go from

    warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    Reduce/reduce conflict on token $end:
      Example              A b .
      First derivation     a -> [ A b . ]
      Second derivation    a -> [ A b -> [ b . ] ]

to

    warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example              A b .
      First derivation     a -> [ A b . ]
      Second derivation    a -> [ A b -> [ b . ] ]

with an hyperlink on -Wcounterexamples.

* src/counterexample.c (counterexample_report_reduce_reduce):
Use complain.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at:
Adjust.
2020-07-20 06:45:21 +02:00
Akim Demaille 1438b79e80 diagnostics: use hyperlinks to point to the only documentation
* src/complain.c (begin_hyperlink, end_hyperlink): New.
(warnings_print_categories): Use them.
* tests/local.at (AT_SET_ENV): Disable hyperlinks in the tests, they
contain random id's, and brackets (which is not so nice for M4).
2020-07-19 19:26:47 +02:00
Akim Demaille 01f3e2969b doc: add anchors for warnings
Unfortunately Texinfo somewhat mangles anchors such as `-Werror` into
`g_t_002dWerror`, so let's not include the dash.

* doc/bison.texi (Diagnostics): here.
2020-07-19 17:28:45 +02:00
Akim Demaille 744da03955 glyphs: fix types
The code was written on top of buffers of `char[26]`, and then was
changed to use `char *`, yet was still using `sizeof buf`, which
became `sizeof (char *)` instead of `sizeof (char[26])`.

Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-07/msg00023.html

* src/glyphs.h, src/glyphs.c: Get rid of uses of `char *`, use only
glyph_buffer_t.
2020-07-19 17:09:01 +02:00
Akim Demaille b28d67b6b0 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-19 09:45:36 +02:00
Akim Demaille cf890692f1 version 3.6.92
* NEWS: Record release date.
2020-07-19 09:24:57 +02:00
Akim Demaille 6932023f4d style: avoid strncpy
syntax-check seems to dislike strncpy.  The GNU Coreutils replaced
their uses of strncpy with stpncpy.

strlcpy is not an option.
  http://sources.redhat.com/ml/libc-alpha/2002-01/msg00159.html
  http://sources.redhat.com/ml/libc-alpha/2002-01/msg00011.html
  http://lists.gnu.org/archive/html/bug-gnulib/2004-09/msg00181.html

* src/glyphs.c: Use stpncpy.
2020-07-19 09:23:42 +02:00
Akim Demaille fff17fe8fe cex: display derivations as trees
Sometimes, understanding the derivations is difficult, because they
are serialized to fit in one line.  For instance, the example taken
from the NEWS file:

    %token ID
    %%
    s: a ID
    a: expr
    expr: expr ID ',' | "expr"

gave

    First example        expr • ID ',' ID $end
    Shift derivation     $accept → [ s → [ a → [ expr → [ expr • ID ',' ] ] ID ] $end ]
    Second example       expr • ID $end
    Reduce derivation    $accept → [ s → [ a → [ expr • ] ID ] $end ]

Printing as trees, it gives:

    First example        expr • ID ',' ID $end
    Shift derivation
      $accept
      ↳ s                      $end
        ↳ a                 ID
          ↳ expr
            ↳ expr • ID ','
    Second example       expr • ID $end
    Reduce derivation
      $accept
      ↳ s             $end
        ↳ a        ID
          ↳ expr •

* src/glyphs.h, src/glyphs.c (down_arrow, empty, derivation_separator):
New.
* src/derivation.c (derivation_print, derivation_print_impl): Rename
as...
(derivation_print_flat, derivation_print_flat_impl): These.
(fputs_if, derivation_depth, derivation_width, derivation_print_tree)
(derivation_print_tree_impl, derivation_print): New.
* src/counterexample.c (print_counterexample): Adjust.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-07-18 07:54:02 +02:00
Akim Demaille 5544615a59 cex: use the glyphs
* src/derivation.c: here.
* src/gram.h, src/gram.c (print_arrow, print_dot, print_fallback):
Remove.
2020-07-16 07:31:25 +02:00
Akim Demaille 346ba14f15 cex: factor the handling of graphical symbols
* src/glyphs.h, src/glyphs.c: New.
2020-07-16 07:31:24 +02:00
Akim Demaille 4d18195ebc cex: style changes
* src/counterexample.c: here.
2020-07-15 06:41:07 +02:00
Akim Demaille dd3e7b3895 cex: simplify tests
* tests/counterexample.at (AT_BISON_CHECK_CEX): Handle the keyword.
Simplify the signature.
2020-07-15 06:38:36 +02:00
Akim Demaille 64a3b6546a cex: more colors
Provided by Daniela Becker.

* data/bison-default.css: More colors.
2020-07-15 06:38:36 +02:00
Akim Demaille bad07a7f66 style: comments changes
* src/print.c: here.
2020-07-14 14:26:02 +02:00
Akim Demaille 88bd814bf1 doc: update GLR sections
Reported by Christian Schoenebeck.

* doc/bison.texi (GLR Parsers): Minor fixes.
(Compiler Requirements for GLR): Remove, quite useless today.
2020-07-14 06:56:15 +02:00
Akim Demaille 4f9ae5de07 cex: display shifts before reductions
When reporting counterexamples for s/r conflicts, put the shift first.
This is more natural, and displays the default resolution first, which
is also what happens for r/r conflicts where the smallest rule number
is displayed first, and "wins".

* src/counterexample.c (counterexample): Add a shift_reduce member.
(new_counterexample): Adjust.
Swap the derivations when this is a s/r conflict.
(print_counterexample): For s/r conflicts, prefer "Shift derivation"
and "Reduce derivation" rather than "First/Second derivation".

* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* NEWS, doc/bison.texi: Ditto.
2020-07-14 06:48:48 +02:00
Akim Demaille 78f72a4516 style: s/lookahead_tokens/lookaheads/g
Currently we use both names.  Let's stick to the short one.

* src/AnnotationList.c, src/conflicts.c, src/counterexample.c,
* src/getargs.c, src/getargs.h, src/graphviz.c, src/ielr.c,
* src/lalr.c, src/print-graph.c, src/print-xml.c, src/print.c,
* src/state-item.c, src/state.c, src/state.h, src/tables.c:
s/lookahead_token/lookahead/gi.
2020-07-14 06:48:48 +02:00
Akim Demaille c04693d651 cex: factor memory allocation
* src/counterexample.c (counterexample_report_state): Allocate once
per conflicted state, instead of once per r/r conflict.
2020-07-14 06:48:48 +02:00
Akim Demaille 12191911ba cex: use state_item_number consistently
* src/counterexample.c, src/state-item.c: here.
(counterexample_report_state): While at it, prefer c2 to j/k, to match
c1.
2020-07-14 06:48:48 +02:00
Akim Demaille d7f27477f4 cex: more consistent memory allocation/copy
* src/counterexample.c, src/parse-simulation.c: It is more usual in
Bison to use sizeof on expressions than on types, especially for
allocation.
Let the compiler do it's job instead of calling memcpy ourselves.
2020-07-14 06:48:48 +02:00
Akim Demaille 5bad15d7ea cex: minor renaming
* src/counterexample.c (has_common_prefix): Rename as...
(have_common_prefix): this.
2020-07-14 06:48:48 +02:00
Akim Demaille cd099edf2d cex: use better type names
There are too many gl_list_t in there, it's hard to understand what is
going on.  Introduce and use more precise types.  I sure can be wrong
in some places, it's hard to tell without proper tool support.

* src/counterexample.c, src/lssi.c, src/lssi.h, src/parse-simulation.c,
* src/parse-simulation.h, src/state-item.c, src/state-item.h
(si_bfs_node_list, search_state_list, ssb_list, lssi_list)
(state_item_list): New.
2020-07-14 06:48:48 +02:00
Akim Demaille 1e12219775 cex: minor style changes
* src/counterexample.h, src/derivation.h, src/derivation.c:
More comments.
Use `out` for FILE*, as elsewhere.
2020-07-14 06:48:48 +02:00
Akim Demaille d8c2af56c1 tests: beware of version numbers from git describe
* tests/report.at: Be robust to version numbers such as
3.6.4.133-fbac-dirty.
2020-07-14 06:48:48 +02:00
Akim Demaille cc11bb037c tests: fix expectations
Broken in ee86ea8839.

* tests/diagnostics.at: here.
2020-07-14 06:48:48 +02:00
Akim Demaille 121dd98508 doc: makeinfo wants @arrow{}, not @arrow
* doc/bison.texi: here.
2020-07-12 08:15:44 +02:00
Akim Demaille 2eddbd0ac4 gnulib: update 2020-07-11 19:11:19 +02:00
Akim Demaille ee86ea8839 cex: prefer → to ::=
It does not make a lot of sense to use ::= in our counterexamples,
that's not something that belongs to the Bison "vocabulary".  Using
the colon makes sense, but it's too discreet.  Let's use the arrow,
which we already use in some reports (HTML and Dot).

* src/gram.h (print_dot_fallback): Generalize into...
(print_fallback): this.
(print_arrow): New.
* src/derivation.c: Use it.

* NEWS, tests/conflicts.at, tests/counterexample.at,
* tests/diagnostics.at, tests/report.at: Adjust.
* doc/bison.texi: Ditto.
Unfortunately the literal `→` is output as `↦`.  So we need to use
@arrow.
2020-07-11 18:43:46 +02:00
Akim Demaille a2ad33dca6 style: cex: prefer the array notation
Prefer `&foos[i]` to `foos + i` when `foos` is an array.  IMHO, it
makes the semantics clearer.

* src/counterexample.c, src/lssi.c, src/parse-simulation.c,
* src/state-item.c: With arrays, prefer the array notation rather than
the pointer one.
2020-07-11 18:07:09 +02:00
Akim Demaille 5b2b7b1ffb style: cex: remove variables that don't make it simpler to read
* src/counterexample.c: With arrays, prefer the array notation rather
than the pointer one.
2020-07-11 18:07:09 +02:00
Akim Demaille dc72b3566d bistromathic: demonstrate caret-diagnostics
* examples/c/bistromathic/parse.y (user_context): We need the current
line.
(yyreport_syntax_error): Quote the guilty line, with squiggles.
* examples/c/bistromathic/bistromathic.test: Adjust.
2020-07-11 18:06:45 +02:00
Akim Demaille c47e1174d4 bistromathic: do not display parse errors on completion
Currently autocompletion on a line with errors leaks the error
messages.  It can be useful to let the user know, but GNU Readline
does not provide us with an nice way to display the error.  So we
actually break into the current line of the user.

So instead, do not show these errors.

* examples/c/bistromathic/parse.y (user_context): New.
Use %param to pass it to the parser and scanner.
Keep quiet when in computing autocompletion.
2020-07-11 18:05:50 +02:00
Akim Demaille 093eeb27e9 bistromathic: don't stupidly reset the location for each token
That quite defeats the whole point of locations...  But anyway, we
should not see these messages at all.

* examples/c/bistromathic/parse.y (expected_tokens): Fix (useless)
location tracking.
2020-07-11 18:05:41 +02:00
Akim Demaille dab23c4a21 bistromathic: promote yytoken_kind_t
* examples/c/bistromathic/parse.y: Use yytoken_kind_t rather than int.
2020-07-11 18:05:35 +02:00
Akim Demaille 38a169bec1 html: capitalize titles
* data/xslt/xml2xhtml.xsl: Use "State 0", not "state 0".
As we do in text reports.
2020-07-11 12:58:45 +02:00
Akim Demaille dc77d6500f html: don't define several times the same anchors
Currently when we output useless rules, they appear before the
grammar, but using the same invocation.  As a result, the anchor is
defined twice, and the wrong one, being first, is honored.

* data/xslt/xml2xhtml.xsl (rule): Take a new 'anchor' parameter to
decide whether being an anchor, or a target.
Let it be true when output the grammar.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille 8262c7dc22 html: simplify
* data/xslt/xml2xhtml.xsl: Merge two identical when-clauses.
2020-07-11 12:58:44 +02:00
Akim Demaille 44f28d10ee reports: let html reports catch up with --report and --graph
* data/xslt/xml2xhtml.xsl: Show the symbol types.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille 44ad466a32 reports: let xml reports catch up with --report and --graph
The text and Dot reports are expected to be identical when generated
directly (--report, --graph) or indirectly (via XML).  The xml
testsuite had not be run for ages, let it catch up a bit.

* src/print-xml.c: Pass the type of the symbols.
* data/xslt/xml2text.xsl
Catch up with the new layout.
Display the symbol types.
Use '•', not '.'
* tests/local.at: Smash '•' to '.' when matching against the direct
text report.
* tests/report.at: Adjust XML expectations.
2020-07-11 12:58:44 +02:00
Akim Demaille a839f4c461 reports: update html ouput
* data/xslt/xml2xhtml.xsl: Improve indentation.
Use ul/li rather that pre.
2020-07-11 12:58:44 +02:00
Akim Demaille 9a51c6a128 tests: check html
* tests/report.at: here.
2020-07-11 12:58:44 +02:00
Akim Demaille 2608b0cf12 style: factor complex expressions
* src/print-xml.c, src/print.c: Introduce a variable pointing to the
current symbol.
2020-07-11 12:58:44 +02:00
Akim Demaille aa766d1560 maint: make it easier to update expectations
* tests/local.mk (update-tests): New.
2020-07-11 12:58:44 +02:00
Akim Demaille a7ed13b25f maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-09 21:38:23 +02:00
Akim Demaille 2d90916067 version 3.6.91
* NEWS: Record release date.
2020-07-09 21:10:23 +02:00
Akim Demaille 91e5a23ff2 news: update 2020-07-09 20:29:24 +02:00
Akim Demaille d4ae66c371 gnulib: update 2020-07-09 20:26:16 +02:00
Akim Demaille 70fb574717 examples: add license headers
Prompted by Rici Lake.
https://stackoverflow.com/questions/62658368/#comment110853985_62661621
Discussed with Paul Eggert.

* doc/bison.texi, examples/c/bistromathic/parse.y,
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l,
* examples/c/pushcalc/calc.y, examples/c/reccalc/parse.y,
* examples/c/reccalc/scan.l, examples/d/calc.y,
* examples/java/calc/Calc.y, examples/java/simple/Calc.y:
Install the GPL3+ header.
2020-07-08 22:19:37 +02:00
Akim Demaille 0820f16ca8 style: update comments
* src/reader.c: action_obstack was removed in 2002...
* src/parse-gram.y: Better names.
* src/scan-code.h: More comments.
2020-07-05 09:59:45 +02:00
Akim Demaille 49f1e5f428 style: update comments in the skeletons
* data/skeletons/c++.m4, data/skeletons/glr.c, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Be more accurate about yychar and yytoken.
Don't name local variables as if they were members.
2020-07-05 09:59:25 +02:00
Akim Demaille 238692ad77 doc: more details about symbols in m4
* data/README.md: here.
* README-hacking.md (Vocabulary): More.
2020-07-05 09:18:27 +02:00
Akim Demaille 5f95583da7 regen 2020-07-05 08:18:51 +02:00
Akim Demaille 964fb2aa6f examples: include the generated header
* examples/c/bistromathic/parse.y, examples/c/lexcalc/parse.y,
* examples/c/reccalc/parse.y: here.
Add some comments.

* src/parse-gram.y (api_version): Pull out of handle_require.
Bump to 3.7.
2020-07-05 08:18:51 +02:00
Akim Demaille 7c0d36b760 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-07-04 12:37:45 +02:00
Akim Demaille b4d18c7fc6 version 3.6.90
* NEWS: Record release date.
2020-07-04 12:14:28 +02:00
Akim Demaille 3e6e51cf5c news: update 2020-07-04 12:12:33 +02:00
Akim Demaille d309bd9f9f package: fix syntax-check errors
* examples/c/bistromathic/bistromathic.test, po/POTFILES.in: here.
2020-07-04 12:10:15 +02:00
Akim Demaille 203f7230ec gnulib: update 2020-07-04 11:43:41 +02:00
Akim Demaille 156e548341 cex: give more details about -Wcex and -rcex
* data/bison-default.css: Cobalt does not seem to be supported.
* doc/bison.texi (Counterexamples): A new section.
(Understanding): Show the counterexamples as it shows in the report:
with its items.
(Bison Options): Document -Wcex and -rcex.
2020-07-04 11:43:35 +02:00
Akim Demaille 526ef45f30 news: update 2020-07-03 07:07:28 +02:00
Akim Demaille d7f7fcd9c7 dot: also use a dot in the output
* src/print-graph.c (print_core): Use a dot instead of a point.
* doc/figs/example-reduce.gv, doc/figs/example-reduce.txt,
* doc/figs/example-shift.gv, doc/figs/example-shift.txt,
* doc/figs/example.gv: Update.
* tests/output.at, tests/report.at: Adjust.
2020-07-03 06:51:57 +02:00
Akim DemailleandAkim Demaille 0fd542c3e0 doc: improve a sentence
* doc/bison.texi: here.
2020-07-02 07:21:33 +02:00
Akim Demaille 413908e5a4 news: formatting changes 2020-07-01 07:05:48 +02:00
Akim Demaille 84ef175287 news, todo: update 2020-07-01 07:05:41 +02:00
Akim Demaille 5234c8390f doc: clarify that the pcontext interface is *.c only
Reported by Rici Lake.
https://lists.gnu.org/r/bug-bison/2020-06/msg00054.html

* doc/bison.texi (Syntax Error Reporting Function): Make it clear that
this is not exported.
Remove C++ details that landed in the C doc.
2020-06-30 20:16:31 +02:00
Akim Demaille 21f7690570 doc: use color in the cex examples
* doc/bison.texi: here.
And use smallexample when it no longer fits in PDF.
2020-06-30 20:16:31 +02:00
Akim Demaille edb39c29a2 doc: repair the references to the Bibliography
In commit c80cdf2db2 ("doc: simplify
uses of @ref", Jan 27 2020, released in Bison 3.6), I broke the
references to the Bibliography.  For instance:

     For a more detailed exposition of the mysterious behavior in LALR parsers
    -and the benefits of IELR, @pxref{Bibliography,,Denny 2008 March}, and
    -@ref{Bibliography,,Denny 2010 November}.
    +and the benefits of IELR, @pxref{Bibliography}, and
    +@ref{Bibliography}.

which results in "see Bibliography" twice, instead of the more precise
reference.

* doc/bison.texi (@pcite, @tcite): New.
Use them instead of @ref to Bibliography.
Cite only the first author (that's what we did for the other entries).
2020-06-30 08:01:40 +02:00
Vincent ImbimboandAkim Demaille 1247d94ba6 doc: cex documentation
* NEWS, doc/bison.texi: Add documentation for conflict counterexample
generation.
2020-06-30 08:01:40 +02:00
Akim Demaille ed9a821caa doc: update Doxygen template file
* doc/Doxyfile.in: here.
2020-06-30 08:01:40 +02:00
Akim Demaille 330552ea49 yacc.c: push: don't clear the parser state when accepting/rejecting
Currently when a push parser finishes its parsing (i.e., it did not
return YYPUSH_MORE), it also clears its state.  It is therefore
impossible to see if it had parse errors.

In the context of autocompletion, because error recovery might have
fired, the parser is actually already in a different state.  For
instance on `(1 + + <TAB>` in the bistromathic, because there's a
`exp: "(" error ")"` recovery rule, `1 + +` tokens have already been
popped, replaced by `error`, and autocompletions think we are ready
for the closing ")".  So here, we would like to see if there was a
syntax error, yet `yynerrs` was cleared.

In the case of a successful parse, we still have a problem: if error
recovery succeeded, we won't know it, since, again, `yynerrs` is
clearer.

It seems much more natural to leave the parser state available for
analysis when there is a failure.

To reuse the parser, we should either:

1. provide an explicit means to reinitialize a parser state for future
   parses.

2. automatically reset the parser state when it is used in a new
   parse.

Option 2 requires to check whether we need to reinitialize the parser
each time we call `yypush_parse`, i.e., each time we give a new token.
This seems expensive compared to Option 1, but benchmarks revealed no
difference.  Option 1 is incompatible with the documentation
("After `yypush_parse` returns a status other than `YYPUSH_MORE`, the
parser instance `yyps` may be reused for a new parse.").

So Option 2 wins, reusing the private `yynew` member to record that a
parse was finished, and therefore that the state must reset in the
next call to `yypull_parse`.

While at it, this implementation now reuses the previously enlarged
stacks from one parse to another.

* data/skeletons/yacc.c (yypstate_new): Set up the stacks in their
initial configurations (setting their bottom to the stack array), and
use yypstate_clear to reset them (moving their top to their bottom).
(yypstate_delete): Adjust.
(yypush_parse): At the beginning, clear yypstate if needed, and at the
end, record when yypstate needs to be clearer.

* examples/c/bistromathic/parse.y (expected_tokens): Do not propose
autocompletion when there are parse errors.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-06-29 19:36:41 +02:00
Akim Demaille 7c609859ee bistromathic: don't display undefined locations
Currently, completion when there is a syntax error shows broken
locations.

* examples/c/bistromathic/parse.y (expected_tokens): Initialize the
location.
* examples/c/bistromathic/bistromathic.test: Check that.
2020-06-29 19:10:05 +02:00
Akim Demaille ed10c308fa yacc.c: simplify initialization of push parsers
The previous commit ("yacc.c: declare and initialize and the same
time") made b4_initialize_parser_state_variables useless.

* data/skeletons/yacc.c (b4_initialize_parser_state_variables): Inline
into...
(yypstate_clear): here.
2020-06-29 19:10:05 +02:00
Akim Demaille b91566edd1 regen 2020-06-29 19:10:05 +02:00
Akim Demaille 29520abb3b yacc.c: declare and initialize and the same time
In order to factor the code of push and pull parsers, the declaration
of the parser's state variable was common (being local variable in
pull parsers, and struct members in push parsers).  This result in
rather poor style in pull parser, with first variable declarations,
and then their initializations.

The initialization is about to differ between push and pull parsers,
so it is no longer worth keeping both cases together.

* data/skeletons/yacc.c (b4_declare_parser_state_variables): Accept an
argument, and when it is set, initialize the variables.
Adjust dependencies.
2020-06-29 19:10:05 +02:00
Akim Demaille 2491de1eef yacc.c: style changes in push mode
* data/skeletons/yacc.c: here.
2020-06-29 19:10:05 +02:00
Akim Demaille ec207d1bb2 yacc.c: simplify yypull_parse
Currently yypull_parse takes a yypstate* as argument, and accepts it
to be NULL.  This does not seem to make a lot of sense: rather it is
its callers that should do that.

I believe this is historical: yypull_parse was introduced
first (c3d503425f), with yyparse being a
macro.  So yyparse could hardly deal with memory allocation properly.
In 7172e23e8f that yyparse was turned
into a genuine function.  At that point, it should have allocated its
own yypstate*, which would have left yypull_parse deal with only one
single non-null ypstate* argument.

Fortunately, it is nowhere documented that it is valid to pass NULL to
yypull_parse.  It is now forbidden.

* data/skeletons/yacc.c (yypull_parse): Don't allocate a yypstate.
Needs a location to issue the error message.
(yyparse): Allocate the yypstate.
2020-06-29 19:10:05 +02:00
Akim Demaille 688b3404a2 doc: tidy the text files
* etc/README: Rename/reformat as...
* etc/README.md: this.
And ship it.
2020-06-29 19:10:05 +02:00
Akim Demaille cd6ef1e7d7 bench: simplify the rand target
* etc/bench.pl.in: There is no need to recompile the bench cases
themselves.
2020-06-29 19:10:05 +02:00
Akim Demaille 2b518d621f bench: make it easy to edit the generated files
* etc/bench.pl.in (&compile): Generate rules that compile the
generated files independently of the source files.
2020-06-29 19:08:15 +02:00
Akim Demaille 1ae4f1d329 tests: don't use $VERBOSE
It is used by the test suite itself, which results in this test
failing.

* tests/c++.at: Use $DEBUG, not $VERBOSE.
2020-06-29 06:45:44 +02:00
Akim Demaille 160df55c56 doc: overhaul of the readmes
* README-hacking.md (Working from the Repository): Make it first to
make it easier to find the instructions to build from the repo.
(Implementation Notes): New.
* README: Provide more links.
2020-06-28 14:57:41 +02:00
Akim Demaille e0b0a67b86 java: rename package as api.package
* data/skeletons/lalr1.java: here.
* doc/bison.texi: Update.
* src/muscle-tab.c: Ensure backward compat.
* tests/java.at: Check it.
2020-06-28 09:49:00 +02:00
Akim Demaille 0e5cbd38b2 style: shift/reduce, not shift-reduce
* src/reader.c: here.
2020-06-28 08:33:24 +02:00
Akim Demaille feb0bb0a59 style: rename endtoken as eoftoken
* src/symtab.h, src/symtab.c (endtoken): Rename as...
(eoftoken): this.
Adjust dependencies.
2020-06-27 17:31:59 +02:00
Akim Demaille d796e11f8f news: fixes
Reported by Jacob L. Mandelson.

* NEWS: here.
2020-06-27 17:04:50 +02:00
Akim Demaille 0895858d8e style: use 'nonterminal' consistently
* doc/bison.texi: Formatting changes.
* src/gram.h, src/gram.c (nvars): Rename as...
(nnterms): this.
Adjust dependencies.
(section): New.  Use it.
Replace "non terminal" and "non-terminal" by "nonterminal".
2020-06-27 11:39:32 +02:00
Akim Demaille 4efb2f7bd2 doc: parse.assert in C++ requires RTTI
* doc/bison.texi (%define Summary): Say it.
2020-06-27 10:31:59 +02:00
Akim Demaille eeafc706e8 c++: by default, use const std::string for file names
Reported by Martin Blais and Yuriy Solodkyy.
https://lists.gnu.org/r/help-bison/2020-05/msg00011.html
https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html

While at it, modernize filename_type as api.filename.type and document
it properly.

* data/skeletons/c++.m4 (filename_type): Rename as...
(api.filename.type): this.
Default to const std::string.
* data/skeletons/location.cc (position, location): Expose the
filename_type type.
Use api.filename.type.
* doc/bison.texi (%define Summary): Document api.filename.type.
(C++ Location Values): Document position::filename_type.
* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.
* tests/c++.at: Check that using const file names is ok.
tests/input.at: Check backward compat.
2020-06-27 10:06:00 +02:00
Akim Demaille cf6d8d0631 ielr: fix crash on memory management
Reported by Dwight Guth.
https://lists.gnu.org/r/bug-bison/2020-06/msg00037.html

* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
Beware that SBITSET__FOR_EACH nests _two_ for-loops, so "break" does
not actually break out of it.
That was the only occurrence in the code.
* src/Sbitset.h (SBITSET__FOR_EACH): Warn passersby.
2020-06-27 08:16:07 +02:00
Akim Demaille 8f44164443 style: factor the access to a rule from its items
* src/counterexample.c (item_rule): Move to...
* src/counterexample.h: here.
* src/AnnotationList.c, src/counterexample.c, src/ielr.c: Use it.
2020-06-25 19:36:07 +02:00
Akim Demaille 1001f48416 style: clean up nullable
* src/nullable.c: Reduce scopes.
Prefer `r` to `rules_ruleno`, which is truly an ugly name.
2020-06-25 19:36:07 +02:00
Akim Demaille 3be228f64c style: clean up ielr
* src/AnnotationList.c, src/ielr.c: Fix include order.
Prefer `res` to `result`.
Reduce scopes.
Be free of the oldish 76 cols limitation when it clutters too much the
code.
Denest when possible (we're starving for horizontal width).
2020-06-25 19:30:06 +02:00
Akim Demaille 670c7e7a75 don't use strlen to compute visual width
* src/output.c (prepare_symbol_names): Use mbswidth.
2020-06-23 08:27:26 +02:00
Akim Demaille c4b1a2b68f doc: use dot/'•' rather than point/'.'
AFAICT, "dotted rule" is a more frequent synonym of "item" than
"pointed rule".  So let's migrate to using "dot" only.

* doc/bison.texi: Use dot/'•' rather than point/'.'.

* src/print-xml.c (print_core): Use dot rather than point.  This is
not backward compatible, but AFAICT, we don't have actual user of the
XML output (but ourselves).  So...
* data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, tests/report.at: ... adjust.
2020-06-23 07:37:29 +02:00
Akim Demaille b65bd16e45 cex: display all the S/R conflicts, not just one per (state, rule)
Before this commit, on

    %%
    exp
    : "if" exp "then" exp
    | "if" exp "then" exp "else" exp
    | exp "+" exp
    | "num"

we used to not display the third counterexample below:

    Shift/reduce conflict on token "+":
      Example              exp "+" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ exp "+" exp . ] "+" exp ]
      Second derivation    exp ::=[ exp "+" exp ::=[ exp . "+" exp ] ]

    Shift/reduce conflict on token "else":
      Example              "if" exp "then" "if" exp "then" exp . "else" exp
      First derivation     exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . ] "else" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . "else" exp ] ]

    Shift/reduce conflict on token "+":
      Example              "if" exp "then" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ "if" exp "then" exp . ] "+" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp ::=[ exp . "+" exp ] ]

    Shift/reduce conflict on token "+":
      Example              "if" exp "then" exp "else" exp . "+" exp
      First derivation     exp ::=[ exp ::=[ "if" exp "then" exp "else" exp . ] "+" exp ]
      Second derivation    exp ::=[ "if" exp "then" exp "else" exp ::=[ exp . "+" exp ] ]

* src/counterexample.c (counterexample_report_state): Don't stop of
the first conflicts.
* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.
2020-06-23 06:56:04 +02:00
Akim Demaille 0f120354b6 cex: don't display twice unifying examples if there is no color
It makes no sense, and is actually confusing, to display twice the
same example with no visible difference.

* src/complain.h, src/complain.c (is_styled): New.
* src/counterexample.c (print_counterexample): Display the unified
example a second time only if it makes a difference.
* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* tests/diagnostics.at: Make sure we do display the unifying examples
twice when colors are enabled.  And check those colors.
2020-06-22 19:33:30 +02:00
Vincent ImbimboandAkim Demaille 69e3b405d9 cex: fix reporting of null nonterminals
I implemented this to print A ::= [ ], but A ::= [ %empty ] might be
clearer.

* src/parse-simulation.c (nullable_closure): Don't generate null
nonterminal derivations as leaves.
* src/derivation.c (derivation_print_impl): Don't print seperator
spaces for null nonterminal.
* tests/counterexample.at: Update test results.
2020-06-22 07:11:31 +02:00
Akim Demaille 3dd8f2305a cex: use the bullet in HTML
* data/xslt/xml2xhtml.xsl: here.
2020-06-22 07:02:29 +02:00
Akim Demaille 9e75066819 cex: style changes
* src/counterexample.c: Simplify a bit.
* src/parse-simulation.c, src/parse-simulation.h: Enforce coding style.
2020-06-19 08:02:18 +02:00
Akim Demaille efb65daa36 c++: get rid of global_tokens_and_yystype
This was a hack to make it easier for people to migrate from yacc.c to
lalr1.cc and from glr.c to glr.cc: when set, YYSTYPE and YYLTYPE were
`#defined`.  It was never documented (just mentioned in NEWS for Bison
2.2, 2006-05-19), but was used to simplify the test suite.  Stop that:
adjust the test suite to the skeletons, not the converse.

In C++ use yy::parser::semantic_type, yy::parser::location_type, and
yy::parser::token::MY_TOKEN, instead of YYSTYPE, YYLTYPE and MY_TOKEN.

* data/skeletons/glr.cc, data/skeletons/lalr1.cc: Remove its support.
* tests/actions.at, tests/c++.at, tests/calc.at: Adjust.
2020-06-16 08:14:42 +02:00
Akim Demaille e077bf1ebc cex: don't assume the terminal supports "•"
Use of print_unicode_char suggested by Bruno Haible.
https://lists.gnu.org/r/bug-gettext/2020-06/msg00012.html

* src/gram.h (print_dot_fallback, print_dot): New.
* src/gram.c, src/derivation.c: Use it.
* tests/counterexample.at, tests/report.at: Adjust the test suite.
* .travis.yml, README-hacking.md: Adjust.
2020-06-16 07:58:40 +02:00
Akim Demaille c35e829a76 cex: also include in the report on --report=counterexamples
And let --report=all include the counterexamples.

* src/getargs.h, src/getargs.c (report_cex): New.
* src/main.c: Compute counterexamples when -rcex is specified.
* src/print.c: Include the counterexamples when -rcex is specified.

* tests/conflicts.at, tests/existing.at, tests/local.at: Adjust.
2020-06-16 07:30:46 +02:00
Akim Demaille d4f854e5b2 cex: also include the counterexamples in the report
The report is the best place to show the details about
counterexamples, since we have the state right under the nose.

For instance:

State 7

    1 exp: exp . "⊕" exp
    2    | exp . "+" exp
    2    | exp "+" exp .  [$end, "+", "⊕"]
    3    | exp . "+" exp
    3    | exp "+" exp .  [$end, "+", "⊕"]

    "⊕"  shift, and go to state 6

    $end      reduce using rule 2 (exp)
    $end      [reduce using rule 3 (exp)]
    "+"       reduce using rule 2 (exp)
    "+"       [reduce using rule 3 (exp)]
    "⊕"       [reduce using rule 2 (exp)]
    "⊕"       [reduce using rule 3 (exp)]
    $default  reduce using rule 2 (exp)

    Conflict between rule 2 and token "+" resolved as reduce (%left "+").

    Shift/reduce conflict on token "⊕":
        2 exp: exp "+" exp .
        1 exp: exp . "⊕" exp
      Example                  exp "+" exp • "⊕" exp
      First derivation         exp ::=[ exp ::=[ exp "+" exp • ] "⊕" exp ]
      Example                  exp "+" exp • "⊕" exp
      Second derivation        exp ::=[ exp "+" exp ::=[ exp • "⊕" exp ] ]

    Reduce/reduce conflict on tokens $end, "+", "⊕":
        2 exp: exp "+" exp .
        3 exp: exp "+" exp .
      Example                  exp "+" exp •
      First derivation         exp ::=[ exp "+" exp • ]
      Example                  exp "+" exp •
      Second derivation        exp ::=[ exp "+" exp • ]

    Shift/reduce conflict on token "⊕":
        3 exp: exp "+" exp .
        1 exp: exp . "⊕" exp
      Example                  exp "+" exp • "⊕" exp
      First derivation         exp ::=[ exp ::=[ exp "+" exp • ] "⊕" exp ]
      Example                  exp "+" exp • "⊕" exp
      Second derivation        exp ::=[ exp "+" exp ::=[ exp • "⊕" exp ] ]

* src/conflicts.h, src/conflicts.c (has_conflicts): New.
* src/counterexample.h, src/counterexample.c (print_counterexample):
Add a `prefix` argument.
(counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Show the items when there's a
prefix.
* src/state-item.h, src/state-item.c (print_state_item):
Add a `prefix` argument.
* src/derivation.h, src/derivation.c (derivation_print)
(derivation_print_leaves): Add a prefix argument.
* src/print.c (print_state): When -Wcex is enabled, show the
conflicts.
* tests/report.at: Adjust.
2020-06-16 07:30:26 +02:00
Akim Demaille 35c0fe6789 cex: indent the diagnostics to highlight the structure
Instead of

    Shift/reduce conflict on token D:
    Example              A a • D
    First derivation     s ::=[ A a a ::=[ b ::=[ c ::=[ • ] ] ] d ::=[ D ] ]
    Example              A a • D
    Second derivation    s ::=[ A a d ::=[ • D ] ]

display

    Shift/reduce conflict on token D:
      Example              A a • D
      First derivation     s ::=[ A a a ::=[ b ::=[ c ::=[ • ] ] ] d ::=[ D ] ]
      Example              A a • D
      Second derivation    s ::=[ A a d ::=[ • D ] ]

* src/counterexample.c (print_counterexample): Indent.
* tests/counterexample.at: Adjust.
2020-06-16 07:29:46 +02:00
Akim Demaille 22f62414f9 cex: don't report the items
Showing the items (with the state numbers) is really something we
should restrict to the report.

* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Don't show the pointed rules,
we will do that in the report.
* tests/counterexample.at: Adjust.
2020-06-16 07:29:46 +02:00
Akim Demaille 9206b15c4e cex: make sure traces go to stderr
* src/parse-simulation.h, src/parse-simulation.c (print_parse_state):
here.
2020-06-16 07:29:46 +02:00
Akim Demaille 5edac5e15a cex: add an argument to the reporting functions to specify the stream
* src/conflicts.c (find_state_item_number, report_state_counterexamples):
Move to...
* src/counterexample.h, src/counterexample.c (find_state_item_number)
(counterexample_report_state): this.
Add support for `out` as an argument.
(counterexample_report_reduce_reduce, counterexample_report_shift_reduce):
Accept an `out` argument, and be static.
2020-06-16 07:29:46 +02:00
Akim Demaille 1c3189734c style: more uses of const
* src/print.c, src/state.h, src/state.c: here.
2020-06-16 07:29:46 +02:00
Akim Demaille c662b23735 Merge 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.4
  glr.cc: don't leak glr.c/glr.cc scaffolding to the user

Some fixes were needed to adjust to recent changes in glr.cc and
glr.c.

* data/skeletons/glr.cc: Stop messing with the user's epilogue to
insert glr.cc code.  We need that code to be inserted _before_ the
user's epilogue, not after.  So define b4_glr_cc_pre_epilogue.
* data/skeletons/glr.c: Use it.
2020-06-16 07:16:00 +02:00
Akim Demaille 627fecb19e maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-15 20:39:01 +02:00
Akim Demaille 2a069f22c6 version 3.6.4
* NEWS: Record release date.
2020-06-15 20:18:50 +02:00
Akim Demaille 3f4ffea6f2 glr.cc: don't leak glr.c/glr.cc scaffolding to the user
Until we have a decent reimplementation of glr.cc, we have to use
tricks to shoehorn C++ symbols to the C engine of glr.c.  Some of them
are done via #define.  Unfortunately in Bison 3.6 some of these we
done in the header file, which broke valid user code.

Reported by Egor Pugin.
https://lists.gnu.org/r/bug-bison/2020-06/msg00003.html

* data/skeletons/glr.cc: Stop playing tricks with b4_pre_epilogue.
(b4_glr_cc_setup, b4_glr_cc_cleanup): New.
Much cleaner way to instal glr.cc's scaffolding around glr.c.
* data/skeletons/glr.c: Adjust to use them.
2020-06-15 20:18:47 +02:00
Akim Demaille 251e1b137f reports: the column width differs from the byte count
From

    "number"          shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

to

    "number"  shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

* src/print.c: Use mbswidth, not strlen, to compute visual columns.
* tests/report.at: Adjust.
2020-06-13 17:21:51 +02:00
Akim Demaille efbcadeca7 reports: don't escape the labels
Currently we use "quotearg" to escape the strings output in Dot.  As a
result, if the user's locale is C for instance, all the non-ASCII are
escaped.  Unfortunately graphviz does not interpret this style of
escaping.

For instance:

    5 -> 2 [style=solid label="\"\303\221\303\271\341\271\203\303\251\342\204\235\303\264\""]

was displayed as a sequence of numbers.  We now output:

    5 -> 2 [style=solid label="\"Ñùṃéℝô\""]

independently of the user's locale.

* src/system.h (obstack_backslash): New.
* src/graphviz.h, src/graphviz.c (escape): Remove, use
obstack_backslash instead.
* src/print-graph.c: Likewise.
* tests/report.at: Adjust.
2020-06-13 16:58:13 +02:00
Akim Demaille e4d33cf579 regen 2020-06-13 16:58:03 +02:00
Akim Demaille 5855da4722 parser: keep string aliases as the user wrote it
Currently our scanner decodes all the escapes in the strings, and we
later reescape the strings when we emit them.

This is troublesome, as we do not respect the user input.  For
instance, when the user writes in UTF-8, we destroy her string when we
write it back.  And this shows everywhere: in the reports we show the
escaped string instead of the actual alias:

    0 $accept: . exp $end
    1 exp: . exp "\342\212\225" exp
    2    | . exp "+" exp
    3    | . exp "+" exp
    4    | . "number"
    5    | . "\303\221\303\271\341\271\203\303\251\342\204\235\303\264"

    "number"                                                    shift, and go to state 1
    "\303\221\303\271\341\271\203\303\251\342\204\235\303\264"  shift, and go to state 2

This commit preserves the user's exact spelling of the string aliases,
instead of interpreting the escapes and then reescaping.  The report
now shows:

    0 $accept: . exp $end
    1 exp: . exp "⊕" exp
    2    | . exp "+" exp
    3    | . exp "+" exp
    4    | . "number"
    5    | . "Ñùṃéℝô"

    "number"          shift, and go to state 1
    "Ñùṃéℝô"  shift, and go to state 2

Likewise, the XML (and therefore HTML) outputs are fixed.

* src/scan-gram.l (STRING, TSTRING): Do not interpret the escapes in
the resulting string.
* src/parse-gram.y (unquote, parser_init, parser_free, unquote_free)
(handle_defines, handle_language, obstack_for_unquote): New.
Use them to unquote where needed.
* tests/regression.at, tests/report.at: Update.
2020-06-13 16:56:40 +02:00
Akim Demaille 5d5e1df1dc tests: check reports with conflicts and UTF-8
This is to record the current state of the report, which escapes the
UTF-8 characters (as parse.error="verbose" does), but shouldn't (as
parse.error="detailed" does).

* tests/report.at: here.
2020-06-13 15:58:32 +02:00
Akim Demaille cef13e11f5 style: factor common bits about string scanning
* src/scan-gram.l: here.
2020-06-13 15:20:56 +02:00
Akim Demaille b7fbfd050e style: introduce & use STRING_1GROW
* src/flex-scanner.h (STRING_1GROW): New.
* src/scan-gram.l, src/scan-skel.l: Use it.
2020-06-13 15:20:56 +02:00
Akim Demaille e088b4f90f style: reduce scopes
* src/scan-gram.l (STRING_GROW_ESCAPE): Move the static_assert about
type sizes here.
2020-06-13 15:20:56 +02:00
Akim Demaille c857ed4f72 style: prefer 'FOO ()' to 'FOO' for function-like macros
* src/flex-scanner.h (STRING_GROW, STRING_FINISH, STRING_FREE):
Make them function-like macros.
Adjust dependencies.
2020-06-13 15:20:56 +02:00
Akim Demaille 1998606a90 regen 2020-06-11 19:11:33 +02:00
Akim Demaille b0bb4cde2e cex: suggest -Wcounterexamples when there are unexpected conflicts
Suggesting -Wcounterexamples when there are conflicts is probably not
what the user wants.  If she knows her conflicts and has set
%expect/%expect-rr appropriately, we shouldn't warn.

The commit also swaps the counterexamples and the report of conflicts,
into, IMHO, a more natural order: from

    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

to

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

* src/conflicts.c (rule_conflicts_print): Rename as...
(report_rule_expectation_mismatches): this.
Move the handling of report_counterexamples to...
(conflicts_print): Here.
Display this warning when applicable.
2020-06-10 09:51:39 +02:00
Akim Demaille d2acc4b401 cex: rename -Wcounterexample as -Wcounterexamples, and support -Wcex
Plural vs. singular is always a problem...

But we already have conflicts-sr and conflicts-rr, so counterexamples
makes more sense than counterexample.  Besides, -Wcounterexample will
still be accepted as an unambiguous prefix of -Wcounterexamples.

Add -Wcex as a convenient alias.

While at it, use only "counterexample", never "counter example".

* src/complain.h, src/complain.c
(Wcounterexample, warning_counterexample): Rename as...
(Wcounterexamples, warning_counterexamples): these.
(argmatch_warning_docs): Rename -Wcounterexample as -Wcounterexamples.
(argmatch_warning_args): Likewise.
Add support for -Wcex.
Adjust dependencies.
2020-06-10 07:53:44 +02:00
Akim Demaille a53c6026cd api.header.include: document it, and fix its default value
While defining api.header.include worked as expected, its default
value was incorrectly defined.  As a result, by default, the generated
parsers still duplicated the content of the generated header instead
of including it.

* data/skeletons/yacc.c (api.header.include): Fix its default value.
* tests/output.at: Check it.
* doc/bison.texi (%define Summary): Document api.header.include.
While at it, move the definition of api.namespace at the proper
place.
2020-06-09 08:09:26 +02:00
Akim Demaille ae5edcc23b cex: color the counterexamples
Use colors to show the counterexamples and the derivations in color,
to highlight their structure.  Align the outputs, and add i18n
support. Reduce width by using a one-space separator instead of
two-space.

From

    Example  A  •  B  C
    First  derivation  s ::=[ a ::=[ A  • ]  x ::=[ B  C ] ]
    Second derivation  s ::=[ y ::=[ A  •  B ]  c ::=[ C ] ]

to

    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

with colors.

* data/bison-default.css (cex-dot, cex-0, cex-1, cex-2, cex-3, cex-4)
(cex-5, cex-6, cex-7, cex-step, cex-leaf): New.
* src/derivation.c (derivation_print_styled_impl): New.
(derivation_print, derivation_print_leaves): Use it.
* src/counterexample.c: Reformat the output.
* tests/counterexample.at: Adjust.
2020-06-07 09:18:58 +02:00
Akim Demaille 296e2f90ab cex: enforce case for tokens/nonterminals
It's unfortunate that the traditions between formal language theory
and Yacc differs, but here, tokens should be upper case, and
nonterminals should be lower case.

* tests/counterexample.at: Comply with this.
2020-06-07 09:18:58 +02:00
Akim Demaille 1ccb4be02b cex: reformat the s/r and r/r reports
In Bison we refer to "shift/reduce" conflicts, not "shift-reduce" (in
Bison 3.6.3 186 occurrences vs 15).  Enforce consistency on this.

Instead of "spending" a second line for each conflict to report the
lookaheads, put that on the same line as the type of conflict.  Also,
prefer "token" to "symbol".  Maybe we should even prefer "lookahead".
While at it, enable internationalization, with plurals where
appropriate.

As a consequence, instead of

    Shift-Reduce Conflict:
    6:    3 b: . %empty
    6:    6 d: c . A
    On Symbol: A

display

    Shift/reduce conflict on token A:
    6:    3 b: . %empty
    6:    6 d: c . A

* NEWS, doc/bison.texi, src/conflicts.c: Spell it "shift/reduce", not
"shift-reduce".
* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Reformat and internationalize
output.
* tests/counterexample.at: Adjust expectations.
2020-06-07 09:18:58 +02:00
Akim Demaille 421662ec88 style: fix syntax-check issues
* src/counterexample.c, src/files.c, src/files.h, src/lssi.c,
* src/state-item.c: here.
2020-06-07 09:18:58 +02:00
Akim Demaille 39be113b1f all: show the rules in comments before the user actions
For instance, in the case of Bison's own parser:

    -  case 40:
    +  case 40:  /* grammar_declaration: "%code" "identifier" "{...}"  */
         {
           muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]),
                                     translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])),
                                     (yylsp[0]));
           code_scanner_last_string_free ();
         }
         break;

* data/skeletons/c.m4: Modified.
* data/skeletons/d.m4: Modified.
* data/skeletons/java.m4: Modified.
* src/output.c (output_escaped): New.
(quoted_output): Use it, and rename as...
(output_quoted): this.
Adjust dependencies.
(rule_output): New.
(user_actions_output): Use it.
* data/skeletons/c.m4, data/skeletons/d.m4, data/skeletons/java.m4
(b4_case): Add support for $3, an optional comment.
2020-06-07 06:50:58 +02:00
Akim Demaille 2101b0e210 CI: use GCC10 on ppc too
We were still using GCC9, because GCC10 was failing.

* .travis.yml (PPC64le): Use GCC10.
While at it, use -O2 instead of -O3: it's certainly nicer for the
CPUs, and allows to test different sets of compiler flags (we use -O3
in several other configurations).
2020-06-06 07:48:40 +02:00
Akim Demaille b1327c56f7 examples: fix missing includes
* examples/c/bistromathic/parse.y: Use abort rather than assert so
that the "unused result" warning is silenced even with -DNDEBUG.
2020-06-06 07:37:20 +02:00
Akim Demaille ae03b16785 warnings: fix -Wmissing-prototypes issues
* src/counterexample.c, src/lssi.c, src/parse-simulation.c,
* src/state-item.c:
Here.
2020-06-03 08:31:08 +02:00
Akim Demaille 7e16bd2cae Merge maint into HEAD
* upstream/maint:
  maint: post-release administrivia
  version 3.6.3
  build: check -Wmissing-prototypes
  tests: show logs
  c++: fix printing of state number on streams
2020-06-03 08:12:10 +02:00
Akim Demaille 508ac09939 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-03 07:52:30 +02:00
Akim Demaille 0535d2a608 version 3.6.3
* NEWS: Record release date.
2020-06-03 07:31:43 +02:00
Akim Demaille 94f7606db6 build: check -Wstrict-aliasing
* configure.ac (warn_common): Add -Wstrict-aliasing.
2020-06-01 18:52:23 +02:00
Akim Demaille de5be4a693 doc: using asan
* README-hacking.md: here.
2020-06-01 18:52:23 +02:00
Akim Demaille 03a6b439f6 style: fix includes
* src/fixits.c: Follow our usual pattern.
* src/scan-code.l, src/scan-gram.l, src/scan-skel.l: Prefer "" to
include src/ headers.
* README-hacking.md: Document the pattern.
2020-06-01 18:52:22 +02:00
Akim Demaille 742910838e lists: fix various issues with the use of gnulib's list
First, we should avoid code such as

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    derivation *child = NULL;
    while (gl_list_iterator_next (&it, (const void **) &child, NULL))
      {
        derivation_print (child, f);

because of -Wstrict-aliasing (whose job is to catch type-punning
issues).  See https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html.

Rather we need

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    const void **p = NULL;
    while (gl_list_iterator_next (&it, &p, NULL))
      {
        derivation *child = (derivation *) p;
        derivation_print (child, f);

Second, list iterators actually have destructors.  Even though they
are noop in the case of linked-lists, we should use them.

Let's address both issues with typed wrappers (such as
derivation_list_next) that take care of both issues, and besides allow
to scope the iterators within the loop:

    derivation *child;
    for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
         derivation_list_next (&it, &child);
         )
      {
        derivation_print (child, f);

* src/derivation.h, src/derivation.c (derivation_list_next): New.
Use it where appropriate.
* src/counterexample.c (search_state_list_next): New.
Use it where appropriate.
* src/parse-simulation.h, src/parse-simulation.c
* src/state-item.h (state_item_list_next): New.
Use it where appropriate.
2020-06-01 18:50:35 +02:00
Akim Demaille 52ce2a008b build: check -Wmissing-prototypes
pstate_clear is lacking a prototype.
Reported by Ryan
https://lists.gnu.org/r/bug-bison/2020-05/msg00101.html

Besides, none of the C examples were compiled with the warning flags.

* configure.ac (warn_c): Add -Wmissing-prototypes.
* data/skeletons/yacc.c (pstate_clear): Make it static.
* examples/local.mk (TEST_CFLAGS): New.
* examples/c/bistromathic/local.mk, examples/c/calc/local.mk,
* examples/c/lexcalc/local.mk, examples/c/mfcalc/local.mk,
* examples/c/pushcalc/local.mk, examples/c/reccalc/local.mk,
* examples/c/rpcalc/local.mk:
Use it.

GCC's warn_unused_result is not silenced by a cast to void, so we have
to "use" scanf's result.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Flex generated code produces too many warnings, including things such
as, with ICC:

    examples/c/lexcalc/scan.c(1088): error #1682: implicit conversion
              of a 64-bit integral type to a smaller integral type (potential portability problem)
    2259                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
    2260                ^
    2261
    2262

I am tired of trying to fix Flex's output.  The project does not seem
maintained.  We ought to avoid it.  So, for the time being, don't try
to enable warnings with Flex.

* examples/c/bistromathic/parse.y, examples/c/reccalc/scan.l: Fix
warnings.
* doc/bison.texi: Discard scanf's return value to defeat
-Werror=unused-result.
2020-06-01 08:29:53 +02:00
Akim Demaille bb311cfbed gnulib: update 2020-05-31 12:49:08 +02:00
Akim Demaille 518dc6ca26 style: make item_index a truly different type from item_number
See previous commit.

* src/gram.h (item_index): Make it unsigned.
Fix remaiming issues.
2020-05-25 07:41:05 +02:00
Vincent ImbimboandAkim Demaille 6a1a681fd2 style: decouple different uses of item_number
item_number is used for elements of ritem as well as indices into
ritem which is fairly confusing.  Introduce item_index to represent
indices into ritem.

* src/gram.h (item_index): Introduce it for ritem indices.
* src/closure.h, src/closure.c, src/ielr.c, src/lr0.c,
* src/print-graph.c, src/state.h, src/state.h:
Replace uses of item_number with item_index where appropriate.
2020-05-25 07:14:34 +02:00
Joshua WattandAkim Demaille dd878d1851 bison: add command line option to map file prefixes
Teaches bison about a new command line option, --file-prefix-map OLD=NEW
(based on the -ffile-prefix-map option from GCC) which causes it to
replace and file path of OLD in the text of the output file with NEW,
mainly for header guards and comments. The primary use of this is to
make builds reproducible with different input paths, and in particular
the debugging information produced when the source code is compiled. For
example, a distro may know that the bison source code will be located at
"/usr/src/bison" and thus can generate bison files that are reproducible
with the following command:

    bison --output=/build/bison/parse.c -d --file-prefix-map=/build/bison/=/usr/src/bison/ parse.y

Importantly, this will change the header guards and #line directives
from:

    #ifndef YY_BUILD_BISON_PARSE_H
    #line 100 "/build/bison/parse.h"

to

    #ifndef YY_USR_SRC_BISON_PARSE_H
    #line 100 "/usr/src/bison/parse.h"

which is reproducible.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00016.html
Signed-off-by: Joshua Watt <[email protected]>

* src/files.h, src/files.c (spec_mapped_header_file)
(mapped_dir_prefix, map_file_name, add_prefix_map): New.
* src/getargs.c (-M, --file-prefix-map): New option.
* src/output.c (prepare): Define b4_mapped_dir_prefix and
b4_spec_header_file.
* src/scan-skel.l (@ofile@): Output the mapped file name.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/location.cc,
* data/skeletons/yacc.c:
Adjust.
* doc/bison.texi: Document.
* tests/input.at, tests/output.at: Check.
2020-05-24 15:17:15 +02:00
Akim Demaille 6ed813c122 tests: fix expectations
Should have been part of 1ec93ca2a2.

* tests/counterexample.at: here.
2020-05-24 15:17:14 +02:00
Akim Demaille 1ec93ca2a2 cex: clean the display of conflicted symbols
Instead of `On Symbols: {b,c,}`, display `On Symbols: b, c`.

* src/counterexample.c (counterexample_report_reduce_reduce): We don't
need braces.
Use commas as a separator, not a terminator.
* tests/counterexample.at: Adjust.
2020-05-23 18:23:07 +02:00
Akim Demaille 12f4091de4 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 18:02:44 +02:00
Akim Demaille 8ece778cb8 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 18:02:24 +02:00
Akim Demaille f32ba07f94 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 17:45:03 +02:00
Vincent ImbimboandAkim Demaille 50cd3f16de cex: fix pruning crash
Fixes a crash on Cim's grammar.
https://lists.gnu.org/r/bison-patches/2020-05/msg00107.html

* src/state-item.c (prune_disabled_paths): Prune forward and backwards
paths in seperate passes.
(prune_forward, prune_backward): New.
(disable_state_item): Change function argument from state_item_number
to state_item.
(state_items_report): Add disabling to graph print-out.
* src/conflicts.c (find_state_item_number,
report_state_counterexamples): Add SI_DISABLED checks.
2020-05-23 17:35:19 +02:00
Akim Demaille 37da3c4b42 regen 2020-05-23 15:41:29 +02:00
Akim Demaille 79bae4d6bb kinds: use the symbol kinds where applicable
Instead of generating switch statements with numbers, let's use the
symbol kinds.  Not only is this more readable, it also makes reading
diff easier, as a change in symbol numbers won't have such a large
effect on the implementation of symbol actions.

* data/skeletons/bison.m4 (_b4_symbol_case): Use the symbol kind
rather than its number.
2020-05-23 15:41:29 +02:00
Akim Demaille 23f7554188 kinds: also define the possibly qualified symbol kinds
* data/skeletons/bison.m4 (b4_symbol_kind): Rename as...
(b4_symbol_kind_base): this.
(b4_symbol_kind): New, for fully qualified kind name.
* data/skeletons/lalr1.cc (b4_symbol_kind): New.
Adjust to use b4_symbol_kind where appropriate.
* src/parse-gram.h, src/parse-gram.c: regen.
2020-05-23 15:41:29 +02:00
Akim Demaille 3ff248ebfe m4: simplify useless quotation
* data/skeletons/bison.m4: The result of b4_symbol is "quoted"
already, no need for m4_expand.
2020-05-23 15:40:48 +02:00
Akim Demaille 4e1a5aae96 m4: use m4_shift2 etc.
* data/skeletons/bison.m4 (m4_shift4): New.
Use them where applicable.
2020-05-23 14:59:18 +02:00
Akim Demaille 8e70880af1 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 13:47:31 +02:00
Akim Demaille 3fea8fade8 style: spell fixes
* Makefile.am (codespell): New.
* doc/bison.texi: Fixes.
Use @option for options.
* src/lssi.c, src/lssi.h, src/parse-simulation.h, src/state-item.c:
Fix spellos.
2020-05-23 11:19:27 +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 339d11badf Merge maint into master
* upstream/maint:
  fix generated comments
  traces: provide a means to get short m4 traces
  traces: show the full m4 invocation
2020-05-22 20:35:13 +02:00
Vincent ImbimboandAkim Demaille 99260caef9 cex: replace state-item data structures
* src/state-item.h: Add trans, prods, and revs edges to state-item
struct.
(si_trans, si_revs, si_prods_lookup): Remove.
* src/state-item.c, src/lssi.c, src/parse-simulation.c,
* src/counterexample.c: Update state-item API usage accordingly.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille c19af5cbb4 cex: fix bad reference counting
* src/counterexample.c (si_bfs_free): Fix reference_count
decrementing.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille b54181ff9b cex: fix miscellaneous leaks
* src/counterexample.c (unifying_counterexample): Always free
stage3result when it exists.
* src/conflicts.c (report_state_counterexamples): free leaked bitset.
* src/state-item.c (prune_disabled_paths): free leaked queue.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 86c45be582 cex: fix counterexample leak
* src/counterexample.c (free_counterexample): New.
Free counterexamples after printing.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille b5e0351c3e cex: fix lssi leaks
* src/lssi.c (shortest_path_from_start): Free the root of
shortest_path_from_start search.
Free eligible bitset.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 150b2318ed cex: fix parse state leaks
* src/parse_simulation.c: Fix bug in parse_state_free.
Free new_root when simulate_reduction generates zero states.

* src/parse-simulation.c, src/parse-simulation.h
(parse_state_list, parse_state_list_append): New.
* src/parse-simulation.c, src/parse-simulation.h,
* src/counterexample.c: Replace all uses of lists of parse states and
appends to parse_state_lists with the new API.
2020-05-22 08:45:44 +02:00
Vincent ImbimboandAkim Demaille 35c4a8e65e cex: derivation reference counting
* src/derivation.h, src/derivation.c: Make derivation struct opaque.
Add derivation_list type for clarity.
(derivation_list_new): New.
(derivation_list_append): New.
(derivation_list_prepend): New.
(derivation_new_leaf): New constructor for derivations with no
children.
* src/counterexample.c, src/parse-simulation.c,
* src/parse-simulation.h: Replace uses of gl_list_t containing
derivations with derivation_list and its API.
Replace calls of dervation_new using null children with
derivation_new_leaf.
* src/parse-simulation.c: replace ps_chunk and its API with typed
versions si_chunk and deriv_chunk.
* src/parse-simlation.h, src/parse-simulation.c: Remove
parse_state_retain_deriv in favor of derivation reference counting.
* src/counterexample.c: Remove search_state_retain_deriv.
2020-05-22 08:45:44 +02:00
Akim Demaille fc39ccab6b cex: style changes in parse-simulation
* src/parse-simulation.c: Formatting changes.
(parse_state_list_new): New.
Use it.
2020-05-22 08:45:44 +02:00
Akim Demaille 9a33fb9317 cex: style: prefer res for returned value
* src/lssi.c, src/parse-simulation.c: here.
2020-05-22 08:45:44 +02:00
Akim Demaille 866bc6a49f cex: fix memory leaks when there are conflicts
* src/counterexample.c (production_step, reduction_step): Release
memory of temporary objects.
2020-05-22 08:45:43 +02:00
Akim Demaille e8619330e8 cex: be sure to always reclaim memory put in hashes
One call to hash_initialize did not provide a function to free memory.

* src/state-item.c (hash_pair_table_create): New.
Use it.
2020-05-22 08:45:43 +02:00
Akim Demaille 193dc86965 cex: properly reclaim hash's allocated memory
* src/state-item.c: Use hash_free where appropriate.
2020-05-22 08:45:43 +02:00
Akim Demaille 51fa2ab0a2 cex: avoid gratuitous heap allocations
There's no need to go for the heap when using gnulib's hash module.

* src/state-item.c (hash_pair_lookup, hash_pair_remove,
state_sym_lookup): Use the heap Luke.
That removes a leak from hash_pair_lookup.
(init_prods): Use hash_pair_insert instead of duplicating it.
2020-05-22 08:45:43 +02:00
Vincent ImbimboandAkim Demaille 2d8c3edbf8 cex: fix leaks
* src/state-item.c: Various functions were using heap allocated locals
and not freeing them.
2020-05-22 08:45:43 +02:00
Akim Demaille 4590071287 style: use hash_xinsert
* gnulib: Update to get hash_xinsert.
Use it where appropriate.
2020-05-22 08:45:43 +02:00
Akim Demaille ac3b6c18a5 cex: style changes in state-item
* src/state-item.h, src/state-item.c (state_item): Make the state
const.
(state_item_set): Make it clearer that it works in the state_items
global array.
2020-05-22 08:45:43 +02:00
Akim Demaille f3ef847539 cex: stylistic changes
* src/counterexample.c: Use 'res' as a variable name for returned
value, as elsewhere.
Avoid uninitialized variables, especially pointers.
Avoid assignment where possible.
2020-05-22 08:45:43 +02:00
Akim Demaille 16f2353723 cex: avoid uninitialized variables
* src/counterexample.c (item_rule_bounds): Split into...
(item_rule_start, item_rule_end): these.
Adjust dependencies.
* src/conflicts.c (find_state_item_number): New.
Use it to avoid uninitialized variables.
2020-05-22 08:45:29 +02:00
Akim Demaille da5317cc9d cex: isolate missing API from gl_list
* src/counterexample.c (list_get_end): New.
Use it.
Reduce scopes.
2020-05-22 07:52:27 +02:00
Akim Demaille e0cb91a922 cex: tests: be robust to variations in time limit reports
The CI has "failures" such as (253, "Null nonterminals"):

    @@ -21,7 +21,7 @@
     3:    3 b: . %empty
     3:    4 c: . %empty
     On Symbols: {A,}
    -time limit exceeded: 6.000000
    +time limit exceeded: 11.000000
     First  Example c  •  c  A  A  $end
     First  derivation  $accept ::=[ a ::=[ c  d ::=[ a ::=[ b ::=[ • ]  d ::=[ c  A  A ] ] ] ]  $end ]
     Second Example c  •  A  $end

* tests/counterexample.at (AT_BISON_CHECK_CEX): New.
Use it to neutralize differences in timeout values.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 482b370540 cex: fix stack overflow
* src/parse-simulation.c: Replace reference counting with
parse_state_retain everywhere.
(free_parse_state): Make this function iterative instead of
recursive. Long parse_state chains were causing stack exhaustion.

* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 66283fb625 cex: fix crash from zombie result
Fixes the SEGV in test 247 (counterexample.at:195): "S/R after first
token".

* src/counterexample.c: here.
* tests/counterexample.at: Fix expectations.
2020-05-22 07:52:27 +02:00
Akim Demaille 93c849ef0d cex: fixes, and enable tests
* src/counterexample.c, src/derivation.c:
Do not output diagnostics on stdout, that's the job of stderr, and the
testsuite heavily depend on this.
Do not leave trailing spaces in the output.
* tests/counterexample.at: Use AT_KEYWORDS.
Specify the expected outputs.
* tests/local.mk: Add counterexample.at.
2020-05-22 07:52:27 +02:00
Akim Demaille 6279945003 cex: fix a crash
* src/state-item.c (init_state_items): If the rule has no reductions
at all, don't read at all in its list of reduced rules.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille dcb6c972a2 cex: add tests
* tests/counterexample.at: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille af0441cfd2 cex: bind counterexample generation
* src/complain.h, src/complain.c: Add support for -Wcounterexample.
* src/conflicts.c (report_counterexamples): New.
(rule_conflicts_print): Use it when -Wcounterexample is given.
* src/getargs.h, src/getargs.c: Add support for --trace=cex.
* src/main.c (main): Init and deinit counterexample generation.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille bbb63b1ca9 cex: introduce counterexample search
* src/counterexample.h, src/counterexample.c: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille ac54d19eba cex: introduce the parse simulator
* src/derivation.h, src/derivation.c,
* src/parse-simulation.h, src/parse-simulation.c: New.
2020-05-22 07:52:27 +02:00
Vincent ImbimboandAkim Demaille 5807dd9279 cex: add support for state-item pair graph generation
* src/lssi.h, src/lssi.c, src/state-item.h, src/state-item.c: New.
2020-05-22 07:52:27 +02:00
Akim Demaille 94bfdf3b4b cex: add gnulib dependencies
* bootstrap.conf (gnulib_modules): Add linked-list.
2020-05-22 07:52:27 +02:00
Akim Demaille f80890c4bb fix generated comments
In Bison 3.6.2, the comments with brackets lose their brackets, for
improper m4 quotation.

* data/skeletons/bison.m4 (b4_gsub): New.
* data/skeletons/c-like.m4 (_b4_comment): Use it.
* tests/m4.at: Check b4_gsub.
2020-05-21 20:14:59 +02:00
Akim Demaille 1ebc2ac55c traces: provide a means to get short m4 traces
Let --trace=m4-early dump all the logs from the start (as --trace=m4
used to do), and have --trace=m4 now start traces only when actually
working of the user's grammar.

Can make a big difference in the case of small inputs.  E.g.

    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4 |& wc
       3952   19446  251068
    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4-early |& wc
      19491  131904 1830495

* data/skeletons/traceon.m4: New.
* src/getargs.h, src/getargs.c: Introduce --trace=m4-early.
* src/output.c (output_skeleton): Adjust for --trace=m4 and --trace=m4-early.
2020-05-21 20:13:04 +02:00
Akim Demaille 94952779b6 traces: show the full m4 invocation
Unfortunately the effect of -dV is still position independent.

* src/output.c (output_skeleton): here.
2020-05-21 20:13:04 +02:00
Thomas PetazzoniandAkim Demaille ed7d5c2b5b src: make path to m4 relocatable
Commit a4ede8f85b ("package: make bison
a relocatable package") made Bison relocatable, but in fact it still
contains one absolute reference: the M4 variable, which points to the
M4 program. Let's fix that by using relocate(), see if an M4 binary is
available at the relocated location, and otherwise fallback to the
original M4 location.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00078.html,
and https://lists.gnu.org/r/bison-patches/2020-05/msg00087.html.

* src/files.h, src/files.c (m4path): New.
* src/output.c: Use it.
2020-05-20 08:09:27 +02:00
Akim Demaille 1ce02e13c3 CI: fix PPC recipe 2020-05-17 11:01:19 +02:00
Akim Demaille 8ef0b12eb7 Merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.2
  tests: improve update-test
  CI: add GCC 10 and Clang 10
  fix: do not emit nested comments
  todo: update
  examples: use markdown hyperlinks
  tests: don't use == to compare const char *...
  gnulib: update
2020-05-17 09:16:51 +02:00
Akim Demaille e6d83116ae c: more fixes for _Noreturn
The previous fix was insufficient.

    tests/types.at:366: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    ++ ccache clang++-mp-9.0 -Qunused-arguments -ggdb -Wall -Wextra -Wcast-align -Wchar-subscripts -fparse-all-comments -Wdocumentation -Wformat -Wimplicit-fallthrough -Wnull-dereference -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare -Wpointer-arith -Wshadow -Wwrite-strings -Wextra-semi -Wold-style-cast -Wundefined-func-template -Wweak-vtables -Wunreachable-code -Wundef -pedantic -Wconversion -Wdeprecated -Wsign-compare -Wsign-conversion -Wtautological-constant-out-of-range-compare -fno-color-diagnostics -Wno-keyword-macro -Werror -std=c++98 -I/Users/akim/src/gnu/bison/tests -isystem /opt/gostai/include -isystem /opt/local/include -L/opt/gostai/lib -L/opt/local/lib -o test test.cc /Users/akim/src/gnu/bison/_build/c9d/lib/libbison.a -lintl -Wl,-framework -Wl,CoreFoundation
    stderr:
    test.cc:955:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    test.cc:963:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    2 errors generated.

* data/skeletons/c.m4 (b4_attribute_define): Do not use _Noreturn at
all in C++, clang or not.
2020-05-17 09:16:41 +02:00
Akim Demaille 4d9fa28ba8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-17 08:55:47 +02:00
Akim Demaille a100a3c4c1 version 3.6.2
* NEWS: Record release date.
2020-05-17 08:30:46 +02:00
Akim Demaille b18ceb50f1 tests: improve update-test
* build-aux/update-test: When given a directory, use the testsuite.log
which it contains.
Do not accept empty "from"s, as substituting the empty string with
something is rarely a good idea.
2020-05-17 08:28:12 +02:00
Akim Demaille ff4d67ede8 CI: add GCC 10 and Clang 10
* .travis.yml: Here.
* tests/input.at, tests/regression.at: Beware of clang's -Wdocumentation.
2020-05-17 08:28:12 +02:00
Akim Demaille 465babb635 fix: do not emit nested comments
With input such as

    %token<fl> yVL_CLOCK "/*verilator sc_clock*/"

we generate

    yVL_CLOCK = 610,      /* "/*verilator sc_clock*/"  */

which is invalid since the comment will actually be closed on the
first "*/".  Let's turn "*/" into "*\/" to avoid this.  But GCC will
also warn about "/*" inside a comment, so let's "escape" it too.

Reported by Huang Rui.
https://github.com/akimd/bison/issues/38

* data/skeletons/c-like.m4 (_b4_comment): Escape comment delimiters in
comments.
* tests/input.at (Torturing the Scanner): Check thes cases.
* tests/m4.at: New.
2020-05-17 08:28:12 +02:00
Akim Demaille 22c3839168 c: restore definition of _Noreturn as [[noreturn]] in C++
c.m4 contains a definition of _Noreturn which is modeled after
gnulib's lib/_Noreturn.h.  The latter was recently
changed (b61bf2f0e8) to not using
[[noreturn]] at all, because the uses of _Noreturn in gnulib are
sometimes incompatible with the rules of [[noreturn]].

As a result glr.cc started to use _Noreturn in C++, which clang
refuses (all the glr.cc tests currently fail with Clang++).

* data/skeletons/c.m4 (b4_attribute_define): Restore the definition of
_Noreturn as [[noreturn]] in modern C++.
The generated code uses _Noreturn in places where [[noreturn]] is
valid.
2020-05-16 17:29:38 +02:00
Akim Demaille 4619b32dc0 examples: don't promote unchecked function calls
* etc/bench.pl.in, examples/c/bistromathic/parse.y,
* examples/c/calc/calc.y, examples/c/pushcalc/calc.y: Check scanf's
return value.
* doc/bison.texi: Likewise, but only for the second example, to avoid
cluttering the very simple case.
2020-05-16 14:39:57 +02:00
Akim Demaille ad921890c1 gnulib: update 2020-05-16 14:39:57 +02:00
Akim Demaille 6a28e6d412 todo: update 2020-05-15 07:18:15 +02:00
Akim Demaille f4495da337 examples: use markdown hyperlinks
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/README.md: here.
2020-05-14 07:26:55 +02:00
Akim Demaille dbaed0bbf2 tests: don't use == to compare const char *...
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00091.html

* tests/c++.at: here.
2020-05-14 07:26:34 +02:00
Akim Demaille 78c7fb6460 gnulib: update 2020-05-14 07:25:09 +02:00
Akim Demaille 14ce500508 tests: improve update-test
* build-aux/update-test: When given a directory, use the testsuite.log
which it contains.
Do not accept empty "from"s, as substituting the empty string with
something is rarely a good idea.
2020-05-13 19:48:03 +02:00
Akim Demaille acba58ac59 Merge branch maint
* maint:
  news: update
  maint: post-release administrivia
  version 3.6.1
  c++: style: reorder generated code
  c++: provide yy::parser::symbol_type::name
  c++: make parser::symbol_name public
  examples: beware of ~/.inputrc
  build: also provide lzip compressed tarballs
  style: minor fixes
  yacc.c: restore ansi-c compatibility
2020-05-10 17:33:12 +02:00
Akim Demaille da29809969 news: update 2020-05-10 17:32:28 +02:00
Akim Demaille 87e4895189 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-10 14:47:51 +02:00
Akim Demaille 01e3f45f83 version 3.6.1
* NEWS: Record release date.
2020-05-10 14:28:24 +02:00
Akim Demaille 9c21da3363 bench: add support to randomize the order of execution
It's amazing how much the order matters.  To a point that many of
these benches are meaningless.  For instance (some of the benches
where run with `make -C benches/latest rand
BENCHFLAGS=--benchmark_min_time=3`):

    compiler: g++ -std=c++11 -O2
      0. %define nofinal
      1.
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0            1543 ns       1541 ns     441660
    BM_y1            1521 ns       1520 ns     456535
    --------------------------------------------------
    BM_y0            1531 ns       1530 ns     440584
    BM_y1            1512 ns       1511 ns     457591
    --------------------------------------------------
    BM_y0            1539 ns       1538 ns    2749330
    BM_y1            1516 ns       1515 ns    2771500
    --------------------------------------------------
    BM_y0            1571 ns       1570 ns    2600782
    BM_y1            1542 ns       1541 ns    2708349
    --------------------------------------------------
    BM_y0            1530 ns       1529 ns    2670363
    BM_y1            1519 ns       1518 ns    2764096

    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y1            1529 ns       1528 ns     451937
    BM_y0            1508 ns       1507 ns     453944
    --------------------------------------------------
    BM_y1            1525 ns       1524 ns    2750684
    BM_y0            1516 ns       1515 ns    2794034
    --------------------------------------------------
    BM_y1            1526 ns       1525 ns    2749620
    BM_y0            1515 ns       1514 ns    2808112
    --------------------------------------------------
    BM_y1            1524 ns       1523 ns    4475844
    BM_y0            1502 ns       1501 ns    4611665

* etc/bench.pl.in: here.
2020-05-10 11:51:46 +02:00
Akim Demaille febf6115a0 bench: use a Makefile
This makes it much easier to toy with the benchs.

* etc/bench.pl.in: Generate a Makefile instead of directly compiling
the files.
2020-05-10 11:51:41 +02:00
Akim Demaille 11b5bac7bf examples: use markdown hyperlinks
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/README.md: here.
2020-05-10 11:51:17 +02:00
Akim Demaille b61bf2f0e8 don't use stdnoreturn
Reported by Paul Eggert.

* src/getargs.c: We don't need it anyway, since we use _Noreturn.
* data/skeletons/c.m4: While at it, update the definition of _Noreturn
stolen from gnulib.
2020-05-10 10:46:03 +02:00
Akim Demaille 091943f265 c++: style: reorder generated code
The implementation of yy::parser::symbol_name is emitted even before
the implementation of yy::parser::parser.  This makes little sense.

* data/skeletons/lalr1.cc (symbol_name): Move its implementation in
the same place as in the class definition: after "error" and before
"context".
2020-05-10 10:06:11 +02:00
Akim Demaille bf98d94f4f c++: provide yy::parser::symbol_type::name
* data/skeletons/c++.m4 (yy::parser::basic_symbol::name): New.
* data/skeletons/lalr1.cc (yy_print_): Use it.
* doc/bison.texi: Document.
* tests/c++.at: Check.
2020-05-10 10:01:35 +02:00
Akim Demaille 6bb37dbe27 c++: make parser::symbol_name public
Reported by Martin Blais <[email protected]>.
https://lists.gnu.org/r/help-bison/2020-05/msg00005.html

* data/skeletons/lalr1.cc (symbol_name): Make it public.
Add a private hidden hook to enable testing of private parts.
* tests/local.at (AT_DATA_GRAMMAR_PROLOGUE): Help Emacs find the right
language mode.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check that we
can read symbol_name.
2020-05-10 09:42:37 +02:00
Akim Demaille c3585f41ef examples: beware of ~/.inputrc
* examples/c/bistromathic/bistromathic.test: here.
2020-05-10 09:40:07 +02:00
Akim Demaille 6525abdc83 build: also provide lzip compressed tarballs
Suggested by Matias Fonzo <[email protected]>.

* cfg.mk: Post announcements to bison-announce.
* configure.ac: Build lzip packages.
* .travis.yml: Build only xz, we don't care about the other formats
here.
2020-05-10 08:03:49 +02:00
Akim Demaille 2b63c54f5a style: minor fixes
* examples/c/README.md: here.
2020-05-10 08:03:30 +02:00
Akim Demaille 2da399d15f yacc.c: restore ansi-c compatibility
Reported by neok-m4700.
https://github.com/akimd/bison/issues/37

* data/skeletons/yacc.c: Don't use // comments.
2020-05-09 17:05:03 +02:00
Akim Demaille 19f45df02b bench: use *.cc for C++
Using *.c is simpler, but triggers annoying warnings with Clang++.

* etc/bench.pl.in: Please the dictator.
2020-05-09 16:43:59 +02:00
Akim Demaille 2ab4058de0 style: minor fixes
* examples/c/README.md: here.
2020-05-09 16:43:59 +02:00
Akim Demaille f2277c3fec gnulib: update 2020-05-09 15:40:38 +02:00
Akim Demaille fb49a10e2c gnulib: update, and use the attribute module
* gnulib: Update.
* bootstrap.conf: Use attribute.
* src/system.h: Remove macros for attributes.
Adjust dependencies.
* src/scan-gram.l (DEPRECATED): Rename as...
(DEPRECATED_DIRECTIVE): this, to avoid the clash with the DEPRECATED macro.
2020-05-08 18:29:30 +02:00
Akim Demaille f049a57eec build: also provide lzip compressed tarballs
Suggested by Matias Fonzo <[email protected]>.

* cfg.mk: Post announcements to bison-announce.
* configure.ac: Build lzip packages.
* .travis.yml: Build only xz, we don't care about the other formats
here.
2020-05-08 18:29:21 +02:00
Akim Demaille 0c77d69721 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-08 10:15:38 +02:00
Akim Demaille 307fcdee00 version 3.6
* NEWS: Record release date.
2020-05-08 09:57:14 +02:00
Akim Demaille d26d10ad6c examples: beware of portability issue on Windows
Reported by Jannick.
https://lists.gnu.org/r/bug-bison/2020-05/msg00040.html
https://lists.gnu.org/r/bug-bison/2020-05/msg00066.html

* examples/test (diff_opts): Use --strip-trailing-cr if supported, to
avoid \n vs. \r\n issues.
* examples/c/bistromathic/bistromathic.test: When on MSYS, don't try
to check autocompletion.
2020-05-08 09:45:29 +02:00
Akim Demaille 1b4108da3e regen 2020-05-08 09:45:29 +02:00
Akim Demaille 53bfc7df94 doc: fix the generation of the man page
When there is no bison.1 at all, the procedure fails.

* doc/local.mk (bison.1): Be robust to cold starts.
2020-05-08 09:02:45 +02:00
Akim Demaille a5fb4a88ef news: prepare for 3.6 2020-05-08 07:34:30 +02:00
Akim Demaille 54df196d49 doc: complete the table of symbols
* doc/bison.texi: Add YYEMPTY, YYEOF and YYUNDEF.
2020-05-08 07:34:30 +02:00
Akim Demaille 52bb6f0525 doc: clarify the glossary item about kinds
* doc/bison.texi (Glossary): here.
2020-05-07 08:38:58 +02:00
Akim Demaille 76dab18af3 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-06 08:48:05 +02:00
Akim Demaille c982974f33 version 3.5.94
* NEWS: Record release date.
2020-05-06 08:28:36 +02:00
Akim Demaille dc2a3578b7 doc: document yypstate_expected_tokens
* doc/bison.texi (Push Parser Interface): Here.
2020-05-06 08:11:52 +02:00
Akim Demaille 9661b2fcbc doc: restructure the push parser documentation
I don't think it's fair to have yypstate_new, yypstate_delete,
yypush_parse and yypull_parse to have their own section, on par with
yyparse and yylex.  Let them be in a single section about push
parsers.  And show new/delete first.

* doc/bison.texi (Push Parser Interface): New.
Fuse the aforementioned sections into it.
2020-05-06 08:11:52 +02:00
Akim DemailleandAkim Demaille d9a9b054ae all: fix the interface of yyexpected_tokens
The user gives yyexpected_tokens a limit: the max number of tokens she
wants to hear about.  That's because an error message that reports a
bazillion of possible tokens is useless.

In that case yyexpected_tokens returned 0, so the user would not know
if there are too many expected tokens or none (yes, that's possible).

There are several ways to tell the user in which situation she's in:

- return some E2MANY, a negative value.  Then it makes the pattern

    int argsize = yypcontext_expected_tokens (ctx, arg, ARGS_MAX);
    if (argsize < 0)
      return argsize;

  no longer valid, as for E2MANY (i) the user must generate the error
  message anyway, and (ii) she should not return E2MANY

- return ARGS_MAX + 1.  Then it makes it dangerous for the user, as
  she has to iterate update `min (ARGS_MAX, argsize)`.

Returning 0 is definitely simpler and safer for the user, as it tells
her "this is not an error, just generate your message without a list
of expecting tokens".  So let's still return 0, but set arg[0] to the
empty token when the list is really empty.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.java
* data/skeletons/yacc.c (yyexpected_tokens): Put the empty symbol
first if there are no possible tokens at all.
* examples/c/bistromathic/parse.y: Demonstrate how to use that.
2020-05-06 08:11:52 +02:00
Akim Demaille cb9f4cb543 examples: fix handling of syntax errors
The shell grammar does not allow empty statements in then/else part of
an if, but examples/test failed to catch the syntax errors from the
script it ran.  So exited with success anyway.

You would expect 'set -e' to suffice, but with bash 3.2 actually it
does not.  As a matter of fact, I could find a way to have this behave
properly:

    $ cat test.sh
    set -e
    cleanup ()
    {
      status=$?
      echo "cleanup: $status"
      exit $status
    }
    trap cleanup 0 1 2 13 15
    . $1
    s=$?
    echo "test.sh: $s"
    exit $s

    $ cat bistro.test
    if true; then
    fi

    $ /bin/sh ./test.sh ./bistro.test
    ./bistro.test: line 2: syntax error near unexpected token `fi'
    cleanup: 0
    $ echo $?
    0

Remove the set -e (or the trap), and tada, it works...  So we have to
deal with the error by hand.

* examples/test ($exit): Replace with...
($status): this.
Preserve the exit status of the test case.
* examples/c/bistromathic/bistromathic.test: Fix syntax error.
2020-05-05 08:21:12 +02:00
Akim Demaille b86dcaf40b doc: beware of timestamp issues on Haiku
On Haiku, help2man is fired on a freshly extracted tarball.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00055.html

* doc/local.mk (bison.1): Be robust to a missing help2man.
2020-05-04 19:06:59 +02:00
Akim Demaille 0fafbbdefb tests: beware of wchar_t portability issues on AIX
https://lists.gnu.org/r/bug-bison/2020-05/msg00050.html
Reported by Bruno Haible.

* tests/diagnostics.at: here.
2020-05-04 08:09:22 +02:00
Akim Demaille 4b85b969d0 glr.c: beware of portability issues with PTRDIFF_MAX
For instance test 386, "glr.cc api.value.type={double}":

    types.at:366: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    test.cc: In function 'ptrdiff_t yysplitStack(yyGLRStack*, ptrdiff_t)':
    test.cc:490:4: error: 'PTRDIFF_MAX' was not declared in this scope
       (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
        ^
    test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
           ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
                                         ^~~~~~~~~
    test.cc:490:4: note: suggested alternative: '__PTRDIFF_MAX__'
       (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
        ^
    test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
           ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
                                         ^~~~~~~~~

The failing tests are using glr.cc only, which I don't understand, the
problem is rather in glr.c, so I would expect glr.c tests to also fail.

Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00053.html

* data/skeletons/yacc.c: Move the block that defines
YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, and
YYSIZEOF to...
* data/skeletons/c.m4 (b4_sizes_types_define): Here.
(b4_c99_int_type): Also take care of the #undefinition of short.
* data/skeletons/yacc.c, data/skeletons/glr.c: Use
b4_sizes_types_define.
* data/skeletons/glr.c: Adjust to use YYPTRDIFF_T/YYPTRDIFF_MAXIMUM,
YYSIZE_T/YYSIZE_MAXIMUM.
2020-05-04 07:44:42 +02:00
Akim Demaille 7727693711 todo: update 2020-05-04 07:37:40 +02:00
Akim Demaille ce27796b74 examples: beware of strnlen portability issues
One function missing on Solaris 10 Sparc:

     CCLD     examples/c/bistromathic/bistromathic
    Undefined                       first referenced
    symbol                             in file
    strnlen                             examples/c/bistromathic/bistromathic-parse.o
    ld: fatal: symbol referencing errors. No output written to examples/c/bistromathic/bistromathic

Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00048.html

* examples/c/bistromathic/parse.y (xstrndup): Don't use strnlen.
xstrndup is assembled from gnulib's xstrndup, strndup and strnlen...
2020-05-04 06:48:00 +02:00
Akim Demaille 6135fdc152 examples: beware of portability issues with sh's trap
On AIX 7.2, when invoking "exit 77", we actually exit with 127.  The
"cleanup" function, called via trap, received an incorrect exit
status, something described in Autoconf's doc.
Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00029.html
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00047.html

* examples/test (skip): New.
* examples/c/bistromathic/bistromathic.test,
* examples/c/reccalc/reccalc.test: Use it, to ensure $? is set to 77
when the trap is called.
2020-05-04 06:48:00 +02:00
Akim Demaille f1497356e8 tests: beware of portability issues with diff -u
AIX 7.1 supports diff -u, but its output does not match the expected
one.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00049.html

* tests/atlocal.in (DIFF_U_WORKS): New.
* tests/local.at (AT_DIFF_U_CHECK): New.
* tests/existing.at (_AT_TEST_EXISTING_GRAMMAR): Use AT_DIFF_U_CHECK.
2020-05-04 06:48:00 +02:00
Akim Demaille 1429569362 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-03 19:52:38 +02:00
Akim Demaille 506c368ab2 version 3.5.93
* NEWS: Record release date.
2020-05-03 19:32:15 +02:00
Akim Demaille 4f9dc3bdc1 news: update for 3.5.93 2020-05-03 19:32:03 +02:00
Akim Demaille 0d81be2dc7 gnulib: update 2020-05-03 19:32:03 +02:00
Akim Demaille 32f44f4bfb tests: really skip tricky multichar test on Cygwin
In Autotest, anything outside AT_SETUP/AT_CLEANUP is discarded.

* tests/diagnostics.at (AT_TEST): Accept a skip-if test.
Use it to skip on cygwin.
2020-05-03 19:08:16 +02:00
Akim Demaille 38a8287813 bistromathic: beware of portability issues of readline on AIX
Readline may emit escape sequences before the prompt.
Reported by Bruno Haible.
https://lists.gnu.org/r/platform-testers/2020-05/msg00001.html.

* examples/c/bistromathic/bistromathic.test: Trust readline _only_ if
we get what we expect on some reference computation.
2020-05-03 18:10:58 +02:00
Akim Demaille df752784c2 examples: beware of portability issues with cmp
As someone wrote nearly 20 years ago in Autoconf's documentation,
don't use cmp to compare text files, but diff.
https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=abad4f0576a7dc361e5385e19c7681449103cdb1
Reported by Jannick.

* examples/test: Use diff, not cmp.
2020-05-03 17:53:47 +02:00
Akim Demaille 292409e91e build: fix warnings (shown on IRIX)
Appearing on IRIX with gcc -mabi=n32.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html

* examples/c++/variant-11.yy, examples/c/bistromathic/parse.y: Don't
give chars to isdigit, cast them to unsigned char before.
* src/complain.c: Use c_isdigit.
* src/fixits.c (fixits_run): Avoid casts.
* src/lalr.c (goto_print): Use %zu for a size_t.
2020-05-03 17:37:34 +02:00
Akim Demaille eea56d70d9 c++: be compatible with the pre-3.6 way to get a symbol's kind
Reported by Pramod Kumbhar.
https://lists.gnu.org/r/bug-bison/2020-05/msg00025.html

* data/skeletons/c++.m4: here.
2020-05-03 17:06:13 +02:00
Akim Demaille 6e2de439e6 bistromathic: beware of portability issues with strndup
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00026.html

* examples/c/bistromathic/parse.y (xstrndup): New.
Use it.
2020-05-03 17:06:13 +02:00
Akim Demaille e33cd4b824 flex: fix incorrect use of Automake conditional
AM_CONDITIONAL does _not_ define a shell variable...
Reported privately by Denis Excoffier.

* configure.ac (LEX_CXX_WORKS): Fix its definition.
2020-05-03 17:04:15 +02:00
Bruno HaibleandAkim Demaille 0669780ff8 package: fix a link error on IRIX
https://lists.gnu.org/r/bug-bison/2020-05/msg00035.html

* src/local.mk (src_bison_LDADD): Mention libbison.a before, not after, the
system libraries.
2020-05-03 16:49:29 +02:00
Akim Demaille 160df220b1 bistromathic: beware of portability of readline
Don't try to build bistromathic if we don't have readline.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00028.html

* configure.ac (ENABLE_BISTROMATHIC): New.
* examples/c/bistromathic/local.mk: Use it.
* examples/c/bistromathic/bistromathic.test: Exit 77 for skip.
2020-05-03 16:38:34 +02:00
Akim Demaille da5c072a62 tests: beware of portability issues of sh
"foo || bar" does not invoke bar on AIX 7.2 when foo does not exist.
It just dies.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00029.html

* examples/c/reccalc/reccalc.test: Check for seq in a subshell.
2020-05-03 16:38:34 +02:00
Akim Demaille 73ac8ff409 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-03 13:07:08 +02:00
Akim Demaille 0e0fb0efc9 version 3.5.92
* NEWS: Record release date.
2020-05-03 12:48:16 +02:00
Akim Demaille bb1d776be0 news: update for 3.5.92 2020-05-03 12:47:21 +02:00
Akim Demaille d7e1abe656 gnulib: update 2020-05-03 12:43:55 +02:00
Akim Demaille 13a1537dba java: demonstrate push parsers
* data/skeletons/lalr1.java (Location): Make it a static class.
(Lexer.yylex, Lexer.getLVal, Lexer.getStartPos, Lexer.getEndPos):
These are not needed in push parsers.
* examples/java/calc/Calc.y: Demonstrate push parsers in the Java.
* doc/bison.texi: Push parsers have been supported for a long time,
remove incorrect statements stating the opposite.
2020-05-03 11:28:36 +02:00
Akim Demaille ac2ba46053 doc: clarify what a location is
Reported by Arthur Schwarz <[email protected]>
https://lists.gnu.org/r/help-bison/2013-12/msg00009.html

* doc/bison.texi (Location Type): here.
2020-05-03 11:28:36 +02:00
Akim Demaille 2a7a2c1d3a tests: beware of mbswidth portability issues
Shy away from these issues on Cygwin.
Reported Denis Excoffier.
https://lists.gnu.org/r/bug-bison/2020-05/msg00003.html

* tests/diagnostics.at (Tabulations and multibyte characters): Split
in two.
2020-05-03 11:28:36 +02:00
Akim Demaille c9b5b68c73 examples: beware of intl portability issues
Reported by Horst von Brand.
https://lists.gnu.org/r/bug-bison/2020-04/msg00033.html

* examples/c/bistromathic/Makefile: libintl might not be needed, but
libm probably is.
* examples/c/bistromathic/parse.y: Include locale.h.
2020-05-03 10:32:33 +02:00
Akim Demaille 26aef31552 examples: beware of portability issues with readline
On OpenBSD 6.5, the prompt is repeated, but not the actual command
line...  Don't try to cope with that.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00015.html

* examples/c/bistromathic/bistromathic.test: Skip when readline behave
this way.
2020-05-03 10:32:33 +02:00
Akim Demaille 392f3caef6 examples: beware of the portability of flex --header-file
The option --header was introduced in version 2.5.6.
The option --header-file was introduced in version 2.6.4.
Reported by Bruno Haible.
https://lists.gnu.org/r/bug-bison/2020-05/msg00013.html

So use --header, and do bother with versions that don't support it.

* m4/flex.m4: Check whether flex supports --header.
* configure.ac (FLEX_WORKS, FLEX_CXX_WORKS): Set to false if it doesn't.
* * examples/c/reccalc/local.mk, examples/c/reccalc/Makefile:
Use --header rather than --header-file.
2020-05-03 10:32:32 +02:00
Akim Demaille ccaa8e29f9 c++: provide backward compatibility on by_type
To write unit tests for their scanners, some users depended on
symbol_type::token():

    Lexer lex("12345");
    symbol_type t = lex.nextToken();
    assert(t.token() == token::INTLIT);
    assert(t.value.as<int>() == 12345);

But symbol_type::token() was removed in Bison 3.5 because it relied on
a conversion table.  So users had to find other patterns, such as

    assert(t.type_get() == by_type(token::INTLIT).type_get());

which relies on several private implementation details.

As part of transitioning from "token type" to "token kind", and making
this a public and documented interface, "by_type" was renamed
"by_kind" and "type_get()" was renamed as "kind()".  The latter had
backward compatibility mechanisms, not the former.

In Bison 3.6 none of this should be used, but rather

    assert(t.kind() == symbol_kind::S_INTLIT);

Reported by Pramod Kumbhar.
https://lists.gnu.org/r/bug-bison/2020-05/msg00012.html

* data/skeletons/c++.m4 (by_type): Make it an alias to by_kind.
2020-05-03 09:20:08 +02:00
Akim Demaille 76c3bccf40 yacc.c: improve formatting of the generated code
* data/skeletons/yacc.c (yy_reduce_print): here.
2020-05-02 10:17:01 +02:00
Akim Demaille 6275137378 doc: java supports push parsers since 3.0 (2013-07-25)
* doc/bison.texi: Clarify this.
2020-05-02 09:29:05 +02:00
Akim Demaille d0571c846f java: fix coding style
I don't plan to fix everything in one go.  But this was in the way of
the next commit.

* data/skeletons/lalr1.java: Avoid space before parens.
* tests/java.at: Adjust.
2020-05-02 09:27:16 +02:00
Akim Demaille 8c1002e4b7 style: comment changes
* tests/java.at: here.
2020-05-02 09:08:26 +02:00
Akim Demaille dbd8fd71ba todo: more 2020-05-02 08:18:20 +02:00
Akim Demaille 95bac741c3 style: more documentation about errs
Suggested by Angelo Borsotti.
https://lists.gnu.org/r/bug-bison/2014-02/msg00003.html

* src/state.h: here.
2020-05-02 08:18:20 +02:00
Akim Demaille f8ab4d81c0 doc: document the exit status
Suggested by Alexandre Duret-Lutz.
https://lists.gnu.org/r/bug-bison/2013-09/msg00015.html

* doc/bison.texi (Invocation): Here.
2020-05-01 10:48:44 +02:00
Akim Demaille d55c9b001a java: add missing i18n requests
* data/skeletons/lalr1.java (reportSyntaxError): Here.
2020-05-01 10:36:05 +02:00
Akim Demaille 611495999f java: style: fix coding style of yyerror/reportSyntaxError
* data/skeletons/lalr1.java: here.
2020-05-01 10:36:05 +02:00
Akim Demaille 01d5f232a9 java: avoid useless work
* data/skeletons/lalr1.java (yySymbolPrint): Avoid the computation of
the argument if useless.
While at it, fix Java coding style.
2020-05-01 10:36:05 +02:00
Akim Demaille 0407acbc59 java: comment changes
* data/skeletons/lalr1.java, examples/java/calc/Calc.y: here.
2020-05-01 10:36:05 +02:00
Akim Demaille 0c0e778bd1 news: make it more consistent
* NEWS: Use the same pattern for titles.
2020-05-01 10:36:05 +02:00
Akim Demaille 30357ae942 c++: use modern idioms to make classes non-copyable
Reported by Don Macpherson.
https://lists.gnu.org/r/bug-bison/2019-05/msg00015.html
https://github.com/akimd/bison/issues/36

* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/variant.hh: Delete the copy-ctor and the copy operator.
2020-05-01 06:52:04 +02:00
Akim Demaille fb1d76d9a9 yacc.c: avoid the use of a temporary
* data/skeletons/yacc.c: Use YYLLOC_DEFAULT directly with the final
destination.
2020-04-30 08:07:55 +02:00
Akim Demaille a61bc3f9f8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-29 09:07:50 +02:00
Akim Demaille f0942df01a version 3.5.91
* NEWS: Record release date.
2020-04-29 08:47:35 +02:00
Akim Demaille 52ababbc89 build: fix syntax-check issues
* cfg.mk: We do want to gettextize the examples.
* po/POTFILES.in: Adjust.
2020-04-29 08:47:04 +02:00
Akim Demaille 8e11933e41 gnulib: update 2020-04-29 08:32:25 +02:00
Akim Demaille 99efa35369 doc: document YYEOF, YYUNDEF and YYerror
* doc/bison.texi (Special Tokens): New.
* examples/c/bistromathic/parse.y: Formatting changes.
2020-04-29 08:23:55 +02:00
Akim Demaille 547545a795 package: fix distcheck
Bison emits strings to translate in the generated code, for builtin
tokens.  So they appear only in generated parsers, which are not
shipped, so they are not in the src tree, so we cannot use them in our
POTFILE.

Except src/parse-gram.c, which is in the source tree.  And even in the
git repo.  But to avoid useless diffs in the repo, we do not keep the
src/parse-gram.c _with_ the #lines.  This is done in a dist-hook which
regenerates src/parse-gram.c when we run "make dist".

Unfortunately, then, update-po traverses the whole tree and sees that
the location of the strings to translate in src/parse-gram.c have
changed, so the bison.pot is to be updated.  And that is not possible
in the "make dist" which is run within "make distcheck"
(not the one preparing the dist for distcheck, the one run by
distcheck to check that a distributed tarball can build a tarball)
because then the src tree is read-only.

So let's not put src/parse-gram.c in the POTFILE, and expose these
strings to gettextize by hand.

* src/i18n-strings.c: New.
* po/POTFILES.in: Add it, and remove src/parse-gram.c.
2020-04-29 07:01:22 +02:00
Akim Demaille 1b5cf80e32 style: avoid gettextize warnings
* src/scan-gram.l, src/scan-skel.l: Help it see the start and end of
"character literals".
2020-04-29 07:01:22 +02:00
Akim Demaille 4c641c5189 tests: beware of portability of readline
* examples/test: here.
2020-04-29 07:01:22 +02:00
Akim Demaille 3b05de2d05 yacc.c: install backward compatibility for YYERRCODE
Some people have been using that symbol.  Some even have #defined it
themselves.
https://lists.gnu.org/r/bison-patches/2020-04/msg00138.html

Let's provide backward compatibility, having it point to YYUNDEF, so
that an error message is generated.

* data/skeletons/yacc.c (YYERRCODE): New, at the exact same location
it was defined before.
2020-04-28 08:26:49 +02:00
Akim Demaille 902a235ad3 style: c++: s/type/kind/ where appropriate
These are internal details.  `type_get ()` is still there to ensure
backward compatibility, `kind ()` being the modern way.

* data/skeletons/c++.m4 (by_type, by_type::type): Rename as...
(by_kind, by_kind::kind_): this.
Adjust dependencies.
2020-04-28 08:16:05 +02:00
Akim Demaille 11027558c8 java: clean up the definition of token kinds
From

    public interface Lexer {
      /* Token kinds.  */
      /** Token number, to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token number, to be returned by the scanner.  */
      static final int YYERRCODE = 256;
      /** Token number, to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token number, to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use b4_symbol(0, id) instead.  */
      public static final int EOF = YYEOF;

to

    public interface Lexer {
      /* Token kinds.  */
      /** Token "end of file", to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token error, to be returned by the scanner.  */
      static final int YYerror = 256;
      /** Token "invalid token", to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token "!", to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use YYEOF instead.  */
      public static final int EOF = YYEOF;

* data/skeletons/java.m4 (b4_token_enum): Display the symbol's tag in
comment.
* data/skeletons/lalr1.java: Address overquotation issue.
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: Use YYEOF,
not EOF.
2020-04-28 07:56:00 +02:00
Akim Demaille cd4e799da4 error: rename the error token from YYERRCODE to YYerror
See https://lists.gnu.org/r/bison-patches/2020-04/msg00162.html.

* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.java, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/scan-gram.l, src/symtab.c
(YYERRCODE): Rename as...
(YYerror): this.
Adjust dependencies.
2020-04-28 07:54:07 +02:00
Akim Demaille 7346163840 dogfooding: use YYERRCODE in our scanner
* src/scan-gram.l: Use it.
* tests/input.at: Adjust.
2020-04-27 08:21:50 +02:00
Akim Demaille 89c4e1becf scanner: avoid spurious errors about empty character literals
On an invalid character literal such as "'\777'" we used to produce
two errors:

    input.y:2.9-12: error: invalid number after \-escape: 777
    input.y:2.8-13: error: empty character literal

Get rid of the second one.

* src/scan-gram.l (STRING_GROW_ESCAPE): New.
* tests/input.at: Adjust.
2020-04-27 08:06:49 +02:00
Akim Demaille 3262747c5b scanner: bad character literals are errors
* src/scan-gram.l: These are errors, not warnings.
* tests/input.at: Adjust.
2020-04-27 07:17:04 +02:00
Akim Demaille 5f3cd49acc regen 2020-04-27 07:08:55 +02:00
Akim Demaille e6d928c4e8 todo: update 2020-04-26 19:55:52 +02:00
Akim Demaille b254b36db8 all: don't emit an error message when the scanner returns YYERRCODE
I'm quite pleased to see that the tricky case of glr.c was already
prepared by the changes to support syntax_error exceptions.  Better
yet, it is actually syntax_error that becomes a special case of the
general pattern: make yytoken be YYERRCODE.

* data/skeletons/glr.c (YYFAULTYTOK): Remove the now useless (Basil)
Faulty token.
Instead, use the error token.
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: When computing
the action, first check the case of the error token.

* tests/calc.at: Check cases for the error token symbols before and
after it.
2020-04-26 19:55:52 +02:00
Akim Demaille 58e79539fc c: don't emit an error message when the scanner returns YYERRCODE
* data/skeletons/yacc.c (yyparse): When the scanner returns YYERRCODE,
go directly to error recovery (yyerrlab1).
However, don't keep the error token as lookahead, that token is too
special.
* data/skeletons/lalr1.cc: Likewise.

* examples/c/bistromathic/parse.y (yylex): Use that feature to report
nicely invalid characters.
* examples/c/bistromathic/bistromathic.test: Check that.
* examples/test: Neutralize gratuitous differences such as rule
position.

* tests/calc.at: Check that case in C only.
The other case seem to be working, but that's an illusion that the
next commit will address (in fact, they can enter endless loops, and
report the error several times anyway).
2020-04-26 18:05:30 +02:00
Akim Demaille 60366b152b examples: bistromathic: demonstrate error recovery
* examples/c/bistromathic/parse.y: here.
* examples/c/bistromathic/bistromathic.test: Check it.
Included a stupid case where the error is actually ignored.
2020-04-26 16:08:47 +02:00
Akim Demaille c90110efd3 examples: bistromathic: when quitting, close the current line
When the user ctrl-d the line, we left the cursor not at col 0.
Let's fix that.
This revealed a few short-comings in the testing framework.

* examples/test (run): Also display the diffs.
And support -n.
* examples/c/bistromathic/bistromathic.test
* examples/c/bistromathic/parse.y
2020-04-26 16:08:47 +02:00
Akim Demaille 3b50adf7f4 examples: bistromathic: comment changes
* examples/c/bistromathic/parse.y: here.
2020-04-26 16:08:47 +02:00
Akim Demaille 3aaa971096 doc: hacking tricks
* README-hacking.md: Here.
2020-04-26 16:08:42 +02:00
Akim Demaille 7eabe1c70b c++: make valid to print the empty symbol
* data/skeletons/lalr1.cc (yy_print_): here.
2020-04-26 15:09:52 +02:00
Akim Demaille 7fec669e42 c++: always define symbol_name
* data/skeletons/lalr1.cc (symbol_name): Always define it, even when
it's actually yytname which is used.
2020-04-26 15:09:52 +02:00
Akim Demaille cbbbe12e02 c++: fix a few style issues
* data/skeletons/lalr1.cc (yystack_print_, yy_reduce_print_): Add
missing const.
(yystack_print_): Rename as...
(yy_stack_print_): this.
* data/skeletons/glr.cc (yy_symbol_value_print_, yy_symbol_print_):
Add missing const.
2020-04-26 15:09:52 +02:00
Akim Demaille 286d0755f8 all: prefer YYERRCODE to YYERROR
We will not keep YYERRCODE anyway, it causes backward compatibility
issues.  So as a first step, let all the skeletons use that name,
until we have a better one.

* data/skeletons/bison.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c, doc/bison.texi, tests/headers.at,
* tests/input.at:
here.
2020-04-26 15:09:51 +02:00
Akim Demaille 1c3d79b871 style: glr.c: clarify
* data/skeletons/glr.c: Make the code a bit clearer.
2020-04-26 14:49:26 +02:00
Akim Demaille 9c72d3c5a8 style: prefer b4_has_translations_if
* data/skeletons/glr.c, data/skeletons/yacc.c: here.
2020-04-26 13:34:30 +02:00
Akim Demaille bc083be055 style: glr.c: fix indentation issue
* data/skeletons/glr.c (yyparse): here.
2020-04-26 10:57:23 +02:00
Akim Demaille 22eeb1ab8a style: fix a few remaining 'type' instead of 'kind'
* data/skeletons/glr.c, data/skeletons/yacc.c (YY_SYMBOL_PRINT):
Here.
2020-04-26 10:57:22 +02:00
Akim Demaille c4dbc1776c skeletons: make the warning about implementation details clearer
* data/skeletons/bison.m4 (b4_disclaimer): Here.
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: Use it.
2020-04-26 10:57:02 +02:00
Akim Demaille b74fc07d21 style: c: fix a few minor issues about indentation of cpp directives
* README-hacking.md: More about cpp.
* data/skeletons/c.m4, data/skeletons/yacc.c: Style changes.
2020-04-25 12:16:57 +02:00
Akim Demaille 3ab12c1036 bench: store in benches/012 rather than in benches/12
* etc/bench.pl.in ($basedir): New.
Format $count with a least three digits.
2020-04-25 11:34:06 +02:00
Akim Demaille 30ce43b2b5 bench: minor improvements
* etc/bench.pl.in: Don't force parse.error=detailed
Use a simpler way to display the pseudo %bison directive.
(&bench_with_gbenchmark): Give details about the compiler.
2020-04-25 11:06:16 +02:00
Akim Demaille 150dc95395 style: clarify #endif
We could try to avoid the weird "#if 1", but then the indentation of
the inner #if would be wrong.  Let' keep it this way.

* data/skeletons/yacc.c: here.
Also, avoid sticking the comment to the directive.
2020-04-25 11:06:16 +02:00
Akim Demaille bb7c4a5508 style: minor fixes
* data/skeletons/bison.m4, doc/bison.texi: Spell check.
* examples/c/bistromathic/parse.y (N_): Remove, now useless.
2020-04-25 08:00:08 +02:00
Akim Demaille 5c9f50b545 examples: bistromathic: shorten token description
* examples/c/bistromathic/parse.y: "number" is enough.
* doc/bison.texi: Likewise.
2020-04-24 19:03:12 +02:00
Akim Demaille b42702d738 examples: bistromathic: demonstrate internationalization
Currently it was only using stubs.  Let's actually translate the
strings using gettext.

* examples/c/bistromathic/local.mk: Define LOCALEDIR, BISON_LOCALEDIR
and link with libintl.
* examples/c/bistromathic/parse.y: Use them.
Remove useless includes.
Take ENABLE_NLS into account.
(error_format_string): New.
(yyreport_syntax_error): Rewrite to rely on a format string, which is
more appropriate for internationalization.
* examples/c/bistromathic/Makefile: We no longer use Flex.
We need readline and intl.

* doc/bison.texi: Point to bistromathic for a better option for
internationalization.
* po/POTFILES.in: Add bistromathic.
2020-04-24 19:03:12 +02:00
Akim Demaille 401e7c5c36 todo: update for YYERRCODE 2020-04-24 19:03:12 +02:00
Akim Demaille 93fec67c46 regen 2020-04-24 08:23:27 +02:00
Akim Demaille 4378e2dc3c diagnostics: fix a typo
* src/complain.c: here.
2020-04-24 08:22:22 +02:00
Akim Demaille 81334eb5a0 c, c++: provide a default definition for N_
In C/C++, N_ is a no-op.  Define it if the user didn't.
Suggested by Frank Heckenbach.
https://lists.gnu.org/r/bug-bison/2020-04/msg00010.html

* src/output.c (prepare_symbol_names): Rename has_translations as
has_translations_flag.
* data/skeletons/bison.m4 (b4_has_translations_if): New.
* data/skeletons/java.m4 (b4_trans): Use it.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
(N_): Provide a default definition.
2020-04-20 07:37:45 +02:00
Akim Demaille df373f1ea1 i18n: also look in src/parse-gram.c
Some strings appears in the generated file only, e.g., translation of
"end of file".  So don't forget to go and see there.
2020-04-19 15:40:12 +02:00
Akim Demaille 9b7e7077dd style: fix comments
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c: here.
2020-04-19 15:40:12 +02:00
Akim Demaille 5ab0086157 tokens: clean up the translation of special symbols
* src/output.c (prepare_symbol_names): Don't play tricks with the
symbols, it's quite too late.
(has_translations): Move to...
* src/symtab.c: here.
(symbols_pack): Use it to enable translation for special symbols.
2020-04-19 15:40:12 +02:00
Akim Demaille 2831bd376f news: fix typo
Reported by Frank Heckenbach.
2020-04-19 08:20:57 +02:00
Akim Demaille 1d0e3ee896 tests: beware of portability issues with wc
On macOS, wc -l always prepends the result with a tab, even when fed
by stdin.  But anyway, we should have used `grep -c -v`, which appears
to be portable according to Autoconf's "Limitations of Usual Tools"
section.
Reported by Denis Excoffier.
https://lists.gnu.org/r/bug-bison/2020-04/msg00009.html

* tests/calc.at (_AT_CHECK_CALC): Use grep's -c instead.
2020-04-19 08:12:31 +02:00
Akim Demaille 0a64b76430 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-18 10:59:05 +02:00
Akim Demaille 0b948b7696 version 3.5.90
* NEWS: Record release date.
2020-04-18 10:41:20 +02:00
Akim Demaille 8b5fb7c4c3 examples: beware of readline on macOS
macOS' version of readline does not repeat stdin on stdout in
non-interactive mode, contrary to the current version of GNU readline.

* examples/test: Add support for strip_prompt.
* examples/c/bistromathic/bistromathic.test (strip_prompt): Set it
when needed.
Early exit when needed.
2020-04-18 10:37:13 +02:00
Akim Demaille d6ae95fb50 c++: give public access to the symbol kind
symbol_type::token () was removed: it returned the token kind of a
symbol.  To do that, one needs to convert from the symbol kind to the
token kind, which requires a table.

This broke some users' unit tests for scanners, see
https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html
https://lists.gnu.org/r/bug-bison/2020-03/msg00020.html
https://lists.gnu.org/r/help-bison/2020-04/msg00005.html

Instead of making this possible again, let's check the symbol's kind
instead.  So give proper access to a symbol's kind.

That feature existed, undocumented, as 'type_get()'.  Let's rename
this as 'kind()'.

* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc (type_get): Rename as...
(kind): This.
(type_get): Install a backward compatibility alias.
* doc/bison.texi (Complete Symbols): Document symbol_type and
symbol_type::kind.
2020-04-18 08:03:59 +02:00
Akim Demaille e86b14069d doc: token_kind_type in C++
* data/skeletons/c++.m4: Define the old names in terms on the new
ones, instead of the converse.
* doc/bison.texi (C++ Parser Interface): Be more extensive about
token_kind_type.
2020-04-17 08:53:37 +02:00
Akim Demaille 5d983253f7 doc: updates for 3.6
* doc/bison.texi: More s/token type/token kind/.
* NEWS: Update.
2020-04-16 08:44:36 +02:00
Akim Demaille caadfc552b skeletons: use symbol(-2, kind)
Not all the symbols have a fixed symbol code.  UNDEF's one is fixed:
-2.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c: here.
2020-04-16 07:35:06 +02:00
Akim Demaille c4c25e091c style: comments changes about error handling
* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: here.
* data/skeletons/lalr1.cc: Reduce scope.
2020-04-16 07:34:37 +02:00
Akim Demaille fc18b4313a examples: bistro: don't be lazy with switch
* examples/c/bistromathic/parse.y (yylex): Use the switch to
discriminate all the cases.
2020-04-14 08:20:05 +02:00
Akim Demaille 758172a8b9 doc: spell check
* doc/bison.texi, NEWS, README-hacking.md: here.
And elsewhere.
2020-04-13 18:50:05 +02:00
Akim Demaille e9454c3456 gnulib: update 2020-04-13 17:47:20 +02:00
Akim Demaille 8f01cf0269 doc: more about the coding style
* README-hacking.md: here.
(Troubleshooting): New.
2020-04-13 17:08:53 +02:00
Akim Demaille dab08da605 java: promote YYEOF rather that Lexer.EOF
* doc/bison.texi: here.
* data/skeletons/lalr1.java: Use YYEOF.
2020-04-13 17:08:53 +02:00
Akim Demaille 8cedb4b40e java: fix names
* data/skeletons/lalr1.java (yySymbolPrint): There are no pointers
here, remove the `p` suffix.
Use the appropriate type for locations.
2020-04-13 17:04:34 +02:00
Akim Demaille 258c2c967f doc: java: SymbolKind, etc.
Why didn't I think about this before???  symbolName should be a method
of SymbolKind.

* data/skeletons/lalr1.java (YYParser::yysymbolName): Move as...
* data/skeletons/java.m4 (SymbolKind::getName): this.
Make the table a static final table, not a local variable.
Adjust dependencies.
* doc/bison.texi (Java Parser Interface): Document i18n.
(Java Parser Context Interface): Document SymbolKind.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-13 16:54:48 +02:00
Akim Demaille 9a33570493 style: java: get closer to the Java style
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
2020-04-13 16:54:14 +02:00
Akim Demaille 42ab6c1e44 doc: c++: document parser::context
* doc/bison.texi (C++ Parser Context): New.

* data/skeletons/lalr1.cc (parser::yysymbol_name): Rename as...
(parser::symbol_name): this.
(A Complete C++ Example): Promote LAC, now that we have it.
Promote parse.error detailed over verbose.
* examples/c++/calc++/calc++.test, tests/local.at: Adjust.
2020-04-13 16:54:14 +02:00
Akim Demaille dc1035bada doc: promote YYEOF
* NEWS (Deep overhaul of the symbol and token kinds): New.
* doc/bison.texi: Promote YYEOF over "0" in scanners.
(Token Decl): No longer show YYEOF here, it now works by default.
(Token I18n): More details about YYEOF here.
(Calc++): Just use YYEOF.
2020-04-13 16:54:14 +02:00
Akim Demaille 71e3f6d4da d: put YYEMPTY in the TokenKind
* data/skeletons/d.m4, data/skeletons/lalr1.d (b4_token_enums): Rename
YYTokenType as TokenKind.
Define YYEMPTY.
* examples/d/calc.y, tests/calc.at, tests/scanner.at: Adjust.
2020-04-13 16:49:54 +02:00
Akim Demaille 3877b7210e regen 2020-04-13 16:49:54 +02:00
Akim Demaille 64aec0a8d8 c, c++: also define YYEMPTY in yytoken_kind_t
I have been hesitating a lot before doing it ---after all the user
must not use this kind, so what's the point of showing it in
yytoken_kind_t.  And eventually I chose to play it safe with the
typing system and make it possible to use yytoken_kind_t for all the
tokens, even the "empty token".

* data/skeletons/c.m4: Give an id and a tag to YYEMPTY.
(b4_token_enums): Define YYEMPTY.
* data/skeletons/c++.m4 (b4_token_enums): Define YYEMPTY.
* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/yacc.c:
(YYEMPTY): Remove.
Use b4_symbol(-2, id) instead.
2020-04-13 16:49:48 +02:00
Akim Demaille 5e2e9af56d doc: use "code", not "number", for token (and symbol) kinds
"Number" is too much about arithmethics.  "Code" conveys better the
"enum" nature of token kinds.  And of symbol kinds.

* doc/bison.texi: Here.
2020-04-12 19:24:44 +02:00
Akim Demaille 7a226860ef doc: promote yytoken_kind_t, not yytokentype
* data/skeletons/c.m4 (yytoken_kind_t): New.
* data/skeletons/c++.m4, data/skeletons/lalr1.cc (yysymbol_kind_type):
New.
* examples/c/lexcalc/parse.y, examples/c/reccalc/parse.y,
* tests/regression.at:
Use them.
* doc/bison.texi: Replace "enum yytokentype" by "yytoken_kind_t".
(api.token.raw): Explain that it forces "yytoken_kind_t" to coincide
with "yysymbol_kind_t".
(Calling Convention): Mention YYEOF.
(Table of Symbols): Add entries for "yytoken_kind_t" and
"yysymbol_kind_t".
(Glossary): Add entries for "Kind", "Token kind" and "Symbol kind".
2020-04-12 19:24:12 +02:00
Akim Demaille c973361138 doc: document yypcontext_t, and api.symbol.prefix
* doc/bison.texi (%define Summary): Document api.symbol.prefix.
(Syntax Error Reporting Function): Document yypcontext_t,
yypcontext_location, yypcontext_token, yypcontext_expected_tokens, and
yysymbol_kind_t.
2020-04-12 19:24:02 +02:00
Akim Demaille 5839f4d289 c: rename yyexpected_tokens as yypcontext_expected_tokens
The user should think of yypcontext fields as accessible only via
yypcontext_* functions.  So let's rename yyexpected_tokens to reflect
that.

Let's _not_ rename yyreport_syntax_error, as the user may define this
function, and is not allowed to access directly the fields of
yypcontext_t: she *must* use the "accessors".  This is comparable to
the case of C++/Java where the user defines
parser::report_syntax_error, not parser::context::report_syntax_error.

* data/skeletons/glr.c, data/skeletons/yacc.c (yyexpected_tokens):
Rename as...
(yypcontext_expected_tokens): this.
Adjust dependencies.
2020-04-12 19:23:40 +02:00
Akim Demaille ffa46e6516 skeletons: clarify the tag of special tokens
From

    GRAM_EOF = 0,                  /* $end  */
    GRAM_ERRCODE = 1,              /* error  */
    GRAM_UNDEF = 2,                /* $undefined  */

to

    GRAM_EOF = 0,                  /* "end of file"  */
    GRAM_ERRCODE = 1,              /* error  */
    GRAM_UNDEF = 2,                /* "invalid token"  */

* src/output.c (symbol_tag): New.
Use it to pass the token names and the symbol tags to the skeletons.

* tests/input.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille ff50f6f223 skeletons: use "invalid token" instead of "$undefined"
* src/output.c (prepare_symbol_names): Also handle undeftoken.
* tests/actions.at, tests/calc.at, tests/regression.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille 05be0fef95 skeletons: make the eof token translatable if i18n is enabled
* src/output.c (has_translations): New.
(prepare_symbol_names): Translate endtoken if the user already
translated tokens.

* examples/c/bistromathic/parse.y, src/parse-gram.y: Simplify.
2020-04-12 13:56:44 +02:00
Akim Demaille 72c9fa4510 skeletons: use "end of file" instead of "$end"
The name "$end" is nice in the report, in particular it avoids that
pointed-rules (aka items) be too long.  It also helps keeping them
"standard".

But it is bad in error messages, we should report "end of file" (or
maybe "end of input", this is debatable).  So, unless the user already
defined the alias for the error token herself, make it "end of file".
It should even be translated if the user already translated some
tokens, so that there is now no strong reason to redefine the $end
token.

* src/output.c (prepare_symbol_names): Issue "end of file" instead of
"$end".

* data/skeletons/lalr1.java (yytnamerr_): Remove the renaming hack.

* build-aux/update-test: Accept files with names containing a "+",
such as c++.at.
* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/glr-regression.at, tests/regression.at, tests/skeletons.at:
Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille a555b41990 diagnostics: replace "user token number" by "token code"
Yet, don't change the structure identifier to avoid introducing
conflicts in Vincent Imbimbo's PR (which, amusingly enough, is about
conflicts).

* src/symtab.c: here.
* tests/diagnostics.at, tests/input.at: Adjust.
2020-04-12 13:56:44 +02:00
Akim Demaille ecf5cb7e0e c++: remove the yy prefix from some functions
yy::parser features a parse() function, not a yyparse() one.

* data/skeletons/lalr1.cc (yyreport_syntax_error)
(context::yyexpected_tokens): Rename as...
(report_syntax_error, context::expected_tokens): these.
2020-04-12 13:56:44 +02:00
Akim Demaille e50de09886 tokens: properly define the YYEOF token kind
Currently EOF is handled in an adhoc way, with a #define YYEOF 0 in
the implementation file.  As a result, the user has to define her own
EOF token if she wants to use it, which is a pity.

Give the $end token a visible kind name, YYEOF.  Except that in C,
where enums are not scoped, we would have collisions between all the
definitions of YYEOFs in the header files, so in C, make it
<api.PREFIX>EOF.

* data/skeletons/c.m4 (YYEOF): Override its name to avoid collisions.
Unless the user already gave it a different name.
* data/skeletons/glr.c (YYEOF): Remove.
Use ]b4_symbol(0, [id])[ instead.
Add support for "pre_epilogue", for glr.cc.
* data/skeletons/glr.cc: Remove dead code (never emitted #undefs).
* data/skeletons/yacc.c
* src/parse-gram.c
* src/reader.c
* src/symtab.c
* tests/actions.at
* tests/input.at
2020-04-12 13:56:44 +02:00
Akim Demaille 95421df67b tokens: define the "$undefined" token kind
* data/skeletons/bison.m4 (b4_symbol_token_kind): Give a definition to
$undefined.
(b4_token_visible_if): $undefined has an id.
* src/output.c (prepare_symbol_definitions): Stop lying: $undefined
_is_ a token.
* tests/input.at: Adjust.
2020-04-12 13:56:43 +02:00
Akim Demaille a4ed94bc13 tokens: properly define the "error" token kind
There are people out there that do use YYERRCODE (the token kind of
the error token).  See for instance
https://github.com/borbolla-automation/SPC_Machines/blob/3812012bb782bfdfe7b325950a35cd337925fcad/unixODBC-2.3.2/Drivers/nn/yylex.c.

Currently, YYERRCODE is defined by yacc.c in an adhoc way as a #define
in the *.c file only.  It belongs with the other token kinds.

YYERRCODE is not a nice name, it does not fit in our naming scheme.
YYERROR would be more logical, but it collides with the YYERROR macro.
Shall we keep the same name in all the skeletons?  Besides, to avoid
collisions in C, we need to apply the api prefix: YYERRCODE is
actually <PREFIX>ERRCODE.  This is not needed in the other languages.

* data/skeletons/bison.m4 (b4_symbol_token_kind): New.
Map the error token to "YYERRCODE".
* data/skeletons/yacc.c (YYERRCODE): Don't define it, it's handled by...
* src/output.c (prepare_symbol_definitions): this.
* tests/input.at (Redefining the error token): Check it.
2020-04-12 13:56:43 +02:00
Akim Demaille 07726f1178 tokens: style: minor fixes
* data/skeletons/bison.m4 (b4_symbol_kind): Dispatch on the UNDEF
token number rather than its name.
* data/skeletons/c++.m4, data/skeletons/c.m4, data/skeletons/java.m4:
Comment changes.
2020-04-12 13:56:43 +02:00
Akim Demaille e78596955d glr.cc: remove dead code
* data/skeletons/glr.cc: here.
2020-04-12 13:56:43 +02:00
Akim Demaille ecd5cae2d4 c++: fix generated headers
A forthcoming commit (tokens: properly define the "error" token kind)
revealed a problem in the C++ generated headers: they are not
self-contained.  With this file:

    %language "c++"
    %define api.value.type variant

    %code {
      static int yylex (yy::parser::semantic_type *lvalp);
    }

    %token <int> X

    %%

    exp:
      X { printf ("x\n"); }
    ;

    %%

    void
    yy::parser::error (const std::string& m)
    {
      std::cerr << m << '\n';
    }

    static
    int yylex (yy::parser::semantic_type *lvalp)
    {
      static int const input[] = {yy::parser::token::X, 0};
      static int toknum = 0;
      return input[toknum++];
    }

    int
    main (int argc, char const* argv[])
    {
      yy::parser p;
      return p.parse ();
    }

the generated header fails to compile cleanly (foo.cc just #includes
the generated header):

    $ clang++-mp-9.0 -c -Wundefined-func-template foo.cc
    In file included from foo.cc:1:
    bar.tab.hh:550:12: warning: instantiation of function 'yy::parser::basic_symbol<yy::parser::by_type>::basic_symbol' required here, but no definition is available
          [-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    bar.tab.hh:436:7: note: forward declaration of template entity is here
          basic_symbol (basic_symbol&& that);
          ^
    bar.tab.hh:550:12: note: add an explicit instantiation declaration to suppress this warning if 'yy::parser::basic_symbol<yy::parser::by_type>::basic_symbol' is explicitly instantiated
          in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 warning generated.

* data/skeletons/c++.m4 (b4_public_types_define): Move the
implementation of the basic_symbol move-ctor to...
(b4_public_types_define): here, its declaration.
* tests/headers.at (Sane headers): Use a declared token so that the
corresponding token constructor is declared.  Which triggers the
aforementioned issue.
2020-04-12 13:56:21 +02:00
Akim Demaille 8dcc25a1e4 style: rename YYNOMEM as YYENOMEM
This is clearer.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): Rename as...
(YYENOMEM): here.
2020-04-10 18:35:29 +02:00
Akim Demaille 1a5f74d2f6 todo: update 2020-04-10 18:35:29 +02:00
Akim Demaille 00a654c8ad c++: improvements on symbol kinds
Instead of

    /// (Internal) symbol kind.
    enum symbol_kind_type
    {
      YYNTOKENS = 5, ///< Number of tokens.
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      // END_OF_FILE
      YYSYMBOL_YYERROR = 1,                    // error
      YYSYMBOL_YYUNDEF = 2,                    // $undefined
      YYSYMBOL_TEXT = 3,                       // TEXT
      YYSYMBOL_NUMBER = 4,                     // NUMBER
      YYSYMBOL_YYACCEPT = 5,                   // $accept
      YYSYMBOL_result = 6,                     // result
      YYSYMBOL_list = 7,                       // list
      YYSYMBOL_item = 8                        // item
    };

generate

    /// Symbol kinds.
    struct symbol_kind
    {
      enum symbol_kind_type
      {
        YYNTOKENS = 5, ///< Number of tokens.
        S_YYEMPTY = -2,
        S_YYEOF = 0,                             // END_OF_FILE
        S_YYERROR = 1,                           // error
        S_YYUNDEF = 2,                           // $undefined
        S_TEXT = 3,                              // TEXT
        S_NUMBER = 4,                            // NUMBER
        S_YYACCEPT = 5,                          // $accept
        S_result = 6,                            // result
        S_list = 7,                              // list
        S_item = 8                               // item
      };
    };

* data/skeletons/c++.m4 (api.symbol.prefix): Define to S_.
Adjust all the uses.
(b4_public_types_declare): Nest the enum inside 'struct symbol_kind'.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* tests/headers.at, tests/local.at: Adjust.
2020-04-10 18:35:29 +02:00
Akim Demaille 6c5f690da4 d: improvements on symbol kinds
public enum SymbolKind
    {
      S_YYEMPTY = -2,    /* No symbol.  */
      S_YYEOF = 0,       /* $end  */
      S_YYERROR = 1,     /* error  */
      S_YYUNDEF = 2,     /* $undefined  */
      S_EQ = 3,          /* "="  */

* data/skeletons/d.m4 (api.symbol.prefix): Default to S_.
Output the symbol kind definitions with a comment.
2020-04-10 18:35:29 +02:00
Akim Demaille 007e1b5f0a symbols: minor fixes
* data/skeletons/bison.m4 (b4_symbol_kind): Series of _ are useless,
one is enough.
* data/skeletons/c.m4 (b4_token_enum): Fix overquoting.
2020-04-10 18:33:02 +02:00
Akim Demaille bbb9750b3e skeletons: introduce api.symbol.prefix
* data/skeletons/bison.m4 (b4_symbol_prefix): New.
(b4_symbol_kind): Use it.
* data/skeletons/c++.m4, data/skeletons/c.m4, data/skeletons/d.m4
* data/skeletons/java.m4 (api.symbol.prefix): Provide a default value.

* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java, data/skeletons/yacc.c:
Adjust: use b4_symbol_prefix instead of YYSYMBOL_.
2020-04-07 08:40:16 +02:00
Akim Demaille 52d0e77c2c java: also emit documenting comments for symbol kinds
* data/skeletons/java.m4 (b4_symbol_enum): here.
And stop defined YYSYMBOL_YYEMPTY, we no longer use it.
2020-04-07 08:39:54 +02:00
Akim Demaille 088d5668a9 todo: update
* TODO (YYERRCODE): Remove, handled by YYSYMBOL_ERROR.
2020-04-06 19:20:02 +02:00
Akim Demaille 87579e03e0 skeletons: beware not to use yyarg when it's null
Reported by Adrian Vogelsgesang.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Here.
2020-04-06 19:14:11 +02:00
Akim Demaille 11225a5d2f java: document new features
* data/skeletons/lalr1.java: More comments.
(Context.EMPTY): Remove.
* doc/bison.texi (Java Parser Context Interface): New.
2020-04-06 19:14:11 +02:00
Akim Demaille 3dcfb4fd88 java: prefer null to YYSYMBOL_YYEMPTY
That's one nice benefit from using enums.

* data/skeletons/lalr1.java (YYSYMBOL_YYEMPTY): No longer define it.
Use 'null' instead.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:11 +02:00
Akim Demaille c0ccb8e5b4 java: rename Lexer.yyreportSyntaxError as reportSyntaxError
* data/skeletons/lalr1.java: here.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:06 +02:00
Akim Demaille 79f967ac0d java: use getExpectedTokens, not yyexpectedTokens
* data/skeletons/lalr1.java, examples/java/calc/Calc.y, tests/local.at:
here.
2020-04-06 18:43:34 +02:00
Akim Demaille 0f6ab8e692 java: style: fix coding style
* data/skeletons/java.m4: Indent by two.
* data/skeletons/lalr1.java (yynnts_): Remove.
(yyfinal_, yyntokens_, yylast_, yyempty_): Rename as...
(YYFINAL_, YYNTOKENS_, YYLAST_, YYEMPTY_): these, they are constants.
2020-04-06 18:43:34 +02:00
Akim Demaille e657f04b62 c: make the symbol kind definition nicer to read
From

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,
      YYSYMBOL_YYERROR = 1,
      YYSYMBOL_YYUNDEF = 2,

to

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
      YYSYMBOL_YYERROR = 1,                    /* error  */
      YYSYMBOL_YYUNDEF = 2,                    /* $undefined  */

* data/skeletons/bison.m4 (b4_last_symbol): New.
(b4_symbol_enum, b4_symbol_enums): Reformat the output.
* data/skeletons/c.m4
2020-04-06 18:43:34 +02:00
Akim Demaille 10e61eec6d c: make the token kind definition nicer to read
From

    enum gram_tokentype
    {
      GRAM_EOF = 0,
      STRING = 3,
      TSTRING = 4,
      PERCENT_TOKEN = 5,

To

    enum gram_tokentype
    {
      GRAM_EOF = 0,                  /* "end of file"  */
      STRING = 3,                    /* "string"  */
      TSTRING = 4,                   /* "translatable string"  */
      PERCENT_TOKEN = 5,             /* "%token"  */

* data/skeletons/bison.m4 (b4_last_enum_token): New.
* data/skeletons/c.m4 (b4_token_enum, b4_token_enums): Show the
corresponding symbol.
2020-04-06 18:43:34 +02:00
Akim Demaille 149e280aab c: make the generated YYSTYPE nicer to read
From

    union GRAM_STYPE
    {
      /* precedence_declarator  */
      assoc precedence_declarator;
      /* "string"  */
      char* STRING;
      /* "translatable string"  */
      char* TSTRING;
      /* "{...}"  */
      char* BRACED_CODE;
      /* "%?{...}"  */

to

    union GRAM_STYPE
    {
      assoc precedence_declarator;             /* precedence_declarator  */
      char* STRING;                            /* "string"  */
      char* TSTRING;                           /* "translatable string"  */
      char* BRACED_CODE;                       /* "{...}"  */

* data/skeletons/c.m4 (b4_symbol_type_register): Use m4_format to
align the comments.
* src/parse-gram.h: Regen.
2020-04-06 18:43:34 +02:00
Akim Demaille e9fddab715 regen 2020-04-05 19:14:39 +02:00
Akim Demaille cc68bbf799 bison: use consistently "token kind", not "token type"
* src/output.c, src/reader.c, src/scan-gram.l, src/tables.c: here.
2020-04-05 19:14:39 +02:00
Akim Demaille f0bb82ae9e skeletons: use consistently "kind" instead of "type" in the code
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java:
Refer to the "kind" of a symbol, not its "type", where appropriate.
2020-04-05 19:14:39 +02:00
Akim Demaille 04d62346f3 doc: refer to the token kind rather than the token type
* doc/bison.texi: Replace occurrences of "token type" with "token
kind".
Stop referring to the "macro definitions" of the token kinds, just
name them "definitions".
2020-04-05 19:14:39 +02:00
Akim Demaille 9b70d69f39 m4: we don't need undef_token_number
It's replaced by YYSYMBOL_YYUNDEF.
2020-04-05 14:56:19 +02:00
Akim Demaille 2b7bde9d13 m4: rename b4_symbol_sid as b4_symbol_kind
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/d.m4, data/skeletons/java.m4
(b4_symbol_sid): Rename as...
(b4_symbol_kind): this.
Adjust dependencies.
* data/README.md: Document the kind.
2020-04-05 14:56:19 +02:00
Akim Demaille ff2fc62138 d, java: rename SymbolType as SymbolKind
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html.

* data/skeletons/d.m4, data/skeletons/lalr1.d,
* data/skeletons/java.m4, data/skeletons/lalr1.java
(SymbolType): Rename as...
(SymbolKind): this.
Adjust dependencies.
2020-04-05 14:56:19 +02:00
Akim Demaille 2c05fc750a c, c++: rename yysymbol_type_t as yysymbol_kind_t
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/yacc.c
(yysymbol_type_t): Rename as...
(yysymbol_kind_t): this.
Adjust dependencies.
* data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/lalr1.cc
(symbol_type_type): Rename as...
(symbol_kind_type): this.
Adjust dependencies.
2020-04-05 14:56:18 +02:00
Akim Demaille 57bc3c9013 doc: remove obsolete release instructions
* README-hacking.md: here.
2020-04-05 14:49:46 +02:00
Akim Demaille 7aee4586ca Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.4
  examples: reccalc: really compile cleanly in C99
  news: announce that Bison 3.6 drops YYERROR_VERBOSE
  news: update for 3.5.4
  style: fix spellos
  typo: succesful -> successful
  package: improve the readme
  java: check and fix support for api.token.raw
  java: style: prefer 'int[] foo' to 'int foo[]'
  build: fix syntax-check issues
  tests: recheck: work properly when the test suite was interrupted
  doc: c++: promote api.token.raw
  build: fix compatibility with old compilers
  examples: reccalc: compile cleanly in C99
2020-04-05 09:38:15 +02:00
Akim Demaille 6c44f2dce3 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-05 09:27:36 +02:00
Akim Demaille 225a67321b news: update the yyreport_syntax_error example
* examples/c/bistromathic/parse.y, tests/local.at
(yyreport_syntax_error): Fix use of YYSYMBOL_YYEMPTY.
* NEWS: Update.
2020-04-05 08:56:23 +02:00
Akim Demaille 4e3c06b0f8 todo: update 2020-04-05 08:56:23 +02:00
Akim Demaille 4e26809ab9 style: rename yysyntax_error_arguments as yy_syntax_error_arguments
It's a private implementation detail.

* NEWS, data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, doc/bison.texi: here.
2020-04-05 08:56:21 +02:00
Akim Demaille 76e11b5a3e c: rename yyparse_context_t as yypcontext_t
The first name is too long.  We already have `yypstate`, so
`yypcontext` is ok.  We are also migrating to using `*_t` for our
types.

* NEWS, data/skeletons/glr.c, data/skeletons/yacc.c, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/parse-gram.y, tests/local.at:
(yyparse_context_t, yyparse_context_location, yyparse_context_token):
Rename as...
(yypcontext_t, yypcontext_location, yypcontext_token): these.
2020-04-04 19:20:29 +02:00
Akim Demaille f9c73eec5f readme: more about the coding style 2020-04-04 19:20:29 +02:00
Akim Demaille f6dcecb287 java: fixes in SymbolType
Reported by Paolo Bonzini.
https://github.com/akimd/bison/pull/34#issuecomment-609029634

* data/skeletons/java.m4 (SymbolType): Use 'final' where possible.
(get): Rewrite on top of an array instead of a switch.
2020-04-04 17:11:02 +02:00
Akim Demaille ad31c3cdf4 java: use SymbolType
The Java enums are very different from the C model.  As a consequence,
one cannot "build" an enum directly from an integer, we must retrieve
it.  That's the purpose of the SymbolType.get class method.

* data/skeletons/java.m4 (b4_symbol_enum, b4_case_code_symbol)
(b4_declare_symbol_enum): New.
* data/skeletons/lalr1.java: Use SymbolType,
SymbolType.YYSYMBOL_YYEMPTY, etc.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille 7fa23136ca examples: java: use explicit token identifiers
* examples/java/calc/Calc.y: Declare all the tokens, so that we are
compatibile with api.token.raw.
* examples/java/calc/Calc.test: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille fd98afaf10 d: use the SymbolType enum for symbol kinds
* data/skeletons/d.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/lalr1.d: Use them.
Use SymbolType, SymbolType.YYSYMBOL_YYEMPTY etc. where appropriate.
(undef_token_, token_number_type, yy_error_token_): Remove.
2020-04-04 10:31:50 +02:00
Akim Demaille a0ee2a7543 c++: replace symbol_number_type with symbol_type_type
* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc: here.
2020-04-01 08:32:58 +02:00
Akim Demaille 7e28dbea11 c++: also use symbol_type_type
Because of the insane current implementation of glr.cc, things are a
bit nasty.  We will rename symbol_number_type as symbol_type_type
later, to keep this commit small.

* data/skeletons/c++.m4 (b4_declare_symbol_enum): New.
Also define YYNTOKENS to avoid type clashes when yyntokens_ was
actually defined in another enum.
Use it.
(symbol_number_type): Be an alias of symbol_type_type.
Use YYSYMBOL_YYEMPTY and the like.
Use symbol_number_type where appropriate.
(empty_symbol): Remove.
(yytranslate_): Use symbol_number_type, not token_number_type.
* data/skeletons/lalr1.cc: Use symbol_number_type where appropriate.
Adjust to the replacement of empty_symbol by YYSYMBOL_YYEMPTY.
(yy_error_token_, yy_undef_token_, yyeof_, yyntokens_): Remove.
Adjust dependencies.

* data/skeletons/glr.cc: Use symbol_number_type where appropriate.
Forward definitions of YYSYMBOL_YYEMPTY, etc. to glr.c.

* tests/headers.at: Accept YYNTOKENS and other YYSYMBOL_*.
* tests/local.at (AT_YYERROR_DEFINE(c++)): Use symbol_number_type.
2020-04-01 08:32:50 +02:00
Akim Demaille 65df8d6747 glr.c: remove the yySymbol alias
* data/skeletons/glr.c: Use yysymbol_type_t only.
2020-04-01 08:31:48 +02:00
Akim Demaille beea39b2ec regen 2020-04-01 08:31:48 +02:00
Akim Demaille 086506bf23 glr.c, yacc.c: propagate yysymbol_type_t
Now that yacc.c and glr.c both know yysymbol_type_t, convert the
common routines.

* data/skeletons/c.m4 (yydestruct, yy_symbol_value_print)
(yy_symbol_print): Use yysymbol_type_t instead of int.
* data/skeletons/glr.c: Use yySymbol where appropriate.
* data/skeletons/yacc.c (YY_ACCESSING_SYMBOL): New wrapper around
yystos.
Use it.
* tests/local.at (yyreport_syntax_error): Use yysymbol_type_t where
appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille 39792f57fb glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc.
Apply the same changes as in yacc.c.  Now yySymbol and yysymbol_type_t
are aliases.  We will remove the former later, to avoid cluttering
this commit.

* data/skeletons/glr.c: Use b4_declare_symbol_enum.
Use YYSYMBOL_YYEOF etc. where appropriate.
(YYUNDEFTOK, YYTERROR): Remove.
(YYTRANSLATE, yySymbol, yyexpected_tokens, yysyntax_error_arguments):
Adjust.
(yy_accessing_symbol): New.
Use it where appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille 65bbaf9598 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 9039c571f4 yacc.c: fix more errors from make maintainer-check-g++
* data/skeletons/yacc.c (yyexpected_tokens): Use casts where needed.
2020-04-01 08:31:48 +02:00
Akim Demaille d3db22d788 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 9434571f95 yacc.c: revert to not using yysymbol_type_t in the yytranslate table
This triggers warnings with several compilers.  For instance ICC fills
the logs with pages and pages of

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
             ^

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
                    ^

And so does G++9 when compiling yacc.c's (C) output

    input.c:545:8: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |        ^
          |        |
          |        int
    input.c:545:15: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |               ^
          |               |
          |               int

Clang++ is no exception

    input.c:545:8: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
           ^
    input.c:545:15: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
                  ^

At some point we could use yysymbol_type_t's enumerators to define
yytranslate.  Meanwhile...

* data/skeletons/yacc.c (yytranslate): Use the original integral type
to define it.
(YYTRANSLATE): Cast the result into yysymbol_type_t.
2020-04-01 08:31:48 +02:00
Akim Demaille 0cdbcee0ce regen 2020-04-01 08:31:48 +02:00
Akim Demaille fd37eb057e yysymbol_type_t: always assign an enumerator
Currently we define enumerators only for symbols that have an
identifier.  That rules out tokens such as '+', and nonterminals such
as foo-bar and foo.bar.  As a consequence we are taking chances: the
compiler might compile yysymbol_type_t as too small an integral type
for some symbol codes.

* data/skeletons/bison.m4 (b4_symbol_sid): Forge a unique symbol
identifier for symbols that don't have an ID.
2020-04-01 08:31:48 +02:00
Akim Demaille ecc3a13c34 bistromathic: use symbol numbers instead of YYTRANSLATE
* examples/c/bistromathic/parse.y: here.
2020-04-01 08:31:48 +02:00
Akim Demaille 04904e4d28 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 75a605454d yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error
* data/skeletons/bison.m4 (b4_symbol_sid): Map "error" to YYSYMBOL_YYERROR.
* data/skeletons/yacc.c: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille d7f39ac507 regen 2020-04-01 08:31:48 +02:00
Akim Demaille f3c18c8e80 yacc.c: also define a symbol number for the empty token
This is not only cleaner, it also protects us from mixing signed
values (YYEMPTY is #defined as -2) with unsigned types (the
yysymbol_type_t enum is typically compiled as a small unsigned).
For instance GCC 9:

    input.c: In function 'yyparse':
    input.c:1107:7: error: conversion to 'unsigned int' from 'int'
                           may change the sign of the result
                           [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |       ^~
    input.c:1107:10: error: conversion to 'int' from 'unsigned int'
                            may change the sign of the result
                            [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |          ^~~~~~~
    input.c:1108:47: error: comparison of integer expressions of
                            different signedness:
                            'yytype_int8' {aka 'const signed char'} and
                            'yysymbol_type_t' {aka 'enum yysymbol_type_t'}
                            [-Werror=sign-compare]
     1108 |   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
          |                                               ^~
    input.c:702:25: error: operand of ?: changes signedness from 'int'
                           to 'unsigned int' due to unsignedness of
                           other operand [-Werror=sign-compare]
      702 | #define YYEMPTY         (-2)
          |                         ^~~~
    input.c:1220:33: note: in expansion of macro 'YYEMPTY'
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                 ^~~~~~~
    input.c:1220:41: error: unsigned conversion from 'int' to
                            'unsigned int' changes value
                            from '-2' to '4294967294'
                            [-Werror=sign-conversion]
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                         ^

Eventually, it might be interesting to move away from -2 (which is the
only possible negative symbol number) and use the next available
number, to save bits.  We could actually even simply use "0" and shift
the rest, which would allow to write "!yytoken" to mean really
"yytoken != YYEMPTY".

* data/skeletons/c.m4 (b4_declare_symbol_enum): Define YYSYMBOL_YYEMPTY.
* data/skeletons/yacc.c: Use it.

* src/parse-gram.y (yyreport_syntax_error): Use YYSYMBOL_YYEMPTY, not
YYEMPTY, when dealing with a symbol.

* tests/regression.at: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille 00c80bc96c yacc.c: use yysymbol_type_t instead of int for yytoken
Now that we have a proper type for internal symbol numbers, let's use
it.  More code needs conversion, e.g., printers and destructors, but
they are shared with glr.c, which is not ready yet for this change.

It will also help us deal with warnings such as (GCC9 on GNU/Linux):

    input.c: In function 'int yyparse()':
    input.c:475:37: error: enumeral and non-enumeral type in conditional expression [-Werror=extra]
      475 |   (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF)
          |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    input.c:1024:17: note: in expansion of macro 'YYTRANSLATE'
     1024 |       yytoken = YYTRANSLATE (yychar);
          |                 ^~~~~~~~~~~

* data/skeletons/yacc.c (yytranslate, yysymbol_name)
(yyparse_context_t, yyexpected_tokens, yypstate_expected_tokens)
(yysyntax_error_arguments):
Use yysymbol_type_t instead of int.
2020-04-01 08:31:48 +02:00
Akim Demaille f62f1db298 regen 2020-04-01 08:31:48 +02:00
Akim Demaille 3ba001baac yacc.c: introduce an enum that defines the symbol's number
There's a number of advantage in exposing the symbol (internal)
numbers:

- custom error messages can use them to decide how to represent a
  given symbol, or a set of symbols.

- we need something similar in uses of yyexpected_tokens.  For
  instance, currently, bistromathic's completion() reads:

    int ntokens = expected_tokens (line, tokens, YYNTOKENS);
    [...]
    for (int i = 0; i < ntokens; ++i)
      if (tokens[i] == YYTRANSLATE (TOK_VAR))
      [...]
      else if (tokens[i] == YYTRANSLATE (TOK_FUN))
      [...]
      else
      [...]

- now that it's a compile-time expression, we can easily build static
  tables, switch, etc.

- some users depended on the ability to get the token number from a
  symbol to write test cases for their scanners.  But Bison 3.5
  removed the table this feature depended upon (a reverse
  yytranslate).  Now they can check against the actual symbol number,
  without having pay (space and time) a conversion.
  See https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html, and
  https://lists.gnu.org/archive/html/bug-bison/2020-03/msg00015.html.

- it helps us clearly separate the internal symbol numbers from the
  external token numbers, whose difference is sometimes blurred in the
  code when values coincide (e.g. "yychar = yytoken = YYEOF").

- it allows us to get rid of ugly macros with inconsistent names such
  as YYUNDEFTOK and YYTERROR, and to group related definitions
  together.

- similarly it provides a clean access to the $accept symbol (which
  proves convenient in a current experimentation of mine with several
  %start symbols).

Let's declare this type as a private type (in the *.c file, not
the *.h one).  So it does not need to be influenced by the api prefix.

* data/skeletons/bison.m4 (b4_symbol_sid): New.
(b4_symbol): Use it.
* data/skeletons/c.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/yacc.c: Use b4_declare_symbol_enum.
(YYUNDEFTOK, YYTERROR): Remove.
Use the corresponding symbol enum instead.
2020-04-01 08:31:33 +02:00
Akim Demaille 4140320a0a style: comment changes about token numbers
* data/skeletons/bison.m4, data/skeletons/c.m4: here.
2020-03-30 08:41:12 +02:00
Akim Demaille af19fd7e0f tests: recheck: work properly when the test suite was interrupted
* tests/local.mk (recheck): Look at the per-test logs, not the overall
log, which, when interrupted, contains only information about... the
tests that passed.
2020-03-30 08:41:12 +02:00
Akim Demaille 2c74872991 java: move away from _ for internationalization
The "_" is becoming a keyword in Java, which causes tons of warnings
currently in our test suite.  GNU Gettext is now using "i18n" instead
of "_"
(https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=e89fea36545f27487d9652a13e6a0adbea1117d0).

* data/skeletons/java.m4: Use "i18n", not "_".
* examples/java/calc/Calc.y, tests/calc.at: Adjust.
2020-03-30 08:03:10 +02:00
Akim Demaille 50517d578c regen 2020-03-28 15:13:27 +01:00
Akim Demaille 59d820d1ef c: use YYNOMEM instead of -2
See 84b1972c96.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): New.
Use it.
2020-03-28 15:13:27 +01:00
Akim Demaille 90f0500ef8 todo: update
* TODO (Token Number): We have to clean this.
(Naming conventions, Symbol numbers): New.
(Bad styling): Addressed in e21ff47f5d.
2020-03-28 15:13:27 +01:00
Akim Demaille 17a9542c4f regen 2020-03-28 15:13:27 +01:00
Akim Demaille b7045aa706 java: make yysyntaxErrorArguments a private detail
* data/skeletons/lalr1.java (yysyntaxErrorArguments): Move it from the
context, to the parser object.
Generate only for detailed and verbose error messages.
* tests/local.at (AT_YYERROR_DEFINE(java)): Use yyexpectedTokens
instead.
2020-03-28 15:13:27 +01:00
Akim Demaille ee56b6e0f2 skeletons: make yysyntax_error_arguments a private detail
We could just "inline yysyntax_error_arguments back" in the routines
it was originally extracted from, but I think the code is nicer to
read this way.

* data/skeletons/glr.c (yysyntax_error_arguments): Generate only for
detailed and verbose error messages.
* data/skeletons/yacc.c: Likewise.
* data/skeletons/lalr1.cc (parser::context::yysyntax_error_arguments):
Move as...
(parser::yysyntax_error_arguments_): this.
And only for detailed and verbose error messages.
2020-03-28 15:13:27 +01:00
Akim Demaille 1edc98f793 lalr1.cc: avoid using yysyntax_error_arguments
* data/skeletons/lalr1.cc (context::token): New.
* tests/local.at (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
2020-03-28 15:13:27 +01:00
Akim Demaille 4192de1f41 bison: avoid using yysyntax_error_arguments
* src/parse-gram.y (yyreport_syntax_error): Use yyparse_context_token
and yyexpected_tokens.
2020-03-28 15:13:27 +01:00
Akim Demaille 00b0d02955 tests: yacc.c: avoid yysyntax_error_arguments
Because glr.c shares the same testing routines, we also need to
convert it.

* data/skeletons/glr.c (yyparse_context_token): New.
* tests/local.at (yyreport_syntax_error): here.
2020-03-28 15:13:27 +01:00
Akim Demaille 1045c8d0ef examples: don't use yysyntax_error_arguments
Suggested by Adrian Vogelsgesang.
https://lists.gnu.org/archive/html/bison-patches/2020-02/msg00069.html

* data/skeletons/lalr1.java (Context.EMPTY, Context.getToken): New.
(Context.yyntokens): Rename as...
(Context.NTOKENS): this.
Because (i) all the Java coding styles recommend upper case for
constants, and (ii) the Java Skeleton exposes Lexer.EOF, not
Lexer.YYEOF.
* data/skeletons/yacc.c (yyparse_context_token): New.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
* examples/java/calc/Calc.y (yyreportSyntaxError): Likewise.
2020-03-28 15:13:27 +01:00
Akim Demaille ef8965b5f5 skeletons: fix incorrect type for translatable tokens
* data/skeletons/glr.c, data/skeletons/lalr1.c, data/skeletons/yacc.c:
Fix confusion between the "translatable" and the "translate" tables.
2020-03-28 15:13:27 +01:00
Akim Demaille 84b1972c96 yacc.c: use negative numbers for errors in auxiliary functions
yyparse returns 0, 1, 2 since ages (accept, reject, memory exhausted).
Some of our auxiliary functions such as yy_lac and
yyreport_syntax_error also need to return error codes and also use 0,
1, 2.  Because it uses yy_lac, yyexpected_tokens also needs to return
"problem", "memory exhausted", but in case of success, it needs to
return the number of tokens, so it cannot use 1 and 2 as error code.
Currently it uses -1 and -2, which is later converted into 1 and 2 as
yacc.c expects it.

Let's simplify this and use consistently -1 and -2 for auxiliary
functions that are not exposed (or not yet exposed) to the user.  In
particular this will save the user from having to convert
yyexpected_tokens's -2 into yyreport_syntax_error's 2: both return -1
or -2.

* data/skeletons/yacc.c (yy_lac, yyreport_syntax_error)
(yy_lac_stack_realloc): Return -1, -2 for errors instead of 1, 2.
Adjust callers.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Do take
error codes into account.
Issue a syntax error message even if we ran out of memory.
* src/parse-gram.y, tests/local.at (yyreport_syntax_error): Adjust.
2020-03-23 07:02:36 +01:00
Akim Demaille 1079595b2a style: reduce length of private constant
* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
(YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(YYARGS_MAX): this.
* src/parse-gram.y (YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(ARGS_MAX): this.
2020-03-23 07:02:34 +01:00
Akim Demaille e364bcdbc5 doc: c++: promote api.token.raw
* doc/bison.texi (Calc++ Parser): Here.
2020-03-23 07:02:32 +01:00
Akim Demaille 5a8db8a739 bench: calc: no need for super long inputs
* etc/bench.pl.in ($iterations): Restore initial value, -1, meaning
"at least one second".
($calc_input): There is no need to generate 400 lines.
2020-03-22 15:59:22 +01:00
Akim Demaille 5acc29041e bench: calc: work on a string instead of a file
The cost of the file layer is large and makes benchmarks too coarse,
as seen for in following example, first with a file, then with a
literal string:

    0. %skeleton "yacc.c" %define parse.lac full
    1. %skeleton "yacc-v1.c" %define nofinal %define parse.lac full
    2. %skeleton "yacc-v2.c" %define nofinal %define parse.lac full
    3. %skeleton "yacc-v3.c" %define nofinal %define parse.lac full
    4. %skeleton "yacc.c"
    5. %skeleton "yacc-v1.c" %define nofinal
    6. %skeleton "yacc-v2.c" %define nofinal
    7. %skeleton "yacc-v3.c" %define nofinal
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0           32558 ns      32537 ns      21228
    BM_y1           32400 ns      32369 ns      21233
    BM_y2           33485 ns      33464 ns      20625
    BM_y3           32139 ns      32125 ns      21446
    BM_y4           31343 ns      31329 ns      21747
    BM_y5           31344 ns      31317 ns      22035
    BM_y6           31287 ns      31255 ns      22039
    BM_y7           31387 ns      31373 ns      22178
    --------------------------------------------------
    Benchmark           Time           CPU Iterations
    --------------------------------------------------
    BM_y0           10642 ns      10634 ns      63601
    BM_y1           10657 ns      10654 ns      63625
    BM_y2           10441 ns      10432 ns      65957
    BM_y3           10558 ns      10554 ns      64546
    BM_y4            9521 ns       9516 ns      72011
    BM_y5            9179 ns       9157 ns      75028
    BM_y6            9360 ns       9356 ns      73770
    BM_y7            9365 ns       9359 ns      72609

Of course, at the same time it is less realistic: most users read
files rather that strings, so it might lead to us to pay attention to
costs most people don't see.

* etc/bench.pl.in (&calc_input): Output into a file given as argument.
Output in C syntax.
(&generate_grammar_calc): Use it.
Simplify the grammar: remove operators we don't care about.
Rewrite the scanner to work on a char* instead of a FILE*.
2020-03-22 15:59:22 +01:00
Akim Demaille 5b0b0a1e08 bench: add a "latest" symlink
* etc/bench.pl.in: here.
2020-03-22 15:59:14 +01:00
Akim Demaille 1c694e08cc bench: use the same prefix in both bench methods
* etc/bench.pl.in (&bench_with_timethese): Also use y$i, as in
&bench_with_gbenchmark.
(&generate_grammar_calc): Don't add a prefix, let the callers do it.
2020-03-22 15:59:13 +01:00
Akim Demaille 4cfb067d93 bench: use a C++-11 compiler
See https://github.com/google/benchmark#a-faster-keeprunning-loop.

* etc/bench.pl.in ($cxx): Be C++11.
(&bench_with_gbenchmark): Adjust.
2020-03-22 15:59:13 +01:00
Akim Demaille cf60d0a617 bench: create a README file with benches
* etc/bench.pl.in (&bench_with_gbenchmark): Here.
2020-03-22 15:59:13 +01:00
Akim Demaille c0e8489605 bench: calc: add support for google benchmark
* etc/bench.pl.in (&compiler): New, extracted from...
(&compile): here.
Don't link when using gbm.
(&calc_input): Don't make massive input for micro
benchmarks.
(&generate_grammar_calc): When using gbm, use api.prefix to avoid name
collisions.
Be ready to issue BENCHMARKS instead of a main.
(&bench): Rename as...
(&bench_with_timethese): this.
(&bench_with_gbenchmark): New.
(&bench): New.
Dispatch on these two.
2020-03-21 18:19:14 +01:00
Akim Demaille 788b1a6858 bench: better error messages on invalid input
* etc/bench.pl.in: here.
2020-03-21 18:17:09 +01:00
Akim Demaille 56414791e9 bench: simplify the calc grammar
* etc/bench.pl.in (generate_grammar_calc): We don't need global_result
etc.
2020-03-21 18:17:02 +01:00
Akim Demaille 675dcf1962 bench: die clearly on incorrect --grammar arguments
* etc/bench.pl.in (getopt): here.
2020-03-21 14:52:41 +01:00
Akim Demaille 466fb66578 regen 2020-03-17 19:21:24 +01:00
Akim Demaille cbb967dbad yacc.c: style: prefer switch to if
* data/skeletons/yacc.c: Prefer switch to decode yy_lac's return value.
2020-03-17 19:21:07 +01:00
Akim Demaille 44ac18d136 yacc.c: yypstate_expected_tokens
In push parsers, when asking for the list of expected tokens at some
point, it makes no sense to build a yyparse_context_t: the yypstate
alone suffices (the only difference being the lookahead).  Instead of
forcing the user to build a useless shell around yypstate, let's offer
yypstate_expected_tokens.

See https://lists.gnu.org/r/bison-patches/2020-03/msg00025.html.

* data/skeletons/yacc.c (yypstate): Declare earlier, so that we can
use it for...
(yypstate_expected_tokens): this new function, when in push parsers.
Adjust dependencies.
* examples/c/bistromathic/parse.y: Simplify: use
yypstate_expected_tokens.
Style fixes.
Reduce scopes (reported by Joel E. Denny).
2020-03-17 19:20:13 +01:00
Akim Demaille 0c3dd3a669 examples: bistromathic: simplify
* examples/c/bistromathic/parse.y (expected_tokens): Remove useless "break".
2020-03-09 07:24:33 +01:00
Akim Demaille 951da960e6 merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.5.3
  news: update for 3.5.3
  yacc.c: make sure we properly propagated the user's number for error
  diagnostics: don't crash because of repeated definitions of error
  style: initialize some struct members
  diagnostics: beware of zero-width characters
  diagnostics: be sure to close the styling when lines are too short
  muscles: fix incorrect decoding of $
  code: be robust to reference with invalid tags
  build: fix typo
  doc: update recommandation for libtextstyle
  style: comment changes
  examples: use consistently the GFDL header for readmes
  style: remove useless declarations
  typo: succesful -> successful
  README: point to tests/bison, and document --trace
  gnulib: update
  maint: post-release administrivia
2020-03-08 10:13:16 +01:00
Akim Demaille ecd922024e README: point to tests/bison, and document --trace
Reported by Victor Morales Cayuela.

* README, README-hacking.md: here.
2020-03-05 17:56:55 +01:00
Akim Demaille 2353ce7216 yacc.c: simplify yyparse_context_t member names
* data/skeletons/yacc.c (yyparse_context_t): Rename yyes_p and
yyes_capacity_p as...
(yyes, yyes_capacity): These.
2020-03-05 07:26:50 +01:00
Akim Demaille 9cc76ee62c yacc.c: yyerror_range does not need to be preserved accross calls
* data/skeletons/yacc.c (b4_parse_state_variable_macros): Don't define
yyerror_range.
(yyparse): Add yyerror_range as local variable.
2020-03-05 07:26:49 +01:00
Akim Demaille 2f83ef57f3 yacc.c: push: undefine the pstate macros for the epilogue
* data/skeletons/yacc.c (b4_macro_define, b4_macro_undef)
(b4_pstate_macro_define, b4_parse_state_variable_macros):
New.
Use them.
* examples/c/bistromathic/parse.y: Remove now useless undefs.
2020-03-05 07:26:49 +01:00
Akim Demaille 744171ddbf yacc.c: push: initialize the pstate variables in pstate_new
Currently pstate_new does not set up its variables, this task is left
to yypush_parse.  This was probably to share more code with usual pull
parsers, where these (local) variables are indeed initialized by
yyparse.

But as a consequence yyexpected_tokens crashes at the very beginning
of the parse, since, for instance, the stacks are not even set up.
See https://lists.gnu.org/r/bison-patches/2020-03/msg00001.html.

The fix could have very simple, but the documentation actually makes
it very clear that we can reuse a pstate for several parses:

    After yypush_parse returns a status other than YYPUSH_MORE, the
    parser instance yyps may be reused for a new parse.

so we need to restore the parser to its pristine state so that (i) it
is ready to run the next parse, (ii) it properly supports
yyexpected_tokens for the next run.

* data/skeletons/yacc.c (b4_initialize_parser_state_variables): New,
extracted from the top of yyparse/yypush_parse.
(yypstate_clear): New.
(yypstate_new): Use it when push parsers are enabled.
Define after the yyps macros so that we can use the same code as the
regular pull parsers.
(yyparse): Use it when push parsers are _not_ enabled.

* examples/c/bistromathic/bistromathic.test: Check the completion on
the beginning of the line.
2020-03-05 07:13:23 +01:00
Akim Demaille 4fd3282dd7 style: formatting changes
* data/skeletons/yacc.c, tests/torture.at: here.
2020-03-04 08:24:36 +01:00
Akim Demaille 67793793e8 bistromathic: properly compute the lcp, as expected by readline
Currently completion on "at" proposes only "atan", but does not
actually complete "at" into "atan".

* examples/c/bistromathic/parse.y (completion): Install the lcp in
matches[0].
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-03-04 08:24:36 +01:00
Akim Demaille f334775dbf bistromathic: don't require spaces after operators for completion
Currently "(1+<TAB>" does not work as expected, because "+" is not a
word breaking character.

* examples/c/bistromathic/parse.y (init_readline): Specify our word
breaking characters.
* examples/c/bistromathic/bistromathic.test: Avoid trailing spaces.
2020-03-04 08:24:35 +01:00
Akim Demaille feb1011c8b bistromathic: check completion
* examples/c/bistromathic/bistromathic.test: here.
* examples/c/bistromathic/parse.y (expected_tokens): Fix a memory
leak.
2020-03-02 06:58:25 +01:00
Akim Demaille 99bedadf23 m4: remove b4_function_define and b4_function_declare
* data/skeletons/c.m4: here.
2020-03-02 06:58:20 +01:00
Akim Demaille 79c3f2b8fd m4: decommission b4_function_declare
* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/yacc.c:
Stop using b4_function_declare.
2020-03-02 06:58:14 +01:00
Akim Demaille 4cca30d2e6 m4: decommission function generating macro
These macros have been extremely useful when we had to support K&R C,
which we dropped long ago.  Now, they merely make the code uselessly
hard to read.

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/yacc.c:
Stop using b4_function_define.
2020-03-02 06:57:50 +01:00
Akim Demaille 5789f9d91e examples: bistromathic: demonstrate the use of yyexpected_tokens
Let's use GNU readline and its TAB autocompletion to demonstrate the
use of yyexpected_tokens.

This shows a number of weaknesses in our current approach:

- some macros (yyssp, etc.) from push parsers "leak" in user code, we
  need to undefine them

- the context needed by yyexpected_tokens does not need the token,
  yypstate actually suffices

- yypstate is not properly setup when first allocated, which results
  in a crash of yyexpected_tokens if fired before a first token was
  read.  We should move initialization from yypush_parse into
  yypstate_new.

* examples/c/bistromathic/parse.y (yylex): Take input as a string, not
a file.
(EXIT): New token.
(input): Adjust to work only on a line.
(line): Remove.
(symbol_count, process_line, expected_tokens, completion)
(init_readline): New.
* examples/c/bistromathic/bistromathic.test: Adjust expectations.
2020-03-01 12:31:39 +01:00
Akim Demaille b269a45fa4 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/pushcalc/README.md, examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-01 07:56:02 +01:00
Akim Demaille 1478fccd23 gnulib: use readline 2020-03-01 06:23:49 +01:00
Akim Demaille 535281f0ff examples: bistromathic: don't use Flex
This example will soon use GNU readline, so its scanner should be easy
to use (concurrently) on strings, not streams.  This is not a place
where Flex shines, and anyway, these are examples of Bison, not Flex.
There's already lexcalc and reccalc that demonstrate the use of Flex.

* examples/c/bistromathic/scan.l: Remove.
* examples/c/bistromathic/parse.y (yylex): New.
Adjust dependencies.
2020-02-29 17:52:08 +01:00
Akim Demaille c4a7e7a1ab examples: bistromathic: strengthen tests
* examples/c/bistromathic/bistromathic.test: here.
* examples/test: Be clearer on failing tests.
2020-02-29 12:22:31 +01:00
Akim Demaille 388e12ac0f examples: lexcalc: demonstrate location tracking
The bistromathic example should not use Flex, it makes it too complex.
But it was the only example to show location tracking with Flex.

* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Demonstrate location tracking as is done
in bistromathic.
2020-02-29 12:15:19 +01:00
Akim Demaille b870d5fee4 c++: don't copy the lookahead
The current implementation of parser::context keeps a copy of the
lookahead.  This is troublesome since we support move-only types.
Besides, while GCC is happy with the current implementation, Clang
complains that the ctor it needs to build the copy of the lookahead is
not yet available.

    461. calc.at:1120: testing Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  ...
    calc.at:1120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    calc.at:1120: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    In file included from calc-lex.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    In file included from calc-main.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    stdout:
    calc.at:1120: exit code was 1, expected 0
    461. calc.at:1120: 461. Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  (calc.at:1120): FAILED (calc.at:1120)

* data/skeletons/lalr1.cc (context::yyla_): Make it a const-ref.
Move the implementation out of the declaration.
2020-02-27 21:49:56 +01:00
Akim Demaille 30d01b21e7 c++: minor fixes
Address compiler warnings such as

    warning: declaration of 'yyla' shadows a member of 'yy::parser::context' [-Wshadow]

* data/skeletons/lalr1.cc (context): Don't use the same names for
variables and members.
Use foo_ for private members, as in parser.
Also, use the + trick in array accesses to please ICC and provide it
with an int.
2020-02-27 21:31:09 +01:00
Adrian VogelsgesangandAkim Demaille c2cca46795 c++: add support for parse.error=custom
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added test cases
* tests/local.at: added yyreport_syntax_error implementation
   for C++ test cases
2020-02-27 18:13:44 +01:00
Adrian VogelsgesangandAkim Demaille 879530cb95 c++: add parser::context for syntax error handling
* data/skeletons/lalr1.cc: here
2020-02-27 18:13:44 +01:00
Adrian VogelsgesangandAkim Demaille 72acecb30c c++: add support for parse.error=detailed
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added a test case
2020-02-27 18:13:43 +01:00
Adrian VogelsgesangandAkim Demaille d4fcd5c3d0 skeletons: prefer b4_parse_error_{case,bmatch} over manual solution
Prefer b4_parse_error_case over the adhoc solution
`m4_case + b4_percent_define_get`. Same for b4_parse_error_bmatch.

* data/skeletons/glr.c: here
* data/skeletons/yacc.c: here
2020-02-27 18:13:43 +01:00
Adrian VogelsgesangandAkim Demaille 368fcf0af5 typo: succesful -> successful
* data/skeletons/lalr1.cc: here
* etc/bench.pl.in: here
* src/location.c: here
* tests/calc.at: and here
2020-02-27 18:10:39 +01:00
Akim Demaille 6fe063da8f bench.pl: clean up the dust
* etc/bench.pl.in: Adjust to the current use of %define's values.
Don't use %error-verbose.
Prefer Bison to CPP (e.g., api.value.type).
Avoid returning characters directly, so that %define api.token.raw works.
2020-02-24 08:42:16 +01:00
Akim Demaille 296660304c style: comment changes
* src/symtab.h, src/lr0.c: here.
2020-02-23 08:25:53 +01:00
Akim Demaille 323731ff74 style: avoid using 'this' as an identifier
LLDB insists on parsing 'this' as a C++ keyword, even when debugging a
C program.

* src/symtab.c: Please the dictator.
2020-02-23 08:25:53 +01:00
Akim Demaille 6f7f949708 style: remove useless declarations
* src/reader.h: Don't duplicate what parse-gram.h already exposes.
* src/lr0.h: Remove useless include.
2020-02-23 08:25:53 +01:00
Akim Demaille 15e57d9108 examples: fix c/calc
* examples/c/calc/calc.y: Remove experiment traces.
2020-02-19 14:58:39 +01:00
Akim Demaille 30ba94081c todo: update 2020-02-19 14:57:17 +01:00
Akim Demaille 0e7bc7a6d8 doc: update recommandation for libtextstyle
* README: here.
2020-02-15 11:17:33 +01:00
Akimn Demaille eff4d16175 build: fix typo
* build-aux/cross-options.pl: here.
2020-02-15 10:50:19 +01:00
Akim Demaille b0e11f4523 doc: simplify the cross references
* doc/bison.texi: here.
2020-02-15 09:59:50 +01:00
Akim Demaille d9b2270bed doc: document token internationalization
* doc/bison.texi (Parser Internationalization): Move most of its
content into...
(Enabling I18n): this new node.
(Token I18n): New.
(Token Decl): Refer to token internationalization.
(Error Reporting Function): Promote parse.error detailed.
2020-02-15 09:55:59 +01:00
Akim Demaille 7a28659495 regen 2020-02-15 08:28:57 +01:00
Victor Morales CayuelaandAkim Demaille e09a72eeb0 diagnostics: modernize the display of submessages
Since Bison 2.7, output was indented four spaces for explanatory
statements.  For example:

    input.y:2.7-13: error: %type redeclaration for exp
    input.y:1.7-11:     previous declaration

Since the introduction of caret-diagnostics, it became less clear.
Remove the indentation and display submessages as in GCC:

    input.y:2.7-13: error: %type redeclaration for exp
        2 | %type <float> exp
          |       ^~~~~~~
    input.y:1.7-11: note: previous declaration
        1 | %type <int> exp
          |       ^~~~~

* src/complain.h (SUB_INDENT): Remove.
(warnings): Add "note" to the enum.
* src/complain.h, src/complain.c (complain_indent): Replace by...
(subcomplain): this.
Adjust all dependencies.
* tests/actions.at, tests/diagnostics.at, tests/glr-regression.at,
* tests/input.at, tests/named-refs.at, tests/regression.at:
Adjust expectations.
2020-02-15 08:28:40 +01:00
Akim Demaille a09d0ae4d1 doc: simplify uses of references
This reverts "doc: work around problems with PDF generation", commit
d810aa3d8f.  Upstream issue is fixed.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00006.html

* gnulib: Update.
* doc/bison.texi: Simplify.
2020-02-13 19:22:51 +01:00
Akim Demaille 1e25cb44d1 java: provide a Context ctor
This is really a private auxiliary inner class, so it should not
matter.  But it's better style.

* data/skeletons/lalr1.java: here.
2020-02-13 19:22:10 +01:00
Akim Demaille 3ed42d2487 Merge tag 'v3.5.2'
bison 3.5.2

* tag 'v3.5.2':
  version 3.5.2
  news: 3.5.2
  gnulib: update
  doc: update Doxygen template
  java: avoid trailing white spaces
  m4: fix b4_token_format
  doc: clearly state that %yacc only makes sense with yacc.c
  doc: spell check
  examples: be more robust to spaces in paths
  larlr1.cc: Reject unsupported values for parse.lac
2020-02-13 19:19:11 +01:00
Akim Demaille e7a202d762 examples: bistromathic: demonstrate named references
* examples/c/bistromathic/parse.y: here.
2020-02-12 00:18:47 +01:00
Akim Demaille 11e2b755f0 c++: simplify
* data/skeletons/stack.hh (ssize): Remove, same as size.
2020-02-12 00:09:15 +01:00
Akim Demaille f3d33c3613 tests: check calls to yyerror from the user actions
This revealed a number of things I had not realized:

- the Java location tracking was aliasing the same pair of positions
  for all the symbols (see previous commit).

- in impure parsers, it's quite easy to use incorrect locations for
  diagnostics, since yyerror uses yylloc, which is the location of the
  lookahead, not that of the current lhs.  So we need something like

    {
      YYLTYPE old_yylloc = yylloc;
      yylloc = @$;
      yyerror (]AT_PARAM_IF([result, count, nerrs, ])[buf);
      yylloc = old_yylloc;
    }

  Maybe we should do that little yylloc dance in the skeleton instead
  of leaving it to the user?  It might be costly...  But that's only
  for users of the impure parsers, which are asking for trouble
  anyway.

- in glr.cc invoking yyerror is somewhat cumbersome: the C++ interface
  is not available as we are in yyparse (which in C), and yyerror is
  used by glr.cc itself to bind it to the user's parser::error.  If we
  call yyerror, we need:

    yyerror (]AT_LOCATION_IF([[&@$, ]])[yyparser, ]AT_PARAM_IF([result, count, nerrs, ])[msg);

  However calling yy::parser::error is easier, once we know that the
  current parser object is available as 'yyparser'.  Which also saves
  us from having to pass the parse-params ourselves:

    yyparser.error (]AT_LOCATION_IF([[@$, ]])[msg);

* tests/calc.at: Invoke yyerror by hand, instead of using fprintf etc.
Adjust expectations.
2020-02-12 00:00:05 +01:00
Akim Demaille 163a35d6dd java: beware not to alias the locations of the various symbols
* examples/java/calc/Calc.y, tests/calc.at, tests/local.at
(getStartPos, getEndPos): Always return a new object.
* doc/bison.texi: Clarify this.
2020-02-11 21:31:44 +01:00
Akim Demaille cdb42f7730 java: check that parse.error custom|detailed work with push parsers
* tests/calc.at: here.
2020-02-11 08:39:08 +01:00
Akim Demaille 126252333d java: don't expose the Context's members
* data/skeletons/lalr1.java (Context): Make data members private.
(Context.getLocation): New.
* examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.
2020-02-11 08:39:03 +01:00
Akim Demaille 8637f2c7d6 build: pacify syntax-check
* src/complain.c: Fix indentation.
* cfg.mk: Using strcmp is ok in the tests.
Test cases and examples don't need Bison's PO support.
2020-02-10 20:46:56 +01:00
Akim Demaille 6946149701 regen 2020-02-10 20:42:23 +01:00
Akim Demaille 1368b9dbc9 gnulib: update 2020-02-10 20:42:23 +01:00
Akim Demaille 0e96eaf612 build: prefer %D% and %C% to hard coded values
* doc/local.mk: here.
2020-02-10 20:15:46 +01:00
Akim Demaille 77bdcc6f0c parse.error: document and diagnose the incompatibility with %token-table
* doc/bison.texi (Tokens from Literals): Move to code using
%token-table to...
(Decl Summary: %token-table): here.
* data/skeletons/bison.m4: Implement mutual exclusion.
* tests/input.at: Check it.
* doc/local.mk: Be robust to the removal of doc/.
2020-02-10 20:15:46 +01:00
Akim Demaille 57647bb656 doc: spell check
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille 63cd2918ff doc: formatting changes
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille d810aa3d8f doc: work around problems with PDF generation
With texinfo.tex 2019-09-24.13, node names with + are not properly
handled.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00004.html

* doc/bison.texi: Always use the three-argument form for references to
node with a + in the name.
2020-02-10 20:15:41 +01:00
Akim Demaille ed1eedbbcb java: revert "style: avoid useless initializers"
This reverts commit ebab1ffca8.
This commit removed "useless" initializers, going from

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte yypact_[] = yypact_init ();
    private static final byte[] yypact_init ()
    {
      return new byte[]
      {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
      };
    }

to

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte[] yypact_ =
    {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
    };

But it turns out that this was on purpose, to work around the 64KB
limitation in JVM methods.  It was introduced on the 2008-11-10 by
Di-an Jan in 09ccae9b18: "Work around
Java's ``code too large'' problem for parser tables".  See
https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.  A real
test, where we would hit the JVM limitation, would be nice.

To avoid further regressions, add comments.
2020-02-10 07:34:07 +01:00
Akim Demaille bc74b4b15a skeletons: avoid b4_error_verbose_if, which is confusing
parse.error has more than two possible values.

* data/skeletons/bison.m4 (b4_error_verbose_if, b4_error_verbose_flag):
Remove.
(b4_parse_error_case, b4_parse_error_bmatch): New.
Adjust dependencies.
2020-02-10 07:24:38 +01:00
Akim Demaille 8dd8137c38 skeletons: decorelate %token-table from verbose error messages
Reported by Adrian Vogelsgesang.

* data/skeletons/bison.m4: Here.
* data/skeletons/lalr1.cc: Adjust.
2020-02-10 07:24:38 +01:00
Akim Demaille 1388e5b276 doc: formatting changes
* doc/bison.texi: here.
2020-02-10 07:24:38 +01:00
Akim Demaille 6f5465c917 doc: clearly state that %yacc only makes sense with yacc.c
* doc/bison.texi: here.
* tests/calc.at: Stop testing %yacc with non yacc.c skeletons.
2020-02-09 15:58:55 +01:00
Adrian VogelsgesangandAkim Demaille bb02acc2ed style: stylistic cleanups in the C skeletons
* data/skeletons/glr.c, data/skeletons/yacc.c:
Avoid duplicated declaration of yysymbol_name.
2020-02-09 15:58:27 +01:00
Akim Demaille 80a4389377 java: provide Context with a more OO interface
* data/skeletons/lalr1.java (yyexpectedTokens)
(yysyntaxErrorArguments): Make them methods of Context.
(Context.yysymbolName): New.
* tests/local.at: Adjust.
2020-02-08 16:17:53 +01:00
Akim Demaille ef097719ea java: add support for parse.error custom
* data/skeletons/lalr1.java: Add support for custom parse errors.
(yyntokens_): Make it public.  Under...
(yyntokens): this name.
(Context): Capture the location too.
* examples/c/bistromathic/parse.y,
* examples/c/bistromathic/bistromathic.test:
Improve error message.
* examples/java/calc/Calc.test, examples/java/calc/Calc.y: Use custom
error messages.
* tests/calc.at, tests/local.at: Check custom error messages.
2020-02-08 16:03:50 +01:00
Akim Demaille 0c90c59795 java: let the Context give access to yyntokens
* data/skeletons/lalr1.java (Context.yytokens): New.
2020-02-08 15:54:16 +01:00
Akim Demaille 18a7cfc7cf java: make the syntax error format string translatable
The error format should be translated, but contrary to the case of
C/C++, we cannot just depend on macros to adapt on the
presence/absence of '_'.  Let's consider that the message format is to
be translated iff there are some internationalized tokens.

* src/output.c (prepare_symbol_names): Define b4_has_translations.
* data/skeletons/java.m4 (b4_trans): New.
* data/skeletons/lalr1.java: Use it to emit translatable or not the
format string.
2020-02-08 11:24:53 +01:00
Akim Demaille 088356cb2f java: introduce yyexpectedTokens
And allow syntax error messages for 'detailed' and 'verbose' to be
translated.

* data/skeletons/lalr1.java (Context, yyexpectedTokens)
(yysyntaxErrorArguments): New.
(yysyntax_error): Use it.
2020-02-08 11:24:53 +01:00
Akim Demaille 52db24b2bc java: add support for parse.error=detailed
In Java there is no need for N_ and yytranslate_.  So instead of
hard-coding the use of N_ in the table of the symbol names, rely on
b4_symbol_translate.

* src/output.c (prepare_symbol_names): Use b4_symbol_translate instead
of N_.
* data/skeletons/c.m4 (b4_symbol_translate): New.
* data/skeletons/lalr1.java (yysymbolName): New.
Use it.
* examples/java/calc/Calc.y: Use parse.error=detailed.
* tests/calc.at: Check parse.error=detailed.
2020-02-08 11:24:53 +01:00
Akim Demaille 650b253843 m4: fix b4_token_format
We used to emit:

    /** Token number,to be returned by the scanner.  */
    static final int NUM = 258;
    /** Token number,to be returned by the scanner.  */
    static final int NEG = 259;

with no space after the comma.  Fix that.

* data/skeletons/bison.m4 (b4_token_format): Quote where appropriate.
2020-02-08 11:24:53 +01:00
Akim Demaille 7781254e01 java: tests: remove now redundant tests
* tests/javapush.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille fa226d773c java: tests: check push parsers like the others
Currently in javapush.at.

* tests/calc.at: Here.
2020-02-05 13:17:00 +01:00
Akim Demaille 1cc83505c5 java: tests: remove now redundant tests
* tests/java.at: Calculator tests are now in calc.at.
2020-02-05 13:17:00 +01:00
Akim Demaille 2d97fe86fd java: tests: check location tracking in the calculator
Unfortunately in the Java skeleton the user cannot override the way
locations are displayed, and locations don't know the structure of the
positions.  So they cannot implement the tricks used in the C/C++
skeletons to display "1.1" instead of "1.1-1.2".

* tests/local.at (Java): Add support for column tracking in the
locations, as we did in examples/java/calc.
* tests/calc.at: Use AT_CALC_YYLEX.
2020-02-05 13:17:00 +01:00
Akim Demaille 3239866f4a java: tests: prepare the replacement of calculator tests
Soon calculator tests for Java will move from java.at to calc.at.
Which implies improving the Java testing infrastructure in
local.at (for instance really tracking columns in positions, not just
token number).  Detach java.at from local.at.

* tests/java.at (AT_JAVA_POSITION_DEFINE_OLD): New.
Use it.
2020-02-05 13:17:00 +01:00
Akim Demaille ebab1ffca8 java: style: avoid useless initializers
Instead of

      /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte yypact_[] = yypact_init ();
      private static final byte[] yypact_init ()
      {
        return new byte[]
        {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
        };
      }

generate

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte[] yypact_ =
      {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
      };

I have no idea what motivated the previous approach.

* data/skeletons/java.m4 (b4_typed_parser_table_define): Here.
2020-02-05 13:17:00 +01:00
Akim Demaille f705e9abdb java: style: prefer putting the square brackets on the type
* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/local.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille d6f576102e java: examples: fix the tracking of locations
* examples/java/calc/Calc.y: The StreamTokenizer cannot "peek" for the
next character, it reads it, and keeps it for the next call.  So the
current location is one passed the end of the current token.  To avoid
this, keep the previous position, and use it to end the current token.
* examples/java/calc/Calc.test: Adjust.
2020-02-05 13:17:00 +01:00
Akim Demaille 0f587e9931 java: examples: prefer switch to chains of else-if
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
* examples/java/simple/Calc.y: Use the tokenizer's handling of blanks.
2020-02-05 13:17:00 +01:00
Akim Demaille 48be689a73 java: examples: split in two
* examples/java: Split in...
* examples/java/simple, examples/java/calc: these.
2020-02-05 13:17:00 +01:00
Akim Demaille d727e0ff23 traces: don't print the stack before the gotos
The C, C++ and D skeletons used to show the stack right after popping
the stack during the reduction.  Now that the stack is printed after
reaching a new state, that has become useless:

    Entering state 1
    Stack now 0 1
    Reducing stack by rule 5 (line 83):
       $1 = token "number" (1)
    -> $$ = nterm exp (1)
    Stack now 0
    Entering state 8
    Stack now 0 8

Remove the "Stack now 0" line.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Here.
2020-02-05 07:40:07 +01:00
Akim Demaille 37aeda6fb3 traces: show the stack after reading a token
Currently, if we have long rules and series of shift, we stack states
without showing stack.  Let's be more incremental, and do how the Java
skeleton does.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c:
Here.
Adjust test cases.
* tests/torture.at (AT_DATA_STACK_TORTURE): Disable stack traces: this
test produces a very large stack, and showing the stack each time we
shift a token goes quadatric.
2020-02-05 06:48:42 +01:00
Akim Demaille bba2f0a3a0 traces: write the "Reading a token" alone on its line
The Java skeleton displays

    Reading a token:
    Next token is token "number" (1)

while the other display

    Reading a token: Next token is token "number" (1)

When generating logs in the scanner, the first part is separated from
the second, and the end of the scanner logs have the second part
pasted in.  So let's propagate the Java way, but with the colon.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Do it.
Adjust test cases and doc.
2020-02-04 07:02:24 +01:00
Akim Demaille fe14fb1c40 java: use the same calc tests as the other skeletons
* tests/local.at (AT_LANG_MATCH): New.
(AT_YYERROR_DECLARE(java), AT_YYERROR_DECLARE_EXTERN(java)): New.
* tests/calc.at: The grammar file for Java is quite different for the
others, and continuing to assemble it from pieces makes the grammar
file hard to understand.  Let's also dispatch on the language to
assemble it, and isolate Java from the others.
Most of this comes from java.at.
2020-02-02 11:33:16 +01:00
Akim Demaille 88d1ab421a java: add access to the number of errors
* data/skeletons/lalr1.java (yynewrrs, getNumberOfErrors): New.
Formatting changes.
2020-02-02 11:33:16 +01:00
Akim Demaille edf495b38e java: formatting changes
* data/skeletons/java.m4, data/skeletons/lalr1.java: here.
2020-02-02 11:33:16 +01:00
Akim Demaille ba69beafac java: avoid trailing white spaces
* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
2020-02-02 11:33:16 +01:00
Akim Demaille c16fcaf2fb java: example: properly track the locations
This example, so far, was tracking the current token number, not the
current column number.  This is not nice for an example...

* examples/java/Calc.y (PositionReader): New.
Use it.
* examples/java/Calc.test: Check the output.
2020-02-02 11:33:13 +01:00
Akim Demaille 7e99f67592 java: example: improve
* examples/java/Calc.y: Propagate the exit status.
Support -p.
2020-02-02 11:33:03 +01:00
Akim Demaille d5f929d407 java: example: rely on autoboxing
AFAICT, autoboxing/unboxing was added in Java 5 (September 30, 2004).
I think we can afford to use it.  It should help us merge some Java
tests with the main ones.

However, beware that != does not unbox: it compares the object
addresses.

* examples/java/Calc.y, tests/java.at: Simplify.
* examples/java/Calc.test, tests/java.at: Improve tests.
2020-02-02 11:32:55 +01:00
Akim Demaille c5b215b5e6 tests: comment changes
* tests/calc.at: Shorten titles and reduce redundancy.
2020-02-02 11:28:45 +01:00
Akim Demaille 0774b2c6e3 skeletons: add support for %code epilogue
When building the test cases, emitting code in the epilogue is very
constraining.  Let's make it simpler thanks to %code epilogue.

However, I don't want to document this: it is bad style to use it (we
should avoid having too many ways to write the same thing,
TI!MTOWTDI), just put your code in the true epilogue section.

* data/skeletons/glr.c, data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c: Implement support for %code epilogue.
Remove useless comments.
* tests/calc.at, tests/java.at: Simplify.
2020-02-02 11:28:45 +01:00
Akim Demaille 493359b758 examples: bistromathic: fix location tracking
* examples/c/bistromathic/scan.l (LOCATION_STEP): New.
Use to properly ignore blanks.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-02-02 11:28:45 +01:00
Akim Demaille 23ba9e5dfa doc: document new features of parse.error
* doc/bison.texi (Error Reporting): Rename as...
(Error Reporting Function): this.
Adjust dependencies.
Make it a subsection of this...
(Error Reporting): new section.
(Syntax Error Reporting Function): New.
(parse.error): Update description.
2020-02-02 09:19:58 +01:00
Akim Demaille 792fc34016 glr.c: add support for parse.error=custom
* data/skeletons/glr.c (yyreportSyntaxError): Call the user's
yyreport_syntax_error in custom mode.
* tests/calc.at: Check it.
2020-01-29 19:48:16 +01:00
Akim Demaille c4a08d1899 glr.c: add support for parse.error=detailed
* data/skeletons/glr.c (yystrlen, yysymbol_name): New.
Implement parse.error detailed.
* tests/calc.at: Check it.
2020-01-29 19:48:12 +01:00
Akim Demaille 50fb1e6e0c glr.c: introduce yyexpected_tokens and yysyntax_error_arguments
Modeled after what was done in yacc.c, yet somewhat different since
yyGLRStack play the role of the full yyparse_context_t.  It will
probably be defined as a alias, to make interfaces compatible.

LAC is not supported here.  And is somewhat tricky.

* data/skeletons/glr.c (yyexpected_tokens, yysyntax_error_arguments): New.
2020-01-29 19:27:42 +01:00
Akim Demaille 6bd0527a50 glr.c: move code around
* data/skeletons/glr.c: Move the handling of error messages after the
definition of types.  Especially after yyGLRStack, which we will need
in forthcoming patches.
Simplify: yyGLRStack is defined at this point.
2020-01-29 19:27:24 +01:00
Akim Demaille 1aa9d40b24 glr.c: rename yyStateNum as yy_state_t
* data/skeletons/glr.c: here.
For consistency with yacc.c.
2020-01-29 07:15:19 +01:00
Akim Demaille a1da9b9fe8 yacc.c: fix misleading indentation
* data/skeletons/yacc.c: here.
2020-01-29 07:15:19 +01:00
Akim Demaille c80cdf2db2 doc: simplify uses of @ref
The PDF output is more consistent: some nodes were not pointed to with
their title.  The HTML output becomes "see section Foo" instead of
"see Foo", but this should be addressed in the next Texinfo release.
Info output is simplified, as it uses only the node name and not its
title.  But it's considered easier to read this way.
See https://lists.gnu.org/r/help-texinfo/2020-01/msg00031.html.

* doc/bison.texi: Set @xrefautomaticsectiontitle on.
Simplify all uses of ref.
2020-01-27 07:22:22 +01:00
Akim Demaille 3197d0fac9 examples: be more robust to spaces in paths
Reported by Nikki Valen.
https://lists.gnu.org/r/bug-bison/2020-01/msg00032.html

* examples/test ($prog): Remove, replaced by...
(prog): This new function, which pays attention to quoting shell
variables.
2020-01-27 07:22:22 +01:00
Akim Demaille 78e43ce8ff doc: don't pretend trigonometry is part of arithmetics
* doc/bison.texi (arith_funs): Rename as...
(funs): this.
2020-01-27 06:43:19 +01:00
Akim Demaille fe23e19323 doc: update Doxygen template
* Doxyfile.in: Run doxygen -u on it.
2020-01-27 06:43:19 +01:00
Akim Demaille f374310119 examples: add a complete example with all the bells and whistles
* examples/c/bistromathic/Makefile,
* examples/c/bistromathic/README.md,
* examples/c/bistromathic/bistromathic.test,
* examples/c/bistromathic/local.mk,
* examples/c/bistromathic/parse.y,
* examples/c/bistromathic/scan.l:
New.

* Makefile.am (AM_YFLAGS_WITH_LINES): Add -Wdangling-alias.
* examples/test: Make failure errors easier to read.
2020-01-27 06:41:11 +01:00
Akim Demaille 7bfff37f01 examples: add an example of a push parser
Add an example to demonstrate the use of push parser.  I'm pleasantly
surprised: parse.error=detailed works like a charm with push parsers.

* examples/c/local.mk, examples/c/pushcalc/Makefile
* examples/c/pushcalc/README.md, examples/c/pushcalc/calc.test,
* examples/c/pushcalc/calc.y, examples/c/pushcalc/local.mk:
New.
2020-01-26 14:02:08 +01:00
Akim Demaille 26fba6fc94 examples: more tests
* examples/c/mfcalc/mfcalc.test: here.
2020-01-26 14:02:08 +01:00
Akim Demaille c592202345 examples: clean up
* examples/c/calc/calc.y: Restore to its original state, with
parse.error=detailed instead of parse.error=custom (this example
should be simple).
* examples/c/calc/calc.test: Check syntax errors.
* examples/c/lexcalc/parse.y: Add comments.
2020-01-26 14:02:08 +01:00
Akim Demaille 0917f4dc76 tests: check custom error messages and push parsers
* tests/local.at (AT_LAC_IF): New.
* tests/calc.at: And also check the suppot for LAC.
2020-01-26 13:29:19 +01:00
Akim Demaille 0f792833c2 style: formatting changes
* data/skeletons/lalr1.java: here.
2020-01-26 13:29:19 +01:00
Akim Demaille b62e063df5 todo: update 2020-01-26 13:29:19 +01:00
Akim Demaille e6b0612f91 bison: pretend to 3.6 already
* src/parse-gram.y: here.
2020-01-26 13:29:18 +01:00
Akim Demaille 2eb3328afc git: update ignores
* lib/.gitignore: here.
2020-01-26 13:29:18 +01:00
Akim Demaille 81849520cd regen 2020-01-23 08:30:51 +01:00
Akim Demaille fc2191f137 diagnostics: modernize bison's syntax errors
We used to display the unexpected token first:

    $ bison foo.y
    foo.y:1.8-13: error: syntax error, unexpected %token, expecting character literal or identifier or <tag>
        1 | %token %token
          |        ^~~~~~

GCC uses a different format:

    $ gcc-mp-9 foo.c
    foo.c:1:5: error: expected identifier or '(' before ')' token
        1 | int()()()
          |     ^

and so does Clang:

    $ clang-mp-9.0 foo.c
    foo.c:1:5: error: expected identifier or '('
    int()()()
        ^
    1 error generated.

They display the unexpected token last (or not at all).  Also, they
don't waste width with "syntax error".  Let's try that.  It gives, for
the same example as above:

    $ bison foo.y
    foo.y:1.8-13: error: expected character literal or identifier or <tag> before %token
        1 | %token %token
          |        ^~~~~~

* src/complain.h, src/complain.c (syntax_error): New.
* src/parse-gram.y (yyreport_syntax_error): Use it.
2020-01-23 08:30:28 +01:00
Akim Demaille 6fb362c87a regen 2020-01-23 08:26:33 +01:00
Akim Demaille 46ab1d0cbe diagnostics: report syntax errors in color
* src/parse-gram.y (parse.error): Set to 'custom'.
(yyreport_syntax_error): New.
* data/bison-default.css (.expected, .unexpected): New.
* tests/diagnostics.at: Adjust.
2020-01-23 08:26:33 +01:00
Akim Demaille f54a5b303b regen 2020-01-23 08:26:33 +01:00
Akim Demaille 2cc361387c diagnostics: translate bison's own tokens
As a test case, support translations in Bison itself.

* src/parse-gram.y: Mark the translatable tokens.
While at it, use clearer names.
* tests/input.at: Adjust expectations.
2020-01-23 08:26:28 +01:00
Akim Demaille e6d1289f4a diagnostics: handle -fno-caret in the called functions
Don't force callers of location_caret to have to deal with flags that
disable it.

* src/location.h, src/location.c (location_caret)
(location_caret_suggestion): Early return if disabled.
* src/complain.c: Simplify.
2020-01-22 22:31:41 +01:00
Akim Demaille 16c77b4ba2 yacc.c: fixes
* data/skeletons/yacc.c: Avoid warnings about unused functions.
Fix typo.
2020-01-22 22:31:07 +01:00
Adrian VogelsgesangandAkim Demaille 172f103c1e larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:22:27 +01:00
Akim Demaille 6ada985ff3 parsers: issue tname with i18n markup
Some users would like to avoid having to "parse" the *.y file to find
the strings to translate.  Let's issue the translatable tokens with N_
to allow "parsing" the generated parsers instead.

See
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00015.html

* src/output.c (prepare_symbol_names): Issue symbol_names with N_()
markup.
2020-01-19 21:23:11 +01:00
Akim Demaille 2e12257803 tests: check token internationalization
* tests/calc.at: Check it.
2020-01-19 21:23:11 +01:00
Akim Demaille 1db962716a regen 2020-01-19 21:23:11 +01:00
Akim Demaille 9096955fba parsers: support translatable token aliases
In addition to

    %token NUM "number"

accept

    %token NUM _("number")

in which case the token will be translated in error messages.
Do not use _() in the output if there are no translatable tokens.

* src/symtab.h, src/symtab.c (symbol): Add a 'translatable' member.
* src/parse-gram.y (TSTRING): New token.
(string_as_id.opt): Replace with...
(alias): this.
Use it.
* src/scan-gram.l (SC_ESCAPED_TSTRING): New start conditions, to match
TSTRINGs.
* src/output.c (prepare_symbols): Define b4_translatable if there are
translatable strings.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c (yytnamerr): Receive b4_translatable, and use it.
2020-01-19 21:23:11 +01:00
Akim Demaille e9d404415a tests: check that detailed error messages preserve UTF-8 characters
* tests/regression.at: here.
2020-01-19 21:23:03 +01:00
Akim Demaille d9df62bfcd yacc.c: escape trigraphs in detailed parse.error
* src/output.c (escape_trigraphs, xescape_trigraphs): New.
(prepare_symbol_names): Use it.
* tests/regression.at: Check the handling of trigraphs with
parse.error = detailed.
2020-01-19 21:22:41 +01:00
Akim Demaille adac9a17f0 regen 2020-01-19 14:51:14 +01:00
Akim Demaille 3b4b157369 bison: use detailed error messages
* #: .
2020-01-19 14:51:14 +01:00
Akim Demaille 5c332d70d7 regen 2020-01-19 14:51:14 +01:00
Akim Demaille 91247f50d7 yacc.c: tests: check detailed error messages
* tests/local.at (AT_ERROR_DETAILED_IF): New.
(AT_ERROR_SIMPLE_IF): Adjust.
* tests/calc.at: Check parse.error=detailed.
2020-01-19 14:51:14 +01:00
Akim Demaille f443673450 yacc.c: add support for parse.error detailed
"detailed" error messages are almost like "verbose", except that we
don't double escape them, they don't get inner quotes, we don't use
yytnamerr, and we hide the table.

"custom" is exposed with the "detailed" tokens, not the "verbose"
ones: they are not double-quoted.

Because there's a risk that some people use yytname even without
"verbose", let's keep yytname (instead of yys_name) in "simple"
parse.error.

* src/output.c (prepare_symbol_names): Be ready to output symbol names
unquoted.
(prepare_symbol_names): Output both the old tname table, and the new
symbol_names one.
* data/skeletons/bison.m4: Accept 'detailed'.
* data/skeletons/yacc.c: When parse.error is 'detailed', don't emit
yytname and yytnamerr, just yysymbol_name with the table inside.
* tests/calc.at: Adjust.
2020-01-19 14:51:14 +01:00
Akim Demaille 8e6233353f c: use yysymbol_name in traces
Only parse.error verbose and simple will get the original yytname: the
other options will rely on a different table.  So let's move on top of
the yysymbol_name function.

* data/skeletons/c.m4 (yy_symbol_print): Use yysymbol_name.
* data/skeletons/glr.c (yytokenName): Rename as...
(yysymbol_name): this.
The change of naming scheme is unfortunate, but it's definitely glr.c
which is "wrong".
2020-01-19 14:51:14 +01:00
Akim Demaille e5a5da16ed glr.c: move some functions after the definition of types
Currently yy_symbol_print is defined before yytokenName, although it
should use it instead of read yytname directly.  Move blocks around to
avoid this.

* data/skeletons/glr.c (yy_symbol_print): Move its definition after
that of yytokenName.
2020-01-19 14:51:14 +01:00
Akim Demaille ebe427bbf3 Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.1
  news: update
  CI: use ICC again
  warnings: pacify ICC in lalr1.cc
  test: report.at: avoid tiny new failure
  git: update ignores
2020-01-19 14:50:09 +01:00
Akim Demaille c6e2dcabae regen 2020-01-17 06:51:24 +01:00
Akim Demaille e1197fcc3d yacc.c: portability to G++ 4.8
Currently we get warnings with GCC 4.8 when running the
maintainer-check-g++ tests:

    143. skeletons.at:85: testing Installed skeleton file names ...
    ../../tests/skeletons.at:120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret --skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y
    ../../tests/skeletons.at:121: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o input-cmd-line input-cmd-line.c $LIBS
    stderr:
    input-cmd-line.c: In function 'int yysyntax_error(long int*, char**, const yyparse_context_t*)':
    input-cmd-line.c:977:52: error: conversion to 'int' from 'long int' may alter its value [-Werror=conversion]
                                       YYSIZEOF (yyarg) / YYSIZEOF (*yyarg));
                                                        ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/skeletons.at:121: exit code was 1, expected 0

and

    429. calc.at:823: testing Calculator parse.error=custom %locations api.prefix={calc}  ...
    ../../tests/calc.at:823: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:823: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c $LIBS
    stderr:
    calc.y: In function 'int yyreport_syntax_error(const yyparse_context_t*)':
    calc.y:157:58: error: conversion to 'int' from 'long unsigned int' may alter its value [-Werror=conversion]
       int n = yysyntax_error_arguments (ctx, arg, sizeof arg / sizeof *arg);
                                                              ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:823: exit code was 1, expected 0

We could use a cast to avoid the warning, but it becomes too
cluttered.  We can also use YYPTRDIFF_T, but that forces the user to
use YYPTRDIFF_T too, although this is an array of tokens, which is
limited by YYNTOKENS, an int.  So let's completely avoid this warning.

* data/skeletons/yacc.c, tests/local.at (yyreport_syntax_error): Avoid
relying on sizeof to compute the array capacity.
2020-01-17 06:49:59 +01:00
Akim Demaille 1854429e40 yacc.c: pass the parse-params to yyreport_syntax_error
Enhance the calculator tests: show that passing arguments to yyerror
works.

* tests/calc.at: Add a new parse-param, nerrs, which counts the number
of syntax errors in a run.
* tests/local.at: Adjust to handle the new 'nerrs' argument, when
present.

The custom error reporting function show sees the user's additional
arguments.  Let's experiment with passing them as arguments to
yyreport_syntax_error, but maybe storing them in the context would be
a bettter alternative.

* data/skeletons/yacc.c (yyreport_syntax_error): Handle the
parse-params.
* tests/calc.at, tests/local.at: Adjust.
2020-01-17 06:49:59 +01:00
Akim Demaille cece227f95 tests: a clearer test for parse-params
Currently the parse-params are tested in calc.at by checking that the
global variable and the parse-params have the same value.  But it does
not check that value, that could remain being 0 just as well.

* tests/calc.at: Don't define the params when they are not used.
Check the final value of result and count.
Also, do count the number of line of logs.
2020-01-17 06:49:59 +01:00
Akim Demaille e83077c617 yacc.c: check custom error messages with parse-params
* tests/calc.at: Check with prefix and parse-params.
2020-01-17 06:49:59 +01:00
Akim Demaille fd33cc9c8b yacc.c: let custom error messages see the location
* data/skeletons/yacc.c (yyparse_context_t): Add yylloc when
applicable.
(yyparse_context_location): New.
* tests/local.at (AT_YYERROR_DEFINE(c)): Handle the location.
* tests/calc.at: Check it.
2020-01-17 06:49:59 +01:00
Akim Demaille 8637438cee yacc.c: isolate yyexpected_tokens
Provide users with a means to query for the currently allowed tokens.
Could be used for autocompletion for instance.

* data/skeletons/yacc.c (yyexpected_tokens): New, extracted from
yysyntax_error_arguments.
* examples/c/calc/calc.y (PRINT_EXPECTED_TOKENS): New.
Use it.
2020-01-17 06:49:59 +01:00
Akim Demaille ee97f37cb4 tests: compute verbose error messages from the custom ones
We use a different format to check parse.error custom.  Compute the
"verbose" one from it instead of forcing the test author to provide
the various formats of expected error messages.

* tests/calc.at (_AT_CHECK_CALC_ERROR): Handle this transformation
when needed.
Simplify callers.
2020-01-17 06:49:59 +01:00
Akim Demaille 68ef3a0466 yacc.c: check custom error messages
* tests/local.at (AT_ERROR_CUSTOM_IF, AT_ERROR_VERBOSE_IF)
(AT_ERROR_SIMPLE_IF): New.
(AT_YYERROR_DEFINE(c)): Generate yyreport_syntax_error.
* tests/calc.at (_AT_CHECK_CALC_ERROR): Accept custom error messages
as additional test case.
Use it.
Add a new test case for %define parse.error custom.
2020-01-17 06:49:59 +01:00
Akim Demaille cda1934606 yacc.c: add custom error message generation
When parse.error is custom, let users define a yyreport_syntax_error
function, and use it.

* data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'.
* data/skeletons/yacc.c: Implement it.
* examples/c/calc/calc.y: Experiment with it.
2020-01-17 06:49:59 +01:00
Akim Demaille 5b883180e6 yacc.c: style: avoid macros
* data/skeletons/yacc.c (YYSYNTAX_ERROR): Remove, the call is now
sufficiently small so that we can afford to duplicate it.
2020-01-17 06:49:59 +01:00
Akim Demaille 135d0336d5 yacc.c: store token numbers, not token strings
That allows users to cover more cases, such as easily filtering some
arguments they don't want to expose.  But they now have to call
yysymbol_name explicitly.

* data/skeletons/yacc.c (yysyntax_error_arguments, yysyntax_error):
Deal with symbol numbers instead of symbol names.
2020-01-17 06:49:59 +01:00
Akim Demaille cc6c647f00 yacc.c: extract yyerror_message_arguments
Isolate a function that returns the list of expected and unexpected
tokens.  It will be exposed to users willing to customize their error
messages.

* data/skeletons/yacc.c (yyparse_context_t): New.
(yyerror_message_arguments): New, extracted from yysyntax_error.
2020-01-17 06:49:59 +01:00
Akim Demaille a1aef9825a regen 2020-01-17 06:49:45 +01:00
Akim Demaille ece99a890c tests: make AT_PARSE_PARAMS usable at the end of arguments
When not empty, AT_PARSE_PARAMS was guaranteed to end with a comma.
Remove the trailing comma, so that we can use AT_PARSE_PARAMS at the
end of the arguments, not only at the beginning.

* tests/local.at: here.
Unfortunately, m4_append relies on the macro not being defined whereas
we would have preferred it to check for emptiness.  So use
m4_define/m4_undefine instead of m4_pushdef/m4_popdef.
2020-01-15 08:55:51 +01:00
Akim Demaille 169c2530e4 tests: fix AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS pairs
* tests/glr-regression.at, tests/java.at, tests/javapush.at:
Close properly what is opened.
Do not nest.
2020-01-15 08:54:52 +01:00
Akim Demaille c894a6e2ce d, java: use traces more alike that of C
Same order, same places, same content.

* data/skeletons/lalr1.d, data/skeletons/lalr1.java: here.
2020-01-15 06:23:46 +01:00
Akim Demaille 187c2ac344 c++: report the stack at the same places as in C
Let's have C be the reference, and match it elsewhere.  Maybe C is too
verbose and some adjustments are needed, but then that would be done
in another batch of patches.

* data/skeletons/lalr1.cc: Print the stack once we popped after
YYERROR, and before emptying the stack at the end of parsing.
2020-01-15 06:22:42 +01:00
Akim Demaille f06c0d2c05 c++: display the stack in the same order as in C
Currently the C and C++ parse traces differ in the order in which the
stack is displayed: bottom up in C, top down in C++.  Let's stick to
the C order.

* data/skeletons/stack.hh (stack::iterator, stack::const_iterator)
(begin, end): Be forward, not backward.
2020-01-15 06:22:31 +01:00
Akim Demaille 975be86ccc style: avoid redundancy in the tests
* tests/local.at (m4_rpatsubst): New.
Use it to handle %parse-params.
* tests/calc.at: Use %parse-params with several arguments.
2020-01-15 06:22:19 +01:00
Akim Demaille 1c0adb410d yacc.c: comment changes
In particular, import Adrian Vogelsgesang's comments about LAC from
lalr1.cc.

* data/skeletons/yacc.c: here.
2020-01-11 18:01:39 +01:00
Akim Demaille 32b529f038 yacc.c: style: double-quote the argument of b4_percent_define_get
* data/skeletons/yacc.c: Here, for consistency.
2020-01-11 17:35:24 +01:00
Akim Demaille 46cce832fd yacc.c: introduce yysymbol_name
Provide the users with a public API to get the name of the tokens.  A
thin wrapper around yytname.

* data/skeletons/yacc.c (yysymbol_name): New.
Use it.
2020-01-11 16:14:06 +01:00
Akim Demaille 98a1045bea CI: check on PPC64le, ARM64 and s390x
I was hoping it would help us catch warnings when char is
unsigned (see 78bb152a63), but it does
not seem to help.  It's a pity that the compiler is the same all over
the place, I would have preferred testing others.

* .travis.yml: here.
2020-01-11 16:11:45 +01:00
Akim Demaille 8426663631 todo: update 2020-01-11 08:59:51 +01:00
Akim Demaille a0675d707f Merge branch 'maint' into HEAD
* maint:
  gnulib: update
  lalr1.cc: avoid static_cast
  glr.c: add missing cast
  regen
  package: bump copyrights to 2020
  gitignore: update
2020-01-11 07:38:39 +01:00
Akim Demaille e419eda5e2 regen 2020-01-10 18:38:02 +01:00
Akim Demaille 2116af766a yacc.c: simplify use of YYDPRINTF
* data/skeletons/yacc.c (YYDPRINTF): Expand to no-op (instead of
nothing) when disabled.
Simplify callers.
2020-01-09 09:02:55 +01:00
Akim Demaille 8036635251 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-05 10:26:35 +01:00
Akim Demaille c442b5de9d gitignore: update 2020-01-05 09:40:46 +01:00
Akim Demaille da4587fcd7 doc: YYERROR_VERBOSE is no longer supported
* doc/bison.texi (Table of Symbols): Remove last reference to it.
* NEWS: Be clear about that.
2020-01-04 09:14:19 +01:00
Akim Demaille 86a3ec0f8d glr.c: no longer support YYERROR_VERBOSE
* data/skeletons/glr.c: Rather, dispatch directly on parse.error's
value.
2020-01-04 09:14:19 +01:00
Akim Demaille 7122d747cf yacc.c: no longer support YYERROR_VERBOSE
Supporting YYERROR_VERBOSE via cpp is a nuisance: m4 is in charge of
handling alternatives.  When adding more options for %define
parse.error, supporting both CPP and M4 is too complex.  Anyway,
YYERROR_VERBOSE was deprecated long ago.

* data/skeletons/yacc.c: Use m4 only to handle verbose/simple error
messages.
2020-01-04 09:12:43 +01:00
Akim Demaille 69fe4b9eb6 yacc.c: avoid negations
* data/skeletons/yacc.c (yyerrlab): here.
2020-01-03 09:07:40 +01:00
Akim Demaille 385fb345bf glr.c: clarify yyreportSyntaxError
See the previous commit.

* data/skeletons/glr.c (yyreportSyntaxError): First compute the
arguments of the error message, _then_ th error message size.
2019-12-31 12:00:04 +01:00
Akim Demaille f983d00e77 yacc: restructure and fix yysyntax_error
I would like to offer new ways to build the error message.  As a first
step, let's simplify yysyntax_error whose first loop does two things
at the same time: (i) collect the tokens to be reported in the error
message, and (ii) accumulate their sizes and possibly return
"overflow".  Let's pull (ii) in a second step.

Then test 525 (regression.at:1193: parse.error=verbose overflow)
failed.  This test checks that we correctly report "memory overflow"
when the error message is too large.  However the test is mistaken: it
is triggered in a place where there are five (large) expected tokens,
so anyway we would not display them, so there is no (memory) overflow
here!  Transform this test to (i) check that indeed there is no
overflow, and (ii) create syntax_error3 which does check the intended
behavior, but with four expected tokens.

* data/skeletons/yacc.c (yysyntax_error): First compute the list of
arguments, then compute yysize.
* tests/regression.at (parse.error=verbose overflow): Enhance and fix.
2019-12-31 12:00:04 +01:00
322 changed files with 39653 additions and 13101 deletions
+2 -1
View File
@@ -1 +1,2 @@
*.at diff=autotest
*.texi diff=texinfo
+12
View File
@@ -0,0 +1,12 @@
# To use this gitconfig file, run
#
# git config --local include.path ../.gitconfig
#
# It adds an `[include]` section in .git/config.
# See <https://git-scm.com/docs/git-config#_includes>.
[diff "autotest"]
xfuncname = "^((m4_define|m4_pushdef|AT_SETUP).*)$"
[diff "texinfo"]
xfuncname = "^@node .*$"
+11 -4
View File
@@ -1,10 +1,19 @@
*.a
*.bak
*.diff
*.exe
*.log *.log
*.o *.o
*.orig
*.out
*.output
*.pdf *.pdf
*.rej
*.stamp *.stamp
*.tmp
*.trs *.trs
*~ *~
.deps .deps/
.dirstamp .dirstamp
/*.cache /*.cache
/*.flc /*.flc
@@ -20,11 +29,9 @@
/Makefile.in /Makefile.in
/README-release /README-release
/_* /_*
/a.exe
/a.out
/aclocal.m4 /aclocal.m4
/b.out
/bison-* /bison-*
/build-aux/move-if-change
/conf[0-9]* /conf[0-9]*
/confdefs* /confdefs*
/config.log /config.log
+1 -1
View File
@@ -1 +1 @@
3.5.3 3.8.2
+185 -78
View File
@@ -29,12 +29,13 @@ jobs:
clone: true clone: true
dist: bionic dist: bionic
script: script:
- sudo apt-get install -qq autoconf automake autopoint flex gettext graphviz help2man m4 texinfo - sudo apt-get install -qq autoconf automake autopoint flex gettext gperf graphviz help2man m4 texinfo
- autoconf --version - autoconf --version
- automake --version - automake --version
- autopoint --version - autopoint --version
- dot -V - dot -V
- gettext --version - gettext --version
- gperf --version
- help2man --version - help2man --version
- makeinfo --version - makeinfo --version
- m4 --version - m4 --version
@@ -43,12 +44,15 @@ jobs:
- git fetch --unshallow || true - git fetch --unshallow || true
- git submodule update --init --recursive - git submodule update --init --recursive
# As of 2021-08, we don't have Autoconf 2.71 on Ubuntu.
- sed -i 's/AC_PREREQ(\[2\.71])/AC_PREREQ([2.69])/g' configure.ac
- ./bootstrap - ./bootstrap
- ./configure --enable-gcc-warnings || { cat config.log && false; } - ./configure --enable-gcc-warnings || { cat config.log && false; }
- make -j2 - make -j2
- make -j2 dist - make -j2 dist-xz
# Can help understanding why we get "dirty" tarballs. # Can help understanding why we get "dirty" tarballs.
- git status - git status
- git diff
- dist=$(echo bison*.xz) - dist=$(echo bison*.xz)
# Unfortunately we cannot deterministically know the name of the tarball without the full # Unfortunately we cannot deterministically know the name of the tarball without the full
@@ -67,10 +71,139 @@ jobs:
## First. ## ## First. ##
## ------- ## ## ------- ##
# Start with three completely different environments, to get # Start with three completely different environments, to get errors asap.
# errors asap.
- name: "GCC 9 -O3" - name: "GCC 11 -O3"
stage: check
os: linux
dist: bionic
addons: &gcc11
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-11
env:
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
# ASAN is time consuming, and we timeout the 50min granted by
# Travis if we run all the tests in one go. Run in two parts.
- name: "Clang 11 libc++ and ASAN part 1"
stage: check
os: linux
dist: bionic
addons: &clang11
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-11
- libc++-11-dev
- libc++abi-11-dev
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-11 -fsanitize=address'
- CXX='clang++-11 -fsanitize=address -stdlib=libc++'
- PART=1
- name: "Clang 11 libc++ and ASAN part 2"
stage: check
os: linux
dist: bionic
addons: *clang11
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-11 -fsanitize=address'
- CXX='clang++-11 -fsanitize=address -stdlib=libc++'
- PART=2
# See https://github.com/simd-everywhere/simde/blob/master/.travis.yml
# and https://software.intel.com/content/www/us/en/develop/documentation/get-started-with-intel-oneapi-render-linux/top/configure-your-system.html.
- name: "ICC"
stage: check
os: linux
compiler: icc
env:
- CC=icc
- CXX=icpc
install:
- source /opt/intel/oneapi/compiler/latest/env/vars.sh
addons:
apt:
sources:
- sourceline: 'deb https://apt.repos.intel.com/oneapi all main'
key_url: 'https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB'
packages:
- intel-oneapi-icc
- name: "ARM64: GCC 11 -O2 part 1"
stage: check
os: linux
arch: arm64
dist: bionic
addons: *gcc11
env:
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "PPC64le: GCC 11 -O2 part 1"
stage: check
os: linux
arch: ppc64le
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-11
env:
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "s390x: GCC 11 -O2 part 1"
stage: check
os: linux
arch: s390x
dist: bionic
addons: *gcc11
env:
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
## ----- ##
## GCC. ##
## ----- ##
- name: "GCC 10 with sanitizers part 1"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-10
env:
- CC='gcc-10 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CXX='g++-10 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CONFIGUREFLAGS='CFLAGS=-O1 CXXFLAGS=-O1'
- PART=1
# With glr2.cc, we run out of time with the full test suite.
- name: "GCC 9 part 1"
stage: check stage: check
os: linux os: linux
dist: bionic dist: bionic
@@ -83,76 +216,10 @@ jobs:
env: env:
- CC=gcc-9 - CC=gcc-9
- CXX=g++-9 - CXX=g++-9
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
# ASAN is time consuming, and we timeout the 50min granted by
# Travis if we run all the tests in one go. Run in two parts.
- name: "Clang 9 libc++ and ASAN part 1"
stage: check
os: linux
dist: bionic
addons: &clang9
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-9
- libc++-9-dev
- libc++abi-9-dev
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-9 -fsanitize=address'
- CXX='clang++-9 -fsanitize=address -stdlib=libc++'
- PART=1 - PART=1
- name: "Clang 9 libc++ and ASAN part 2" # With glr2.cc, we run out of time with the full test suite.
stage: check - name: "GCC 8 part 1"
os: linux
dist: bionic
addons: *clang9
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-9 -fsanitize=address'
- CXX='clang++-9 -fsanitize=address -stdlib=libc++'
- PART=2
- name: "ICC"
stage: check
os: linux
compiler: icc
env:
- CC=icc
- CXX=icpc
install:
- source /opt/intel/inteloneapi/compiler/latest/env/vars.sh
addons:
apt:
sources:
- sourceline: 'deb https://apt.repos.intel.com/oneapi all main'
key_url: 'https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB'
packages:
- intel-oneapi-icc
## ----- ##
## GCC. ##
## ----- ##
- name: "GCC 8 with sanitizers part 1"
os: linux
dist: bionic
addons:
apt:
packages: g++-8
env:
- CC='gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CXX='g++-8 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CONFIGUREFLAGS='CFLAGS=-O1 CXXFLAGS=-O1'
- PART=1
- name: "GCC 8"
stage: check stage: check
os: linux os: linux
dist: bionic dist: bionic
@@ -162,6 +229,7 @@ jobs:
env: env:
- CC=gcc-8 - CC=gcc-8
- CXX=g++-8 - CXX=g++-8
- PART=1
- name: "GCC 7" - name: "GCC 7"
stage: check stage: check
@@ -250,7 +318,47 @@ jobs:
## Clang. ## ## Clang. ##
## ------- ## ## ------- ##
- name: "Clang 8 -O3" - name: "Clang 10 -O3, libc++, part 1"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-10
- libc++-10-dev
- libc++abi-10-dev
env:
- CC='clang-10'
- CXX='clang++-10 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- PART=1
- name: "Clang 9 and libc++"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-9
- libc++-9-dev
- libc++abi-9-dev
env:
- CC='clang-9'
- CXX='clang++-9 -stdlib=libc++'
- name: "Clang 8 and libc++"
stage: check stage: check
os: linux os: linux
dist: bionic dist: bionic
@@ -263,9 +371,8 @@ jobs:
env: env:
- CC=clang-8 - CC=clang-8
- CXX='clang++-8 -stdlib=libc++' - CXX='clang++-8 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- name: "Clang 7" - name: "Clang 7 and libc++"
stage: check stage: check
os: linux os: linux
dist: bionic dist: bionic
@@ -437,11 +544,11 @@ script:
- sudo apt-get install -qq doxygen flex m4 - sudo apt-get install -qq doxygen flex m4
# Install and activate dmd. # Install and activate dmd.
- mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh - mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
- source $(source ~/dlang/install.sh dmd -a) - source $(source ~/dlang/install.sh dmd -a) || true
- $CC --version - $CC --version
- $CXX --version - $CXX --version
- dmd --version - dmd --version || true
- doxygen --version - doxygen --version
- flex --version - flex --version
- ld --version - ld --version
+3 -2
View File
@@ -24,7 +24,8 @@ and nasty bugs.
----- -----
Copyright (C) 1998-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 1998-2015, 2018-2022, 2025-2026 Free Software Foundation,
Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -39,4 +40,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
+4 -4
View File
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail. Also add information on how to contact you by electronic and paper mail.
@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school, You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>. <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>. <https://www.gnu.org/licenses/why-not-lgpl.html>.
+210 -211
View File
File diff suppressed because it is too large Load Diff
+24 -3
View File
@@ -1,6 +1,7 @@
## Process this file with automake to produce Makefile.in. ## Process this file with automake to produce Makefile.in.
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2001-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,7 +14,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
@@ -42,7 +43,7 @@ dependencies = $(BISON_IN) $(src_bison_SOURCES) $(dist_skeletons_DATA)
BISON = $(top_builddir)/tests/bison BISON = $(top_builddir)/tests/bison
BISON_IN = $(top_srcdir)/tests/bison.in BISON_IN = $(top_srcdir)/tests/bison.in
YACC = $(BISON) -o y.tab.c YACC = $(BISON) -o y.tab.c
AM_YFLAGS_WITH_LINES = --defines -Werror -Wall --report=all AM_YFLAGS_WITH_LINES = --defines -Werror -Wall,dangling-alias --report=all
AM_YFLAGS = $(AM_YFLAGS_WITH_LINES) --no-lines AM_YFLAGS = $(AM_YFLAGS_WITH_LINES) --no-lines
# Initialization before completion by local.mk's. # Initialization before completion by local.mk's.
@@ -76,6 +77,13 @@ include tests/local.mk
clean-local: clean-local:
rm -rf $(CLEANDIRS) rm -rf $(CLEANDIRS)
.PHONY: gitsort
gitsort:
cd $(srcdir) \
&& for i in $$(git ls-files '*.gitignore' | grep -v doc); do \
LC_ALL=C sort $$i -o $$i; \
done
# See comments in build-aux/git-version-gen. However, we make .version depend # See comments in build-aux/git-version-gen. However, we make .version depend
# on configure so that .version and VERSION/PACKAGE_VERSION stay in sync in the # on configure so that .version and VERSION/PACKAGE_VERSION stay in sync in the
# working copy (for example, when you run autoreconf && make). Allowing these # working copy (for example, when you run autoreconf && make). Allowing these
@@ -127,3 +135,16 @@ gen-ChangeLog:
--since=$(gen_start_date) > $$cl.tmp && \ --since=$(gen_start_date) > $$cl.tmp && \
mv -f $$cl.tmp $$cl; \ mv -f $$cl.tmp $$cl; \
fi fi
# Useful to debug.
.c.i:
$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -o $@ -E $<
.PHONY: codespell
CODESPELL = codespell
codespell:
$(AM_V_GEN) cd $(srcdir) \
&& $(CODESPELL) \
--regex "[\\w\\-'\`]+\+*" \
--ignore-words-list "ba,circularly,cloneable,copyable,define'd,dout,froms,iff,ifset,od,ois" \
$$(git ls-files data doc lib src tests)
+935 -86
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -36,8 +36,8 @@ to the bison package.
----- -----
Copyright (C) 2002, 2005, 2009-2015, 2018-2020 Free Software Foundation, Copyright (C) 2002, 2005, 2009-2015, 2018-2022, 2025-2026 Free Software
Inc. Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -52,4 +52,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
+31 -21
View File
@@ -7,7 +7,7 @@ simple desk calculators to complex programming languages.
Bison is upward compatible with Yacc: all properly-written Yacc grammars Bison is upward compatible with Yacc: all properly-written Yacc grammars
work with Bison with no change. Anyone familiar with Yacc should be able to work with Bison with no change. Anyone familiar with Yacc should be able to
use Bison with little trouble. You need to be fluent in C, C++ or Java use Bison with little trouble. You need to be fluent in C, C++, D or Java
programming in order to use Bison. programming in order to use Bison.
Bison and the parsers it generates are portable, they do not require any Bison and the parsers it generates are portable, they do not require any
@@ -17,17 +17,18 @@ GNU Bison's home page is https://gnu.org/software/bison/.
# Installation # Installation
## Build from git ## Build from git
Here are basic installation instructions for a repository checkout: The [README-hacking.md file](README-hacking.md) is about building, modifying
and checking Bison. See its "Working from the Repository" section to build
Bison from the git repo. Roughly, run:
$ git submodule update --init $ git submodule update --init
$ ./bootstrap $ ./bootstrap
then proceed with the usual `configure && make` steps. then proceed with the usual `configure && make` steps.
The file README-hacking.md is about building, modifying and checking Bison.
## Build from tarball ## Build from tarball
See the file INSTALL for generic compilation and installation instructions. See the [INSTALL file](INSTALL) for generic compilation and installation
instructions.
Bison requires GNU m4 1.4.6 or later. See Bison requires GNU m4 1.4.6 or later. See
https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz. https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz.
@@ -41,9 +42,11 @@ installing it. In that case, do not use `src/bison`: it would use the
As an experimental feature, diagnostics are now colored, controlled by the As an experimental feature, diagnostics are now colored, controlled by the
`--color` and `--style` options. `--color` and `--style` options.
To use them, install the libtextstyle library before configuring Bison. It To use them, install the libtextstyle library, 0.20.5 or newer, before
is available from https://alpha.gnu.org/gnu/gettext/, for instance configuring Bison. It is available from https://alpha.gnu.org/gnu/gettext/,
https://alpha.gnu.org/pub/gnu/gettext/libtextstyle-0.20.5.tar.gz. for instance https://alpha.gnu.org/gnu/gettext/libtextstyle-0.20.5.tar.gz,
or as part of Gettext 0.21 or newer, for instance
https://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.gz.
The option --color supports the following arguments: The option --color supports the following arguments:
- always, yes: Enable colors. - always, yes: Enable colors.
@@ -60,6 +63,13 @@ To customize the styles, create a CSS file, say `bison-bw.css`, similar to
then invoke bison with `--style=bison-bw.css`, or set the `BISON_STYLE` then invoke bison with `--style=bison-bw.css`, or set the `BISON_STYLE`
environment variable to `bison-bw.css`. environment variable to `bison-bw.css`.
In some diagnostics, bison uses libtextstyle to emit special escapes to
generate clickable hyperlinks. The environment variable
`NO_TERM_HYPERLINKS` can be used to suppress them. This may be useful for
terminal emulators which produce garbage output when they receive the escape
sequence for a hyperlink. Currently (as of 2020), this affects some versions
of emacs, guake, konsole, lxterminal, rxvt, yakuake.
## Relocatability ## Relocatability
If you pass `--enable-relocatable` to `configure`, Bison is relocatable. If you pass `--enable-relocatable` to `configure`, Bison is relocatable.
@@ -77,7 +87,7 @@ for the user-side parser execution). The requirements between both differ:
bison needs ngettext, the generated parsers do not. To simplify the build bison needs ngettext, the generated parsers do not. To simplify the build
system, neither are installed if ngettext is not supported, even if system, neither are installed if ngettext is not supported, even if
generated parsers could have been localized. See generated parsers could have been localized. See
http://lists.gnu.org/archive/html/bug-bison/2009-08/msg00006.html for more https://lists.gnu.org/r/bug-bison/2009-08/msg00006.html for more
details. details.
# Questions # Questions
@@ -100,8 +110,18 @@ that the range specifies every single year in that closed interval.
<!-- <!--
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2020 Free LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american md
Software Foundation, Inc. LocalWords: MERCHANTABILITY GLR LALR IELR submodule init README src bw
LocalWords: Relocatability symlinks symlink
Local Variables:
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2022,
2025-2026 Free Software Foundation, Inc.
This file is part of GNU bison, the GNU Compiler Compiler. This file is part of GNU bison, the GNU Compiler Compiler.
@@ -112,14 +132,4 @@ Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution. Documentation License" file as part of this distribution.
Local Variables:
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american md
LocalWords: MERCHANTABILITY GLR LALR IELR submodule init README src bw
LocalWords: Relocatability symlinks symlink
--> -->
+3 -3
View File
@@ -12,8 +12,8 @@ the problems you encounter.
----- -----
Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Copyright (C) 2002, 2004, 2009-2015, 2018-2022, 2025-2026 Free Software
Inc. Foundation, Inc.
This file is part of GNU Bison. This file is part of GNU Bison.
@@ -28,4 +28,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
+375 -255
View File
@@ -2,62 +2,11 @@ This file attempts to describe the rules to use when hacking Bison.
Don't put this file into the distribution. Don't put this file into the distribution.
Everything related to the development of Bison is on Savannah: Everything related to the development of Bison is on Savannah:
http://savannah.gnu.org/projects/bison/. https://savannah.gnu.org/projects/bison/.
# Administrivia Working from the Repository
===========================
## If you incorporate a change from somebody on the net:
First, if it is a large change, you must make sure they have signed the
appropriate paperwork. Second, be sure to add their name and email address
to THANKS.
## If a change fixes a test, mention the test in the commit message.
## Bug reports
If somebody reports a new bug, mention his name in the commit message and in
the test case you write. Put him into THANKS.
The correct response to most actual bugs is to write a new test case which
demonstrates the bug. Then fix the bug, re-run the test suite, and check
everything in.
# Hacking
## Visible changes
Which include serious bug fixes, must be mentioned in NEWS.
## Translations
Only user visible strings are to be translated: error messages, bits of the
.output file etc. This excludes impossible error messages (comparable to
assert/abort), and all the --trace output which is meant for the maintainers
only.
## Coding style
Follow the GNU Coding Standards.
Don't reinvent the wheel: we use gnulib, which features many components.
Actually, Bison has legacy code that we should replace with gnulib modules
(e.g., many adhoc implementations of lists).
Do not add horizontal tab characters to any file in Bison's repository
except where required. For example, do not use tabs to format C code.
However, make files, ChangeLog, and some regular expressions require tabs.
Also, test cases might need to contain tabs to check that Bison properly
processes tabs in its input.
## Commit messages
Please, imitate the style we use. Use `git log` to get sources of
inspiration.
## Debugging
Bison supports tracing of its various steps, via the `--trace` option.
Since it is not meant for the end user, it is not displayed by `bison
--help`, nor is it documented in the manual. Instead, run `bison
--trace=help`.
# Working from the repository
These notes intend to help people working on the checked-out sources. These These notes intend to help people working on the checked-out sources. These
requirements do not apply when building from a distribution tarball. requirements do not apply when building from a distribution tarball.
@@ -70,27 +19,28 @@ requirements on anyone wishing to build from the just-checked-out sources.
For example, you have to use the latest stable versions of the maintainer For example, you have to use the latest stable versions of the maintainer
tools we depend upon, including: tools we depend upon, including:
- Autoconf <http://www.gnu.org/software/autoconf/> - Autoconf <https://www.gnu.org/software/autoconf/>
- Automake <http://www.gnu.org/software/automake/> - Automake <https://www.gnu.org/software/automake/>
- Flex <http://www.gnu.org/software/flex/> - Flex <https://www.gnu.org/software/flex/>
- Gettext <http://www.gnu.org/software/gettext/> - Gettext <https://www.gnu.org/software/gettext/>
- Graphviz <http://www.graphviz.org> - Gperf <https://www.gnu.org/software/gperf/>
- Gzip <http://www.gnu.org/software/gzip/> - Graphviz <https://www.graphviz.org>
- Help2man <http://www.gnu.org/software/help2man/> - Gzip <https://www.gnu.org/software/gzip/>
- Perl <http://www.cpan.org/> - Help2man <https://www.gnu.org/software/help2man/>
- Rsync <http://samba.anu.edu.au/rsync/> - Perl <https://www.cpan.org/>
- Tar <http://www.gnu.org/software/tar/> - Rsync <https://rsync.samba.org/>
- Texinfo <http://www.gnu.org/software/texinfo/> - Tar <https://www.gnu.org/software/tar/>
- Texinfo <https://www.gnu.org/software/texinfo/>
Valgrind <http://valgrind.org/> is also highly recommended, if it supports Valgrind <https://www.valgrind.org/> is also highly recommended, if it
your architecture. supports your architecture.
If you're using a GNU/Linux distribution, the easiest way to install the If you're using a GNU/Linux distribution, the easiest way to install the
above packages depends on your system. The following shell command should above packages depends on your system. The following shell command should
work for Debian-based systems such as Ubuntu: work for Debian-based systems such as Ubuntu:
sudo apt-get install \ sudo apt-get install \
autoconf automake autopoint flex graphviz help2man texinfo valgrind autoconf automake autopoint flex gperf graphviz help2man texinfo valgrind
Bison is written using Bison grammars, so there are bootstrapping issues. Bison is written using Bison grammars, so there are bootstrapping issues.
The bootstrap script attempts to discover when the C code generated from the The bootstrap script attempts to discover when the C code generated from the
@@ -107,7 +57,7 @@ might be needed.
Obviously, if you are reading these notes, you did manage to check out this Obviously, if you are reading these notes, you did manage to check out this
package from the repository. For the record, you will find all the relevant package from the repository. For the record, you will find all the relevant
information on http://savannah.gnu.org/git/?group=bison. information on https://savannah.gnu.org/git/?group=bison.
Bison uses Git submodules: subscriptions to other Git repositories. In Bison uses Git submodules: subscriptions to other Git repositories. In
particular it uses gnulib, the GNU portability library. To ask Git to particular it uses gnulib, the GNU portability library. To ask Git to
@@ -189,7 +139,7 @@ Register your changes.
For a suggestion of what gnulib commit might be stable enough for a formal For a suggestion of what gnulib commit might be stable enough for a formal
release, see the ChangeLog in the latest gnulib snapshot at release, see the ChangeLog in the latest gnulib snapshot at
http://erislabs.net/ianb/projects/gnulib/. https://erislabs.net/ianb/projects/gnulib/.
The Autoconf files we use are currently: The Autoconf files we use are currently:
- m4/m4.m4 - m4/m4.m4
@@ -200,7 +150,233 @@ These files don't change very often in Autoconf, so it should be relatively
straight-forward to examine the differences in order to decide whether to straight-forward to examine the differences in order to decide whether to
update. update.
# Test Suite ## Troubleshooting
Bison is self-hosted: its parser is generated by Bison. We don't force
ourselves to use the previous release of Bison, we use the current git
master for several reasons:
- dogfooding: let Bison be its first user
- monitoring: seeing the diff on the generated parsers with git is very
helpful, as it allows to see easily the impact of the changes on a real
case parser.
If you are unlucky the generated files, src/parse-gram.[ch], may be older
than their source, src/parse-gram.y. And your current version of Bison
might not be able to grok it. In that case, first refresh the generated
files:
$ touch src/parse-gram.[ch]
Then proceed.
In case you wrecked your current copy of the parser, get back the previous
version, compile bison, then force it to recreate the files:
$ git checkout HEAD^ src/parse-gram.[ch]
$ make -C _build
$ touch src/parse-gram.y
$ make -C _build
Administrivia
=============
## If you incorporate a change from somebody on the net:
First, if it is a large change, you must make sure they have signed the
appropriate paperwork. Second, be sure to add their name and email address
to THANKS.
## If a change fixes a test, mention the test in the commit message.
## Bug reports
If somebody reports a new bug, mention his name in the commit message and in
the test case you write. Put him into THANKS.
The correct response to most actual bugs is to write a new test case which
demonstrates the bug. Then fix the bug, re-run the test suite, and check
everything in.
Hacking
=======
## Visible Changes
Which include serious bug fixes, must be mentioned in NEWS.
## Translations
Only user visible strings are to be translated: error messages, bits of the
.output file etc. This excludes impossible error messages (comparable to
assert/abort), and all the --trace output which is meant for the maintainers
only.
## Vocabulary
- "lookahead", not "look-ahead".
- "midrule", not "mid-rule".
- "nonterminal", not "variable" or "non-terminal" or "non terminal".
Abbreviated as "nterm".
- "shift/reduce" and "reduce/reduce", not "shift-reduce" or "shift reduce",
etc.
## Syntax Highlighting
It's quite nice to be in C++ mode when editing lalr1.cc for instance.
However tools such as Emacs will be fooled by the fact that braces and
parens do not nest, as in `[[}]]`. As a consequence you might be misguided
by its visual pairing to parens. The m4-mode is safer. Unfortunately the
m4-mode is also fooled by `#` which is sees as a comment, stops pairing with
parens/brackets that are inside...
## Implementation Notes
There are several places with interesting details about the implementation:
- [Understanding C parsers generated by GNU
Bison](https://www.cs.uic.edu/~spopuri/cparser.html) by Satya Kiran Popuri,
is a wonderful piece of work that explains the implementation of Bison,
- [src/gram.h](src/gram.h) documents the way the grammar is represented
- [src/tables.h](src/tables.h) documents the generated tables
- [data/README.md](data/README.md) contains details about the m4 implementation
## Coding Style
Do not add horizontal tab characters to any file in Bison's repository
except where required. For example, do not use tabs to format C code.
However, make files, ChangeLog, and some regular expressions require tabs.
Also, test cases might need to contain tabs to check that Bison properly
processes tabs in its input.
Prefer `res` as the name of the local variable that will be "return"ed by
the function.
In writing arithmetic comparisons, use "<" and "<=" rather than ">" and ">="
<https://public-inbox.org/git/7vfyw7yebj.fsf_-_@assigned-by-dhcp.cox.net/>.
### Bison
Follow the GNU Coding Standards.
Don't reinvent the wheel: we use gnulib, which features many components.
Actually, Bison has legacy code that we should replace with gnulib modules
(e.g., many ad hoc implementations of lists).
#### Includes
The `#include` directives follow an order:
- first section for *.c files is `<config.h>`. Don't include it in header
files
- then, for *.c files, the corresponding *.h file
- then possibly the `"system.h"` header
- then the system headers.
Consider headers from `lib/` like system headers (i.e., `#include
<verify.h>`, not `#include "verify.h"`).
- then headers from src/ with double quotes (`#include "getargs.h"`).
Keep headers sorted alphabetically in each section.
See also the [Header
files](https://www.gnu.org/software/gnulib/manual/html_node/Header-files.html)
and the [Implementation
files](https://www.gnu.org/software/gnulib/manual/html_node/Implementation-files.html#Implementation-files)
nodes of the gnulib documentation.
Some source files are in the build tree (e.g., `src/scan-gram.c` made from
`src/scan-gram.l`). For them to find the headers from `src/`, we actually
use `#include "src/getargs.h"` instead of `#include "getargs.h"`---that
saves us from additional `-I` flags.
### Skeletons
We try to use the "typical" coding style for each language.
#### CPP
We indent the CPP directives this way:
```
#if FOO
# if BAR
# define BAZ
# endif
#endif
```
Don't indent with leading spaces in the skeletons (it's OK in the grammar
files though, e.g., in `%code {...}` blocks).
On occasions, use `cppi -c` to see where we stand. We don't aim at full
correctness: depending `-d`, some bits can be in the *.c file, or the *.h
file within the double-inclusion cpp-guards. In that case, favor the case
of the *.h file, but don't waste time on this.
Don't hesitate to leave a comment on the `#endif` (e.g., `#endif /* FOO
*/`), especially for long blocks.
There is no consistency on `! defined` vs. `!defined`. The day gnulib
decides, we'll follow them.
#### C/C++
Follow the GNU Coding Standards.
The `glr.c` skeleton was implemented with `camlCase`. We are migrating it
to `snake_case`. Because we are gradually standardizing the code, it is
currently inconsistent.
Use `YYFOO` and `yyfoo` for entities that are exposed to the user. They are
part of our contract with the users wrt backward compatibility.
Use `YY_FOO` and `yy_foo` for private matters. Users should not use them,
we are free to change them without fear of backward compatibility issues.
Use `*_t` for types, especially for `yy*_t` in which case we shouldn't worry
about the C standard introducing such a name.
#### C++
Follow the [C++ Core
Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
The [Google ones](https://google.github.io/styleguide/cppguide.html) may be
interesting too.
Our enumerators, such as the kinds (symbol and token kinds), should be lower
case, but it was too late to follow that track for token kinds, and symbol
kind enumerators are made to be consistent with them.
Use `*_type` for type aliases. Use `foo_get()` and `foo_set(v)` for
accessors, or simply `foo()` and `foo(v)`.
Use the `yy` prefix for private stuff, but there's no need for it in the
public API. The `yy` prefix is already taken care of via the namespace.
#### Java
We follow the [Java Code
Conventions](https://www.oracle.com/technetwork/java/codeconventions-150003.pdf)
and [Google Java Style
Guide](https://google.github.io/styleguide/javaguide.html). Unfortunately
at some point some GNU Coding Style was installed in Java, but it's an
error. So we should for instance stop putting spaces in function calls.
Because we are standardizing the code, it is currently inconsistent. Treat
acronyms as words: `YYLacStack`, not `YYLACStack`.
Use a 2-space indentation (Google) rather than 4 (Oracle).
Don't use the `yy` prefix for public members: `getExpectedTokens`, not
`yyexpectedTokens` or `yygetExpectedTokens`. Keep the `yy` prefix though
for private details.
## Commit Messages
Imitate the style we use. Use `git log` to get sources of inspiration.
If the changes have a small impact on Bison's generated parser, embed these
changes in the commit itself. If the impact is large, first push all the
changes except those about src/parse-gram.[ch], and then another commit
named "regen" which is only about them.
## Debugging
Bison supports tracing of its various steps, via the `--trace` option.
Since it is not meant for the end user, it is not displayed by `bison
--help`, nor is it documented in the manual. Instead, run `bison
--trace=help`.
## Documentation
Use `@option` for options and options with their argument if they have no
space (e.g., `@option{-Dfoo=bar}`). However, use `@samp` elsewhere (e.g.,
`@samp{-I foo}`).
Test Suite
==========
## make check ## make check
Consume without moderation. It is composed of two kinds of tests: the Consume without moderation. It is composed of two kinds of tests: the
@@ -208,9 +384,14 @@ examples, and the main test suite.
### The Examples ### The Examples
In examples/, there is a number of ready-to-use examples (see In examples/, there is a number of ready-to-use examples (see
examples/README.md). These examples have small test suites run by `make [examples/README.md](examples/README.md)). These examples have small test
check`. The test results are in local `*.log` files (e.g., suites run by `make check`. The test results are in local `*.log` files
`$build/examples/c/calc/calc.log`). (e.g., `$build/examples/c/calc/calc.log`).
To check only the examples, run `make check-examples`. To check just one
example,
make check-examples TESTS='examples/c/bistromathic/bistromathic.test'
### The Main Test Suite ### The Main Test Suite
The main test suite, in tests/, is written on top of GNU Autotest, which is The main test suite, in tests/, is written on top of GNU Autotest, which is
@@ -225,28 +406,23 @@ contains lots of details that should help diagnosing issues, including build
issues. The per-test logs are more convenient when working locally. issues. The per-test logs are more convenient when working locally.
#### TESTSUITEFLAGS #### TESTSUITEFLAGS
To run just the main test suite, run `make check-local`. To run just the main test suite, run `make check-tests`.
The default is for make check-local to run all tests sequentially. This can The default is for `make check-tests` to run all tests sequentially. This
be very time consuming when checking repeatedly or on slower setups. This can be very time consuming when checking repeatedly or on slower setups.
can be sped up in two ways: This can be sped up in two ways.
Using -j, in a make-like fashion, for example: 1. Using -j, in a make-like fashion, for example:
$ make check-local TESTSUITEFLAGS='-j8' $ make check-tests TESTSUITEFLAGS='-j8'
Actually, when using GNU Make, TESTSUITEFLAGS defaults to the -jN passed to When using GNU Make, TESTSUITEFLAGS defaults to the -jN passed to it, so you
it, so you may simply run may simply run
$ make check-local -j8 $ make check-tests -j8
Running only the tests of a certain category, as specified in the AT files 2. Running only the tests of a certain category. See
with AT_KEYWORDS([[category]]). Categories include: [tests/README.md](tests/README.md#keywords) for the list of categories.
- c++, for c++ parsers
- deprec, for tests concerning deprecated constructs.
- glr, for glr parsers
- java, for java parsers
- report, for automaton dumps
To get a list of all the tests (and their keywords for -k), run To get a list of all the tests (and their keywords for -k), run
@@ -254,11 +430,11 @@ To get a list of all the tests (and their keywords for -k), run
To run a specific set of tests, use -k (for "keyword"). For example: To run a specific set of tests, use -k (for "keyword"). For example:
$ make check-local TESTSUITEFLAGS='-k c++' $ make check-tests TESTSUITEFLAGS='-k c++'
Both can be combined. Both can be combined.
$ make check-local TESTSUITEFLAGS='-j8 -k c++' $ make check-tests TESTSUITEFLAGS='-j8 -k c++'
To rerun the tests that failed: To rerun the tests that failed:
@@ -270,7 +446,7 @@ added the `[-Wother]` part to all the warnings). Part of the update can be
done with a crude tool: `build-aux/update-test`. done with a crude tool: `build-aux/update-test`.
Once you ran the test suite, and therefore have many `testsuite.log` files, Once you ran the test suite, and therefore have many `testsuite.log` files,
run, from the source tree: run `make update-tests`. Or, by hand, from the *source* tree:
$ ./build-aux/update-test $build/tests/testsuite.dir/*/testsuite.log $ ./build-aux/update-test $build/tests/testsuite.dir/*/testsuite.log
@@ -280,6 +456,64 @@ again, since some early failures may stop latter tests from being run. Yet
at some point, you'll have to fix remaining issues by hand... at some point, you'll have to fix remaining issues by hand...
## Running Java parsers
Use the `javaexec.sh` script. For instance to run the parser of test case
504:
$ sh ./_build/javaexec.sh -cp ./_build/tests/testsuite.dir/504 Calc
## Using Sanitizers
Address sanitizer (ASAN) and undefined-behavior sanitizer (UBSAN) are very
useful. Here's one way to set them up with GCC 10 on Mac Ports
1. Configure with
```
$ ./configure -C --enable-gcc-warnings \
CPPFLAGS='-isystem /opt/local/include' \
CC='gcc-mp-10 -fsanitize=address -fsanitize=undefined' \
CFLAGS='-ggdb' \
CXX='g++-mp-10.0 -fsanitize=address -fsanitize=undefined' \
CXXFLAGS='-ggdb' \
LDFLAGS='-L/opt/local/lib'
```
2. Compile
3. Generate debug symbols:
```
$ dsymutil src/bison
```
4. Run the tests with leak detection enabled
(`ASAN_OPTIONS=detect_leaks=1`). E.g. for counterexamples:
```
$ make check-tests TESTSUITEFLAGS='-j5 -k cex' ASAN_OPTIONS=detect_leaks=1
```
5. You might need a suppression file. See
https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions.
With G++ on a Mac, you might need a suppression file (say `leak.supp`)
that contains:
```
leak:std::clog
```
and pass the additional flags
`LSAN_OPTIONS=suppressions=$PWD/leak.supp,print_suppressions=0`
6. To run the debugger, you might want something like this:
```
$ YYDEBUG=1 \
UBSAN_OPTIONS=print_stacktrace=1 \
LSAN_OPTIONS=suppressions=$PWD/leak.supp,print_suppressions=0 \
ASAN_OPTIONS=detect_leaks=1 \
lldb -- ./_build/tests/testsuite.dir/712/glr-regr2a ./_build/tests/testsuite.dir/712/input1.txt
```
In lldb to set a break on ubsan, try `rbreak ^__ubsan_handle_`.
## make maintainer-check-valgrind ## make maintainer-check-valgrind
This target uses valgrind both to check bison, and the generated parsers. This target uses valgrind both to check bison, and the generated parsers.
@@ -307,7 +541,7 @@ release:
- Maybe build with -DGNULIB_POSIXCHECK, which suggests gnulib modules that - Maybe build with -DGNULIB_POSIXCHECK, which suggests gnulib modules that
can fix portability issues. See if you really want to pay attention to can fix portability issues. See if you really want to pay attention to
its warnings; there's no need to obey blindly to it its warnings; there's no need to obey blindly to it
(<http://lists.gnu.org/archive/html/bison-patches/2012-05/msg00057.html>). (<https://lists.gnu.org/r/bison-patches/2012-05/msg00057.html>).
- Check with `make syntax-check` if there are issues diagnosed by gnulib. - Check with `make syntax-check` if there are issues diagnosed by gnulib.
@@ -354,176 +588,58 @@ re-run the tests, run:
./configure -C CC='gcc-mp-8 -fsanitize=undefined' CFLAGS='-ggdb' ./configure -C CC='gcc-mp-8 -fsanitize=undefined' CFLAGS='-ggdb'
make check make check
# Release Procedure
This section needs to be updated to take into account features from gnulib.
In particular, be sure to read README-release.
## Update the submodules. See above. ## Docker
## Update maintainer tools, such as Autoconf. See above. Running old compilers is not very easy. Docker can be used for some of
them. Have a look at .travis.yml for setups. Move the tarball in `/tmp`
and run, for instance:
## Try to get the *.pot files to the Translation Project at least one ```
week before a stable release, to give them time to translate them. Before docker run -v /tmp:/tmp -it ubuntu:xenial
generating the *.pot files, make sure that po/POTFILES.in and ```
runtime-po/POTFILES.in list all files with translatable strings. This
helps: `grep -l '\<_(' *`.
## Tests This way, the host and guest machines share `/tmp`.
See above.
## Update the foreign files ### GCC 4.6
Running `./bootstrap` in the top level should update them all for you. This On Ubuntu Xenial.
covers PO files too. Sometimes a PO file contains problems that causes it
to be rejected by recent Gettext releases; please report these to the
Translation Project.
## Update README ```
Make sure the information in README is current. Most notably, make sure it apt-get update
recommends a version of GNU M4 that is compatible with the latest Bison apt-get install software-properties-common
sources. apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
apt-get update
apt-get install -y gcc-4.6 g++-4.6 m4 make
```
## Check copyright years. ## Stow
We update years in copyright statements throughout Bison once at the start
of every year by running `make update-copyright`. However, before a
release, it's good to verify that it's actually been run. Besides the
copyright statement for each Bison file, check the copyright statements that
the skeletons insert into generated parsers, and check all occurrences of
`PACKAGE_COPYRIGHT_YEAR` in configure.ac.
## Update NEWS, commit and tag. If you want to install several versions of Bison using GNU Stow, do
See do-release-commit-and-tag in README-release. For a while, we used beta something like this:
names such as `2.6_rc1`. Now that we use gnulib in the release procedure,
we must use `2.5.90`, which has the additional benefit of being properly
sorted in `git tag -l`.
## make alpha, beta, or stable ```
See README-release. for v in 3.7 3.7.1
do
cd /tmp
wget https://ftp.gnu.org/gnu/bison/bison-$v.tar.xz
tar xf bison-$v.tar.xz
cd bison-$v
./configure --prefix /usr/local/stow/bison-$v
make -j4
sudo make install
done
```
## Upload Release Procedure
There are two ways to upload the tarballs to the GNU servers: using gnupload =================
(from gnulib), or by hand. Obviously prefer the former. But in either
case, be sure to read the following paragraph.
### Setup See the [README-release file](README-release), created when the package is
You need `gnupg`. bootstrapped.
Make sure your public key has been uploaded at least to keys.gnupg.net. You
can upload it with:
gpg --keyserver keys.gnupg.net --send-keys F125BDF3
where F125BDF3 should be replaced with your key ID.
### Using gnupload
You need `ncftp`.
At the end `make stable` (or alpha/beta) will display the procedure to run.
Just copy and paste it in your shell.
### By hand
The generic GNU upload procedure is at
http://www.gnu.org/prep/maintain/maintain.html#Automated-FTP-Uploads.
Follow the instructions there to register your information so you're permitted
to upload.
Here's a brief reminder of how to roll the tarballs and upload them:
### make distcheck
### gpg -b bison-2.3b.tar.gz
### In a file named `bison-2.3b.tar.gz.directive`, type:
version: 1.1
directory: bison
filename: bison-2.3b.tar.gz
### gpg --clearsign bison-2.3b.tar.gz.directive
### ftp ftp-upload.gnu.org # Log in as anonymous.
### cd /incoming/alpha # cd /incoming/ftp for full release.
### put bison-2.3b.tar.gz # This can take a while.
### put bison-2.3b.tar.gz.sig
### put bison-2.3b.tar.gz.directive.asc
### Repeat all these steps for bison-2.3b.tar.xz.
## Update Bison manual on www.gnu.org.
The instructions below are obsolete, and left in case one would like to run
the commands by hand. Today, one just needs to run
$ make web-manual-update
See README-release.
### You need a non-anonymous checkout of the web pages directory.
$ cvs -d YOUR_USERID@cvs.savannah.gnu.org:/web/bison checkout bison
### Get familiar with the instructions for web page maintainers.
http://www.gnu.org/server/standards/readme_index.html
http://www.gnu.org/server/standards/README.software.html
especially the note about symlinks.
### Build the web pages.
Assuming BISON_CHECKOUT refers to a checkout of the Bison dir, and
BISON_WWW_CHECKOUT refers to the web directory created above, do:
$ cd $BISON_CHECKOUT/doc
$ make stamp-vti
$ ../build-aux/gendocs.sh -o "$BISON_WWW_CHECKOUT/manual" \
bison "Bison - GNU parser generator"
$ cd $BISON_WWW_CHECKOUT
Verify that the result looks sane.
### Commit the modified and the new files.
### Remove old files.
Find the files which have not been overwritten (because they belonged to
sections that have been removed or renamed):
$ cd manual/html_node
$ ls -lt
Remove these files and commit their removal to CVS. For each of these
files, add a line to the file .symlinks. This will ensure that hyperlinks
to the removed files will redirect to the entire manual; this is better than
a 404 error.
## Announce
The "make release" command just created a template,
`$HOME/announce-bison-X.Y`. Otherwise, to generate it, run:
make RELEASE_TYPE=alpha gpg_key_ID=F125BDF3 announcement
where alpha can be replaced by `beta` or `table` and F125BDF3 should be
replaced with your key ID.
Complete/fix the announcement file. The generated list of recipients
(info-gnu@gnu.org, bison-announce@gnu.org, bug-bison@gnu.org,
help-bison@gnu.org, bison-patches@gnu.org, and
coordinator@translationproject.org) is appropriate for a stable release or a
"serious beta". For any other release, drop at least info-gnu@gnu.org. For
an example of how to fill out the rest of the template, search the mailing
list archives for the most recent release announcement.
For a stable release, send the same announcement on the comp.compilers
newsgroup by sending email to compilers@iecc.com. Do not make any Cc as the
moderator will throw away anything cross-posted or Cc'ed. It really needs
to be a separate message.
## Prepare NEWS
So that developers don't accidentally add new items to the old NEWS entry,
create a new empty entry in line 3 (without the two leading spaces):
* Noteworthy changes in release ?.? (????-??-??) [?]
Push these changes.
<!-- <!--
Copyright (C) 2002-2005, 2007-2015, 2018-2020 Free Software Foundation, Copyright (C) 2002-2005, 2007-2015, 2018-2022, 2025-2026 Free Software
Inc. Foundation, Inc.
This file is part of GNU Bison. This file is part of GNU Bison.
@@ -538,7 +654,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Local Variables: Local Variables:
mode: markdown mode: markdown
@@ -551,9 +667,13 @@ LocalWords: submodule init cd distcheck ChangeLog valgrind sigreturn sudo
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
LocalWords: symlinks vti html lt POSIX Cc'ed Graphviz Texinfo autoconf jN LocalWords: symlinks vti html lt POSIX Cc'ed Graphviz Texinfo autoconf jN
LocalWords: automake autopoint graphviz texinfo PROG Wother parsers LocalWords: automake autopoint graphviz texinfo PROG Wother parsers YYFOO
LocalWords: TESTSUITEFLAGS deprec struct gnulib's getopt config ggdb LocalWords: TESTSUITEFLAGS deprec struct gnulib's getopt config ggdb yyfoo
LocalWords: bitset fsanitize symlink CFLAGS MERCHANTABILITY ispell LocalWords: bitset fsanitize symlink CFLAGS MERCHANTABILITY ispell wrt YY
LocalWords: american LocalWords: american Administrivia camlCase yy accessors namespace src hoc
LocalWords: getExpectedTokens yyexpectedTokens yygetExpectedTokens parens
LocalWords: regen dogfooding Autotest testsuite getargs CPP BAZ endif cppi
LocalWords: cpp javaexec cp Calc ASAN UBSAN CPPFLAGS isystem CXX cex Gperf
LocalWords: CXXFLAGS LDFLAGS dsymutil gperf
--> -->
+22 -2
View File
@@ -4,6 +4,7 @@ it is today without the invaluable help of these people:
Aaro Koskinen [email protected] Aaro Koskinen [email protected]
Аскар Сафин [email protected] Аскар Сафин [email protected]
Adam Sampson [email protected] Adam Sampson [email protected]
Adrian Vogelsgesang [email protected]
Ahcheong Lee [email protected] Ahcheong Lee [email protected]
Airy Andre [email protected] Airy Andre [email protected]
Akim Demaille [email protected] Akim Demaille [email protected]
@@ -13,12 +14,14 @@ Alexandre Duret-Lutz [email protected]
Andre da Costa Barros [email protected] Andre da Costa Barros [email protected]
Andreas Damm [email protected] Andreas Damm [email protected]
Andreas Schwab [email protected] Andreas Schwab [email protected]
Andrei Malashkin [email protected]
Andrew Suffield [email protected] Andrew Suffield [email protected]
Angelo Borsotti [email protected] Angelo Borsotti [email protected]
Anthony Heading [email protected] Anthony Heading [email protected]
Antonio Silva Correia [email protected] Antonio Silva Correia [email protected]
Arnold Robbins [email protected] Arnold Robbins [email protected]
Art Haas [email protected] Art Haas [email protected]
Arthur Schwarz [email protected]
Askar Safin [email protected] Askar Safin [email protected]
Balázs Scheidler [email protected] Balázs Scheidler [email protected]
Baron Schwartz [email protected] Baron Schwartz [email protected]
@@ -32,6 +35,7 @@ Bob Rossi [email protected]
Brandon Lucia [email protected] Brandon Lucia [email protected]
Brooks Moses [email protected] Brooks Moses [email protected]
Bruce Lilly [email protected] Bruce Lilly [email protected]
Bruno Belanyi [email protected]
Bruno Haible [email protected] Bruno Haible [email protected]
Charles-Henri de Boysson [email protected] Charles-Henri de Boysson [email protected]
Christian Burger [email protected] Christian Burger [email protected]
@@ -44,6 +48,7 @@ Dagobert Michelsen [email protected]
Daniel Frużyński [email protected] Daniel Frużyński [email protected]
Daniel Galloway [email protected] Daniel Galloway [email protected]
Daniel Hagerty [email protected] Daniel Hagerty [email protected]
Daniela Becker [email protected]
David Barto [email protected] David Barto [email protected]
David J. MacKenzie [email protected] David J. MacKenzie [email protected]
David Kastrup [email protected] David Kastrup [email protected]
@@ -56,6 +61,8 @@ Derek M. Jones [email protected]
Di-an Jan [email protected] Di-an Jan [email protected]
Dick Streefland [email protected] Dick Streefland [email protected]
Didier Godefroy [email protected] Didier Godefroy [email protected]
Don Macpherson [email protected]
Dwight Guth [email protected]
Efi Fogel [email protected] Efi Fogel [email protected]
Enrico Scholz [email protected] Enrico Scholz [email protected]
Eric Blake [email protected] Eric Blake [email protected]
@@ -75,11 +82,13 @@ Gavin Smith [email protected]
Georg Sauthoff [email protected] Georg Sauthoff [email protected]
George Neuner [email protected] George Neuner [email protected]
Gilles Espinasse [email protected] Gilles Espinasse [email protected]
Giorgos Pap [email protected]
Goran Uddeborg [email protected] Goran Uddeborg [email protected]
Guido Trentalancia [email protected] Guido Trentalancia [email protected]
H. Merijn Brand [email protected] H. Merijn Brand [email protected]
Hans Åberg [email protected] Hans Åberg [email protected]
Horst Von Brand [email protected] Horst Von Brand [email protected]
Jacob L. Mandelson [email protected]
Jan Nieuwenhuizen [email protected] Jan Nieuwenhuizen [email protected]
Jannick [email protected] Jannick [email protected]
Jeff Hammond [email protected] Jeff Hammond [email protected]
@@ -100,14 +109,18 @@ Keith Browne [email protected]
Ken Moffat [email protected] Ken Moffat [email protected]
Kiyoshi Kanazawa [email protected] Kiyoshi Kanazawa [email protected]
Lars Maier [email protected] Lars Maier [email protected]
Lars Wendler [email protected]
László Várady [email protected] László Várady [email protected]
Laurent Mascherpa [email protected] Laurent Mascherpa [email protected]
Lie Yan [email protected] Lie Yan [email protected]
Maarten De Braekeleer [email protected]
Magnus Fromreide [email protected] Magnus Fromreide [email protected]
Marc Autret [email protected] Marc Autret [email protected]
Marc Mendiola [email protected] Marc Mendiola [email protected]
Marc Schönefeld [email protected] Marc Schönefeld [email protected]
Mark Boyall [email protected] Mark Boyall [email protected]
Marko Mäkelä [email protected]
Martin Blais [email protected]
Martin Jacobs [email protected] Martin Jacobs [email protected]
Martin Mokrejs [email protected] Martin Mokrejs [email protected]
Martin Nylin [email protected] Martin Nylin [email protected]
@@ -118,6 +131,7 @@ Michael Catanzaro [email protected]
Michael Felt [email protected] Michael Felt [email protected]
Michael Hayes [email protected] Michael Hayes [email protected]
Michael Raskin [email protected] Michael Raskin [email protected]
Michał Majchrowicz [email protected]
Michel d'Hooge [email protected] Michel d'Hooge [email protected]
Michiel De Wilde [email protected] Michiel De Wilde [email protected]
Mickael Labau [email protected] Mickael Labau [email protected]
@@ -132,6 +146,7 @@ Nick Bowler [email protected]
Nicolas Bedon [email protected] Nicolas Bedon [email protected]
Nicolas Burrus [email protected] Nicolas Burrus [email protected]
Nicolas Tisserand [email protected] Nicolas Tisserand [email protected]
Nikita Popov [email protected]
Nikki Valen [email protected] Nikki Valen [email protected]
Noah Friedman [email protected] Noah Friedman [email protected]
Odd Arild Olsen [email protected] Odd Arild Olsen [email protected]
@@ -153,6 +168,7 @@ Petr Machata [email protected]
Pho [email protected] Pho [email protected]
Piotr Gackiewicz [email protected] Piotr Gackiewicz [email protected]
Piotr Marcińczyk [email protected] Piotr Marcińczyk [email protected]
Pramod Kumbhar [email protected]
Quentin Hocquet [email protected] Quentin Hocquet [email protected]
Quoc Peyrot [email protected] Quoc Peyrot [email protected]
R Blake [email protected] R Blake [email protected]
@@ -166,6 +182,7 @@ Rob Vermaas [email protected]
Robert Anisko [email protected] Robert Anisko [email protected]
Robert Yang [email protected] Robert Yang [email protected]
Roland Levillain [email protected] Roland Levillain [email protected]
Ryan [email protected]
Satya Kiran Popuri [email protected] Satya Kiran Popuri [email protected]
Sebastian Setzer [email protected] Sebastian Setzer [email protected]
Sebastien Fricker [email protected] Sebastien Fricker [email protected]
@@ -176,6 +193,7 @@ Simon Sobisch [email protected]
Stefano Lattarini [email protected] Stefano Lattarini [email protected]
Stephen Cameron [email protected] Stephen Cameron [email protected]
Steve Murphy [email protected] Steve Murphy [email protected]
Suhwan Song [email protected]
Sum Wu [email protected] Sum Wu [email protected]
Théophile Ranquet [email protected] Théophile Ranquet [email protected]
Thiru Ramakrishnan [email protected] Thiru Ramakrishnan [email protected]
@@ -209,6 +227,7 @@ Wolfram Wagner [email protected]
Wwp [email protected] Wwp [email protected]
xolodho [email protected] xolodho [email protected]
Yuichiro Kaneko [email protected] Yuichiro Kaneko [email protected]
Yuriy Solodkyy [email protected]
Zack Weinberg [email protected] Zack Weinberg [email protected]
江 祖铭 [email protected] 江 祖铭 [email protected]
長田偉伸 [email protected] 長田偉伸 [email protected]
@@ -224,7 +243,8 @@ End:
----- -----
Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2000-2015, 2018-2022, 2025-2026 Free Software Foundation,
Inc.
This file is part of Bison, the GNU Parser Generator. This file is part of Bison, the GNU Parser Generator.
@@ -239,4 +259,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
+338 -237
View File
@@ -1,121 +1,234 @@
* Bison 3.6 * Soon
** yyerror_range in GLR
It seems useless that it is based on glr_stack_item, it should be doable
with location only.
** scan-code
The default case is scanning char-per-char.
/* By default, grow the string obstack with the input. */
.|\n STRING_GROW ();
make it more eager?
** Missing tests
commit 2c294c132528ede23d8ae4959783a67e9ff05ac5
Author: Vincent Imbimbo <[email protected]>
Date: Sat Jan 23 13:25:18 2021 -0500
cex: fix state-item pruning
See https://lists.gnu.org/r/bug-bison/2021-01/msg00002.html
** pos_set_set
The current approach is correct, but with poor performances. Bitsets need
to support 'assign' and 'shift'. And instead of extending POS_SET just for
the out-of-range new values, we need something like doubling the size.
** glr
There is no test with "Parse on stack %ld rejected by rule %d" in it.
** yyrline etc.
Clarify that rule numbers in the skeletons are 1-based.
** Macros in C++
There are many macros that should obey api.prefix: YY_CPLUSPLUS, YY_MOVE,
etc.
** yyerrok in Java
And add tests in calc.at, to prepare work for D.
** YYERROR and yynerrs
We are missing some cases. Write a test case, and check all the skeletons.
** Cex
*** Improve gnulib
Don't do this (counterexample.c):
// This is the fastest way to get the tail node from the gl_list API.
gl_list_node_t
list_get_end (gl_list_t list)
{
gl_list_node_t sentinel = gl_list_add_last (list, NULL);
gl_list_node_t res = gl_list_previous_node (list, sentinel);
gl_list_remove_node (list, sentinel);
return res;
}
*** Ambiguous rewriting
If the user is stupid enough to have equal rules, then the derivations are
harder to read:
Reduce/reduce conflict on tokens $end, "+", "⊕":
2 exp: exp "+" exp .
3 exp: exp "+" exp .
Example exp "+" exp •
First derivation exp ::=[ exp "+" exp • ]
Example exp "+" exp •
Second derivation exp ::=[ exp "+" exp • ]
Do we care about this? In color, we use twice the same color here, but we
could try to use the same color for the same rule.
*** XML reports
Show the counterexamples. This is going to be really hard and/or painful.
Unless we play it dumb (little structure).
** Bistromathic
- How about not evaluating incomplete lines when the text is not finished
(as shells do).
** Questions
*** Java
- Should i18n be part of the Lexer? Currently it's a static method of
Lexer.
- is there a migration path that would allow to use TokenKinds in
yylex?
- define the tokens as an enum too.
- promote YYEOF rather than EOF.
** YYerror
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
should be updated to not use YYERRCODE. Returning an undef token is good
enough.
** Java
*** calc.at
Stop hard-coding "Calc". Adjust local.at (look for FIXME).
** doc ** doc
I feel its ugly to use the GNU style to declare functions in the doc. It I feel it's ugly to use the GNU style to declare functions in the doc. It
generates tons of white space in the page, and may contribute to bad page generates tons of white space in the page, and may contribute to bad page
breaks. breaks.
Also, we seem to teach YYPRINT very early on, although it should be
considered deprecated: %printer is superior.
** improve syntax errors (UTF-8, internationalization)
Bison depends on the current locale. For instance:
%define parse.error verbose
%code top {
#include <stdio.h>
#include <stdlib.h>
void yyerror(const char* msg) { fprintf(stderr, "%s\n", msg); }
int yylex() { return 0; }
}
%%
exp: "↦" | "🎅🐃" | '\n'
%%
int main() { return yyparse(); }
gives different results with/without LC_ALL=C.
$ LC_ALL=C /opt/local/bin/bison /tmp/mangle.y -o ascii.c
$ /opt/local/bin/bison /tmp/mangle.y -o utf8.c
$ diff -u ascii.c utf8.c -I#line
--- ascii.c 2019-01-12 08:15:35.878010093 +0100
+++ utf8.c 2019-01-12 08:15:38.856495929 +0100
@@ -415,9 +415,8 @@
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
- "$end", "error", "$undefined", "\"\\342\\206\\246\"",
- "\"\\360\\237\\216\\205\\360\\237\\220\\203\"", "'\\n'", "$accept",
- "exp", YY_NULLPTR
+ "$end", "error", "$undefined", "\"↦\"", "\"🎅🐃\"", "'\\n'",
+ "$accept", "exp", YY_NULLPTR
};
#endif
$ gcc ascii.c -o ascii && ./ascii
syntax error, unexpected $end, expecting "\342\206\246" or "\360\237\216\205\360\237\220\203" or '\n'
$ gcc utf8.c -o utf8 && ./utf8
syntax error, unexpected $end, expecting ↦ or 🎅🐃 or '\n'
While at it, we should stop using "$end" by default, in favor of "end of
file", or "end of input", whatever. See how lalr1.java does that.
** consistency ** consistency
token vs terminal, variable vs non terminal. token vs terminal.
** Stop indentation in diagnostics
Before Bison 2.7, we printed "flatly" the dependencies in long diagnostics:
input.y:2.7-12: %type redeclaration for exp
input.y:1.7-12: previous declaration
In Bison 2.7, we indented them
input.y:2.7-12: error: %type redeclaration for exp
input.y:1.7-12: previous declaration
Later we quoted the source in the diagnostics, and today we have:
/tmp/foo.y:1.12-14: warning: symbol FOO redeclared [-Wother]
1 | %token FOO FOO
| ^~~
/tmp/foo.y:1.8-10: previous declaration
1 | %token FOO FOO
| ^~~
The indentation is no longer helping. We should probably get rid of it, or
maybe keep it only when -fno-caret. GCC displays this as a "note":
$ g++-mp-9 -Wall /tmp/foo.c -c
/tmp/foo.c:1:10: error: redefinition of 'int foo'
1 | int foo, foo;
| ^~~
/tmp/foo.c:1:5: note: 'int foo' previously declared here
1 | int foo, foo;
| ^~~
Likewise for Clang, contrary to what I believed (because "note:" is written
in black, so it doesn't show in my terminal :-)
$ clang++-mp-8.0 -Wall /tmp/foo.c -c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
/tmp/foo.c:1:10: error: redefinition of 'foo'
int foo, foo;
^
/tmp/foo.c:1:5: note: previous definition is here
int foo, foo;
^
1 error generated.
See also the item "Complaint submessage indentation" below.
** api.token.raw ** api.token.raw
Maybe we should exhibit the YYUNDEFTOK token. It could also be assigned a The YYUNDEFTOK could be assigned a semantic value so that yyerror could be
semantic value so that yyerror could be used to report invalid lexemes. used to report invalid lexemes.
See also the item "$undefined" below.
** C++ ** push parsers
Move to int everywhere instead of unsigned? stack_size, etc. The parser Consider deprecating impure push parsers. They add a lot of complexity, for
itself uses int (for yylen for instance), yet stack is based on size_t. a bad feature. On the other hand, that would make it much harder to sit
push parsers on top of pull parser. Which is currently not relevant, since
push parsers are measurably slower.
Maybe locations should also move to ints. ** %define parse.error formatted
How about pushing Bistromathic's yyreport_syntax_error as another standard
way to generate the error message, and leave to the user the task of
providing the message formats? Currently in bistro, it reads:
Paul Eggert already covered most of this. But before publishing these const char *
changes, we need to ask our C++ users if they agree with that change, or if error_format_string (int argc)
we need some migration path. Could be a %define variable, or simply {
%require "3.5". switch (argc)
{
default: /* Avoid compiler warnings. */
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
// "unexpected token", and '%0e', '%1e'... are expected tokens
// at this point.
//
// For instance on the expression "1 + * 2", you'd get
//
// 1.5: syntax error: expected - or ( or number or function or variable before *
case 2: return _("%@: syntax error: expected %0e before %u");
case 3: return _("%@: syntax error: expected %0e or %1e before %u");
case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
}
}
* Bison 3.7 The message would have to be generated in a string, and pushed to yyerror.
Which will be a pain in the neck in yacc.c.
If we want to do that, we should think very carefully about the syntax of
the format string.
** yyclearin does not invoke the lookahead token's %destructor
https://lists.gnu.org/r/bug-bison/2018-02/msg00000.html
Rici:
> Modifying yyclearin so that it calls yydestruct seems like the simplest
> solution to this issue, but it is conceivable that such a change would
> break programs which already perform some kind of workaround in order to
> destruct the lookahead symbol. So it might be necessary to use some kind of
> compatibility %define, or to create a new replacement macro with a
> different name such as yydiscardin.
>
> At a minimum, the fact that yyclearin does not invoke the %destructor
> should be highlighted in the documentation, since it is not at all obvious.
** Issues in i18n
Les catégories d'avertissements incluent :
conflicts-sr conflits S/R (activé par défaut)
conflicts-rr conflits R/R (activé par défaut)
dangling-alias l'alias chaîne n'est pas attaché à un symbole
deprecated construction obsolète
empty-rule règle vide sans %empty
midrule-values valeurs de règle intermédiaire non définies ou inutilisées
precedence priorité et associativité inutiles
yacc incompatibilités avec POSIX Yacc
other tous les autres avertissements (activé par défaut)
all tous les avertissements sauf « dangling-alias » et « yacc »
no-CATEGORY désactiver les avertissements dans CATEGORIE
none désactiver tous les avertissements
error[=CATEGORY] traiter les avertissements comme des erreurs
Line -1 and -3 should mention CATEGORIE, not CATEGORY.
* Bison 3.9
** Rewrite glr.cc (currently glr2.cc)
*** custom error messages
*** Remove jumps
We can probably replace setjmp/longjmp with exceptions. That would help
tremendously other languages such as D and Java that probably have no
similar feature. If we remove jumps, we probably no longer need _Noreturn,
so simplify `b4_attribute_define([noreturn])` into `b4_attribute_define`.
After discussing with Valentin, it was decided that it's better to stay with
jumps, since in some places exceptions are ruled out from C++.
*** Coding style
Move to our coding conventions. In particular names such as yy_glr_stack,
not yyGLRStack.
*** yydebug
It should be a member of the parser object, see lalr1.cc. Let the parser
object decide what the debug stream is, rather than open coding std::cerr.
*** Avoid pointers
There are many places where pointers should be replaced with references.
Some occurrences were fixed, but now some have improper names:
-yygetToken (int *yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_pure_if([, glr_stack* yystackp])[]b4_user_formals[)
+yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_pure_if([, glr_stack* yystackp])[]b4_user_formals[)
yycharp is no longer a Pointer. And yystackp should probably also be a reference.
*** parse.assert
Currently all the assertions are enabled. Once we are confident in glr2.cc,
let parse.assert use the same approach as in lalr1.cc.
*** debug_stream
Stop using std::cerr everywhere.
*** glr.c
When glr2.cc fully replaces glr.cc, get rid of the glr.cc scaffolding in
glr.c.
* Chains
** Unit rules / Injection rules (Akim Demaille) ** Unit rules / Injection rules (Akim Demaille)
Maybe we could expand unit rules (or "injections", see Maybe we could expand unit rules (or "injections", see
https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e., https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
@@ -158,18 +271,64 @@ The "automaton" and "set" categories are not so useful. We should probably
introduce lr(0) and lalr, just the way we have ielr categories. The introduce lr(0) and lalr, just the way we have ielr categories. The
"closure" function is too verbose, it should probably have its own category. "closure" function is too verbose, it should probably have its own category.
"set" can still be used for summariring the important sets. That would make "set" can still be used for summarizing the important sets. That would make
tests easy to maintain. tests easy to maintain.
*** complain.* *** complain.*
Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the
name they have in gcc, clang, etc. Likewise for the complain_* series of name they have in GCC, clang, etc. Likewise for the complain_* series of
functions. functions.
*** ritem *** ritem
states/nstates, rules/nrules, ..., ritem/nritems states/nstates, rules/nrules, ..., ritem/nritems
Fix the latter. Fix the latter.
*** m4: slot, type, type_tag
The meaning of type_tag varies depending on api.value.type. We should avoid
that and using clear definitions with stable semantics.
* D programming language
There's a number of features that are missing, here sorted in _suggested_
order of implementation.
When copying code from other skeletons, keep the comments exactly as they
are. Keep the same variable names. If you change the wording in one place,
do it in the others too. In other words: make sure to keep the
maintenance *simple* by avoiding any gratuitous difference.
** CI
Check when gdc and ldc.
** GLR Parser
This is very ambitious. That's the final boss. There are currently no
"clean" implementation to get inspiration from.
glr.c is very clean but:
- is low-level C
- is a different skeleton from yacc.c
glr.cc is (currently) an ugly hack: a C++ shell around glr.c. Valentin
Tolmer is currently rewriting glr.cc to be clean C++, but he is not
finished. There will be a lot a common code between lalr1.cc and glr.cc, so
eventually I would like them to be fused into a single skeleton, supporting
both deterministic and generalized parsing.
It would be great for D to also support this.
The basic ideas of GLR are explained here:
https://www.codeproject.com/Articles/5259825/GLR-Parsing-in-Csharp-How-to-Use-The-Most-Powerful
* Better error messages
The users are not provided with enough tools to forge their error messages.
See for instance "Is there an option to change the message produced by
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
See also
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
https://research.swtch.com/yyerror
http://gallium.inria.fr/~fpottier/publis/fpottier-reachability-cc2016.pdf
* Modernization * Modernization
Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
and older C++ compilers. Currently the code defaults to defining it to and older C++ compilers. Currently the code defaults to defining it to
@@ -177,12 +336,11 @@ and older C++ compilers. Currently the code defaults to defining it to
define it to the same type as the C ptrdiff_t type. define it to the same type as the C ptrdiff_t type.
* Completion * Completion
Several features are not available in all the backends. Several features are not available in all the back-ends.
- push parsers: glr.cc, lalr1.cc - push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
- ielr: C++ and Java - token constructors: Java, C, D (a bit difficult)
- glr: Java - glr: D, Java (super difficult)
- token constructors: Java and C
* Bugs * Bugs
** Autotest has quotation issues ** Autotest has quotation issues
@@ -194,12 +352,9 @@ $ ./tests/testsuite -l | grep errors | sed q
38: input.at:1730 errors 38: input.at:1730 errors
* Short term * Short term
** Get rid of YYPRINT and b4_toknum
Besides yytoknum is wrong when api.token.raw is defined.
** Better design for diagnostics ** Better design for diagnostics
The current implementation of diagnostics is adhoc, it grew organically. It The current implementation of diagnostics is ad hoc, it grew organically.
works as a series of calls to several functions, with dependency of the It works as a series of calls to several functions, with dependency of the
latter calls on the former. For instance: latter calls on the former. For instance:
complain (&sym->location, complain (&sym->location,
@@ -247,7 +402,7 @@ opposite side we have some use of \l, which is graphviz-specific, in what
should be generic code. should be generic code.
Little effort seems to have been given to factoring these files and their Little effort seems to have been given to factoring these files and their
rint{,-xml} counterpart. We would very much like to re-use the pretty format print{,-xml} counterpart. We would very much like to re-use the pretty format
of states from .output for the graphs, etc. of states from .output for the graphs, etc.
Since graphviz dies on medium-to-big grammars, maybe consider an other tool? Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
@@ -314,63 +469,6 @@ It would be a very nice source of inspiration for the other languages.
Valentin Tolmer is working on this. Valentin Tolmer is working on this.
** YYERRCODE
Why don't we output the token name of the error token in the output? It is
explicitly skipped:
/* Skip error token and tokens without identifier. */
if (sym != errtoken && id)
Of course there are issues with name spaces, but if we disable we have
something which seems to be more simpler and more consistent instead
of the special case YYERRCODE.
enum yytokentype {
error = 256,
// ...
};
We could (should?) also treat the case of the undef_token, which is
numbered 257 for yylex, and 2 internal. Both appear for instance in
toknum:
const unsigned short
parser::yytoken_number_[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
while here
enum yytokentype {
TOK_EOF = 0,
TOK_EQ = 258,
so both 256 and 257 are "mysterious".
const char*
const parser::yytname_[] =
{
"\"end of command\"", "error", "$undefined", "\"=\"", "\"break\"",
** yychar == yyempty_
The code in yyerrlab reads:
if (yychar <= YYEOF)
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
There are only two yychar that can be <= YYEOF: YYEMPTY and YYEOF.
But I can't produce the situation where yychar is YYEMPTY here, is it
really possible? The test suite does not exercise this case.
This shows that it would be interesting to manage to install skeleton
coverage analysis to the test suite.
* From lalr1.cc to yacc.c * From lalr1.cc to yacc.c
** Single stack ** Single stack
Merging the three stacks in lalr1.cc simplified the code, prompted for Merging the three stacks in lalr1.cc simplified the code, prompted for
@@ -386,14 +484,6 @@ We need trustworthy benchmarks for Bison, for all our backends. Akim has a
few things scattered around; we need to put them in the repo, and make them few things scattered around; we need to put them in the repo, and make them
more useful. more useful.
** yysyntax_error
The code bw glr.c and yacc.c is really alike, we can certainly factor
some parts.
This should be worked on when we also address the expected improvements for
error generation (e.g., i18n).
* Report * Report
** Figures ** Figures
@@ -420,18 +510,20 @@ undocumented ''features''. Maybe an empty action ought to be
presented too. Shall we try to make a single grammar with all these presented too. Shall we try to make a single grammar with all these
features, or should we have several very small grammars? features, or should we have several very small grammars?
** --report=conflict-path
Provide better assistance for understanding the conflicts by providing
a sample text exhibiting the (LALR) ambiguity. See the paper from
DeRemer and Penello: they already provide the algorithm.
** Statically check for potential ambiguities in GLR grammars
See <http://www.lsv.fr/~schmitz/pub/expamb.pdf> for an approach.
An Experimental Ambiguity Detection Tool Sylvain Schmitz
LORIA, INRIA Nancy - Grand Est, Nancy, France
* Extensions * Extensions
** More languages?
Well, only if there is really some demand for it.
*** PHP
https://github.com/scfc/bison-php/blob/master/data/lalr1.php
*** Python
https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
** Multiple start symbols ** Multiple start symbols
Revert a70e75b8a41755ab96ab211a0ea111ac68a4aadd.
Revert tests: disable "Multistart reports".
Would be very useful when parsing closely related languages. The idea is to Would be very useful when parsing closely related languages. The idea is to
declare several start symbols, for instance declare several start symbols, for instance
@@ -453,21 +545,27 @@ happen with yy_start: stmt | expr). Then adjust the skeletons so that this
initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
corresponding parse function. corresponding parse function.
** Better error messages *** Number of useless symbols
The users are not provided with enough tools to forge their error messages. AT_TEST(
See for instance "Is there an option to change the message produced by [[%start exp;
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help. exp: exp;]],
[[input.y: warning: 2 nonterminals useless in grammar [-Wother]
input.y: warning: 2 rules useless in grammar [-Wother]
input.y:2.8-10: error: start symbol exp does not derive any sentence]])
See also We should say "1 nonterminal": the other one is $accept, which should not
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf participate in the count.
and https://research.swtch.com/yyerror.
*** Tokens
Do we want to disallow terminal start symbols? The limitation is not
technical. Can it be useful to someone to "parse" a token?
** %include ** %include
This is a popular demand. We already made many changes in the parser that This is a popular demand. We already made many changes in the parser that
should make this reasonably easy to implement. should make this reasonably easy to implement.
Bruce Mardle <[email protected]> Bruce Mardle <[email protected]>
https://lists.gnu.org/archive/html/bison-patches/2015-09/msg00000.html https://lists.gnu.org/r/bison-patches/2015-09/msg00000.html
However, there are many other things to do before having such a feature, However, there are many other things to do before having such a feature,
because I don't want a % equivalent to #include (which we all learned to because I don't want a % equivalent to #include (which we all learned to
@@ -476,11 +574,11 @@ them together, paying attention to keep separate bits separated, in pseudo
name spaces. name spaces.
** Push parsers ** Push parsers
There is demand for push parsers in Java and C++. And GLR I guess. There is demand for push parsers in C++.
** Generate code instead of tables ** Generate code instead of tables
This is certainly quite a lot of work. See This is certainly quite a lot of work. See
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.4539. https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.4539.
** $-1 ** $-1
We should find a means to provide an access to values deep in the We should find a means to provide an access to values deep in the
@@ -520,13 +618,6 @@ XML output for GNU Bison and gcc
XML output for GNU Bison XML output for GNU Bison
http://yaxx.sourceforge.net/ http://yaxx.sourceforge.net/
** Counterexample generation
https://lists.gnu.org/archive/html/bug-bison/2016-06/msg00000.html
http://www.cs.cornell.edu/andru/papers/cupex/
Andrew Myers and Vincent Imbimbo are working on this item, see
https://github.com/akimd/bison/issues/12
* Coding system independence * Coding system independence
Paul notes: Paul notes:
@@ -558,15 +649,6 @@ move to partial orders (sounds like series/parallel orders to me).
This is a prerequisite for modules. This is a prerequisite for modules.
* $undefined
From Hans:
- If the Bison generated parser experiences an undefined number in the
character range, that character is written out in diagnostic messages, an
addition to the $undefined value.
Suggest: Change the name $undefined to undefined; looks better in outputs.
* Pre and post actions. * Pre and post actions.
From: Florian Krohm <[email protected]> From: Florian Krohm <[email protected]>
Subject: YYACT_EPILOGUE Subject: YYACT_EPILOGUE
@@ -599,28 +681,47 @@ to bison. If you're interested, I'll work on a patch.
Equip the parser with a means to create the (visual) parse tree. Equip the parser with a means to create the (visual) parse tree.
-----
# LocalWords: Cex gnulib gl Bistromathic TokenKinds yylex enum YYEOF EOF
# LocalWords: YYerror gettext af hb YYERRCODE undef calc FIXME dev yyerror
# LocalWords: Autoconf YYUNDEFTOK lexemes parsers Bistromathic's yyreport
# LocalWords: const argc yacc yyclearin lookahead destructor Rici incluent
# LocalWords: yydestruct yydiscardin catégories d'avertissements sr activé
# LocalWords: conflits défaut rr l'alias chaîne n'est attaché un symbole
# LocalWords: obsolète règle vide midrule valeurs de intermédiaire ou avec
# LocalWords: définies inutilisées priorité associativité inutiles POSIX
# LocalWords: incompatibilités tous les autres avertissements sauf dans rp
# LocalWords: désactiver CATEGORIE traiter comme des erreurs glr Akim bool
# LocalWords: Demaille arith lalr goto struct pathlen nullable ntokens lr
# LocalWords: nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ
# LocalWords: SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed
# LocalWords: nonterminals yykind yycode YYNAMES yynames init getName conv
# LocalWords: TokenKind ival yychar yylval yylexer Tolmer hoc
# LocalWords: Sobisch YYPTRDIFF ptrdiff Autotest toknum yytoknum
# LocalWords: sym Wother stderr FP fixits xgettext fdiagnostics Graphviz
# LocalWords: graphviz VCG bitset xml bw maint yytoken YYABORT deps
# LocalWords: YYACCEPT yytranslate nonnegative destructors yyerrlab repo
# LocalWords: backends stmt expr yy Mardle baz qux Vadim Maslow CPP cpp
# LocalWords: yydebug gcc UCHAR EBCDIC gung PDP NUL Pre Florian Krohm utf
# LocalWords: YYACT YYLLOC YYLSP yyval yyvsp yylen yyloc yylsp endif
# LocalWords: ispell american
Local Variables: Local Variables:
mode: outline mode: outline
coding: utf-8 coding: utf-8
fill-column: 76 fill-column: 76
ispell-dictionary: "american"
End: End:
----- Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2022, 2025-2026 Free
Software Foundation, Inc.
Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2020 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
This program is free software: you can redistribute it and/or modify Permission is granted to copy, distribute and/or modify this document
it under the terms of the GNU General Public License as published by under the terms of the GNU Free Documentation License, Version 1.3 or
the Free Software Foundation, either version 3 of the License, or any later version published by the Free Software Foundation; with no
(at your option) any later version. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
This program is distributed in the hope that it will be useful, Documentation License" file as part of this distribution.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Executable
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# Convenience script for regenerating all autogeneratable files that are
# omitted from the version control repository. In particular, this script
# also regenerates all aclocal.m4, config.h.in, Makefile.in, configure files
# with new versions of autoconf or automake.
# Copyright (C) 2003-2026 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Originally written by Paul Eggert. The canonical version of this
# script is maintained as top/autogen.sh in gnulib. However, to be
# useful to your package, you should place a copy of it under version
# control in the top-level directory of your package. The intent is
# that all customization can be done with a bootstrap.conf file also
# maintained in your version control; gnulib comes with a template
# build-aux/bootstrap.conf to get you started.
#
# Alternatively, you can use an autogen.sh script that is specific
# to your package.
me="$0"
medir=`dirname "$me"`
# Read the function library and the configuration.
. "$medir"/bootstrap-funclib.sh
autogen "$@"
Executable
+37
View File
@@ -0,0 +1,37 @@
#!/bin/sh
# Convenience script for fetching auxiliary files that are omitted from
# the version control repository of this package.
# Copyright (C) 2003-2026 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Originally written by Paul Eggert. The canonical version of this
# script is maintained as top/autopull.sh in gnulib. However, to be
# useful to your package, you should place a copy of it under version
# control in the top-level directory of your package. The intent is
# that all customization can be done with a bootstrap.conf file also
# maintained in your version control; gnulib comes with a template
# build-aux/bootstrap.conf to get you started.
#
# Alternatively, you can use an autopull.sh script that is specific
# to your package.
me="$0"
medir=`dirname "$me"`
# Read the function library and the configuration.
. "$medir"/bootstrap-funclib.sh
autopull "$@"
+149 -976
View File
File diff suppressed because it is too large Load Diff
+1383
View File
File diff suppressed because it is too large Load Diff
+31 -14
View File
@@ -1,6 +1,7 @@
# Bootstrap configuration. # Bootstrap configuration.
# Copyright (C) 2006-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2006-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,37 +14,43 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# gnulib modules used by this package. # gnulib modules used by this package.
gnulib_modules=' gnulib_modules='
argmatch array-list assert assure argmatch array-list assert assure attribute
bitsetv bitsetv
calloc-posix close closeout config-h c-strcase calloc-posix close closeout config-h c-strcase c-strtod
configmake configmake
dirname dirname
error extensions error execute extensions
fdl fopen-safer fstrcmp fopen-safer fstrcmp
getopt-gnu getopt-gnu
gettext-h git-version-gen gitlog-to-changelog gettext-h git-version-gen gitlog-to-changelog
gpl-3.0 intprops inttypes isnan javacomp-script gpl-3.0 intprops inttypes isnan javacomp-script
hash-map
javaexec-script javaexec-script
ldexpl ldexpl
libtextstyle-optional libtextstyle-optional
linked-list
malloc-gnu malloc-gnu
mcel-prefer
mbfile mbswidth mbfile mbswidth
non-recursive-gnulib-prefix-hack
obstack obstack
obstack-printf obstack-printf
perror progname perror progname
quote quotearg quote quotearg
rbtreehash-list
readline
readme-release readme-release
realloc-posix realloc-posix
relocatable-prog relocatable-script relocatable-prog relocatable-script
rename rename
spawn-pipe stdbool stpcpy strdup-posix strerror strverscmp spawn-pipe stdbool stpcpy stpncpy strdup-posix strerror strverscmp
sys_ioctl
termios
timevar timevar
unistd unistd-safer unlink unlocked-io unicodeio unistd unistd-safer unlink unlocked-io
update-copyright unsetenv verify update-copyright unsetenv verify
warnings warnings
winsz-ioctl winsz-ioctl
@@ -53,7 +60,7 @@ gnulib_modules='
xconcat-filename xconcat-filename
xhash xhash
xlist xlist
xmemdup0 xmap xmemdup0
xstrndup xstrndup
fprintf-posix printf-posix snprintf-posix sprintf-posix fprintf-posix printf-posix snprintf-posix sprintf-posix
@@ -74,13 +81,23 @@ XGETTEXT_OPTIONS_RUNTIME=$XGETTEXT_OPTIONS'\\\
--keyword=YY_ \\\ --keyword=YY_ \\\
' '
gnulib_tool_option_extras='--symlink --conditional-dependencies --makefile-name=gnulib.mk --po-base=gnulib-po --po-domain=bison' gnulib_tool_option_extras="\
--automake-subdir\
--automake-subdir-tests\
--avoid=mbiterf\
--conditional-dependencies\
--makefile-name=gnulib.mk\
--po-base=gnulib-po\
--po-domain=bison\
--symlink\
"
gnulib_extra_files="$gnulib_extra_files build-aux/move-if-change"
gnulib_extra_files="$gnulib_extra_files build-aux/epsf.tex"
bootstrap_post_import_hook() bootstrap_post_import_hook()
{ {
# Massage lib/gnulib.mk before using it later in the bootstrapping process.
build-aux/prefix-gnulib-mk --lib-name="$gnulib_name" "lib/$gnulib_mk"
# Ensure that ChangeLog exists, for automake. # Ensure that ChangeLog exists, for automake.
test -f ChangeLog || touch ChangeLog test -f ChangeLog || touch ChangeLog
} }
+6 -7
View File
@@ -1,30 +1,29 @@
/announce-gen /announce-gen
/compile /compile
/config.guess /config.guess
/config.libpath
/config.rpath /config.rpath
/config.rpath~
/config.sub /config.sub
/depcomp /depcomp
/do-release-commit-and-tag /do-release-commit-and-tag
/epsf.tex
/gendocs.sh /gendocs.sh
/git-version-gen /git-version-gen
/gitlog-to-changelog /gitlog-to-changelog
/gnu-web-doc-update /gnu-web-doc-update
/gnupload /gnupload
/install-reloc
/install-sh /install-sh
/javacomp.sh.in /javacomp.sh.in
/javaexec.sh.in /javaexec.sh.in
/libtool-reloc
/mdate-sh /mdate-sh
/missing /missing
/prefix-gnulib-mk /reloc-ldflags
/relocatable.sh.in
/test-driver /test-driver
/texinfo.tex /texinfo.tex
/update-copyright /update-copyright
/useless-if-before-free /useless-if-before-free
/vc-list-files /vc-list-files
/ylwrap /ylwrap
/config.libpath
/install-reloc
/reloc-ldflags
/relocatable.sh.in
/libtool-reloc
+3 -2
View File
@@ -1,4 +1,5 @@
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2012-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -11,7 +12,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Valgrind suppression file for Bison. # Valgrind suppression file for Bison.
+3 -2
View File
@@ -1,4 +1,5 @@
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2012-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -11,7 +12,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Valgrind suppression file for Bison. # Valgrind suppression file for Bison.
+1 -1
View File
@@ -2,7 +2,7 @@
# Generate a release announcement message. # Generate a release announcement message.
# Copyright (C) 2007-2020 Free Software Foundation, Inc. # Copyright (C) 2007-2022, 2025-2026 Free Software Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
+4 -2
View File
@@ -1,4 +1,5 @@
## Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc. ## Copyright (C) 2000-2015, 2018-2022, 2025-2026 Free Software
## Foundation, Inc.
## ##
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -11,12 +12,13 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
EXTRA_DIST += \ EXTRA_DIST += \
build-aux/Darwin.valgrind \ build-aux/Darwin.valgrind \
build-aux/Linux.valgrind \ build-aux/Linux.valgrind \
build-aux/cross-options.pl \ build-aux/cross-options.pl \
build-aux/epsf.tex \
build-aux/move-if-change \ build-aux/move-if-change \
build-aux/prev-version.txt \ build-aux/prev-version.txt \
build-aux/update-b4-copyright build-aux/update-b4-copyright
-1
View File
@@ -1 +0,0 @@
../gnulib/build-aux/move-if-change
+3 -2
View File
@@ -3,7 +3,8 @@
# Update b4_copyright invocations or b4_copyright_years definitions to # Update b4_copyright invocations or b4_copyright_years definitions to
# include the current year. # include the current year.
# Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2009-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict; use strict;
use warnings; use warnings;
+3 -2
View File
@@ -2,7 +2,8 @@
# In configure.ac, update PACKAGE_COPYRIGHT_YEAR to the current year. # In configure.ac, update PACKAGE_COPYRIGHT_YEAR to the current year.
# Copyright (C) 2010-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2010-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict; use strict;
use warnings; use warnings;
+9 -2
View File
@@ -2,7 +2,7 @@
# Update expectations in an Autotest test suite. # Update expectations in an Autotest test suite.
# Copyright (C) 2019-2020 Free Software Foundation, Inc. # Copyright (C) 2019-2022, 2025-2026 Free Software Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -73,6 +73,11 @@ def diff_to_re(match):
is_diff = True is_diff = True
to.append(l) to.append(l)
if is_diff: if is_diff:
# Do not run s//SOMETHING/g (with an emty pattern), that won't
# work well...
if frm == []:
trace("no from for", match.group(1))
return
frm = "\n".join(frm) frm = "\n".join(frm)
to = "\n".join(to) to = "\n".join(to)
subst[frm] = to subst[frm] = to
@@ -102,7 +107,7 @@ def update(at_file, logfile):
def process(logfile): def process(logfile):
log = contents(logfile) log = contents(logfile)
# Look for the file to update. # Look for the file to update.
m = re.search(r'^\d+\. ([-\w]+\.at):\d+: ', log, re.MULTILINE) m = re.search(r'^\d+\. ([\-\+\w]+\.at):\d+: ', log, re.MULTILINE)
if not m: if not m:
trace("no diff found:", logfile) trace("no diff found:", logfile)
return return
@@ -112,4 +117,6 @@ def process(logfile):
for logfile in args.logs: for logfile in args.logs:
trace("FILE:", logfile) trace("FILE:", logfile)
if os.path.isdir(logfile):
logfile = os.path.join(logfile, 'testsuite.log')
process(logfile) process(logfile)
+11 -7
View File
@@ -1,5 +1,6 @@
## Customize maint.mk -*- makefile -*- ## Customize maint.mk -*- makefile -*-
## Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc. ## Copyright (C) 2008-2015, 2018-2022, 2025-2026 Free Software
## Foundation, Inc.
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -12,7 +13,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
# Update version, then recompile so that tests/bison --version be # Update version, then recompile so that tests/bison --version be
# up-to-date, then compile our parser again with our up-to-date bison. # up-to-date, then compile our parser again with our up-to-date bison.
@@ -42,7 +43,7 @@ url_dir_list = \
# Tests not to run as part of "make distcheck". # Tests not to run as part of "make distcheck".
local-checks-to-skip = \ local-checks-to-skip = \
sc_immutable_NEWS \ sc_immutable_NEWS \
sc_prohibit_atoi_atof sc_indent
# The local directory containing the checked-out copy of gnulib used in # The local directory containing the checked-out copy of gnulib used in
# this release. Used solely to get a date for the "announcement" target. # this release. Used solely to get a date for the "announcement" target.
@@ -51,7 +52,7 @@ gnulib_dir = $(srcdir)/gnulib
bootstrap-tools = autoconf,automake,flex,gettext,gnulib bootstrap-tools = autoconf,automake,flex,gettext,gnulib
announcement_Cc_ = \ announcement_Cc_ = \
[email protected], [email protected], bison-patches@gnu.org, \ [email protected], bison-announce@gnu.org, \
[email protected] [email protected]
update-copyright: update-b4-copyright update-package-copyright-year update-copyright: update-b4-copyright update-package-copyright-year
@@ -126,7 +127,7 @@ _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
_space_before_paren_exempt =? \\n\\$$ _space_before_paren_exempt =? \\n\\$$
_space_before_paren_exempt = \ _space_before_paren_exempt = \
(^ *\#|(LA)?LR\([01]\)|percent_(code|define)|b4_syncline|m4_(define|init)|symbol) (^ *\#|(LA)?LR\([01]\)|percent_(code|define)|b4_syncline|m4_(define|init))
# Ensure that there is a space before each open parenthesis in C code. # Ensure that there is a space before each open parenthesis in C code.
sc_space_before_open_paren: sc_space_before_open_paren:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \ @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
@@ -156,16 +157,19 @@ exclude = \
$(call exclude, \ $(call exclude, \
bindtextdomain=^lib/main.c$$ \ bindtextdomain=^lib/main.c$$ \
cast_of_argument_to_free=^src/muscle-tab.c$$ \ cast_of_argument_to_free=^src/muscle-tab.c$$ \
po_check=(^po/POTFILES.in|.md)$$ \ error_message_uppercase=etc/bench.pl.in$$ \
file_system=^doc/Doxyfile.in$$ \
po_check=^tests|(^po/POTFILES.in|.md)$$ \
preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \ preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \
program_name=^lib/main.c$$ \ program_name=^lib/main.c$$ \
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \ prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \ prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
prohibit_always-defined_macros+=?|^tests/regression.at$$ \ prohibit_always-defined_macros+=?|^tests/regression.at$$ \
prohibit_atoi_atof=^(doc|etc|examples|tests)/ \
prohibit_doubled_word=^tests/named-refs.at$$ \ prohibit_doubled_word=^tests/named-refs.at$$ \
prohibit_magic_number_exit=^doc/bison.texi$$ \ prohibit_magic_number_exit=^doc/bison.texi$$ \
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \ prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
prohibit_strcmp=^doc/bison\.texi|examples|tests/local\.at$$ \ prohibit_strcmp=^doc/bison\.texi|examples|tests \
prohibit_tab_based_indentation=install-icc.sh|\.(am|mk)$$|^\.git|tests/input.at|Makefile$$ \ prohibit_tab_based_indentation=install-icc.sh|\.(am|mk)$$|^\.git|tests/input.at|Makefile$$ \
require_config_h=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \ require_config_h=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
require_config_h_first=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \ require_config_h_first=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
+41 -22
View File
@@ -1,6 +1,7 @@
# Configure template for GNU Bison. -*-Autoconf-*- # Configure template for GNU Bison. -*-Autoconf-*-
# #
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2001-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,14 +14,9 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# In order for some versions of Sun Studio to compile our C++ test cases AC_PREREQ([2.71])
# correctly, we need Autoconf 2.64 or better to handle the restrict
# keyword in at least string.h from gnulib. We need Autoconf 2.68 or
# better to avoid a typo in the 'configure --help' entry for the YACC
# environment variable.
AC_PREREQ([2.68])
m4_pattern_forbid([^_?(gl_[A-Z]|AX_|BISON_)]) m4_pattern_forbid([^_?(gl_[A-Z]|AX_|BISON_)])
m4_pattern_allow([^BISON_USE_NLS$]) m4_pattern_allow([^BISON_USE_NLS$])
@@ -29,17 +25,15 @@ AC_INIT([GNU Bison],
[[email protected]], [[email protected]],
[], [],
[https://www.gnu.org/software/bison/]) [https://www.gnu.org/software/bison/])
AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2020]) AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2026])
AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR], AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR],
[The copyright year for this package]) [The copyright year for this package])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
# We use Automake 1.14's %D% and %C%.
#
# When we move to Automake 1.16, simplify examples/c/reccalc/local.mk. # When we move to Automake 1.16, simplify examples/c/reccalc/local.mk.
# Our CI runs on Xenial, which has only Automake 1.15. # Our CI build the packages on Bionic, which has only Automake 1.15.
# #
# We want gnits strictness only when rolling a stable release. For # We want gnits strictness only when rolling a stable release. For
# release candidates, we use version strings like 2.4.3_rc1, but gnits # release candidates, we use version strings like 2.4.3_rc1, but gnits
@@ -47,7 +41,7 @@ AC_CONFIG_MACRO_DIR([m4])
# releases, we want to be able run make dist without being required to # releases, we want to be able run make dist without being required to
# add a bogus NEWS entry. In that case, the version string # add a bogus NEWS entry. In that case, the version string
# automatically contains a dash, which we also let disable gnits. # automatically contains a dash, which we also let disable gnits.
AM_INIT_AUTOMAKE([1.14 dist-xz nostdinc AM_INIT_AUTOMAKE([1.15 dist-lzip dist-xz nostdinc
color-tests parallel-tests color-tests parallel-tests
silent-rules] silent-rules]
m4_bmatch(m4_defn([AC_PACKAGE_VERSION]), [[-_]], m4_bmatch(m4_defn([AC_PACKAGE_VERSION]), [[-_]],
@@ -56,7 +50,7 @@ AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([lib/config.h:lib/config.in.h]) AC_CONFIG_HEADERS([lib/config.h:lib/config.in.h])
# Checks for the compiler. # Checks for the compiler.
AC_PROG_CC_STDC AC_PROG_CC
AC_PROG_CXX AC_PROG_CXX
# Gnulib (early checks). # Gnulib (early checks).
@@ -83,7 +77,8 @@ BISON_CXXSTD([03])
BISON_CXXSTD([11]) BISON_CXXSTD([11])
BISON_CXXSTD([14]) BISON_CXXSTD([14])
BISON_CXXSTD([17]) BISON_CXXSTD([17])
BISON_CXXSTD([2a]) BISON_CXXSTD([20])
BISON_CXXSTD([2b])
AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x]) AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x])
AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x]) AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x])
AC_LANG_POP([C++]) AC_LANG_POP([C++])
@@ -132,13 +127,17 @@ if test "$enable_gcc_warnings" = yes; then
warn_common='-Wall -Wextra warn_common='-Wall -Wextra
-Wcast-align -Wchar-subscripts -Wcast-align -Wchar-subscripts
-fparse-all-comments -Wdocumentation -fparse-all-comments -Wdocumentation
-Wformat -Wimplicit-fallthrough -Wnull-dereference -Wformat -Wimplicit-fallthrough -Wmismatched-dealloc -Wnull-dereference
-Wno-sign-compare -Wno-tautological-constant-out-of-range-compare -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare
-Wpointer-arith -Wshadow -Wpointer-arith -Wshadow -Wstrict-aliasing
-Wunused-but-set-variable
-Wwrite-strings -Wwrite-strings
-wr188 -wr2259 -wr3179' -wr188 -wr2259 -wr3179'
warn_c='-Wbad-function-cast -Wstrict-prototypes' warn_c='-Wbad-function-cast
warn_cxx='-Wextra-semi -Wnoexcept -Wold-style-cast -Wundefined-func-template -Wmissing-prototypes
-Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept -Wsubobject-linkage
-Wold-style-cast -Wundefined-func-template
-Wweak-vtables' -Wweak-vtables'
# Warnings for the test suite only. # Warnings for the test suite only.
# #
@@ -228,6 +227,16 @@ if test "$enable_gcc_warnings" = yes; then
gl_WARN_ADD([-Wno-deprecated], [WNO_DEPRECATED_CXXFLAGS]) gl_WARN_ADD([-Wno-deprecated], [WNO_DEPRECATED_CXXFLAGS])
CXXFLAGS=$save_CXXFLAGS CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++]) AC_LANG_POP([C++])
AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
AH_VERBATIM([FORTIFY_SOURCE],
[/* Enable compile-time and run-time bounds-checking, and some warnings,
without upsetting glibc 2.15+. */
#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
# define _FORTIFY_SOURCE 2
#endif
])
AC_DEFINE([GNULIB_PORTCHECK], [1], [Enable some gnulib portability checks.])
fi fi
@@ -248,7 +257,7 @@ AM_CONDITIONAL([ENABLE_JAVA], [test x"$CONF_JAVAC" != x && test x"$CONF_JAVA" !=
AC_ARG_ENABLE([yacc], AC_ARG_ENABLE([yacc],
[AC_HELP_STRING([--disable-yacc], [AS_HELP_STRING([--disable-yacc],
[do not build a yacc command or an -ly library])], [do not build a yacc command or an -ly library])],
, [enable_yacc=yes]) , [enable_yacc=yes])
AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes]) AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes])
@@ -261,9 +270,9 @@ if ! "$LEX_IS_FLEX" || test "X$LEX" = X:; then
AC_MSG_WARN([bypassing lex because flex is required]) AC_MSG_WARN([bypassing lex because flex is required])
LEX=: LEX=:
fi fi
AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX]) AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT])
AM_CONDITIONAL([FLEX_CXX_WORKS], AM_CONDITIONAL([FLEX_CXX_WORKS],
[$LEX_IS_FLEX && test $bison_cv_cxx_works = yes]) [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT && test $bison_cv_cxx_works = yes])
AC_PROG_YACC AC_PROG_YACC
AC_PROG_RANLIB AC_PROG_RANLIB
AC_PROG_GNU_M4 AC_PROG_GNU_M4
@@ -285,6 +294,9 @@ AC_C_INLINE
# gl_EARLY avoids some redundant checks. # gl_EARLY avoids some redundant checks.
gl_INIT gl_INIT
# We want ostream_printf and hyperlink support.
gl_LIBTEXTSTYLE_OPTIONAL([0.20.5])
# Checks for library functions. # Checks for library functions.
AC_CHECK_FUNCS_ONCE([setlocale]) AC_CHECK_FUNCS_ONCE([setlocale])
@@ -332,6 +344,13 @@ AC_MSG_RESULT([$suppfile])
# Whether we cannot run the compiled bison. # Whether we cannot run the compiled bison.
AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes]) AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
# Build bistromathic if we have the lib and both readline/readline.h
# and readline/history.h.
AM_CONDITIONAL([ENABLE_BISTROMATHIC],
[test "$gl_cv_lib_readline" != no &&
test "$ac_cv_header_readline_readline_h" = yes &&
test "$ac_cv_header_readline_history_h" = yes])
AM_MISSING_PROG([AUTOM4TE], [autom4te]) AM_MISSING_PROG([AUTOM4TE], [autom4te])
# Needed by tests/atlocal.in. # Needed by tests/atlocal.in.
AC_SUBST([GCC]) AC_SUBST([GCC])
+54 -18
View File
@@ -1,6 +1,6 @@
This directory contains data needed by Bison. This directory contains data needed by Bison.
# Directory content # Directory Content
## Skeletons ## Skeletons
Bison skeletons: the general shapes of the different parser kinds, that are Bison skeletons: the general shapes of the different parser kinds, that are
specialized for specific grammars by the bison program. specialized for specific grammars by the bison program.
@@ -48,7 +48,7 @@ various formats.
- xml2xhtml.xsl - xml2xhtml.xsl
Conversion into XHTML. Conversion into XHTML.
# Implementation note about the skeletons # Implementation Notes About the Skeletons
"Skeleton" in Bison parlance means "backend": a skeleton is fed by the bison "Skeleton" in Bison parlance means "backend": a skeleton is fed by the bison
executable with LR tables, facts about the symbols, etc. and they generate executable with LR tables, facts about the symbols, etc. and they generate
@@ -73,36 +73,63 @@ skeletons. If you are to write a new skeleton, please, implement them for
your language. Overall, be sure to follow the same patterns as the existing your language. Overall, be sure to follow the same patterns as the existing
skeletons. skeletons.
## Vocabulary
We use "formal arguments", or "formals" for short, to denote the declared
parameters of a function (e.g., `int argc, const char **argv`). Yes, this
is somewhat contradictory with `param` in the `%param` directives.
We use "effective arguments", or "args" for short, to denote the values
passed in function calls (e.g., `argc, argv`).
## Symbols ## Symbols
### `b4_symbol(NUM, FIELD)` ### `b4_symbol(NUM, FIELD)`
In order to unify the handling of the various aspects of symbols (tag, type In order to unify the handling of the various aspects of symbols (tag, type
name, whether terminal, etc.), bison.exe defines one macro per (token, name, whether terminal, etc.), bison.exe defines one macro per (token,
field), where field can `has_id`, `id`, etc.: see field), where field can `has_id`, `id`, etc.: see
`prepare_symbols_definitions()` in `src/output.c`. `prepare_symbol_definitions()` in `src/output.c`.
The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: NUM can be:
- `empty` to denote the "empty" pseudo-symbol when it exists,
- `eof`, `error`, or `undef`
- a symbol number.
- `has_id`: 0 or 1. FIELD can be:
Whether the symbol has an id. - `has_id`: 0 or 1
Whether the symbol has an `id`.
- `id`: string - `id`: string (e.g., `exp`, `NUM`, or `TOK_NUM` with api.token.prefix)
If has_id, the id (prefixed by api.token.prefix if defined), otherwise If `has_id`, the name of the token kind (prefixed by api.token.prefix if
defined as empty. Guaranteed to be usable as a C identifier. defined), otherwise empty. Guaranteed to be usable as a C identifier.
This is used to define the token kind (i.e., the enum used by the return
value of yylex). Should be named `token_kind`.
- `tag`: string. - `tag`: string
A representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. A human readable representation of the symbol. Can be `'foo'`,
`'foo.id'`, `'"foo"'` etc.
- `user_number`: integer - `code`: integer
The token code associated to the token kind `id`.
The external number as used by yylex. Can be ASCII code when a character, The external number as used by yylex. Can be ASCII code when a character,
some number chosen by bison, or some user number in the case of some number chosen by bison, or some user number in the case of `%token
%token FOO <NUM>. Corresponds to yychar in yacc.c. FOO <NUM>`. Corresponds to `yychar` in `yacc.c`.
- `is_token`: 0 or 1 - `is_token`: 0 or 1
Whether this is a terminal symbol. Whether this is a terminal symbol.
- `kind_base`: string (e.g., `YYSYMBOL_exp`, `YYSYMBOL_NUM`)
The base of the symbol kind, i.e., the enumerator of this symbol (token or
nonterminal) which is mapped to its `number`.
- `kind`: string
Same as `kind_base`, but possibly with a prefix in some languages. E.g.,
EOF's `kind_base` and `kind` are `YYSYMBOL_YYEOF` in C, but are
`S_YYEMPTY` and `symbol_kind::S_YYEMPTY` in C++.
- `number`: integer - `number`: integer
The code associated to the `kind`.
The internal number (computed from the external number by yytranslate). The internal number (computed from the external number by yytranslate).
Corresponds to yytoken in yacc.c. This is the same number that serves as Corresponds to yytoken in yacc.c. This is the same number that serves as
key in b4_symbol(NUM, FIELD). key in b4_symbol(NUM, FIELD).
@@ -129,11 +156,17 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
When api.value.type=union, the generated name for the union member. When api.value.type=union, the generated name for the union member.
yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc.
- `type` - `type`: string
If it has a semantic value, its type tag, or, if variant are used, If it has a semantic value, its type tag, or, if variant are used,
its type. its type.
In the case of api.value.type=union, type is the real type (e.g. int). In the case of api.value.type=union, type is the real type (e.g. int).
- `slot`: string
If it has a semantic value, the name of the union member (i.e., bounces to
either `type_tag` or `type`). It would be better to fix our mess and
always use `type` for the true type of the member, and `type_tag` for the
name of the union member.
- `has_printer`: 0, 1 - `has_printer`: 0, 1
- `printer`: string - `printer`: string
- `printer_file`: string - `printer_file`: string
@@ -166,7 +199,7 @@ The data corresponding to the symbol `#POS`, where the current rule has
Expansion of `$<TYPE>POS`, where the current rule has `RULE-LENGTH` symbols Expansion of `$<TYPE>POS`, where the current rule has `RULE-LENGTH` symbols
on RHS. on RHS.
----- <!--
Local Variables: Local Variables:
mode: markdown mode: markdown
@@ -174,7 +207,8 @@ fill-column: 76
ispell-dictionary: "american" ispell-dictionary: "american"
End: End:
Copyright (C) 2002, 2008-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2002, 2008-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of GNU Bison. This file is part of GNU Bison.
@@ -189,4 +223,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
+31 -1
View File
@@ -1,5 +1,5 @@
/* Default styling rules for Bison when doing terminal output. /* Default styling rules for Bison when doing terminal output.
Copyright (C) 2019-2020 Free Software Foundation, Inc. Copyright (C) 2019-2022, 2025-2026 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -29,3 +29,33 @@
/* "Sections" in traces (--trace). */ /* "Sections" in traces (--trace). */
.trace0 { color: green; } .trace0 { color: green; }
/* Syntax error messages. */
.expected { color: green; }
.unexpected { color: red; }
/* Counterexamples. */
/* Cex: point in rule. */
.cex-dot { color: red; }
/* Cex: coloring various rules. */
.cex-0 { color: yellow; }
.cex-1 { color: green; }
.cex-2 { color: blue; }
.cex-3 { color: purple; }
.cex-4 { color: violet; }
.cex-5 { color: orange; }
.cex-6 { color: brown; }
.cex-7 { color: mauve; }
.cex-8 { color: #013220; } /* Dark green. */
.cex-9 { color: #e75480; } /* Dark pink. */
.cex-10 { color: cyan; }
.cex-11 { color: orange; }
/* Cex: derivation rewriting steps. */
.cex-step { font-style: italic; }
/* Cex: leaves of a derivation. */
.cex-leaf { font-weight: 600; }
+5 -4
View File
@@ -1,5 +1,5 @@
## Copyright (C) 2002, 2005-2015, 2018-2020 Free Software Foundation, ## Copyright (C) 2002, 2005-2015, 2018-2022, 2025-2026 Free Software
## Inc. ## Foundation, Inc.
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -12,7 +12,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
dist_pkgdata_DATA = \ dist_pkgdata_DATA = \
data/README.md \ data/README.md \
@@ -28,18 +28,19 @@ dist_skeletons_DATA = \
data/skeletons/c.m4 \ data/skeletons/c.m4 \
data/skeletons/glr.c \ data/skeletons/glr.c \
data/skeletons/glr.cc \ data/skeletons/glr.cc \
data/skeletons/glr2.cc \
data/skeletons/java-skel.m4 \ data/skeletons/java-skel.m4 \
data/skeletons/java.m4 \ data/skeletons/java.m4 \
data/skeletons/lalr1.cc \ data/skeletons/lalr1.cc \
data/skeletons/lalr1.java \ data/skeletons/lalr1.java \
data/skeletons/location.cc \ data/skeletons/location.cc \
data/skeletons/stack.hh \ data/skeletons/stack.hh \
data/skeletons/traceon.m4 \
data/skeletons/variant.hh \ data/skeletons/variant.hh \
data/skeletons/yacc.c data/skeletons/yacc.c
# Experimental support for the D language. # Experimental support for the D language.
dist_skeletons_DATA += \ dist_skeletons_DATA += \
data/skeletons/README-D.txt \
data/skeletons/d-skel.m4 \ data/skeletons/d-skel.m4 \
data/skeletons/d.m4 \ data/skeletons/d.m4 \
data/skeletons/lalr1.d data/skeletons/lalr1.d
-60
View File
@@ -1,60 +0,0 @@
Some usage notes for the D Parser:
- it is a port of the Java parser, so interface is very similar.
- the lexer class needs to implement the interface 'Lexer' (similar to
java). It typically (depending on options) looks like this:
public interface Lexer
{
/**
* Method to retrieve the beginning position of the last scanned token.
* @return the position at which the last scanned token starts. */
@property YYPosition startPos ();
/**
* Method to retrieve the ending position of the last scanned token.
* @return the first position beyond the last scanned token. */
@property YYPosition endPos ();
/**
* Method to retrieve the semantic value of the last scanned token.
* @return the semantic value of the last scanned token. */
@property YYSemanticType semanticVal ();
/**
* Entry point for the scanner. Returns the token identifier corresponding
* to the next token and prepares to return the semantic value
* and beginning/ending positions of the token.
* @return the token identifier corresponding to the next token. */
YYTokenType yylex ();
/**
* Entry point for error reporting. Emits an error
* referring to the given location in a user-defined way.
*
* @param loc The location of the element to which the
* error message is related
* @param s The string for the error message. */
void yyerror (YYLocation loc, string s);
}
- semantic types are handled by D usions (same as for C/C++ parsers)
- the following (non-standard) %defines are supported:
%define package "<package_name>"
%define api.parser.class "my_class_name>"
%define position_type "my_position_type"
%define location_type "my_location_type"
- the following declarations basically work like in C/C++:
%locations
%error-verbose
%parse-param
%initial-action
%code
%union
- %destructor is not yet supported
+191 -68
View File
@@ -2,8 +2,8 @@
# Language-independent M4 Macros for Bison. # Language-independent M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation, # Copyright (C) 2002, 2004-2015, 2018-2022, 2025-2026 Free Software
# Inc. # Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,30 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...)
# ----------------------------------------------
# m4 equivalent of
#
# $_ = STRING;
# s/RE1/SUBST1/g;
# s/RE2/SUBST2/g;
# ...
#
# Really similar to m4_bpatsubsts, but behaves properly with quotes.
# See m4.at's "Generating Comments". Super inelegant, but so far, I
# did not find any better solution.
m4_define([b4_gsub],
[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]],
[$2], [$3]),
[$4], [$5]),
[$6], [$7])])
# m4_shift2 and m4_shift3 are provided by m4sugar.
m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
## ---------------- ## ## ---------------- ##
@@ -26,7 +49,7 @@
# b4_generated_by # b4_generated_by
# --------------- # ---------------
m4_define([b4_generated_by], m4_define([b4_generated_by],
[b4_comment([A Bison parser, made by GNU Bison b4_version.]) [b4_comment([A Bison parser, made by GNU Bison b4_version_string.])
]) ])
# b4_copyright(TITLE, [YEARS]) # b4_copyright(TITLE, [YEARS])
@@ -51,7 +74,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.]) along with this program. If not, see <https://www.gnu.org/licenses/>.])
b4_comment([As a special exception, you may create a larger work that contains b4_comment([As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work part or all of the Bison parser skeleton and distribute that work
@@ -72,8 +95,9 @@ version 2.2 of Bison.])
# ------------- # -------------
# Issue a warning about private implementation details. # Issue a warning about private implementation details.
m4_define([b4_disclaimer], m4_define([b4_disclaimer],
[b4_comment([Undocumented macros, especially those whose name start with YY_, [b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
are private implementation details. Do not rely on them.]) especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed.])
]) ])
@@ -161,7 +185,7 @@ m4_define([b4_error],
[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl [b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
[m4_if([$#], [4], [], [m4_if([$#], [4], [],
[m4_foreach([b4_arg], [m4_foreach([b4_arg],
m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))), m4_dquote(m4_shift4($@)),
[[@,]b4_arg])])[@)]])]) [[@,]b4_arg])])[@)]])])
# b4_warn(FORMAT, [ARG1], [ARG2], ...) # b4_warn(FORMAT, [ARG1], [ARG2], ...)
@@ -237,6 +261,13 @@ m4_define([b4_fatal_at],
[b4_error([[fatal]], $@)dnl [b4_error([[fatal]], $@)dnl
m4_exit(1)]) m4_exit(1)])
# b4_canary(MSG)
# --------------
# Issue a warning on stderr and in the output. Used in the test suite
# to catch spurious m4 evaluations.
m4_define([b4_canary],
[m4_errprintn([dead canary: $1])DEAD CANARY($1)])
## ------------ ## ## ------------ ##
## Data Types. ## ## Data Types. ##
@@ -308,14 +339,14 @@ number is the opposite. If YYTABLE_NINF, syntax error.]])
$1([check], [b4_check]) $1([check], [b4_check])
$1([stos], [b4_stos], $1([stos], [b4_stos],
[[YYSTOS[STATE-NUM] -- The (internal number of the) accessing [[YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
symbol of state STATE-NUM.]]) state STATE-NUM.]])
$1([r1], [b4_r1], $1([r1], [b4_r1],
[[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]]) [[YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.]])
$1([r2], [b4_r2], $1([r2], [b4_r2],
[[YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.]]) [[YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.]])
]) ])
@@ -367,8 +398,9 @@ m4_define([b4_$3_if],
# b4_FLAG_if(IF-TRUE, IF-FALSE) # b4_FLAG_if(IF-TRUE, IF-FALSE)
# ----------------------------- # -----------------------------
# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
b4_define_flag_if([defines]) # Whether headers are requested.
b4_define_flag_if([glr]) # Whether a GLR parser is requested. b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([has_translations]) # Whether some tokens are internationalized.
b4_define_flag_if([header]) # Whether a header is requested.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
@@ -379,43 +411,100 @@ b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
m4_define([b4_glr_cc_if], m4_define([b4_glr_cc_if],
[m4_if(b4_skeleton, ["glr.cc"], $@)]) [m4_if(b4_skeleton, ["glr.cc"], $@)])
# b4_glr2_cc_if([IF-TRUE], [IF-FALSE])
# ------------------------------------
m4_define([b4_glr2_cc_if],
[m4_if(b4_skeleton, ["glr2.cc"], $@)])
## --------- ## ## --------- ##
## Symbols. ## ## Symbols. ##
## --------- ## ## --------- ##
# For a description of the Symbol handling, see README. # For a description of the Symbol handling, see README.md.
# #
# The following macros provide access to symbol related values. # The following macros provide access to symbol related values.
# __b4_symbol(NUM, FIELD) # __b4_symbol(NUM, FIELD)
# ----------------------- # -----------------------
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if # Fetch FIELD of symbol #NUM. Fail if undefined.
# undefined.
m4_define([__b4_symbol], m4_define([__b4_symbol],
[m4_indir([b4_symbol($1, $2)])]) [m4_indir([b4_symbol($1, $2)])])
# _b4_symbol(NUM, FIELD) # _b4_symbol(NUM, FIELD)
# ---------------------- # ----------------------
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if # Fetch FIELD of symbol #NUM (or "orig NUM", see README.md).
# undefined. # Fail if undefined.
m4_define([_b4_symbol], m4_define([_b4_symbol],
[m4_ifdef([b4_symbol($1, number)], [m4_ifdef([b4_symbol($1, number)],
[__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)], [__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)],
[__b4_symbol([$1], [$2])])]) [__b4_symbol([$1], [$2])])])
# b4_symbol_token_kind(NUM)
# -------------------------
# The token kind of this symbol.
m4_define([b4_symbol_token_kind],
[b4_percent_define_get([api.token.prefix])dnl
_b4_symbol([$1], [id])])
# b4_symbol_kind_base(NUM)
# ------------------------
# Build the name of the kind of this symbol. It must always exist,
# otherwise some symbols might not be represented in the enum, which
# might be compiled into too small a type to contain all the symbol
# numbers.
m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])])
m4_define([b4_symbol_kind_base],
[b4_percent_define_get([api.symbol.prefix])dnl
m4_case([$1],
[-2], [[YYEMPTY]],
[0], [[YYEOF]],
[1], [[YYerror]],
[2], [[YYUNDEF]],
[m4_case(b4_symbol([$1], [tag]),
[$accept], [[YYACCEPT]],
[b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]),
[m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])])
# b4_symbol_kind(NUM)
# -------------------
# Same as b4_symbol_kind, but possibly with a prefix in some
# languages. E.g., EOF's kind_base and kind are YYSYMBOL_YYEOF in C,
# but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++.
m4_copy([b4_symbol_kind_base], [b4_symbol_kind])
# b4_symbol_slot(NUM)
# -------------------
# The name of union member that contains the value of these symbols.
# Currently, we are messy, this should actually be type_tag, but type_tag
# has several meanings.
m4_define([b4_symbol_slot],
[m4_case(b4_percent_define_get([[api.value.type]]),
[union], [b4_symbol([$1], [type_tag])],
[variant], [b4_symbol([$1], [type_tag])],
[b4_symbol([$1], [type])])])
# b4_symbol(NUM, FIELD) # b4_symbol(NUM, FIELD)
# --------------------- # ---------------------
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if # Fetch FIELD of symbol #NUM (or "orig NUM", or "empty"). Fail if undefined.
# undefined. If FIELD = id, prepend the token prefix. #
# If FIELD = id, prepend the token prefix.
m4_define([b4_symbol], m4_define([b4_symbol],
[m4_case([$2], [m4_if([$1], [empty], [b4_symbol([-2], [$2])],
[id], [m4_do([b4_percent_define_get([api.token.prefix])], [$1], [eof], [b4_symbol([0], [$2])],
[_b4_symbol([$1], [id])])], [$1], [error], [b4_symbol([1], [$2])],
[_b4_symbol($@)])]) [$1], [undef], [b4_symbol([2], [$2])],
[m4_case([$2],
[id], [b4_symbol_token_kind([$1])],
[kind_base], [b4_symbol_kind_base([$1])],
[kind], [b4_symbol_kind([$1])],
[slot], [b4_symbol_slot([$1])],
[_b4_symbol($@)])])])
# b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
@@ -437,9 +526,9 @@ m4_define([b4_symbol_tag_comment],
]) ])
# b4_symbol_action(SYMBOL-NUM, KIND) # b4_symbol_action(SYMBOL-NUM, ACTION)
# ---------------------------------- # ------------------------------------
# Run the action KIND (destructor or printer) for SYMBOL-NUM. # Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
m4_define([b4_symbol_action], m4_define([b4_symbol_action],
[b4_symbol_if([$1], [has_$2], [b4_symbol_if([$1], [has_$2],
[b4_dollar_pushdef([(*yyvaluep)], [b4_dollar_pushdef([(*yyvaluep)],
@@ -463,21 +552,21 @@ m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])]) m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
# b4_symbol_actions(KIND, [TYPE = yytype]) # b4_symbol_actions(ACTION, [KIND = yykind])
# ---------------------------------------- # ------------------------------------------
# Emit the symbol actions for KIND ("printer" or "destructor"). # Emit the symbol actions for ACTION ("destructor" or "printer").
# Dispatch on TYPE. # Dispatch on KIND.
m4_define([b4_symbol_actions], m4_define([b4_symbol_actions],
[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl [m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
m4_ifval(m4_defn([b4_actions_]), m4_ifval(m4_defn([b4_actions_]),
[switch (m4_default([$2], [yytype])) [switch (m4_default([$2], [yykind]))
{ {
m4_defn([b4_actions_])[]dnl m4_defn([b4_actions_])[]dnl
default: default:
break; break;
}dnl }dnl
], ],
[YYUSE (m4_default([$2], [yytype]));])dnl [b4_use(m4_default([$2], [yykind]));])dnl
m4_popdef([b4_actions_])dnl m4_popdef([b4_actions_])dnl
]) ])
@@ -487,7 +576,7 @@ m4_popdef([b4_actions_])dnl
# easier to use with m4_map, but then, use []dnl to suppress the last # easier to use with m4_map, but then, use []dnl to suppress the last
# one. # one.
m4_define([_b4_symbol_case], m4_define([_b4_symbol_case],
[case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])]) [case b4_symbol([$1], [kind]): b4_symbol_tag_comment([$1])])
]) ])
@@ -507,13 +596,14 @@ m4_define([b4_symbol_map],
# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE) # b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
# ------------------------------------------- # -------------------------------------------
# Whether NUM denotes a token that has an exported definition (i.e., # Whether NUM denotes a token kind that has an exported definition
# shows in enum yytokentype). # (i.e., shows in enum yytokentype).
m4_define([b4_token_visible_if], m4_define([b4_token_visible_if],
[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [is_token],
[b4_symbol_if([$1], [has_id], [$2], [$3])], [b4_symbol_if([$1], [has_id], [$2], [$3])],
[$3])]) [$3])])
# b4_token_has_definition(NUM) # b4_token_has_definition(NUM)
# ---------------------------- # ----------------------------
# 1 if NUM is visible, nothing otherwise. # 1 if NUM is visible, nothing otherwise.
@@ -530,13 +620,27 @@ m4_define([b4_any_token_visible_if],
# b4_token_format(FORMAT, NUM) # b4_token_format(FORMAT, NUM)
# ---------------------------- # ----------------------------
# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER.
m4_define([b4_token_format], m4_define([b4_token_format],
[b4_token_visible_if([$2], [b4_token_visible_if([$2],
[m4_format([[$1]], [m4_format([[$1]],
m4_quote(b4_symbol([$2], [id])), b4_symbol([$2], [id]),
m4_quote(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])]) b4_symbol([$2], b4_api_token_raw_if([[number]], [[code]])))])])
# b4_last_enum_token
# ------------------
# The code of the last token visible token.
m4_define([_b4_last_enum_token],
[b4_token_visible_if([$1],
[m4_define([b4_last_enum_token], [$1])])])
b4_symbol_foreach([_b4_last_enum_token])
# b4_last_symbol
# --------------
# The code of the last symbol.
m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1))
## ------- ## ## ------- ##
## Types. ## ## Types. ##
## ------- ## ## ------- ##
@@ -558,11 +662,11 @@ m4_define([_b4_type_action],
])]) ])])
# b4_type_foreach(MACRO) # b4_type_foreach(MACRO, [SEP])
# ---------------------- # -----------------------------
# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set. # Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
m4_define([b4_type_foreach], m4_define([b4_type_foreach],
[m4_map([$1], m4_defn([b4_type_names]))]) [m4_map_sep([$1], [$2], m4_defn([b4_type_names]))])
@@ -603,7 +707,7 @@ m4_define([b4_sync_end], [ b4_comment([$2:$1])]
# This generates dependencies on the Bison skeletons hence lots of # This generates dependencies on the Bison skeletons hence lots of
# useless 'git diff'. This location is useless for the regular # useless 'git diff'. This location is useless for the regular
# user (who does not care about the skeletons) and is actually not # user (who does not care about the skeletons) and is actually not
# useful for Bison developpers too (I, Akim, never used this to locate # useful for Bison developers too (I, Akim, never used this to locate
# the code in skeletons that generated output). So disable it # the code in skeletons that generated output). So disable it
# completely. If someone thinks this was actually useful, a %define # completely. If someone thinks this was actually useful, a %define
# variable should be provided to control the level of verbosity of # variable should be provided to control the level of verbosity of
@@ -683,7 +787,7 @@ m4_define([b4_check_user_names],
[m4_pushdef([b4_occurrence], b4_occurrence)dnl [m4_pushdef([b4_occurrence], b4_occurrence)dnl
m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl m4_pushdef([b4_end], m4_shift2(b4_occurrence))dnl
m4_ifndef($3[(]m4_quote(b4_user_name)[)], m4_ifndef($3[(]m4_quote(b4_user_name)[)],
[b4_complain_at([b4_start], [b4_end], [b4_complain_at([b4_start], [b4_end],
[[%s '%s' is not used]], [[%s '%s' is not used]],
@@ -878,15 +982,18 @@ m4_define([b4_percent_define_flag_if],
# For example: # For example:
# #
# b4_percent_define_default([[foo]], [[default value]]) # b4_percent_define_default([[foo]], [[default value]])
m4_define([_b4_percent_define_define],
[m4_define([b4_percent_define(]$1[)], [$2])dnl
m4_define([b4_percent_define_kind(]$1[)],
[m4_default([$3], [keyword])])dnl
m4_define([b4_percent_define_loc(]$1[)],
[[[[<skeleton default value>:-1.-1]],
[[<skeleton default value>:-1.-1]]]])dnl
m4_define([b4_percent_define_syncline(]$1[)], [[]])])
m4_define([b4_percent_define_default], m4_define([b4_percent_define_default],
[_b4_percent_define_ifdef([$1], [], [_b4_percent_define_ifdef([$1], [],
[m4_define([b4_percent_define(]$1[)], [$2])dnl [_b4_percent_define_define($@)])])
m4_define([b4_percent_define_kind(]$1[)],
[m4_default([$3], [keyword])])dnl
m4_define([b4_percent_define_loc(]$1[)],
[[[[<skeleton default value>:-1.-1]],
[[<skeleton default value>:-1.-1]]]])dnl
m4_define([b4_percent_define_syncline(]$1[)], [[]])])])
# b4_percent_define_if_define(NAME, [VARIABLE = NAME]) # b4_percent_define_if_define(NAME, [VARIABLE = NAME])
@@ -896,11 +1003,12 @@ m4_define([b4_percent_define_default],
# to '_'. # to '_'.
m4_define([_b4_percent_define_if_define], m4_define([_b4_percent_define_if_define],
[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
[b4_percent_define_flag_if(m4_default([$2], [$1]), [b4_percent_define_default([m4_default([$2], [$1])], [[false]])dnl
[$3], [$4])])]) b4_percent_define_flag_if(m4_default([$2], [$1]),
[$3], [$4])])])
m4_define([b4_percent_define_if_define], m4_define([b4_percent_define_if_define],
[b4_percent_define_default([m4_default([$2], [$1])], [[false]]) [_b4_percent_define_if_define([$1], [$2], $[1], $[2])])
_b4_percent_define_if_define([$1], [$2], $[1], $[2])])
# b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) # b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain])
@@ -1006,6 +1114,7 @@ b4_percent_define_if_define([token_ctor], [api.token.constructor])
b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([locations]) # Whether locations are tracked.
b4_percent_define_if_define([parse.assert]) b4_percent_define_if_define([parse.assert])
b4_percent_define_if_define([parse.trace]) b4_percent_define_if_define([parse.trace])
b4_percent_define_if_define([posix])
# b4_bison_locations_if([IF-TRUE]) # b4_bison_locations_if([IF-TRUE])
@@ -1016,31 +1125,37 @@ m4_define([b4_bison_locations_if],
[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
# %define parse.error "(custom|detailed|simple|verbose)"
# ------------------------------------------------------ # ------------------------------------------------------
# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
# b4_error_verbose_flag.
b4_percent_define_default([[parse.error]], [[simple]]) b4_percent_define_default([[parse.error]], [[simple]])
b4_percent_define_check_values([[[[parse.error]], b4_percent_define_check_values([[[[parse.error]],
[[simple]], [[verbose]]]]) [[custom]], [[detailed]], [[simple]], [[verbose]]]])
m4_define([b4_error_verbose_flag],
[m4_case(b4_percent_define_get([[parse.error]]),
[simple], [[0]],
[verbose], [[1]])])
b4_define_flag_if([error_verbose])
# yytoken_table is needed to support verbose errors. # b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE)
b4_error_verbose_if([m4_define([b4_token_table_flag], [1])]) # ----------------------------------------------------------
m4_define([b4_parse_error_case],
[m4_case(b4_percent_define_get([[parse.error]]), $@)])
# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE)
# ------------------------------------------------------------------
m4_define([b4_parse_error_bmatch],
[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)])
# b4_union_if([IF-UNION-ARE-USED], [IF-NOT])
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
# ---------------------------------------------- # ----------------------------------------------
b4_percent_define_if_define([variant]) # Depend on whether api.value.type is union, or variant.
m4_define([b4_union_flag], [[0]])
m4_define([b4_variant_flag], [[0]]) m4_define([b4_variant_flag], [[0]])
b4_percent_define_ifdef([[api.value.type]], b4_percent_define_ifdef([[api.value.type]],
[m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword], [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
[m4_case(b4_percent_define_get([[api.value.type]]), [variant], [m4_case(b4_percent_define_get([[api.value.type]]),
[m4_define([b4_variant_flag], [[1]])])])]) [union], [m4_define([b4_union_flag], [[1]])],
[variant], [m4_define([b4_variant_flag], [[1]])])])])
b4_define_flag_if([union])
b4_define_flag_if([variant]) b4_define_flag_if([variant])
@@ -1116,3 +1231,11 @@ b4_percent_define_ifdef([api.value.type],
# api.value.union.name. # api.value.union.name.
b4_percent_define_check_kind([api.value.union.name], [keyword]) b4_percent_define_check_kind([api.value.union.name], [keyword])
# parse.error (custom|detailed) >< token-table.
b4_token_table_if(
[b4_parse_error_bmatch([custom\|detailed],
[b4_complain_at(b4_percent_define_get_loc([parse.error]),
[['%s' and '%s' cannot be used together]],
[%token-table],
[%define parse.error (custom|detailed)])])])
+2 -2
View File
@@ -2,7 +2,7 @@
# C++ skeleton dispatching for Bison. # C++ skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software # Copyright (C) 2006-2007, 2009-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc. # Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])])
b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])])
+237 -104
View File
@@ -2,7 +2,7 @@
# C++ skeleton for Bison # C++ skeleton for Bison
# Copyright (C) 2002-2020 Free Software Foundation, Inc. # Copyright (C) 2002-2022, 2025-2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,13 +15,15 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Sanity checks, before defaults installed by c.m4. # Sanity checks, before defaults installed by c.m4.
b4_percent_define_ifdef([[api.value.union.name]], b4_percent_define_ifdef([[api.value.union.name]],
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
[named %union is invalid in C++])]) [named %union is invalid in C++])])
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
m4_include(b4_skeletonsdir/[c.m4]) m4_include(b4_skeletonsdir/[c.m4])
b4_percent_define_check_kind([api.namespace], [code], [deprecated]) b4_percent_define_check_kind([api.namespace], [code], [deprecated])
@@ -103,11 +105,10 @@ b4_percent_define_default([[api.parser.class]], [[parser]])
# #
# b4_percent_define_default([[api.location.type]], [[location]]) # b4_percent_define_default([[api.location.type]], [[location]])
b4_percent_define_default([[filename_type]], [[std::string]]) b4_percent_define_default([[api.filename.type]], [[const std::string]])
# Make it a warning for those who used betas of Bison 3.0. # Make it a warning for those who used betas of Bison 3.0.
b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix])) b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
b4_percent_define_default([[define_location_comparison]], b4_percent_define_default([[define_location_comparison]],
[m4_if(b4_percent_define_get([[filename_type]]), [m4_if(b4_percent_define_get([[filename_type]]),
[std::string], [[true]], [[false]])]) [std::string], [[true]], [[false]])])
@@ -160,20 +161,42 @@ m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])]) [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
## ------------- ##
## Token kinds. ##
## ------------- ##
# b4_token_enums # b4_token_enums
# -------------- # --------------
# Output the definition of the tokens as enums. # Output the definition of the token kinds.
m4_define([b4_token_enums], m4_define([b4_token_enums],
[[enum yytokentype [[enum token_kind_type
{ {
]m4_join([, ]b4_symbol([-2], [id])[ = -2,
], ]b4_symbol_foreach([b4_token_enum])dnl
b4_symbol_map([b4_token_enum]))[ [ };]dnl
};]dnl
]) ])
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[enum symbol_kind_type
{
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
]b4_symbol(empty, kind_base)[ = -2,
]b4_symbol_foreach([ b4_symbol_enum])dnl
[ };]])
## ----------------- ## ## ----------------- ##
## Semantic Values. ## ## Semantic Values. ##
@@ -183,16 +206,16 @@ m4_define([b4_token_enums],
# b4_value_type_declare # b4_value_type_declare
# --------------------- # ---------------------
# Declare semantic_type. # Declare value_type.
m4_define([b4_value_type_declare], m4_define([b4_value_type_declare],
[b4_value_type_setup[]dnl [b4_value_type_setup[]dnl
[ /// Symbol semantic values. [ /// Symbol semantic values.
]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), ]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
[code], [code],
[[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]], [[ typedef ]b4_percent_define_get([[api.value.type]])[ value_type;]],
[m4_bmatch(b4_percent_define_get([[api.value.type]]), [m4_bmatch(b4_percent_define_get([[api.value.type]]),
[union\|union-directive], [union\|union-directive],
[[ union semantic_type [[ union value_type
{ {
]b4_user_union_members[ ]b4_user_union_members[
};]])])dnl };]])])dnl
@@ -204,11 +227,19 @@ m4_define([b4_value_type_declare],
# Define the public types: token, semantic value, location, and so forth. # Define the public types: token, semantic value, location, and so forth.
# Depending on %define token_lex, may be output in the header or source file. # Depending on %define token_lex, may be output in the header or source file.
m4_define([b4_public_types_declare], m4_define([b4_public_types_declare],
[[#ifndef ]b4_api_PREFIX[STYPE [b4_glr2_cc_if(
]b4_value_type_declare[ [b4_value_type_declare],
[[#ifdef ]b4_api_PREFIX[STYPE
# ifdef __GNUC__
# pragma GCC message "bison: do not #define ]b4_api_PREFIX[STYPE in C++, use %define api.value.type"
# endif
typedef ]b4_api_PREFIX[STYPE value_type;
#else #else
typedef ]b4_api_PREFIX[STYPE semantic_type; ]b4_value_type_declare[
#endif]b4_locations_if([ #endif
/// Backward compatibility (Bison 3.8).
typedef value_type semantic_type;
]])[]b4_locations_if([
/// Symbol locations. /// Symbol locations.
typedef b4_percent_define_get([[api.location.type]], typedef b4_percent_define_get([[api.location.type]],
[[location]]) location_type;])[ [[location]]) location_type;])[
@@ -231,23 +262,31 @@ m4_define([b4_public_types_declare],
location_type location;])[ location_type location;])[
}; };
/// Tokens. /// Token kinds.
struct token struct token
{ {
]b4_token_enums[ ]b4_token_enums[]b4_glr2_cc_if([], [[
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype;]])[
}; };
/// (External) token type, as returned by yylex. /// Token kind, as returned by yylex.
typedef token::yytokentype token_type; typedef token::token_kind_type token_kind_type;]b4_glr2_cc_if([], [[
/// Symbol type: an internal symbol number. /// Backward compatibility alias (Bison 3.6).
typedef int symbol_number_type; typedef token_kind_type token_type;]])[
/// The symbol type number to denote an empty symbol. /// Symbol kinds.
enum { empty_symbol = -2 }; struct symbol_kind
{
]b4_declare_symbol_enum[
};
/// Internal symbol number for tokens (subsumed by symbol_number_type). /// (Internal) symbol kind.
typedef ]b4_int_type_for([b4_translate])[ token_number_type; typedef symbol_kind::symbol_kind_type symbol_kind_type;
/// The number of tokens.
static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
]]) ]])
@@ -258,8 +297,8 @@ m4_define([b4_public_types_declare],
m4_define([b4_symbol_type_define], m4_define([b4_symbol_type_define],
[[ /// A complete symbol. [[ /// A complete symbol.
/// ///
/// Expects its Base type to provide access to the symbol type /// Expects its Base type to provide access to the symbol kind
/// via type_get (). /// via kind ().
/// ///
/// Provide access to semantic value]b4_locations_if([ and location])[. /// Provide access to semantic value]b4_locations_if([ and location])[.
template <typename Base> template <typename Base>
@@ -269,28 +308,36 @@ m4_define([b4_symbol_type_define],
typedef Base super_type; typedef Base super_type;
/// Default constructor. /// Default constructor.
basic_symbol () basic_symbol () YY_NOEXCEPT
: value ()]b4_locations_if([ : value ()]b4_locations_if([
, location ()])[ , location ()])[
{} {}
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
/// Move constructor. /// Move constructor.
basic_symbol (basic_symbol&& that); basic_symbol (basic_symbol&& that)
: Base (std::move (that))
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
, location (std::move (that.location))])[
{]b4_variant_if([
b4_symbol_variant([this->kind ()], [value], [move],
[std::move (that.value)])
])[}
#endif #endif
/// Copy constructor. /// Copy constructor.
basic_symbol (const basic_symbol& that);]b4_variant_if([[ basic_symbol (const basic_symbol& that);]b4_variant_if([[
/// Constructor for valueless symbols, and symbols from each type. /// Constructors for typed symbols.
]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ ]b4_type_foreach([b4_basic_symbol_constructor_define], [
])], [[
/// Constructor for valueless symbols. /// Constructor for valueless symbols.
basic_symbol (typename Base::kind_type t]b4_locations_if([, basic_symbol (typename Base::kind_type t]b4_locations_if([,
YY_MOVE_REF (location_type) l])[); YY_MOVE_REF (location_type) l])[);
/// Constructor for symbols with semantic value. /// Constructor for symbols with semantic value.
basic_symbol (typename Base::kind_type t, basic_symbol (typename Base::kind_type t,
YY_RVREF (semantic_type) v]b4_locations_if([, YY_RVREF (value_type) v]b4_locations_if([,
YY_RVREF (location_type) l])[); YY_RVREF (location_type) l])[);
]])[ ]])[
/// Destroy the symbol. /// Destroy the symbol.
@@ -299,25 +346,75 @@ m4_define([b4_symbol_type_define],
clear (); clear ();
} }
#if 201103L <= YY_CPLUSPLUS
/// Copy assignment.
basic_symbol& operator= (const basic_symbol& that)
{
Base::operator= (that);]b4_variant_if([[
]b4_symbol_variant([this->kind ()], [value], [copy],
[that.value])], [[
value = that.value]])[;]b4_locations_if([[
location = that.location;]])[
return *this;
}
/// Move assignment.
basic_symbol& operator= (basic_symbol&& that)
{
Base::operator= (std::move (that));]b4_variant_if([[
]b4_symbol_variant([this->kind ()], [value], [move],
[std::move (that.value)])], [[
value = std::move (that.value)]])[;]b4_locations_if([[
location = std::move (that.location);]])[
return *this;
}
#endif
/// Destroy contents, and record that is empty. /// Destroy contents, and record that is empty.
void clear () void clear () YY_NOEXCEPT
{]b4_variant_if([[ {]b4_variant_if([[
// User destructor. // User destructor.
symbol_number_type yytype = this->type_get (); symbol_kind_type yykind = this->kind ();
basic_symbol<Base>& yysym = *this; basic_symbol<Base>& yysym = *this;
(void) yysym; (void) yysym;
switch (yytype) switch (yykind)
{ {
]b4_symbol_foreach([b4_symbol_destructor])dnl ]b4_symbol_foreach([b4_symbol_destructor])dnl
[ default: [ default:
break; break;
} }
// Type destructor. // Value type destructor.
]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ ]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[
Base::clear (); Base::clear ();
} }
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of this symbol.
std::string name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]])[]b4_glr2_cc_if([], [[
/// Backward compatibility (Bison 3.6).
symbol_kind_type type_get () const YY_NOEXCEPT;]])[
/// Whether empty. /// Whether empty.
bool empty () const YY_NOEXCEPT; bool empty () const YY_NOEXCEPT;
@@ -325,7 +422,7 @@ m4_define([b4_symbol_type_define],
void move (basic_symbol& s); void move (basic_symbol& s);
/// The semantic value. /// The semantic value.
semantic_type value;]b4_locations_if([ value_type value;]b4_locations_if([
/// The location. /// The location.
location_type location;])[ location_type location;])[
@@ -338,52 +435,65 @@ m4_define([b4_symbol_type_define],
}; };
/// Type access provider for token (enum) based symbols. /// Type access provider for token (enum) based symbols.
struct by_type struct by_kind
{ {
/// The symbol kind as needed by the constructor.
typedef token_kind_type kind_type;
/// Default constructor. /// Default constructor.
by_type (); by_kind () YY_NOEXCEPT;
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
/// Move constructor. /// Move constructor.
by_type (by_type&& that); by_kind (by_kind&& that) YY_NOEXCEPT;
#endif #endif
/// Copy constructor. /// Copy constructor.
by_type (const by_type& that); by_kind (const by_kind& that) YY_NOEXCEPT;
/// The symbol type as needed by the constructor.
typedef token_type kind_type;
/// Constructor from (external) token numbers. /// Constructor from (external) token numbers.
by_type (kind_type t); by_kind (kind_type t) YY_NOEXCEPT;
#if 201103L <= YY_CPLUSPLUS
/// Copy assignment.
by_kind& operator= (const by_kind& that);
/// Move assignment.
by_kind& operator= (by_kind&& that);
#endif
/// Record that this symbol is empty. /// Record that this symbol is empty.
void clear (); void clear () YY_NOEXCEPT;
/// Steal the symbol type from \a that. /// Steal the symbol kind from \a that.
void move (by_type& that); void move (by_kind& that);
/// The (internal) type number (corresponding to \a type). /// The (internal) type number (corresponding to \a type).
/// \a empty when empty. /// \a empty when empty.
symbol_number_type type_get () const YY_NOEXCEPT; symbol_kind_type kind () const YY_NOEXCEPT;]b4_glr2_cc_if([], [[
/// The symbol type. /// Backward compatibility (Bison 3.6).
/// \a empty_symbol when empty. symbol_kind_type type_get () const YY_NOEXCEPT;]])[
/// An int, not token_number_type, to be able to store empty_symbol.
int type; /// The symbol kind.
}; /// \a ]b4_symbol_prefix[YYEMPTY when empty.
symbol_kind_type kind_;
};]b4_glr2_cc_if([], [[
/// Backward compatibility for a private implementation detail (Bison 3.6).
typedef by_kind by_type;]])[
/// "External" symbols: returned by the scanner. /// "External" symbols: returned by the scanner.
struct symbol_type : basic_symbol<by_type> struct symbol_type : basic_symbol<by_kind>
{]b4_variant_if([[ {]b4_variant_if([[
/// Superclass. /// Superclass.
typedef basic_symbol<by_type> super_type; typedef basic_symbol<by_kind> super_type;
/// Empty symbol. /// Empty symbol.
symbol_type () {} symbol_type () YY_NOEXCEPT {}
/// Constructor for valueless symbols, and symbols from each type. /// Constructor for valueless symbols, and symbols from each type.
]b4_type_foreach([_b4_token_constructor_define])dnl ]b4_type_foreach([_b4_symbol_constructor_define])dnl
])[}; ])[};
]]) ]])
@@ -393,25 +503,13 @@ m4_define([b4_symbol_type_define],
# Provide the implementation needed by the public types. # Provide the implementation needed by the public types.
m4_define([b4_public_types_define], m4_define([b4_public_types_define],
[[ // basic_symbol. [[ // basic_symbol.
#if 201103L <= YY_CPLUSPLUS
template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (basic_symbol&& that)
: Base (std::move (that))
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
, location (std::move (that.location))])[
{]b4_variant_if([
b4_symbol_variant([this->type_get ()], [value], [move],
[std::move (that.value)])
])[}
#endif
template <typename Base> template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that) ]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
: Base (that) : Base (that)
, value (]b4_variant_if([], [that.value]))b4_locations_if([ , value (]b4_variant_if([], [that.value]))b4_locations_if([
, location (that.location)])[ , location (that.location)])[
{]b4_variant_if([ {]b4_variant_if([
b4_symbol_variant([this->type_get ()], [value], [copy], b4_symbol_variant([this->kind ()], [value], [copy],
[YY_MOVE (that.value)]) [YY_MOVE (that.value)])
])[} ])[}
@@ -429,20 +527,29 @@ m4_define([b4_public_types_define],
template <typename Base> template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (]b4_join( ]b4_parser_class[::basic_symbol<Base>::basic_symbol (]b4_join(
[typename Base::kind_type t], [typename Base::kind_type t],
[YY_RVREF (semantic_type) v], [YY_RVREF (value_type) v],
b4_locations_if([YY_RVREF (location_type) l]))[) b4_locations_if([YY_RVREF (location_type) l]))[)
: Base (t) : Base (t)
, value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([
, location (YY_MOVE (l))])[ , location (YY_MOVE (l))])[
{]b4_variant_if([[ {]b4_variant_if([[
(void) v; (void) v;
]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ ]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
]b4_glr2_cc_if([], [[
template <typename Base>
]b4_parser_class[::symbol_kind_type
]b4_parser_class[::basic_symbol<Base>::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
]])[
template <typename Base> template <typename Base>
bool bool
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT ]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
{ {
return Base::type_get () == empty_symbol; return this->kind () == ]b4_symbol(empty, kind)[;
} }
template <typename Base> template <typename Base>
@@ -450,57 +557,82 @@ m4_define([b4_public_types_define],
]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s) ]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s)
{ {
super_type::move (s); super_type::move (s);
]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], ]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move],
[YY_MOVE (s.value)])], [YY_MOVE (s.value)])],
[value = YY_MOVE (s.value);])[]b4_locations_if([ [value = YY_MOVE (s.value);])[]b4_locations_if([
location = YY_MOVE (s.location);])[ location = YY_MOVE (s.location);])[
} }
// by_type. // by_kind.
]b4_inline([$1])b4_parser_class[::by_type::by_type () ]b4_inline([$1])b4_parser_class[::by_kind::by_kind () YY_NOEXCEPT
: type (empty_symbol) : kind_ (]b4_symbol(empty, kind)[)
{} {}
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
]b4_inline([$1])b4_parser_class[::by_type::by_type (by_type&& that) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) YY_NOEXCEPT
: type (that.type) : kind_ (that.kind_)
{ {
that.clear (); that.clear ();
} }
#endif #endif
]b4_inline([$1])b4_parser_class[::by_type::by_type (const by_type& that) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) YY_NOEXCEPT
: type (that.type) : kind_ (that.kind_)
{} {}
]b4_inline([$1])b4_parser_class[::by_type::by_type (token_type t) ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) YY_NOEXCEPT
: type (yytranslate_ (t)) : kind_ (yytranslate_ (t))
{} {}
#if 201103L <= YY_CPLUSPLUS
]b4_inline([$1])]b4_parser_class[::by_kind&
b4_parser_class[::by_kind::by_kind::operator= (const by_kind& that)
{
kind_ = that.kind_;
return *this;
}
]b4_inline([$1])]b4_parser_class[::by_kind&
b4_parser_class[::by_kind::by_kind::operator= (by_kind&& that)
{
kind_ = that.kind_;
that.clear ();
return *this;
}
#endif
]b4_inline([$1])[void ]b4_inline([$1])[void
]b4_parser_class[::by_type::clear () ]b4_parser_class[::by_kind::clear () YY_NOEXCEPT
{ {
type = empty_symbol; kind_ = ]b4_symbol(empty, kind)[;
} }
]b4_inline([$1])[void ]b4_inline([$1])[void
]b4_parser_class[::by_type::move (by_type& that) ]b4_parser_class[::by_kind::move (by_kind& that)
{ {
type = that.type; kind_ = that.kind_;
that.clear (); that.clear ();
} }
]b4_inline([$1])[int ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT ]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT
{ {
return type; return kind_;
} }
]b4_glr2_cc_if([], [[
]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
]])[
]]) ]])
# b4_token_constructor_define # b4_token_constructor_define
# ---------------------------- # ----------------------------
# Define symbol constructors for all the value types. # Define make_FOO for all the token kinds.
# Use at class-level. Redefined in variant.hh. # Use at class-level. Redefined in variant.hh.
m4_define([b4_token_constructor_define], []) m4_define([b4_token_constructor_define], [])
@@ -510,27 +642,28 @@ m4_define([b4_token_constructor_define], [])
# Define yytranslate_. Sometimes used in the header file ($1=hh), # Define yytranslate_. Sometimes used in the header file ($1=hh),
# sometimes in the cc file. # sometimes in the cc file.
m4_define([b4_yytranslate_define], m4_define([b4_yytranslate_define],
[ b4_inline([$1])b4_parser_class[::token_number_type [ b4_inline([$1])b4_parser_class[::symbol_kind_type
]b4_parser_class[::yytranslate_ (int t) ]b4_parser_class[::yytranslate_ (int t) YY_NOEXCEPT
{ {
]b4_api_token_raw_if( ]b4_api_token_raw_if(
[[ return static_cast<token_number_type> (t);]], [[ return static_cast<symbol_kind_type> (t);]],
[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to [[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
// TOKEN-NUM as returned by yylex. // TOKEN-NUM as returned by yylex.
static static
const token_number_type const ]b4_int_type_for([b4_translate])[
translate_table[] = translate_table[] =
{ {
]b4_translate[ ]b4_translate[
}; };
const int user_token_number_max_ = ]b4_user_token_number_max[; // Last valid token kind.
const int code_max = ]b4_code_max[;
if (t <= 0) if (t <= 0)
return yyeof_; return symbol_kind::]b4_symbol_prefix[YYEOF;
else if (t <= user_token_number_max_) else if (t <= code_max)
return translate_table[t]; return static_cast <symbol_kind_type> (translate_table[t]);
else else
return yy_undef_token_;]])[ return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
} }
]]) ]])
+10 -3
View File
@@ -2,7 +2,8 @@
# Common code for C-like languages (C, C++, Java, etc.) # Common code for C-like languages (C, C++, Java, etc.)
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2012-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,17 +16,23 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# _b4_comment(TEXT, OPEN, CONTINUE, END) # _b4_comment(TEXT, OPEN, CONTINUE, END)
# -------------------------------------- # --------------------------------------
# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
# Avoid adding indentation to the first line, as the indentation comes # Avoid adding indentation to the first line, as the indentation comes
# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close
# the comments before its end.
# #
# Prefix all the output lines with PREFIX. # Prefix all the output lines with PREFIX.
m4_define([_b4_comment], m4_define([_b4_comment],
[$2[]m4_bpatsubst(m4_expand([[$1]]), [ [$2[]b4_gsub(m4_expand([$1]),
[[*]/], [*\\/],
[/[*]], [/\\*],
[
\(.\)], [ \(.\)], [
$3\1])$4]) $3\1])$4])
+2 -2
View File
@@ -2,7 +2,7 @@
# C skeleton dispatching for Bison. # C skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software # Copyright (C) 2006-2007, 2009-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc. # Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])])
b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])])
+257 -123
View File
@@ -2,8 +2,8 @@
# C M4 Macros for Bison. # C M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation, # Copyright (C) 2002, 2004-2015, 2018-2022, 2025-2026 Free Software
# Inc. # Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[c-like.m4]) m4_include(b4_skeletonsdir/[c-like.m4])
@@ -58,11 +58,11 @@ m4_define([b4_cpp_guard_close],
# b4_pull_flag if they use the values of the %define variables api.pure or # b4_pull_flag if they use the values of the %define variables api.pure or
# api.push-pull. # api.push-pull.
m4_define([b4_identification], m4_define([b4_identification],
[[/* Identify Bison output. */ [[/* Identify Bison output, and Bison version. */
#define YYBISON 1 #define YYBISON ]b4_version[
/* Bison version. */ /* Bison version string. */
#define YYBISON_VERSION "]b4_version[" #define YYBISON_VERSION "]b4_version_string["
/* Skeleton name. */ /* Skeleton name. */
#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
@@ -101,32 +101,45 @@ m4_define_default([b4_prefix], [b4_api_prefix])
b4_percent_define_default([[api.value.union.name]], b4_percent_define_default([[api.value.union.name]],
[b4_api_PREFIX[][STYPE]]) [b4_api_PREFIX[][STYPE]])
b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]])
## ------------------------ ## ## ------------------------ ##
## Pure/impure interfaces. ## ## Pure/impure interfaces. ##
## ------------------------ ## ## ------------------------ ##
# b4_lex_formals # b4_yylex_formals
# -------------- # ----------------
# All the yylex formal arguments. # All the yylex formal arguments.
# b4_lex_param arrives quoted twice, but we want to keep only one level. # b4_lex_param arrives quoted twice, but we want to keep only one level.
m4_define([b4_lex_formals], m4_define([b4_yylex_formals],
[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl [b4_pure_if([[[b4_api_PREFIX[STYPE *yylvalp]], [[&yylval]]][]dnl
b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl b4_locations_if([, [b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) m4_ifdef([b4_lex_param], [, ]b4_lex_param)])
# b4_lex # b4_yylex
# ------ # --------
# Call yylex. # Call yylex.
m4_define([b4_lex], m4_define([b4_yylex],
[b4_function_call([yylex], [int], b4_lex_formals)]) [b4_function_call([yylex], [int], b4_yylex_formals)])
# b4_user_args # b4_user_args
# ------------ # ------------
m4_define([b4_user_args], m4_define([b4_user_args],
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) [m4_ifset([b4_parse_param], [, b4_user_args_no_comma])])
# b4_user_args_no_comma
# ---------------------
m4_define([b4_user_args_no_comma],
[m4_ifset([b4_parse_param], [b4_args(b4_parse_param)])])
# b4_user_formals
# ---------------
# The possible parse-params formal arguments preceded by a comma.
m4_define([b4_user_formals],
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
# b4_parse_param # b4_parse_param
@@ -150,13 +163,20 @@ m4_popdef([$2])dnl
m4_popdef([$1])dnl m4_popdef([$1])dnl
])]) ])])
# b4_use(EXPR)
# ------------
# Pacify the compiler about some maybe unused value.
m4_define([b4_use],
[YY_USE ($1)])
# b4_parse_param_use([VAL], [LOC]) # b4_parse_param_use([VAL], [LOC])
# -------------------------------- # --------------------------------
# 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params. # 'YY_USE' VAL, LOC if locations are enabled, and all the parse-params.
m4_define([b4_parse_param_use], m4_define([b4_parse_param_use],
[m4_ifvaln([$1], [ YYUSE ([$1]);])dnl [m4_ifvaln([$1], [ b4_use([$1]);])dnl
b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl b4_locations_if([m4_ifvaln([$2], [ b4_use([$2]);])])dnl
b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); b4_parse_param_for([Decl], [Formal], [ b4_use(Formal);
])dnl ])dnl
]) ])
@@ -197,7 +217,11 @@ m4_define([b4_c99_int_type],
# Define private types suitable for holding small integers in C99 or later. # Define private types suitable for holding small integers in C99 or later.
m4_define([b4_c99_int_type_define], m4_define([b4_c99_int_type_define],
[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl [m4_copy_force([b4_c99_int_type], [b4_int_type])dnl
[/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure [#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included <limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */ so that the code can choose integer types of a good width. */
@@ -230,6 +254,18 @@ typedef int_least16_t yytype_int16;
typedef short yytype_int16; typedef short yytype_int16;
#endif #endif
/* Work around bug in HP-UX 11.23, which defines these macros
incorrectly for preprocessor constants. This workaround can likely
be removed in 2023, as HPE has promised support for HP-UX 11.23
(aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
<https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
#ifdef __hpux
# undef UINT_LEAST8_MAX
# undef UINT_LEAST16_MAX
# define UINT_LEAST8_MAX 255
# define UINT_LEAST16_MAX 65535
#endif
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8; typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
@@ -253,6 +289,50 @@ typedef int yytype_uint16;
#endif]]) #endif]])
# b4_sizes_types_define
# ---------------------
# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM,
# and YYSIZEOF.
m4_define([b4_sizes_types_define],
[[#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
]])
# b4_int_type_for(NAME) # b4_int_type_for(NAME)
# --------------------- # ---------------------
# Return a narrow int type able to handle numbers ranging from # Return a narrow int type able to handle numbers ranging from
@@ -299,17 +379,27 @@ m4_define([b4_attribute_define],
#endif #endif
]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ ]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */
]dnl This is an exact copy of lib/_Noreturn.h. ]dnl This is close to lib/_Noreturn.h, except that we do enable
dnl the use of [[noreturn]], because _Noreturn is used in places
dnl where [[noreturn]] works in C++. We need this in particular
dnl because of glr.cc which compiles code from glr.c in C++.
dnl And the C++ compiler chokes on _Noreturn. Also, we do not
dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings.
[#ifndef _Noreturn [#ifndef _Noreturn
# if (defined __cplusplus \ # if (defined __cplusplus \
&& ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|| (defined _MSC_VER && 1900 <= _MSC_VER))) || (defined _MSC_VER && 1900 <= _MSC_VER)))
# define _Noreturn [[noreturn]] # define _Noreturn [[noreturn]]
# elif ((!defined __cplusplus || defined __clang__) \ # elif ((!defined __cplusplus || defined __clang__) \
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__))) || (!defined __STRICT_ANSI__ \
&& (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|| (defined __apple_build_version__ \
? 6000000 <= __apple_build_version__ \
: 3 < __clang_major__ + (5 <= __clang_minor__))))))
/* _Noreturn works as-is. */ /* _Noreturn works as-is. */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C # elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
|| 0x5110 <= __SUNPRO_C)
# define _Noreturn __attribute__ ((__noreturn__)) # define _Noreturn __attribute__ ((__noreturn__))
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
# define _Noreturn __declspec (noreturn) # define _Noreturn __declspec (noreturn)
@@ -320,17 +410,23 @@ m4_define([b4_attribute_define],
]])[/* Suppress unused-variable warnings by "using" E. */ ]])[/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__ #if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E)) # define YY_USE(E) ((void) (E))
#else #else
# define YYUSE(E) /* empty */ # define YY_USE(E) /* empty */
#endif #endif
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */ /* Suppress an incorrect diagnostic about yylval being uninitialized. */
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
# else
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# endif
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop") _Pragma ("GCC diagnostic pop")
#else #else
@@ -410,7 +506,7 @@ m4_define([b4_null], [YY_NULLPTR])
# ------------------------------------------------------------- # -------------------------------------------------------------
# Define "yy<TABLE-NAME>" whose contents is CONTENT. # Define "yy<TABLE-NAME>" whose contents is CONTENT.
m4_define([b4_integral_parser_table_define], m4_define([b4_integral_parser_table_define],
[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl [m4_ifvaln([$3], [b4_comment([$3])])dnl
static const b4_int_type_for([$2]) yy$1[[]] = static const b4_int_type_for([$2]) yy$1[[]] =
{ {
$2 $2
@@ -418,9 +514,22 @@ static const b4_int_type_for([$2]) yy$1[[]] =
]) ])
## ------------------------- ## ## ------------- ##
## Assigning token numbers. ## ## Token kinds. ##
## ------------------------- ## ## ------------- ##
# Because C enums are not scoped, because tokens are exposed in the
# header, and because these tokens are common to all the parsers, we
# need to make sure their names don't collide: use the api.prefix.
# YYEOF is special, since the user may give it a different name.
m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]])
m4_define([b4_symbol(-2, tag)], [[No symbol.]])
m4_if(b4_symbol(eof, id), [YYEOF],
[m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])])
m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]])
m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]])
# b4_token_define(TOKEN-NUM) # b4_token_define(TOKEN-NUM)
# -------------------------- # --------------------------
@@ -432,44 +541,92 @@ m4_define([b4_token_define],
# ---------------- # ----------------
# Output the definition of the tokens. # Output the definition of the tokens.
m4_define([b4_token_defines], m4_define([b4_token_defines],
[b4_any_token_visible_if([/* Tokens. */ [[/* Token kinds. */
m4_join([ #define ]b4_symbol(empty, [id])[ -2
]m4_join([
], b4_symbol_map([b4_token_define])) ], b4_symbol_map([b4_token_define]))
])]) ])
# b4_token_enum(TOKEN-NUM) # b4_token_enum(TOKEN-NUM)
# ------------------------ # ------------------------
# Output the definition of this token as an enum. # Output the definition of this token as an enum.
m4_define([b4_token_enum], m4_define([b4_token_enum],
[b4_token_format([%s = %s], [$1])]) [b4_token_visible_if([$1],
[m4_format([ %-30s %s],
m4_format([[%s = %s%s%s]],
b4_symbol([$1], [id]),
b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])),
m4_if([$1], b4_last_enum_token, [], [[,]])),
[b4_symbol_tag_comment([$1])])])])
# b4_token_enums # b4_token_enums
# -------------- # --------------
# Output the definition of the tokens (if there are) as enums. # The definition of the token kinds.
m4_define([b4_token_enums], m4_define([b4_token_enums],
[b4_any_token_visible_if([[/* Token type. */ [b4_any_token_visible_if([[/* Token kinds. */
#ifndef ]b4_api_PREFIX[TOKENTYPE #ifndef ]b4_api_PREFIX[TOKENTYPE
# define ]b4_api_PREFIX[TOKENTYPE # define ]b4_api_PREFIX[TOKENTYPE
enum ]b4_api_prefix[tokentype enum ]b4_api_prefix[tokentype
{ {
]m4_join([, ]b4_symbol(empty, [id])[ = -2,
], ]b4_symbol_foreach([b4_token_enum])dnl
b4_symbol_map([b4_token_enum]))[ [ };
}; typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t;
#endif #endif
]])]) ]])])
# b4_token_enums_defines # b4_token_enums_defines
# ---------------------- # ----------------------
# Output the definition of the tokens (if there are any) as enums and, # The definition of the tokens (if there are any) as enums and,
# if POSIX Yacc is enabled, as #defines. # if POSIX Yacc is enabled, as #defines.
m4_define([b4_token_enums_defines], m4_define([b4_token_enums_defines],
[b4_token_enums[]b4_yacc_if([b4_token_defines])]) [b4_token_enums[]b4_yacc_if([b4_token_defines])])
# b4_symbol_translate(STRING)
# ---------------------------
# Used by "bison" in the array of symbol names to mark those that
# require translation.
m4_define([b4_symbol_translate],
[[N_($1)]])
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-40s %s],
m4_format([[%s = %s%s%s]],
b4_symbol([$1], [kind_base]),
[$1],
m4_if([$1], b4_last_symbol, [], [[,]])),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[/* Symbol kind. */
enum yysymbol_kind_t
{
]b4_symbol(empty, [kind_base])[ = -2,
]b4_symbol_foreach([b4_symbol_enum])dnl
[};
typedef enum yysymbol_kind_t yysymbol_kind_t;
]])])
## ----------------- ## ## ----------------- ##
## Semantic Values. ## ## Semantic Values. ##
## ----------------- ## ## ----------------- ##
@@ -493,15 +650,6 @@ m4_define([b4_symbol_value],
## ---------------------- ## ## ---------------------- ##
# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
# -----------------------------------------------------------
# Declare the function NAME in C.
m4_define([b4_function_define],
[$2
$1 (b4_formals(m4_shift2($@)))[]dnl
])
# b4_formals([DECL1, NAME1], ...) # b4_formals([DECL1, NAME1], ...)
# ------------------------------- # -------------------------------
# The formal arguments of a C function definition. # The formal arguments of a C function definition.
@@ -514,12 +662,6 @@ m4_define([b4_formal],
[$1]) [$1])
## ----------------------- ##
## Declaring C functions. ##
## ----------------------- ##
# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) # b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
# ------------------------------------------------------------ # ------------------------------------------------------------
# Declare the function NAME. # Declare the function NAME.
@@ -529,7 +671,6 @@ m4_define([b4_function_declare],
## --------------------- ## ## --------------------- ##
## Calling C functions. ## ## Calling C functions. ##
## --------------------- ## ## --------------------- ##
@@ -566,10 +707,10 @@ m4_define([b4_sync_start], [[#]line $1 $2])
## User actions. ## ## User actions. ##
## -------------- ## ## -------------- ##
# b4_case(LABEL, STATEMENTS) # b4_case(LABEL, STATEMENTS, [COMMENTS])
# -------------------------- # --------------------------------------
m4_define([b4_case], m4_define([b4_case],
[ case $1: [ case $1:m4_ifval([$3], [ b4_comment([$3])])
$2 $2
b4_syncline([@oline@], [@ofile@])dnl b4_syncline([@oline@], [@ofile@])dnl
break;]) break;])
@@ -593,18 +734,15 @@ m4_define_default([b4_yydestruct_define],
| Release the memory associated to this symbol. | | Release the memory associated to this symbol. |
`-----------------------------------------------*/ `-----------------------------------------------*/
]b4_function_define([yydestruct], static void
[static void], yydestruct (const char *yymsg,
[[const char *yymsg], [yymsg]], yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl
[[int yytype], [yytype]], [[, YYLTYPE *yylocationp]])[]b4_user_formals[)
[[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{ {
]b4_parse_param_use([yyvaluep], [yylocationp])dnl ]b4_parse_param_use([yyvaluep], [yylocationp])dnl
[ if (!yymsg) [ if (!yymsg)
yymsg = "Deleting"; yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_symbol_actions([destructor])[ ]b4_symbol_actions([destructor])[
@@ -622,25 +760,15 @@ m4_define_default([b4_yy_symbol_print_define],
| Print this symbol's value on YYO. | | Print this symbol's value on YYO. |
`-----------------------------------*/ `-----------------------------------*/
]b4_function_define([yy_symbol_value_print], static void
[static void], yy_symbol_value_print (FILE *yyo,
[[FILE *yyo], [yyo]], yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[int yytype], [yytype]], [[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{ {
FILE *yyoutput = yyo; FILE *yyoutput = yyo;
]b4_parse_param_use([yyoutput], [yylocationp])dnl ]b4_parse_param_use([yyoutput], [yylocationp])dnl
[ if (!yyvaluep) [ if (!yyvaluep)
return;] return;]
dnl glr.c does not feature yytoknum.
m4_if(b4_skeleton, ["yacc.c"],
[[# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
# endif
]])dnl
b4_percent_code_get([[pre-printer]])dnl b4_percent_code_get([[pre-printer]])dnl
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
b4_symbol_actions([printer]) b4_symbol_actions([printer])
@@ -653,21 +781,18 @@ b4_percent_code_get([[post-printer]])dnl
| Print this symbol on YYO. | | Print this symbol on YYO. |
`---------------------------*/ `---------------------------*/
]b4_function_define([yy_symbol_print], static void
[static void], yy_symbol_print (FILE *yyo,
[[FILE *yyo], [yyo]], yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[int yytype], [yytype]], [[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{ {
YYFPRINTF (yyo, "%s %s (", YYFPRINTF (yyo, "%s %s (",
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); ]b4_locations_if([ YYLOCATION_PRINT (yyo, yylocationp);
YYFPRINTF (yyo, ": "); YYFPRINTF (yyo, ": ");
])dnl ])dnl
[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl [ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl
b4_locations_if([, yylocationp])[]b4_user_args[); b4_locations_if([, yylocationp])[]b4_user_args[);
YYFPRINTF (yyo, ")"); YYFPRINTF (yyo, ")");
}]dnl }]dnl
@@ -693,11 +818,11 @@ m4_define([b4_symbol_type_register],
[m4_define([b4_symbol($1, type_tag)], [m4_define([b4_symbol($1, type_tag)],
[b4_symbol_if([$1], [has_id], [b4_symbol_if([$1], [has_id],
[b4_symbol([$1], [id])], [b4_symbol([$1], [id])],
[yytype_[]b4_symbol([$1], [number])])])dnl [yykind_[]b4_symbol([$1], [number])])])dnl
m4_append([b4_union_members], m4_append([b4_union_members],
m4_expand([ m4_expand([m4_format([ %-40s %s],
b4_symbol_tag_comment([$1])dnl m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]),
b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);])) [b4_symbol_tag_comment([$1])])]))
]) ])
@@ -851,7 +976,7 @@ struct ]b4_api_PREFIX[LTYPE
# b4_declare_yylstype # b4_declare_yylstype
# ------------------- # -------------------
# Declarations that might either go into the header (if --defines) or # Declarations that might either go into the header (if --header) or
# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
m4_define([b4_declare_yylstype], m4_define([b4_declare_yylstype],
[b4_value_type_define[]b4_locations_if([ [b4_value_type_define[]b4_locations_if([
@@ -921,25 +1046,30 @@ m4_define([b4_yylloc_default_define],
#endif #endif
]]) ]])
# b4_yy_location_print_define # b4_yylocation_print_define
# --------------------------- # --------------------------
# Define YY_LOCATION_PRINT. # Define YYLOCATION_PRINT.
m4_define([b4_yy_location_print_define], m4_define([b4_yylocation_print_define],
[b4_locations_if([[ [b4_locations_if([[
/* YY_LOCATION_PRINT -- Print the location on the stream. /* YYLOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */ we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT # ifndef YYLOCATION_PRINT
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
# if defined YY_LOCATION_PRINT
/* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc))
# elif defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE_UNUSED
]b4_function_define([yy_location_print_], static int
[static int], yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
[[FILE *yyo], [yyo]],
[[YYLTYPE const * const yylocp], [yylocp]])[
{ {
int res = 0; int res = 0;
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
@@ -961,19 +1091,23 @@ YY_ATTRIBUTE_UNUSED
res += YYFPRINTF (yyo, "-%d", end_col); res += YYFPRINTF (yyo, "-%d", end_col);
} }
return res; return res;
} }
# define YY_LOCATION_PRINT(File, Loc) \ # define YYLOCATION_PRINT yy_location_print_
yy_location_print_ (File, &(Loc))
# else /* Temporary convenience wrapper in case some people defined the
# define YY_LOCATION_PRINT(File, Loc) ((void) 0) undocumented and private YY_LOCATION_PRINT macros. */
# endif # define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc))
#endif]],
[[/* This macro is provided for backward compatibility. */ # else
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0) # define YYLOCATION_PRINT(File, Loc) ((void) 0)
#endif]]) /* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YY_LOCATION_PRINT YYLOCATION_PRINT
# endif
# endif /* !defined YYLOCATION_PRINT */]])
]) ])
# b4_yyloc_default # b4_yyloc_default
+2 -2
View File
@@ -2,7 +2,7 @@
# D skeleton dispatching for Bison. # D skeleton dispatching for Bison.
# Copyright (C) 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [b4_complain([%%glr-parser not supported for D])]) b4_glr_if( [b4_complain([%%glr-parser not supported for D])])
b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])]) b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])])
+334 -39
View File
@@ -2,7 +2,7 @@
# D language support for Bison # D language support for Bison
# Copyright (C) 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,27 +15,36 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# _b4_comment(TEXT, OPEN, CONTINUE, END) m4_include(b4_skeletonsdir/[c-like.m4])
# --------------------------------------
# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
# Avoid adding indentation to the first line, as the indentation comes
# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
#
# Prefix all the output lines with PREFIX.
m4_define([_b4_comment],
[$2[]m4_bpatsubst(m4_expand([[$1]]), [
\(.\)], [
$3\1])$4])
# b4_comment(TEXT, [PREFIX]) # b4_symbol_action(SYMBOL-NUM, ACTION)
# -------------------------- # ------------------------------------
# Put TEXT in comment. Prefix all the output lines with PREFIX. # Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
m4_define([b4_comment], m4_define([b4_symbol_action],
[_b4_comment([$1], [$2/* ], [$2 ], [ */])]) [b4_symbol_if([$1], [has_$2],
[b4_dollar_pushdef([yyval],
[$1],
[],
[yyloc])dnl
_b4_symbol_case([$1])[]dnl
b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
b4_symbol([$1], [$2])
b4_syncline([@oline@], [@ofile@])dnl
break;
b4_dollar_popdef[]dnl
])])
# b4_use(EXPR)
# ------------
# Pacify the compiler about some maybe unused value.
m4_define([b4_use],
[])
# b4_sync_start(LINE, FILE) # b4_sync_start(LINE, FILE)
@@ -58,6 +67,23 @@ m4_define([b4_percent_define_get3],
[m4_ifval(m4_quote(b4_percent_define_get([$1])), [m4_ifval(m4_quote(b4_percent_define_get([$1])),
[$2[]b4_percent_define_get([$1])[]$3], [$4])]) [$2[]b4_percent_define_get([$1])[]$3], [$4])])
# b4_percent_define_if_get2(ARG1, ARG2, DEF, NOT)
# -----------------------------------------------
# Expand to the value of DEF if ARG1 or ARG2 are %define'ed,
# otherwise NOT.
m4_define([b4_percent_define_if_get2],
[m4_ifval(m4_quote(b4_percent_define_get([$1])),
[$3], [m4_ifval(m4_quote(b4_percent_define_get([$2])),
[$3], [$4])])])
# b4_percent_define_class_before_interface(CLASS, INTERFACE)
# ----------------------------------------------------------
# Expand to a ', ' if both a class and an interface have been %define'ed
m4_define([b4_percent_define_class_before_interface],
[m4_ifval(m4_quote(b4_percent_define_get([$1])),
[m4_ifval(m4_quote(b4_percent_define_get([$2])),
[, ])])])
# b4_flag_value(BOOLEAN-FLAG) # b4_flag_value(BOOLEAN-FLAG)
# --------------------------- # ---------------------------
@@ -78,8 +104,10 @@ b4_percent_define_flag_if([api.parser.public], [public ])dnl
b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl
b4_percent_define_flag_if([api.parser.final], [final ])dnl b4_percent_define_flag_if([api.parser.final], [final ])dnl
[class ]b4_parser_class[]dnl [class ]b4_parser_class[]dnl
b4_percent_define_get3([api.parser.extends], [ extends ])dnl b4_percent_define_if_get2([api.parser.extends], [api.parser.implements], [ : ])dnl
b4_percent_define_get3([api.parser.implements], [ implements ])]) b4_percent_define_get([api.parser.extends])dnl
b4_percent_define_class_before_interface([api.parser.extends], [api.parser.implements])dnl
b4_percent_define_get([api.parser.implements])])
# b4_lexer_if(TRUE, FALSE) # b4_lexer_if(TRUE, FALSE)
@@ -103,12 +131,12 @@ m4_define([b4_location_type_if],
# b4_identification # b4_identification
# ----------------- # -----------------
m4_define([b4_identification], m4_define([b4_identification],
[/** Version number for the Bison executable that generated this parser. */ [[/** Version number for the Bison executable that generated this parser. */
public static immutable string yy_bison_version = "b4_version"; public static immutable string yy_bison_version = "]b4_version_string[";
/** Name of the skeleton that generated this parser. */ /** Name of the skeleton that generated this parser. */
public static immutable string yy_bison_skeleton = b4_skeleton; public static immutable string yy_bison_skeleton = ]b4_skeleton[;
]) ]])
## ------------ ## ## ------------ ##
@@ -148,9 +176,12 @@ private static immutable b4_int_type_for([$2])[[]] yy$1_ =
]) ])
## ------------------------- ## ## ------------- ##
## Assigning token numbers. ## ## Token kinds. ##
## ------------------------- ## ## ------------- ##
m4_define([b4_symbol(-2, id)], [[YYEMPTY]])
b4_percent_define_default([[api.token.raw]], [[true]])
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# --------------------------------------- # ---------------------------------------
@@ -159,22 +190,120 @@ m4_define([b4_token_enum],
[b4_token_format([ %s = %s, [b4_token_format([ %s = %s,
], [$1])]) ], [$1])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # b4_token_enums
# ----------------------------------------------------- # --------------
# Output the definition of the tokens as enums. # Output the definition of the tokens as enums.
m4_define([b4_token_enums], m4_define([b4_token_enums],
[/* Tokens. */ [/* Token kinds. */
public enum YYTokenType { public enum TokenKind {
]b4_symbol(empty, id)[ = -2,
/** Token returned by the scanner to signal the end of its input. */ b4_symbol_foreach([b4_token_enum])dnl
EOF = 0,
b4_symbol_foreach([b4_token_enum])
} }
]) ])
# b4-case(ID, CODE) # b4_symbol_translate(STRING)
# ----------------- # ---------------------------
m4_define([b4_case], [ case $1: # Used by "bison" in the array of symbol names to mark those that
# require translation.
m4_define([b4_symbol_translate],
[[_($1)]])
# _b4_token_constructor_define(SYMBOL-NUM)
# ----------------------------------------
# Define Symbol.FOO for SYMBOL-NUM.
m4_define([_b4_token_constructor_define],
[b4_token_visible_if([$1],
[[
static auto ]b4_symbol([$1], [id])[(]b4_symbol_if([$1], [has_type],
[b4_union_if([b4_symbol([$1], [type]],
[[typeof(YYSemanticType.]b4_symbol([$1], [type])[]])) [val]])dnl
[]b4_locations_if([b4_symbol_if([$1], [has_type], [[, ]])[Location l]])[)
{
return Symbol(TokenKind.]b4_symbol([$1], [id])[]b4_symbol_if([$1], [has_type],
[[, val]])[]b4_locations_if([[, l]])[);
}]])])
# b4_token_constructor_define
# ---------------------------
# Define Symbol.FOO for each token kind FOO.
m4_define([b4_token_constructor_define],
[[
/* Implementation of token constructors for each symbol type visible to
* the user. The code generates static methods that have the same names
* as the TokenKinds.
*/]b4_symbol_foreach([_b4_token_constructor_define])dnl
])
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_symbol_kind(NUM)
# -------------------
m4_define([b4_symbol_kind],
[SymbolKind.b4_symbol_kind_base($@)])
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-30s %s],
m4_format([[%s = %s,]],
b4_symbol([$1], [kind_base]),
[$1]),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
# Defining YYEMPTY here is important: it forces the compiler
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[ /* Symbol kinds. */
struct SymbolKind
{
enum
{
]b4_symbol(empty, kind_base)[ = -2, /* No symbol. */
]b4_symbol_foreach([b4_symbol_enum])dnl
[ }
private int yycode_;
alias yycode_ this;
this(int code)
{
yycode_ = code;
}
/* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
final void toString(void delegate(const(char)[]) sink) const
{
immutable string[] yy_sname = @{
]b4_symbol_names[
@};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
immutable ]b4_int_type_for([b4_translatable])[[] yytranslatable = @{
]b4_translatable[
@};]])[
sink.formattedWrite!"%s"(yy_sname[yycode_]);
}
}
]])
# b4_case(ID, CODE, [COMMENTS])
# -----------------------------
m4_define([b4_case], [ case $1:m4_ifval([$3], [ b4_comment([$3])])
$2 $2
break;]) break;])
@@ -199,6 +328,109 @@ m4_define([b4_location_type], b4_percent_define_ifdef([[location_type]],[b4_perc
m4_define([b4_position_type], b4_percent_define_ifdef([[position_type]],[b4_percent_define_get([[position_type]])],[YYPosition])) m4_define([b4_position_type], b4_percent_define_ifdef([[position_type]],[b4_percent_define_get([[position_type]])],[YYPosition]))
## ---------------- ##
## api.value.type. ##
## ---------------- ##
# ---------------------- #
# api.value.type=union. #
# ---------------------- #
# b4_symbol_type_register(SYMBOL-NUM)
# -----------------------------------
# Symbol SYMBOL-NUM has a type (for union) instead of a type-tag.
# Extend the definition of %union's body (b4_union_members) with a
# field of that type, and extend the symbol's "type" field to point to
# the field name, instead of the type name.
m4_define([b4_symbol_type_register],
[m4_define([b4_symbol($1, type_tag)],
[b4_symbol_if([$1], [has_id],
[b4_symbol([$1], [id])],
[yykind_[]b4_symbol([$1], [number])])])dnl
m4_append([b4_union_members],
m4_expand([m4_format([ %-40s %s],
m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]),
[b4_symbol_tag_comment([$1])])]))
])
# b4_type_define_tag(SYMBOL1-NUM, ...)
# ------------------------------------
# For the batch of symbols SYMBOL1-NUM... (which all have the same
# type), enhance the %union definition for each of them, and set
# there "type" field to the field tag name, instead of the type name.
m4_define([b4_type_define_tag],
[b4_symbol_if([$1], [has_type],
[m4_map([b4_symbol_type_register], [$@])])
])
# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE])
# ----------------------------------------------
# Same of b4_symbol_value, but when api.value.type=union.
m4_define([b4_symbol_value_union],
[m4_ifval([$3],
[(*($3*)(&$1))],
[m4_ifval([$2],
[b4_symbol_if([$2], [has_type],
[($1.b4_symbol([$2], [type_tag]))],
[$1])],
[$1])])])
# b4_value_type_setup_union
# -------------------------
# Setup support for api.value.type=union. Symbols are defined with a
# type instead of a union member name: build the corresponding union,
# and give the symbols their tag.
m4_define([b4_value_type_setup_union],
[m4_define([b4_union_members])
b4_type_foreach([b4_type_define_tag])
m4_copy_force([b4_symbol_value_union], [b4_symbol_value])
])
# _b4_value_type_setup_keyword
# ----------------------------
# api.value.type is defined with a keyword/string syntax. Check if
# that is properly defined, and prepare its use.
m4_define([_b4_value_type_setup_keyword],
[b4_percent_define_check_values([[[[api.value.type]],
[[none]],
[[union]],
[[union-directive]],
[[yystype]]]])dnl
m4_case(b4_percent_define_get([[api.value.type]]),
[union], [b4_value_type_setup_union])])
# b4_value_type_setup
# -------------------
# Check if api.value.type is properly defined, and possibly prepare
# its use.
b4_define_silent([b4_value_type_setup],
[
# Define default value.
b4_percent_define_ifdef([[api.value.type]], [],
[# %union => api.value.type=union-directive
m4_ifdef([b4_union_members],
[m4_define([b4_percent_define_kind(api.value.type)], [keyword])
m4_define([b4_percent_define(api.value.type)], [union-directive])],
[# no tag seen => api.value.type={int}
m4_if(b4_tag_seen_flag, 0,
[m4_define([b4_percent_define_kind(api.value.type)], [code])
m4_define([b4_percent_define(api.value.type)], [int])],
[# otherwise api.value.type=yystype
m4_define([b4_percent_define_kind(api.value.type)], [keyword])
m4_define([b4_percent_define(api.value.type)], [yystype])])])])
# Set up.
m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
[keyword], [_b4_value_type_setup_keyword])
])
## ----------------- ## ## ----------------- ##
## Semantic Values. ## ## Semantic Values. ##
## ----------------- ## ## ----------------- ##
@@ -245,7 +477,7 @@ m4_define([b4_lhs_location],
# Expansion of @POS, where the current rule has RULE-LENGTH symbols # Expansion of @POS, where the current rule has RULE-LENGTH symbols
# on RHS. # on RHS.
m4_define([b4_rhs_location], m4_define([b4_rhs_location],
[yystack.locationAt ([$1], [$2])]) [yystack.locationAt (b4_subtract($@))])
# b4_lex_param # b4_lex_param
@@ -330,3 +562,66 @@ m4_define([b4_var_decls],
], [$@])]) ], [$@])])
m4_define([b4_var_decl], m4_define([b4_var_decl],
[ protected $1;]) [ protected $1;])
# b4_public_types_declare
# -----------------------
# Define the public types: token, semantic value, location, and so forth.
# Depending on %define token_lex, may be output in the header or source file.
m4_define([b4_public_types_declare],
[[
alias Symbol = ]b4_parser_class[.Symbol;
alias Value = ]b4_yystype[;]b4_locations_if([[
alias Location = ]b4_location_type[;
alias Position = ]b4_position_type[;]b4_push_if([[
alias PUSH_MORE = ]b4_parser_class[.YYPUSH_MORE;
alias ABORT = ]b4_parser_class[.YYABORT;
alias ACCEPT = ]b4_parser_class[.YYACCEPT;]])[]])[
]])
# b4_basic_symbol_constructor_define
# ----------------------------------
# Create Symbol struct constructors for all the visible types.
m4_define([b4_basic_symbol_constructor_define],
[b4_token_visible_if([$1],
[[ this(TokenKind token]b4_symbol_if([$1], [has_type],
[[, ]b4_union_if([], [[typeof(YYSemanticType.]])b4_symbol([$1], [type])dnl
[]b4_union_if([], [[) ]])[ val]])[]b4_locations_if([[, Location loc]])[)
{
kind = yytranslate_(token);]b4_union_if([b4_symbol_if([$1], [has_type], [[
static foreach (member; __traits(allMembers, YYSemanticType))
{
static if (is(typeof(mixin("value_." ~ member)) == ]b4_symbol([$1], [type])[))
{
mixin("value_." ~ member ~ " = val;");
}
}]])], [b4_symbol_if([$1], [has_type], [[
value_.]b4_symbol([$1], [type])[ = val;]])])[]b4_locations_if([
location_ = loc;])[
}
]])])
# b4_symbol_type_define
# ---------------------
# Define symbol_type, the external type for symbols used for symbol
# constructors.
m4_define([b4_symbol_type_define],
[[
/**
* A complete symbol
*/
struct Symbol
{
private SymbolKind kind;
private Value value_;]b4_locations_if([[
private Location location_;]])[
]b4_type_foreach([b4_basic_symbol_constructor_define])[
SymbolKind token() { return kind; }
Value value() { return value_; }]b4_locations_if([[
Location location() { return location_; }]])[
]b4_token_ctor_if([b4_token_constructor_define])[
}
]])
+588 -463
View File
File diff suppressed because it is too large Load Diff
+114 -100
View File
@@ -1,6 +1,7 @@
# C++ GLR skeleton for Bison # C++ GLR skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2002-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,7 +14,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# This skeleton produces a C++ class that encapsulates a C glr parser. # This skeleton produces a C++ class that encapsulates a C glr parser.
@@ -72,24 +73,17 @@ m4_defn([b4_parse_param]))],
# Bypass the default implementation to generate the "yy_symbol_print" # Bypass the default implementation to generate the "yy_symbol_print"
# and "yy_symbol_value_print" functions. # and "yy_symbol_value_print" functions.
m4_define([b4_yy_symbol_print_define], m4_define([b4_yy_symbol_print_define],
[[ [[/*--------------------.
/*--------------------.
| Print this symbol. | | Print this symbol. |
`--------------------*/ `--------------------*/
]b4_function_define([yy_symbol_print], static void
[static void], yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken,
[[FILE *], []], const ]b4_namespace_ref::b4_parser_class[::value_type *yyvaluep]b4_locations_if([[,
[[int yytype], [yytype]], const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[)
[[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep],
[yyvaluep]][]dnl
b4_locations_if([,
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
[yylocationp]]]),
b4_parse_param)[
{ {
]b4_parse_param_use[]dnl ]b4_parse_param_use[]dnl
[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[); [ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[);
} }
]])[ ]])[
@@ -101,45 +95,24 @@ m4_defn([b4_initial_action])]))])[
# Hijack the post prologue to declare yyerror. # Hijack the post prologue to declare yyerror.
]m4_append([b4_post_prologue], ]m4_append([b4_post_prologue],
[b4_syncline([@oline@], [@ofile@])dnl [b4_syncline([@oline@], [@ofile@])dnl
b4_function_declare([yyerror], [static void
[static void],b4_locations_if([ yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
[yylocationp]],]) ])[const char* msg);]])[
b4_parse_param,
[[const char* msg], [msg]])])[
# Inserted before the epilogue to define implementations (yyerror, parser member
#undef yynerrs
#undef yychar
#undef yylval]b4_locations_if([
#undef yylloc])
m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */
#define yyparse ]b4_prefix[parse
#define yylex ]b4_prefix[lex
#define yyerror ]b4_prefix[error
#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[
#define yylval ]b4_prefix[lval
#define yychar ]b4_prefix[char
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])]))
# Hijack the epilogue to define implementations (yyerror, parser member
# functions etc.). # functions etc.).
m4_append([b4_epilogue], ]m4_define([b4_glr_cc_pre_epilogue],
[b4_syncline([@oline@], [@ofile@])dnl [b4_syncline([@oline@], [@ofile@])dnl
[ [
/*------------------. /*------------------.
| Report an error. | | Report an error. |
`------------------*/ `------------------*/
]b4_function_define([yyerror], static void
[static void],b4_locations_if([ yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
[yylocationp]],]) ])[const char* msg)
b4_parse_param,
[[const char* msg], [msg]])[
{ {
]b4_parse_param_use[]dnl ]b4_parse_param_use[]dnl
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg); [ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
@@ -172,7 +145,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
int int
]b4_parser_class[::parse () ]b4_parser_class[::parse ()
{ {
return ::yyparse (*this]b4_user_args[); return ::yy_parse_impl (*this]b4_user_args[);
} }
#if ]b4_api_PREFIX[DEBUG #if ]b4_api_PREFIX[DEBUG
@@ -181,28 +154,28 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
`--------------------*/ `--------------------*/
void void
]b4_parser_class[::yy_symbol_value_print_ (int yytype, ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[, const value_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[) const location_type* yylocationp]])[) const
{]b4_locations_if([[ {]b4_locations_if([[
YYUSE (yylocationp);]])[ YY_USE (yylocationp);]])[
YYUSE (yyvaluep); YY_USE (yyvaluep);
std::ostream& yyo = debug_stream (); std::ostream& yyo = debug_stream ();
std::ostream& yyoutput = yyo; std::ostream& yyoutput = yyo;
YYUSE (yyoutput); YY_USE (yyoutput);
]b4_symbol_actions([printer])[ ]b4_symbol_actions([printer])[
} }
void void
]b4_parser_class[::yy_symbol_print_ (int yytype, ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[, const value_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[) const location_type* yylocationp]])[) const
{ {
*yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm") *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << yytname[yytype] << " ("]b4_locations_if([[ << ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[
<< *yylocationp << ": "]])[; << *yylocationp << ": "]])[;
yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[); yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
*yycdebug_ << ')'; *yycdebug_ << ')';
} }
@@ -238,23 +211,18 @@ b4_namespace_close[]dnl
]) ])
# b4_shared_declarations(hh|cc) m4_define([b4_define_symbol_kind],
# ----------------------------- [m4_format([#define %-15s %s],
# Declaration that might either go into the header (if --defines, $1 = hh) b4_symbol($][1, kind_base),
# or in the implementation file. b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base))
m4_define([b4_shared_declarations], ])
[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
b4_percent_code_get([[requires]])[
#include <iostream>
#include <stdexcept>
#include <string>
]b4_cxx_portability[ # b4_glr_cc_setup
]m4_ifdef([b4_location_include], # ---------------
[[# include ]b4_location_include])[ # Setup redirections for glr.c: Map the names used in c.m4 to the ones used
]b4_variant_if([b4_variant_includes])[ # in c++.m4.
m4_define([b4_glr_cc_setup],
]b4_attribute_define[ [[]b4_attribute_define[
]b4_null_define[ ]b4_null_define[
// This skeleton is based on C, yet compiles it as C++. // This skeleton is based on C, yet compiles it as C++.
@@ -272,6 +240,62 @@ b4_percent_code_get([[requires]])[
# pragma clang diagnostic ignored "-Wc++11-long-long" # pragma clang diagnostic ignored "-Wc++11-long-long"
#endif #endif
#undef ]b4_symbol(empty, [id])[
#define ]b4_symbol(empty, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, [id])[
#undef ]b4_symbol(eof, [id])[
#define ]b4_symbol(eof, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(eof, [id])[
#undef ]b4_symbol(error, [id])[
#define ]b4_symbol(error, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, [id])[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::value_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
// Expose C++ symbol kinds to C.
]b4_define_symbol_kind(-2)dnl
b4_symbol_foreach([b4_define_symbol_kind])])[
]])
m4_define([b4_undef_symbol_kind],
[[#undef ]b4_symbol($1, kind_base)[
]])
# b4_glr_cc_cleanup
# -----------------
# Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup],
[[#undef ]b4_symbol(empty, [id])[
#undef ]b4_symbol(eof, [id])[
#undef ]b4_symbol(error, [id])[
]b4_undef_symbol_kind(-2)dnl
b4_symbol_foreach([b4_undef_symbol_kind])dnl
])
# b4_shared_declarations(hh|cc)
# -----------------------------
# Declaration that might either go into the header (if --header, $1 = hh)
# or in the implementation file.
m4_define([b4_shared_declarations],
[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
b4_percent_code_get([[requires]])[
#include <iostream>
#include <stdexcept>
#include <string>
]b4_cxx_portability[
]m4_ifdef([b4_location_include],
[[# include ]b4_location_include])[
]b4_variant_if([b4_variant_includes])[
// Whether we are compiled with exception support. // Whether we are compiled with exception support.
#ifndef YY_EXCEPTIONS #ifndef YY_EXCEPTIONS
# if defined __GNUC__ && !defined __EXCEPTIONS # if defined __GNUC__ && !defined __EXCEPTIONS
@@ -328,53 +352,43 @@ b4_percent_code_get([[requires]])[
# if ]b4_api_PREFIX[DEBUG # if ]b4_api_PREFIX[DEBUG
public: public:
/// \brief Report a symbol value on the debug stream. /// \brief Report a symbol value on the debug stream.
/// \param yytype The token type. /// \param yykind The symbol kind.
/// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[ /// \param yylocationp Its location.]])[
virtual void yy_symbol_value_print_ (int yytype, virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[, const value_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[); const location_type* yylocationp]])[) const;
/// \brief Report a symbol on the debug stream. /// \brief Report a symbol on the debug stream.
/// \param yytype The token type. /// \param yykind The symbol kind.
/// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[ /// \param yylocationp Its location.]])[
virtual void yy_symbol_print_ (int yytype, virtual void yy_symbol_print_ (symbol_kind_type yykind,
const semantic_type* yyvaluep]b4_locations_if([[, const value_type* yyvaluep]b4_locations_if([[,
const location_type* yylocationp]])[); const location_type* yylocationp]])[) const;
private: private:
// Debugging. /// Debug stream.
std::ostream* yycdebug_; std::ostream* yycdebug_;
#endif #endif
]b4_parse_param_vars[ ]b4_parse_param_vars[
}; };
]dnl Redirections for glr.c.
b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines])
[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
]b4_namespace_close[ ]b4_namespace_close[
]b4_percent_code_get([[provides]])[ ]b4_percent_code_get([[provides]])[
]m4_popdef([b4_parse_param])dnl ]m4_popdef([b4_parse_param])dnl
]) ])[
b4_defines_if( ]b4_header_if(
[b4_output_begin([b4_spec_header_file]) [b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++], b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[ [2002-2015, 2018-2022, 2025-2026])[
// C++ GLR parser skeleton written by Akim Demaille. // C++ GLR parser skeleton written by Akim Demaille.
]b4_disclaimer[ ]b4_disclaimer[
]b4_cpp_guard_open([b4_spec_header_file])[ ]b4_cpp_guard_open([b4_spec_mapped_header_file])[
]b4_shared_declarations[ ]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_header_file])[ ]b4_cpp_guard_close([b4_spec_mapped_header_file])[
]b4_output_end]) ]b4_output_end])
# Let glr.c (and b4_shared_declarations) believe that the user # Let glr.c (and b4_shared_declarations) believe that the user
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -2,8 +2,8 @@
# Java skeleton dispatching for Bison. # Java skeleton dispatching for Bison.
# Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation, # Copyright (C) 2007, 2009-2015, 2018-2022, 2025-2026 Free Software
# Inc. # Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [b4_complain([%%glr-parser not supported for Java])]) b4_glr_if( [b4_complain([%%glr-parser not supported for Java])])
b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])]) b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])])
+153 -16
View File
@@ -2,7 +2,8 @@
# Java language support for Bison # Java language support for Bison
# Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2007-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[c-like.m4]) m4_include(b4_skeletonsdir/[c-like.m4])
@@ -71,12 +72,12 @@ m4_define([b4_lexer_if],
# b4_identification # b4_identification
# ----------------- # -----------------
m4_define([b4_identification], m4_define([b4_identification],
[ /** Version number for the Bison executable that generated this parser. */ [[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "b4_version"; public static final String bisonVersion = "]b4_version_string[";
/** Name of the skeleton that generated this parser. */ /** Name of the skeleton that generated this parser. */
public static final String bisonSkeleton = b4_skeleton; public static final String bisonSkeleton = ]b4_skeleton[;
]) ]])
## ------------ ## ## ------------ ##
@@ -106,6 +107,9 @@ m4_define([b4_null], [null])
# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT) # b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
# ------------------------------------------------------- # -------------------------------------------------------
# We use intermediate functions (e.g., yypact_init) to work around the
# 64KB limit for JVM methods. See
# https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.
m4_define([b4_typed_parser_table_define], m4_define([b4_typed_parser_table_define],
[m4_ifval([$4], [b4_comment([$4]) [m4_ifval([$4], [b4_comment([$4])
])dnl ])dnl
@@ -125,35 +129,151 @@ m4_define([b4_integral_parser_table_define],
[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])]) [b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
## ------------------------- ## ## ------------- ##
## Assigning token numbers. ## ## Token kinds. ##
## ------------------------- ## ## ------------- ##
# b4_token_enum(TOKEN-NUM) # b4_token_enum(TOKEN-NUM)
# ------------------------ # ------------------------
# Output the definition of this token as an enum. # Output the definition of this token as an enum.
m4_define([b4_token_enum], m4_define([b4_token_enum],
[b4_token_format([ /** Token number, to be returned by the scanner. */ [b4_token_visible_if([$1],
static final int %s = %s; [m4_format([[ /** Token %s, to be returned by the scanner. */
], [$1])]) static final int %s = %s%s;
]],
b4_symbol([$1], [tag]),
b4_symbol([$1], [id]),
b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])))])])
# b4_token_enums # b4_token_enums
# -------------- # --------------
# Output the definition of the tokens (if there are) as enums. # Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums], m4_define([b4_token_enums],
[b4_any_token_visible_if([/* Tokens. */ [b4_any_token_visible_if([ /* Token kinds. */
b4_symbol_foreach([b4_token_enum])])]) b4_symbol_foreach([b4_token_enum])])])
# b4-case(ID, CODE)
# -----------------
## -------------- ##
## Symbol kinds. ##
## -------------- ##
# b4_symbol_kind(NUM)
# -------------------
m4_define([b4_symbol_kind],
[SymbolKind.b4_symbol_kind_base($@)])
# b4_symbol_enum(SYMBOL-NUM)
# --------------------------
# Output the definition of this symbol as an enum.
m4_define([b4_symbol_enum],
[m4_format([ %-30s %s],
m4_format([[%s(%s)%s]],
b4_symbol([$1], [kind_base]),
[$1],
m4_if([$1], b4_last_symbol, [[;]], [[,]])),
[b4_symbol_tag_comment([$1])])])
# b4_declare_symbol_enum
# ----------------------
# The definition of the symbol internal numbers as an enum.
m4_define([b4_declare_symbol_enum],
[[ public enum SymbolKind
{
]b4_symbol_foreach([b4_symbol_enum])[
private final int yycode_;
SymbolKind (int n) {
this.yycode_ = n;
}
private static final SymbolKind[] values_ = {
]m4_map_args_sep([b4_symbol_kind(], [)], [,
], b4_symbol_numbers)[
};
static final SymbolKind get(int code) {
return values_[code];
}
public final int getCode() {
return this.yycode_;
}
]b4_parse_error_bmatch(
[simple\|verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
private static String yytnamerr_(String yystr)
{
if (yystr.charAt (0) == '"')
{
StringBuffer yyr = new StringBuffer();
strip_quotes: for (int i = 1; i < yystr.length(); i++)
switch (yystr.charAt(i))
{
case '\'':
case ',':
break strip_quotes;
case '\\':
if (yystr.charAt(++i) != '\\')
break strip_quotes;
/* Fall through. */
default:
yyr.append(yystr.charAt(i));
break;
case '"':
return yyr.toString();
}
}
return yystr;
}
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
/* The user-facing name of this symbol. */
public final String getName() {
return yytnamerr_(yytname_[yycode_]);
}
]],
[custom\|detailed],
[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[
/* The user-facing name of this symbol. */
public final String getName() {
return yynames_[yycode_];
}]])[
};
]])])
# b4_case(ID, CODE, [COMMENTS])
# -----------------------------
# We need to fool Java's stupid unreachable code detection. # We need to fool Java's stupid unreachable code detection.
m4_define([b4_case], m4_define([b4_case],
[ case $1: [ case $1:m4_ifval([$3], [ b4_comment([$3])])
if (yyn == $1) if (yyn == $1)
$2; $2;
break; break;
]) ])
# b4_predicate_case(LABEL, CONDITIONS) # b4_predicate_case(LABEL, CONDITIONS)
# ------------------------------------ # ------------------------------------
m4_define([b4_predicate_case], m4_define([b4_predicate_case],
@@ -185,6 +305,7 @@ b4_percent_define_check_kind([[throws]], [code], [deprecated])
m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])]) m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
b4_percent_define_default([[api.value.type]], [[Object]]) b4_percent_define_default([[api.value.type]], [[Object]])
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
# b4_api_prefix, b4_api_PREFIX # b4_api_prefix, b4_api_PREFIX
# ---------------------------- # ----------------------------
@@ -224,6 +345,22 @@ m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
## ----------------- ## ## ----------------- ##
# b4_symbol_translate(STRING)
# ---------------------------
# Used by "bison" in the array of symbol names to mark those that
# require translation.
m4_define([b4_symbol_translate],
[[i18n($1)]])
# b4_trans(STRING)
# ----------------
# Translate a string if i18n is enabled. Avoid collision with b4_translate.
m4_define([b4_trans],
[b4_has_translations_if([i18n($1)], [$1])])
# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) # b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])
# ---------------------------------------------- # ----------------------------------------------
# See README. # See README.
+437 -265
View File
File diff suppressed because it is too large Load Diff
+732 -299
View File
File diff suppressed because it is too large Load Diff
+601 -343
View File
File diff suppressed because it is too large Load Diff
+25 -17
View File
@@ -1,6 +1,7 @@
# C++ skeleton for Bison # C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2002-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,17 +14,10 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_pushdef([b4_copyright_years], m4_pushdef([b4_copyright_years],
[2002-2015, 2018-2020]) [2002-2015, 2018-2022, 2025-2026])
# b4_position_file
# ----------------
# Name of the file containing the position class, if we want this file.
b4_defines_if([b4_required_version_if([302], [],
[m4_define([b4_position_file], [position.hh])])])])
# b4_location_file # b4_location_file
@@ -32,7 +26,7 @@ b4_defines_if([b4_required_version_if([302], [],
# if we want this file. # if we want this file.
b4_percent_define_check_file([b4_location_file], b4_percent_define_check_file([b4_location_file],
[[api.location.file]], [[api.location.file]],
b4_defines_if([[location.hh]])) b4_header_if([[location.hh]]))
# b4_location_include # b4_location_include
# ------------------- # -------------------
@@ -48,12 +42,22 @@ m4_ifdef([b4_location_file],
["b4_location_file"])]) ["b4_location_file"])])
m4_define([b4_location_path], m4_define([b4_location_path],
b4_percent_define_get([[api.location.include]], b4_percent_define_get([[api.location.include]],
["b4_dir_prefix[]b4_location_file"])) ["b4_mapped_dir_prefix[]b4_location_file"]))
m4_define([b4_location_path], m4_define([b4_location_path],
m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2)))
]) ])
# b4_position_file
# ----------------
# Name of the file containing the position class, if we want this file.
b4_header_if(
[b4_required_version_if(
[30200], [],
[m4_ifdef([b4_location_file],
[m4_define([b4_position_file], [position.hh])])])])
# b4_location_define # b4_location_define
# ------------------ # ------------------
@@ -63,11 +67,13 @@ m4_define([b4_location_define],
class position class position
{ {
public: public:
/// Type for file name.
typedef ]b4_percent_define_get([[api.filename.type]])[ filename_type;
/// Type for line and column numbers. /// Type for line and column numbers.
typedef int counter_type; typedef int counter_type;
]m4_ifdef([b4_location_constructors], [[ ]m4_ifdef([b4_location_constructors], [[
/// Construct a position. /// Construct a position.
explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, explicit position (filename_type* f = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[, counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[) counter_type c = ]b4_location_initial_column[)
: filename (f) : filename (f)
@@ -77,7 +83,7 @@ m4_define([b4_location_define],
]])[ ]])[
/// Initialization. /// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULLPTR, void initialize (filename_type* fn = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[, counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[) counter_type c = ]b4_location_initial_column[)
{ {
@@ -106,7 +112,7 @@ m4_define([b4_location_define],
/** \} */ /** \} */
/// File name to which this position refers. /// File name to which this position refers.
]b4_percent_define_get([[filename_type]])[* filename; filename_type* filename;
/// Current line number. /// Current line number.
counter_type line; counter_type line;
/// Current column number. /// Current column number.
@@ -184,6 +190,8 @@ m4_define([b4_location_define],
class location class location
{ {
public: public:
/// Type for file name.
typedef position::filename_type filename_type;
/// Type for line and column numbers. /// Type for line and column numbers.
typedef position::counter_type counter_type; typedef position::counter_type counter_type;
]m4_ifdef([b4_location_constructors], [ ]m4_ifdef([b4_location_constructors], [
@@ -200,7 +208,7 @@ m4_define([b4_location_define],
{} {}
/// Construct a 0-width location in \a f, \a l, \a c. /// Construct a 0-width location in \a f, \a l, \a c.
explicit location (]b4_percent_define_get([[filename_type]])[* f, explicit location (filename_type* f,
counter_type l = ]b4_location_initial_line[, counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[) counter_type c = ]b4_location_initial_column[)
: begin (f, l, c) : begin (f, l, c)
@@ -209,7 +217,7 @@ m4_define([b4_location_define],
])[ ])[
/// Initialization. /// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, void initialize (filename_type* f = YY_NULLPTR,
counter_type l = ]b4_location_initial_line[, counter_type l = ]b4_location_initial_line[,
counter_type c = ]b4_location_initial_column[) counter_type c = ]b4_location_initial_column[)
{ {
+22 -16
View File
@@ -1,6 +1,7 @@
# C++ skeleton for Bison # C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2002-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,14 +14,14 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# b4_stack_file # b4_stack_file
# ------------- # -------------
# Name of the file containing the stack class, if we want this file. # Name of the file containing the stack class, if we want this file.
b4_defines_if([b4_required_version_if([302], [], b4_header_if([b4_required_version_if([30200], [],
[m4_define([b4_stack_file], [stack.hh])])]) [m4_define([b4_stack_file], [stack.hh])])])
# b4_stack_define # b4_stack_define
@@ -32,15 +33,22 @@ m4_define([b4_stack_define],
{ {
public: public:
// Hide our reversed order. // Hide our reversed order.
typedef typename S::reverse_iterator iterator; typedef typename S::iterator iterator;
typedef typename S::const_reverse_iterator const_iterator; typedef typename S::const_iterator const_iterator;
typedef typename S::size_type size_type; typedef typename S::size_type size_type;
typedef typename std::ptrdiff_t index_type; typedef typename std::ptrdiff_t index_type;
stack (size_type n = 200) stack (size_type n = 200) YY_NOEXCEPT
: seq_ (n) : seq_ (n)
{} {}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
stack (const stack&) = delete;
/// Non copyable.
stack& operator= (const stack&) = delete;
#endif
/// Random access. /// Random access.
/// ///
/// Index 0 returns the topmost element. /// Index 0 returns the topmost element.
@@ -91,31 +99,25 @@ m4_define([b4_stack_define],
return index_type (seq_.size ()); return index_type (seq_.size ());
} }
std::ptrdiff_t
ssize () const YY_NOEXCEPT
{
return std::ptrdiff_t (size ());
}
/// Iterator on top of the stack (going downwards). /// Iterator on top of the stack (going downwards).
const_iterator const_iterator
begin () const YY_NOEXCEPT begin () const YY_NOEXCEPT
{ {
return seq_.rbegin (); return seq_.begin ();
} }
/// Bottom of the stack. /// Bottom of the stack.
const_iterator const_iterator
end () const YY_NOEXCEPT end () const YY_NOEXCEPT
{ {
return seq_.rend (); return seq_.end ();
} }
/// Present a slice of the top of a stack. /// Present a slice of the top of a stack.
class slice class slice
{ {
public: public:
slice (const stack& stack, index_type range) slice (const stack& stack, index_type range) YY_NOEXCEPT
: stack_ (stack) : stack_ (stack)
, range_ (range) , range_ (range)
{} {}
@@ -132,8 +134,12 @@ m4_define([b4_stack_define],
}; };
private: private:
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
stack (const stack&); stack (const stack&);
/// Non copyable.
stack& operator= (const stack&); stack& operator= (const stack&);
#endif
/// The wrapped container. /// The wrapped container.
S seq_; S seq_;
}; };
+2
View File
@@ -0,0 +1,2 @@
dnl GNU M4 treats -dV in a position-independent manner.
m4_debugmode(V)m4_traceon()dnl
+142 -69
View File
@@ -1,6 +1,7 @@
# C++ skeleton for Bison # C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2002-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,13 +14,20 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
## --------- ## ## --------- ##
## variant. ## ## variant. ##
## --------- ## ## --------- ##
# b4_assert
# ---------
# The name of YY_ASSERT.
m4_define([b4_assert],
[b4_api_PREFIX[]_ASSERT])
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
# ------------------------------------------------ # ------------------------------------------------
# Run some ACTION ("build", or "destroy") on YYVAL of symbol type # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
@@ -71,12 +79,12 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl
# ------------------- # -------------------
# The needed includes for variants support. # The needed includes for variants support.
m4_define([b4_variant_includes], m4_define([b4_variant_includes],
[b4_parse_assert_if([[#include <typeinfo>]])[ [b4_parse_assert_if([[#include <typeinfo>
#ifndef YY_ASSERT #ifndef ]b4_assert[
# include <cassert> # include <cassert>
# define YY_ASSERT assert # define ]b4_assert[ assert
#endif #endif
]]) ]])])
@@ -87,38 +95,45 @@ m4_define([b4_variant_includes],
# b4_value_type_declare # b4_value_type_declare
# --------------------- # ---------------------
# Define semantic_type. # Define value_type.
m4_define([b4_value_type_declare], m4_define([b4_value_type_declare],
[[ /// A buffer to store and retrieve objects. [[ /// A buffer to store and retrieve objects.
/// ///
/// Sort of a variant, but does not keep track of the nature /// Sort of a variant, but does not keep track of the nature
/// of the stored data, since that knowledge is available /// of the stored data, since that knowledge is available
/// via the current parser state. /// via the current parser state.
class semantic_type class value_type
{ {
public: public:
/// Type of *this. /// Type of *this.
typedef semantic_type self_type; typedef value_type self_type;
/// Empty construction. /// Empty construction.
semantic_type () YY_NOEXCEPT value_type () YY_NOEXCEPT
: yybuffer_ ()]b4_parse_assert_if([ : yyraw_ ()]b4_parse_assert_if([
, yytypeid_ (YY_NULLPTR)])[ , yytypeid_ (YY_NULLPTR)])[
{} {}
/// Construct and fill. /// Construct and fill.
template <typename T> template <typename T>
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([ value_type (YY_RVREF (T) t)]b4_parse_assert_if([
: yytypeid_ (&typeid (T))])[ : yytypeid_ (&typeid (T))])[
{ {]b4_parse_assert_if([[
YY_ASSERT (sizeof (T) <= size); ]b4_assert[ (sizeof (T) <= size);]])[
new (yyas_<T> ()) T (YY_MOVE (t)); new (yyas_<T> ()) T (YY_MOVE (t));
} }
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
value_type (const self_type&) = delete;
/// Non copyable.
self_type& operator= (const self_type&) = delete;
#endif
/// Destruction, allowed only if empty. /// Destruction, allowed only if empty.
~semantic_type () YY_NOEXCEPT ~value_type () YY_NOEXCEPT
{]b4_parse_assert_if([ {]b4_parse_assert_if([
YY_ASSERT (!yytypeid_); ]b4_assert[ (!yytypeid_);
])[} ])[}
# if 201103L <= YY_CPLUSPLUS # if 201103L <= YY_CPLUSPLUS
@@ -126,10 +141,10 @@ m4_define([b4_value_type_declare],
template <typename T, typename... U> template <typename T, typename... U>
T& T&
emplace (U&&... u) emplace (U&&... u)
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (!yytypeid_); ]b4_assert[ (!yytypeid_);
YY_ASSERT (sizeof (T) <= size); ]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[ yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (std::forward <U>(u)...); return *new (yyas_<T> ()) T (std::forward <U>(u)...);
} }
# else # else
@@ -137,10 +152,10 @@ m4_define([b4_value_type_declare],
template <typename T> template <typename T>
T& T&
emplace () emplace ()
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (!yytypeid_); ]b4_assert[ (!yytypeid_);
YY_ASSERT (sizeof (T) <= size); ]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[ yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (); return *new (yyas_<T> ()) T ();
} }
@@ -148,10 +163,10 @@ m4_define([b4_value_type_declare],
template <typename T> template <typename T>
T& T&
emplace (const T& t) emplace (const T& t)
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (!yytypeid_); ]b4_assert[ (!yytypeid_);
YY_ASSERT (sizeof (T) <= size); ]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[ yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (t); return *new (yyas_<T> ()) T (t);
} }
# endif # endif
@@ -178,10 +193,10 @@ m4_define([b4_value_type_declare],
template <typename T> template <typename T>
T& T&
as () YY_NOEXCEPT as () YY_NOEXCEPT
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (yytypeid_); ]b4_assert[ (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T)); ]b4_assert[ (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[ ]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> (); return *yyas_<T> ();
} }
@@ -189,10 +204,10 @@ m4_define([b4_value_type_declare],
template <typename T> template <typename T>
const T& const T&
as () const YY_NOEXCEPT as () const YY_NOEXCEPT
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (yytypeid_); ]b4_assert[ (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T)); ]b4_assert[ (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[ ]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> (); return *yyas_<T> ();
} }
@@ -207,9 +222,9 @@ m4_define([b4_value_type_declare],
template <typename T> template <typename T>
void void
swap (self_type& that) YY_NOEXCEPT swap (self_type& that) YY_NOEXCEPT
{]b4_parse_assert_if([ {]b4_parse_assert_if([[
YY_ASSERT (yytypeid_); ]b4_assert[ (yytypeid_);
YY_ASSERT (*yytypeid_ == *that.yytypeid_);])[ ]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[
std::swap (as<T> (), that.as<T> ()); std::swap (as<T> (), that.as<T> ());
} }
@@ -258,16 +273,19 @@ m4_define([b4_value_type_declare],
} }
private: private:
/// Prohibit blind copies. #if YY_CPLUSPLUS < 201103L
/// Non copyable.
value_type (const self_type&);
/// Non copyable.
self_type& operator= (const self_type&); self_type& operator= (const self_type&);
semantic_type (const self_type&); #endif
/// Accessor to raw memory as \a T. /// Accessor to raw memory as \a T.
template <typename T> template <typename T>
T* T*
yyas_ () YY_NOEXCEPT yyas_ () YY_NOEXCEPT
{ {
void *yyp = yybuffer_.yyraw; void *yyp = yyraw_;
return static_cast<T*> (yyp); return static_cast<T*> (yyp);
} }
@@ -276,7 +294,7 @@ m4_define([b4_value_type_declare],
const T* const T*
yyas_ () const YY_NOEXCEPT yyas_ () const YY_NOEXCEPT
{ {
const void *yyp = yybuffer_.yyraw; const void *yyp = yyraw_;
return static_cast<const T*> (yyp); return static_cast<const T*> (yyp);
} }
@@ -291,10 +309,10 @@ m4_define([b4_value_type_declare],
union union
{ {
/// Strongest alignment constraints. /// Strongest alignment constraints.
long double yyalign_me; long double yyalign_me_;
/// A buffer large enough to store any of the semantic values. /// A buffer large enough to store any of the semantic values.
char yyraw[size]; char yyraw_[size];
} yybuffer_;]b4_parse_assert_if([ };]b4_parse_assert_if([
/// Whether the content is built: if defined, the name of the stored type. /// Whether the content is built: if defined, the name of the stored type.
const std::type_info *yytypeid_;])[ const std::type_info *yytypeid_;])[
@@ -378,18 +396,74 @@ m4_define([_b4_token_maker_define],
])]) ])])
m4_define([_b4_type_clause], # b4_token_kind(SYMBOL-NUM)
[b4_symbol_if([$1], [is_token], # -------------------------
[b4_symbol_if([$1], [has_id], # Some tokens don't have an ID.
[tok == token::b4_symbol([$1], [id])], m4_define([b4_token_kind],
[tok == b4_symbol([$1], [user_number])])])]) [b4_symbol_if([$1], [has_id],
[token::b4_symbol([$1], [id])],
[b4_symbol([$1], [code])])])
# _b4_token_constructor_define(SYMBOL-NUM...) # _b4_tok_in(SYMBOL-NUM, ...)
# ------------------------------------------- # ---------------------------
# Define a unique make_symbol for all the SYMBOL-NUM (they # See b4_tok_in below. The SYMBOL-NUMs... are tokens only.
#
# We iterate over the tokens to group them by "range" of token numbers (not
# symbols numbers!).
#
# b4_fst is the start of that range.
# b4_prev is the previous value.
# b4_val is the current value.
# If b4_val is the successor of b4_prev in token numbers, update the latter,
# otherwise emit the code for range b4_fst .. b4_prev.
# $1 is also used as a terminator in the foreach, but it will not be printed.
#
m4_define([_b4_tok_in],
[m4_pushdef([b4_prev], [$1])dnl
m4_pushdef([b4_fst], [$1])dnl
m4_pushdef([b4_sep], [])dnl
m4_foreach([b4_val], m4_dquote(m4_shift($@, $1)),
[m4_if(b4_symbol(b4_val, [code]), m4_eval(b4_symbol(b4_prev, [code]) + 1), [],
[b4_sep[]m4_if(b4_fst, b4_prev,
[tok == b4_token_kind(b4_fst)],
[(b4_token_kind(b4_fst) <= tok && tok <= b4_token_kind(b4_prev))])[]dnl
m4_define([b4_fst], b4_val)dnl
m4_define([b4_sep], [
|| ])])dnl
m4_define([b4_prev], b4_val)])dnl
m4_popdef([b4_sep])dnl
m4_popdef([b4_fst])dnl
m4_popdef([b4_prev])dnl
])
# _b4_filter_tokens(SYMBOL-NUM, ...)
# ----------------------------------
# Expand as the list of tokens amongst SYMBOL-NUM.
m4_define([_b4_filter_tokens],
[m4_pushdef([b4_sep])dnl
m4_foreach([b4_val], [$@],
[b4_symbol_if(b4_val, [is_token], [b4_sep[]b4_val[]m4_define([b4_sep], [,])])])dnl
m4_popdef([b4_sep])dnl
])
# b4_tok_in(SYMBOL-NUM, ...)
# ---------------------------
# A C++ conditional that checks that `tok` is a member of this list of symbol
# numbers.
m4_define([b4_tok_in],
[_$0(_b4_filter_tokens($@))])
# _b4_symbol_constructor_define(SYMBOL-NUM...)
# --------------------------------------------
# Define a symbol_type constructor common to all the SYMBOL-NUM (they
# have the same type). Use at class-level. # have the same type). Use at class-level.
m4_define([_b4_token_constructor_define], m4_define([_b4_symbol_constructor_define],
[m4_ifval(_b4_includes_tokens($@), [m4_ifval(_b4_includes_tokens($@),
[[#if 201103L <= YY_CPLUSPLUS [[#if 201103L <= YY_CPLUSPLUS
symbol_type (]b4_join( symbol_type (]b4_join(
@@ -397,25 +471,24 @@ m4_define([_b4_token_constructor_define],
b4_symbol_if([$1], [has_type], b4_symbol_if([$1], [has_type],
[b4_symbol([$1], [type]) v]), [b4_symbol([$1], [type]) v]),
b4_locations_if([location_type l]))[) b4_locations_if([location_type l]))[)
: super_type(]b4_join([token_type (tok)], : super_type (]b4_join([token_kind_type (tok)],
b4_symbol_if([$1], [has_type], [std::move (v)]), b4_symbol_if([$1], [has_type], [std::move (v)]),
b4_locations_if([std::move (l)]))[) b4_locations_if([std::move (l)]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#else #else
symbol_type (]b4_join( symbol_type (]b4_join(
[int tok], [int tok],
b4_symbol_if([$1], [has_type], b4_symbol_if([$1], [has_type],
[const b4_symbol([$1], [type])& v]), [const b4_symbol([$1], [type])& v]),
b4_locations_if([const location_type& l]))[) b4_locations_if([const location_type& l]))[)
: super_type(]b4_join([token_type (tok)], : super_type (]b4_join([token_kind_type (tok)],
b4_symbol_if([$1], [has_type], [v]), b4_symbol_if([$1], [has_type], [v]),
b4_locations_if([l]))[) b4_locations_if([l]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#endif #endif
{]b4_parse_assert_if([[
#if !defined _MSC_VER || defined __clang__
]b4_assert[ (]b4_tok_in($@)[);
#endif
]])[}
]])]) ]])])
@@ -447,7 +520,7 @@ m4_define([b4_basic_symbol_constructor_define],
# b4_token_constructor_define # b4_token_constructor_define
# --------------------------- # ---------------------------
# Define the overloaded versions of make_symbol for all the value types. # Define the overloaded versions of make_FOO for all the token kinds.
m4_define([b4_token_constructor_define], m4_define([b4_token_constructor_define],
[ // Implementation of make_symbol for each symbol type. [ // Implementation of make_symbol for each token kind.
b4_symbol_foreach([_b4_token_maker_define])]) b4_symbol_foreach([_b4_token_maker_define])])
+739 -477
View File
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -3,7 +3,8 @@
<!-- <!--
bison.xsl - common templates for Bison XSLT. bison.xsl - common templates for Bison XSLT.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2007-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -18,12 +19,12 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/"> xmlns:bison="https://www.gnu.org/software/bison/">
<xsl:key <xsl:key
name="bison:symbolByName" name="bison:symbolByName"
+8 -7
View File
@@ -3,7 +3,8 @@
<!-- <!--
xml2dot.xsl - transform Bison XML Report into DOT. xml2dot.xsl - transform Bison XML Report into DOT.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2007-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -18,14 +19,14 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>. Written by Wojciech Polak <polak@gnu.org>.
--> -->
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/"> xmlns:bison="https://www.gnu.org/software/bison/">
<xsl:import href="bison.xsl"/> <xsl:import href="bison.xsl"/>
<xsl:output method="text" encoding="UTF-8" indent="no"/> <xsl:output method="text" encoding="UTF-8" indent="no"/>
@@ -159,7 +160,7 @@
<xsl:param name="prev-rule-number" <xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@rule-number"/> select="preceding-sibling::item[1]/@rule-number"/>
<xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)"> <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
<xsl:with-param name="point" select="@point"/> <xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="num" select="@rule-number"/> <xsl:with-param name="num" select="@rule-number"/>
<xsl:with-param name="prev-lhs" <xsl:with-param name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]" select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
@@ -169,7 +170,7 @@
</xsl:template> </xsl:template>
<xsl:template match="rule"> <xsl:template match="rule">
<xsl:param name="point"/> <xsl:param name="dot"/>
<xsl:param name="num"/> <xsl:param name="num"/>
<xsl:param name="prev-lhs"/> <xsl:param name="prev-lhs"/>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
@@ -198,14 +199,14 @@
<xsl:text>:</xsl:text> <xsl:text>:</xsl:text>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:if test="$point = 0"> <xsl:if test="$dot = 0">
<xsl:text> .</xsl:text> <xsl:text> .</xsl:text>
</xsl:if> </xsl:if>
<!-- RHS --> <!-- RHS -->
<xsl:for-each select="rhs/symbol|rhs/empty"> <xsl:for-each select="rhs/symbol|rhs/empty">
<xsl:apply-templates select="."/> <xsl:apply-templates select="."/>
<xsl:if test="$point = position()"> <xsl:if test="$dot = position()">
<xsl:text> .</xsl:text> <xsl:text> .</xsl:text>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
+22 -13
View File
@@ -3,7 +3,8 @@
<!-- <!--
xml2text.xsl - transform Bison XML Report into plain text. xml2text.xsl - transform Bison XML Report into plain text.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2007-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -18,14 +19,14 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>. Written by Wojciech Polak <polak@gnu.org>.
--> -->
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/"> xmlns:bison="https://www.gnu.org/software/bison/">
<xsl:import href="bison.xsl"/> <xsl:import href="bison.xsl"/>
<xsl:output method="text" encoding="UTF-8" indent="no"/> <xsl:output method="text" encoding="UTF-8" indent="no"/>
@@ -52,7 +53,7 @@
<xsl:if test="nonterminal[@usefulness='useless-in-grammar']"> <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
<xsl:text>Nonterminals useless in grammar&#10;&#10;</xsl:text> <xsl:text>Nonterminals useless in grammar&#10;&#10;</xsl:text>
<xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']"> <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:for-each> </xsl:for-each>
@@ -65,7 +66,7 @@
<xsl:text>Terminals unused in grammar&#10;&#10;</xsl:text> <xsl:text>Terminals unused in grammar&#10;&#10;</xsl:text>
<xsl:for-each select="terminal[@usefulness='unused-in-grammar']"> <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
<xsl:sort select="@symbol-number" data-type="number"/> <xsl:sort select="@symbol-number" data-type="number"/>
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:for-each> </xsl:for-each>
@@ -136,6 +137,7 @@
</xsl:template> </xsl:template>
<xsl:template match="terminal"> <xsl:template match="terminal">
<xsl:text> </xsl:text>
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:call-template name="line-wrap"> <xsl:call-template name="line-wrap">
<xsl:with-param name="first-line-length"> <xsl:with-param name="first-line-length">
@@ -148,6 +150,9 @@
</xsl:with-param> </xsl:with-param>
<xsl:with-param name="line-length" select="66" /> <xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text"> <xsl:with-param name="text">
<xsl:if test="string-length(@type) != 0">
<xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
</xsl:if>
<xsl:value-of select="concat(' (', @token-number, ')')"/> <xsl:value-of select="concat(' (', @token-number, ')')"/>
<xsl:for-each select="key('bison:ruleByRhs', @name)"> <xsl:for-each select="key('bison:ruleByRhs', @name)">
<xsl:value-of select="concat(' ', @number)"/> <xsl:value-of select="concat(' ', @number)"/>
@@ -157,14 +162,18 @@
</xsl:template> </xsl:template>
<xsl:template match="nonterminal"> <xsl:template match="nonterminal">
<xsl:text> </xsl:text>
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:if test="string-length(@type) != 0">
<xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
</xsl:if>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/> <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
<xsl:variable name="output"> <xsl:variable name="output">
<xsl:call-template name="line-wrap"> <xsl:call-template name="line-wrap">
<xsl:with-param name="line-length" select="66" /> <xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text"> <xsl:with-param name="text">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:if test="key('bison:ruleByLhs', @name)"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on@left:</xsl:text> <xsl:text>on@left:</xsl:text>
<xsl:for-each select="key('bison:ruleByLhs', @name)"> <xsl:for-each select="key('bison:ruleByLhs', @name)">
@@ -173,7 +182,7 @@
</xsl:if> </xsl:if>
<xsl:if test="key('bison:ruleByRhs', @name)"> <xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:if test="key('bison:ruleByLhs', @name)"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>, </xsl:text> <xsl:text>&#10; </xsl:text>
</xsl:if> </xsl:if>
<xsl:text>on@right:</xsl:text> <xsl:text>on@right:</xsl:text>
<xsl:for-each select="key('bison:ruleByRhs', @name)"> <xsl:for-each select="key('bison:ruleByRhs', @name)">
@@ -300,7 +309,7 @@
name="prev-lhs" name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]" select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
/> />
<xsl:with-param name="point" select="@point"/> <xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="lookaheads"> <xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/> <xsl:apply-templates select="lookaheads"/>
</xsl:with-param> </xsl:with-param>
@@ -311,7 +320,7 @@
<xsl:param name="itemset"/> <xsl:param name="itemset"/>
<xsl:param name="pad"/> <xsl:param name="pad"/>
<xsl:param name="prev-lhs"/> <xsl:param name="prev-lhs"/>
<xsl:param name="point"/> <xsl:param name="dot"/>
<xsl:param name="lookaheads"/> <xsl:param name="lookaheads"/>
<xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])"> <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
@@ -347,12 +356,12 @@
<!-- RHS --> <!-- RHS -->
<xsl:for-each select="rhs/*"> <xsl:for-each select="rhs/*">
<xsl:if test="position() = $point + 1"> <xsl:if test="position() = $dot + 1">
<xsl:text> .</xsl:text> <xsl:text> </xsl:text>
</xsl:if> </xsl:if>
<xsl:apply-templates select="."/> <xsl:apply-templates select="."/>
<xsl:if test="position() = last() and position() = $point"> <xsl:if test="position() = last() and position() = $dot">
<xsl:text> .</xsl:text> <xsl:text> </xsl:text>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
<xsl:if test="$lookaheads"> <xsl:if test="$lookaheads">
+84 -59
View File
@@ -3,7 +3,8 @@
<!-- <!--
xml2html.xsl - transform Bison XML Report into XHTML. xml2html.xsl - transform Bison XML Report into XHTML.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc. Copyright (C) 2007-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -18,7 +19,7 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>. Written by Wojciech Polak <polak@gnu.org>.
--> -->
@@ -26,7 +27,7 @@
<xsl:stylesheet version="1.0" <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:bison="http://www.gnu.org/software/bison/"> xmlns:bison="https://www.gnu.org/software/bison/">
<xsl:import href="bison.xsl"/> <xsl:import href="bison.xsl"/>
@@ -75,7 +76,7 @@
ol.lower-alpha { ol.lower-alpha {
list-style-type: lower-alpha; list-style-type: lower-alpha;
} }
.point { .dot {
color: #cc0000; color: #cc0000;
} }
#footer { #footer {
@@ -88,7 +89,7 @@
<xsl:apply-templates select="bison-xml-report"/> <xsl:apply-templates select="bison-xml-report"/>
<xsl:text>&#10;&#10;</xsl:text> <xsl:text>&#10;&#10;</xsl:text>
<div id="footer"><hr />This document was generated using <div id="footer"><hr />This document was generated using
<a href="http://www.gnu.org/software/bison/" title="GNU Bison"> <a href="https://www.gnu.org/software/bison/" title="GNU Bison">
GNU Bison <xsl:value-of select="/bison-xml-report/@version"/></a> GNU Bison <xsl:value-of select="/bison-xml-report/@version"/></a>
XML Automaton Report.<br /> XML Automaton Report.<br />
<!-- default copying notice --> <!-- default copying notice -->
@@ -227,6 +228,7 @@
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
<p class="pre"> <p class="pre">
<xsl:call-template name="style-rule-set"> <xsl:call-template name="style-rule-set">
<xsl:with-param name="anchor" select="'true'" />
<xsl:with-param <xsl:with-param
name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']" name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
/> />
@@ -238,9 +240,11 @@
</xsl:template> </xsl:template>
<xsl:template name="style-rule-set"> <xsl:template name="style-rule-set">
<xsl:param name="anchor"/>
<xsl:param name="rule-set"/> <xsl:param name="rule-set"/>
<xsl:for-each select="$rule-set"> <xsl:for-each select="$rule-set">
<xsl:apply-templates select="."> <xsl:apply-templates select=".">
<xsl:with-param name="anchor" select="$anchor"/>
<xsl:with-param name="pad" select="'3'"/> <xsl:with-param name="pad" select="'3'"/>
<xsl:with-param name="prev-lhs"> <xsl:with-param name="prev-lhs">
<xsl:if test="position()>1"> <xsl:if test="position()>1">
@@ -306,9 +310,10 @@
<xsl:text> Terminals, with rules where they appear</xsl:text> <xsl:text> Terminals, with rules where they appear</xsl:text>
</h3> </h3>
<xsl:text>&#10;&#10;</xsl:text> <xsl:text>&#10;&#10;</xsl:text>
<p class="pre"> <ul>
<xsl:text>&#10;</xsl:text>
<xsl:apply-templates select="terminal"/> <xsl:apply-templates select="terminal"/>
</p> </ul>
<xsl:text>&#10;&#10;</xsl:text> <xsl:text>&#10;&#10;</xsl:text>
</xsl:template> </xsl:template>
@@ -318,41 +323,64 @@
<xsl:text> Nonterminals, with rules where they appear</xsl:text> <xsl:text> Nonterminals, with rules where they appear</xsl:text>
</h3> </h3>
<xsl:text>&#10;&#10;</xsl:text> <xsl:text>&#10;&#10;</xsl:text>
<p class="pre"> <ul>
<xsl:text>&#10;</xsl:text>
<xsl:apply-templates <xsl:apply-templates
select="nonterminal[@usefulness!='useless-in-grammar']" select="nonterminal[@usefulness!='useless-in-grammar']"
/> />
</p> </ul>
</xsl:template> </xsl:template>
<xsl:template match="terminal"> <xsl:template match="terminal">
<b><xsl:value-of select="@name"/></b> <xsl:text> </xsl:text>
<xsl:value-of select="concat(' (', @token-number, ')')"/> <li>
<xsl:for-each select="key('bison:ruleByRhs', @name)"> <b><xsl:value-of select="@name"/></b>
<xsl:apply-templates select="." mode="number-link"/> <xsl:if test="string-length(@type) != 0">
</xsl:for-each> <xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
</xsl:if>
<xsl:value-of select="concat(' (', @token-number, ')')"/>
<xsl:for-each select="key('bison:ruleByRhs', @name)">
<xsl:apply-templates select="." mode="number-link"/>
</xsl:for-each>
</li>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:template> </xsl:template>
<xsl:template match="nonterminal"> <xsl:template match="nonterminal">
<b><xsl:value-of select="@name"/></b> <xsl:text> </xsl:text>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/> <li>
<xsl:text>&#10; </xsl:text> <b><xsl:value-of select="@name"/></b>
<xsl:if test="key('bison:ruleByLhs', @name)"> <xsl:if test="string-length(@type) != 0">
<xsl:text>on left:</xsl:text> <xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
<xsl:for-each select="key('bison:ruleByLhs', @name)">
<xsl:apply-templates select="." mode="number-link"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>&#10; </xsl:text>
</xsl:if> </xsl:if>
<xsl:text>on right:</xsl:text> <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:for-each select="key('bison:ruleByRhs', @name)"> <xsl:text>&#10; </xsl:text>
<xsl:apply-templates select="." mode="number-link"/> <ul>
</xsl:for-each> <xsl:text>&#10;</xsl:text>
</xsl:if> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text> </xsl:text>
<li>
<xsl:text>on left:</xsl:text>
<xsl:for-each select="key('bison:ruleByLhs', @name)">
<xsl:apply-templates select="." mode="number-link"/>
</xsl:for-each>
</li>
<xsl:text>&#10;</xsl:text>
</xsl:if>
<xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:text> </xsl:text>
<li>
<xsl:text>on right:</xsl:text>
<xsl:for-each select="key('bison:ruleByRhs', @name)">
<xsl:apply-templates select="." mode="number-link"/>
</xsl:for-each>
</li>
<xsl:text>&#10;</xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
</ul>
<xsl:text>&#10; </xsl:text>
</li>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:template> </xsl:template>
@@ -385,7 +413,7 @@
<xsl:value-of select="concat('state_', @number)"/> <xsl:value-of select="concat('state_', @number)"/>
</xsl:attribute> </xsl:attribute>
</a> </a>
<xsl:text>state </xsl:text> <xsl:text>State </xsl:text>
<xsl:value-of select="@number"/> <xsl:value-of select="@number"/>
</h3> </h3>
<xsl:text>&#10;&#10;</xsl:text> <xsl:text>&#10;&#10;</xsl:text>
@@ -457,35 +485,44 @@
<xsl:with-param name="prev-lhs" <xsl:with-param name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]" select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
/> />
<xsl:with-param name="point" select="@point"/> <xsl:with-param name="dot" select="@dot"/>
<xsl:with-param name="lookaheads"> <xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/> <xsl:apply-templates select="lookaheads"/>
</xsl:with-param> </xsl:with-param>
</xsl:apply-templates> </xsl:apply-templates>
</xsl:template> </xsl:template>
<!--
anchor = 'true': define as an <a> anchor.
itemset = 'true': show the items.
-->
<xsl:template match="rule"> <xsl:template match="rule">
<xsl:param name="anchor"/>
<xsl:param name="itemset"/> <xsl:param name="itemset"/>
<xsl:param name="pad"/> <xsl:param name="pad"/>
<xsl:param name="prev-lhs"/> <xsl:param name="prev-lhs"/>
<xsl:param name="point"/> <xsl:param name="dot"/>
<xsl:param name="lookaheads"/> <xsl:param name="lookaheads"/>
<xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])"> <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:if> </xsl:if>
<xsl:if test="$itemset != 'true'">
<a>
<xsl:attribute name="name">
<xsl:value-of select="concat('rule_', @number)"/>
</xsl:attribute>
</a>
</xsl:if>
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:choose> <xsl:choose>
<xsl:when test="$itemset = 'true'"> <xsl:when test="$anchor = 'true'">
<a>
<xsl:attribute name="name">
<xsl:value-of select="concat('rule_', @number)"/>
</xsl:attribute>
<xsl:call-template name="lpad">
<xsl:with-param name="str" select="string(@number)"/>
<xsl:with-param name="pad" select="number($pad)"/>
</xsl:call-template>
</a>
</xsl:when>
<xsl:otherwise>
<a> <a>
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="concat('#rule_', @number)"/> <xsl:value-of select="concat('#rule_', @number)"/>
@@ -495,25 +532,13 @@
<xsl:with-param name="pad" select="number($pad)"/> <xsl:with-param name="pad" select="number($pad)"/>
</xsl:call-template> </xsl:call-template>
</a> </a>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="lpad">
<xsl:with-param name="str" select="string(@number)"/>
<xsl:with-param name="pad" select="number($pad)"/>
</xsl:call-template>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<!-- LHS --> <!-- LHS -->
<xsl:choose> <xsl:choose>
<xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]"> <xsl:when test="$prev-lhs = lhs[text()]">
<xsl:call-template name="lpad">
<xsl:with-param name="str" select="'|'"/>
<xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
<xsl:call-template name="lpad"> <xsl:call-template name="lpad">
<xsl:with-param name="str" select="'|'"/> <xsl:with-param name="str" select="'|'"/>
<xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/> <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
@@ -529,14 +554,14 @@
<!-- RHS --> <!-- RHS -->
<xsl:for-each select="rhs/*"> <xsl:for-each select="rhs/*">
<xsl:if test="position() = $point + 1"> <xsl:if test="position() = $dot + 1">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<span class="point">.</span> <span class="dot">&#x2022;</span>
</xsl:if> </xsl:if>
<xsl:apply-templates select="."/> <xsl:apply-templates select="."/>
<xsl:if test="position() = last() and position() = $point"> <xsl:if test="position() = last() and position() = $dot">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<span class="point">.</span> <span class="dot">&#x2022;</span>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
<xsl:if test="$lookaheads"> <xsl:if test="$lookaheads">
+5 -15
View File
@@ -8,29 +8,19 @@
#/bison.cp #/bison.cp
#/bison.cps #/bison.cps
#/bison.toc #/bison.toc
*.dvi
/*~ *.ps
/.dirstamp
/bison.1 /bison.1
/bison.dvi
/bison.help /bison.help
/bison.html /bison.html
/bison.info /bison.info
/bison.info.bak
/bison.log
/bison.pdf
/bison.ps
/cross-options.texi /cross-options.texi
/fdl.texi /figs/*.eps
/figs/*.svg
/gendocs_template /gendocs_template
/gendocs_template_min /gendocs_template_min
/gpl-3.0.texi /gpl-3.0.texi
/refcard.dvi /relocatable.texi
/refcard.log
/refcard.ps
/stamp-vti /stamp-vti
/version.texi /version.texi
/yacc.1 /yacc.1
/relocatable.texi
/figs/*.eps
/figs/*.svg
+134 -62
View File
@@ -1,4 +1,4 @@
# Doxyfile 1.8.17 # Doxyfile 1.9.1
# This file describes the settings to be used by the documentation system # This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project. # doxygen (www.doxygen.org) for a project.
@@ -32,13 +32,13 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places. # title of most generated pages and in a few other places.
# The default value is: My Project. # The default value is: My Project.
PROJECT_NAME = "@PACKAGE_NAME@" PROJECT_NAME = @PACKAGE_NAME@
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This # The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = "@PACKAGE_VERSION@" PROJECT_NUMBER = @PACKAGE_VERSION@
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a
@@ -217,6 +217,14 @@ QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO MULTILINE_CPP_IS_BRIEF = NO
# By default Python docstrings are displayed as preformatted text and doxygen's
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
# doxygen's special commands can be used and the contents of the docstring
# documentation blocks is shown as doxygen documentation.
# The default value is: YES.
PYTHON_DOCSTRING = YES
# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
# documentation from any documented member that it re-implements. # documentation from any documented member that it re-implements.
# The default value is: YES. # The default value is: YES.
@@ -253,12 +261,6 @@ TAB_SIZE = 8
ALIASES = ALIASES =
# This tag can be used to specify a number of word-keyword mappings (TCL only).
# A mapping has the form "name=value". For example adding "class=itcl::class"
# will allow you to use the command class in the itcl::class meaning.
TCL_SUBST =
# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
# only. Doxygen will then generate output that is more tailored for C. For # only. Doxygen will then generate output that is more tailored for C. For
# instance, some of the names that are used will be different. The list of all # instance, some of the names that are used will be different. The list of all
@@ -300,18 +302,21 @@ OPTIMIZE_OUTPUT_SLICE = NO
# extension. Doxygen has a built-in mapping, but you can override or extend it # extension. Doxygen has a built-in mapping, but you can override or extend it
# using this tag. The format is ext=language, where ext is a file extension, and # using this tag. The format is ext=language, where ext is a file extension, and
# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, # language is one of the parsers supported by doxygen: IDL, Java, JavaScript,
# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, # Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, VHDL,
# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: # Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser # FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
# tries to guess whether the code is fixed or free formatted code, this is the # tries to guess whether the code is fixed or free formatted code, this is the
# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat # default for Fortran type files). For instance to make doxygen treat .inc files
# .inc files as Fortran files (default is PHP), and .f files as C (default is # as Fortran files (default is PHP), and .f files as C (default is Fortran),
# Fortran), use: inc=Fortran f=C. # use: inc=Fortran f=C.
# #
# Note: For files without extension you can use no_extension as a placeholder. # Note: For files without extension you can use no_extension as a placeholder.
# #
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise # Note that for custom extensions you also need to set FILE_PATTERNS otherwise
# the files are not read by doxygen. # the files are not read by doxygen. When specifying no_extension you should add
# * to the FILE_PATTERNS.
#
# Note see also the list of default file extension mappings.
EXTENSION_MAPPING = EXTENSION_MAPPING =
@@ -445,6 +450,19 @@ TYPEDEF_HIDES_STRUCT = NO
LOOKUP_CACHE_SIZE = 0 LOOKUP_CACHE_SIZE = 0
# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use
# during processing. When set to 0 doxygen will based this on the number of
# cores available in the system. You can set it explicitly to a value larger
# than 0 to get more control over the balance between CPU load and processing
# speed. At this moment only the input processing can be done using multiple
# threads. Since this is still an experimental feature the default is set to 1,
# which efficively disables parallel processing. Please report any issues you
# encounter. Generating dot graphs in parallel is controlled by the
# DOT_NUM_THREADS setting.
# Minimum value: 0, maximum value: 32, default value: 1.
NUM_PROC_THREADS = 1
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Build related configuration options # Build related configuration options
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
@@ -508,6 +526,13 @@ EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO EXTRACT_ANON_NSPACES = NO
# If this flag is set to YES, the name of an unnamed parameter in a declaration
# will be determined by the corresponding definition. By default unnamed
# parameters remain unnamed in the output.
# The default value is: YES.
RESOLVE_UNNAMED_PARAMS = YES
# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
# undocumented members inside documented classes or files. If set to NO these # undocumented members inside documented classes or files. If set to NO these
# members will be included in the various overviews, but no documentation # members will be included in the various overviews, but no documentation
@@ -545,11 +570,18 @@ HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO INTERNAL_DOCS = NO
# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file # With the correct setting of option CASE_SENSE_NAMES doxygen will better be
# names in lower-case letters. If set to YES, upper-case letters are also # able to match the capabilities of the underlying filesystem. In case the
# allowed. This is useful if you have classes or files whose names only differ # filesystem is case sensitive (i.e. it supports files in the same directory
# in case and if your file system supports case sensitive file names. Windows # whose names only differ in casing), the option must be set to YES to properly
# (including Cygwin) ands Mac users are advised to set this option to NO. # deal with such files in case they appear in the input. For filesystems that
# are not case sensitive the option should be be set to NO to properly deal with
# output files written for symbols that only differ in casing, such as for two
# classes, one named CLASS and the other named Class, and to also support
# references to files without having to specify the exact matching casing. On
# Windows (including Cygwin) and MacOS, users should typically set this option
# to NO, whereas on Linux or other Unix flavors it should typically be set to
# YES.
# The default value is: system dependent. # The default value is: system dependent.
CASE_SENSE_NAMES = YES CASE_SENSE_NAMES = YES
@@ -788,7 +820,10 @@ WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO WARN_NO_PARAMDOC = NO
# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
# a warning is encountered. # a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS
# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but
# at the end of the doxygen process doxygen will return with a non-zero status.
# Possible values are: NO, YES and FAIL_ON_WARNINGS.
# The default value is: NO. # The default value is: NO.
WARN_AS_ERROR = NO WARN_AS_ERROR = NO
@@ -825,8 +860,8 @@ INPUT = @top_srcdir@/src \
# This tag can be used to specify the character encoding of the source files # This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv # libiconv (or the iconv built into libc) for the transcoding. See the libiconv
# documentation (see: https://www.gnu.org/software/libiconv/) for the list of # documentation (see:
# possible encodings. # https://www.gnu.org/software/libiconv/) for the list of possible encodings.
# The default value is: UTF-8. # The default value is: UTF-8.
INPUT_ENCODING = UTF-8 INPUT_ENCODING = UTF-8
@@ -839,13 +874,15 @@ INPUT_ENCODING = UTF-8
# need to set EXTENSION_MAPPING for the extension otherwise the files are not # need to set EXTENSION_MAPPING for the extension otherwise the files are not
# read by doxygen. # read by doxygen.
# #
# Note the list of default checked file patterns might differ from the list of
# default file extension mappings.
#
# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, # *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, # *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment), # *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment),
# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen # *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f, *.for, *.tcl, *.vhd, # *.ucf, *.qsf and *.ice.
# *.vhdl, *.ucf, *.qsf and *.ice.
FILE_PATTERNS = *.c \ FILE_PATTERNS = *.c \
*.h \ *.h \
@@ -1075,13 +1112,6 @@ VERBATIM_HEADERS = YES
ALPHABETICAL_INDEX = YES ALPHABETICAL_INDEX = YES
# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
# which the alphabetical index list will be split.
# Minimum value: 1, maximum value: 20, default value: 5.
# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
COLS_IN_ALPHA_INDEX = 5
# In case all classes in a project start with a common prefix, all classes will # In case all classes in a project start with a common prefix, all classes will
# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
# can be used to specify a prefix (or a list of prefixes) that should be ignored # can be used to specify a prefix (or a list of prefixes) that should be ignored
@@ -1252,10 +1282,11 @@ HTML_INDEX_NUM_ENTRIES = 100
# If the GENERATE_DOCSET tag is set to YES, additional index files will be # If the GENERATE_DOCSET tag is set to YES, additional index files will be
# generated that can be used as input for Apple's Xcode 3 integrated development # generated that can be used as input for Apple's Xcode 3 integrated development
# environment (see: https://developer.apple.com/xcode/), introduced with OSX # environment (see:
# 10.5 (Leopard). To create a documentation set, doxygen will generate a # https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
# Makefile in the HTML output directory. Running make will produce the docset in # create a documentation set, doxygen will generate a Makefile in the HTML
# that directory and running make install will install the docset in # output directory. Running make will produce the docset in that directory and
# running make install will install the docset in
# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy # startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
# genXcode/_index.html for more information. # genXcode/_index.html for more information.
@@ -1297,8 +1328,8 @@ DOCSET_PUBLISHER_NAME = Publisher
# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
# additional HTML index files: index.hhp, index.hhc, and index.hhk. The # additional HTML index files: index.hhp, index.hhc, and index.hhk. The
# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on # (see:
# Windows. # https://www.microsoft.com/en-us/download/details.aspx?id=21138) on Windows.
# #
# The HTML Help Workshop contains a compiler that can convert all HTML output # The HTML Help Workshop contains a compiler that can convert all HTML output
# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
@@ -1328,7 +1359,7 @@ CHM_FILE =
HHC_LOCATION = HHC_LOCATION =
# The GENERATE_CHI flag controls if a separate .chi index file is generated # The GENERATE_CHI flag controls if a separate .chi index file is generated
# (YES) or that it should be included in the master .chm file (NO). # (YES) or that it should be included in the main .chm file (NO).
# The default value is: NO. # The default value is: NO.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES. # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
@@ -1373,7 +1404,8 @@ QCH_FILE =
# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
# Project output. For more information please see Qt Help Project / Namespace # Project output. For more information please see Qt Help Project / Namespace
# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # (see:
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
# The default value is: org.doxygen.Project. # The default value is: org.doxygen.Project.
# This tag requires that the tag GENERATE_QHP is set to YES. # This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1381,8 +1413,8 @@ QHP_NAMESPACE = org.doxygen.Project
# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
# Help Project output. For more information please see Qt Help Project / Virtual # Help Project output. For more information please see Qt Help Project / Virtual
# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual- # Folders (see:
# folders). # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders).
# The default value is: doc. # The default value is: doc.
# This tag requires that the tag GENERATE_QHP is set to YES. # This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1390,16 +1422,16 @@ QHP_VIRTUAL_FOLDER = doc
# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
# filter to add. For more information please see Qt Help Project / Custom # filter to add. For more information please see Qt Help Project / Custom
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # Filters (see:
# filters). # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES. # This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_NAME = QHP_CUST_FILTER_NAME =
# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
# custom filter to add. For more information please see Qt Help Project / Custom # custom filter to add. For more information please see Qt Help Project / Custom
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # Filters (see:
# filters). # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES. # This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_ATTRS = QHP_CUST_FILTER_ATTRS =
@@ -1411,9 +1443,9 @@ QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS = QHP_SECT_FILTER_ATTRS =
# The QHG_LOCATION tag can be used to specify the location of Qt's # The QHG_LOCATION tag can be used to specify the location (absolute path
# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the # including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to
# generated .qhp file. # run qhelpgenerator on the generated .qhp file.
# This tag requires that the tag GENERATE_QHP is set to YES. # This tag requires that the tag GENERATE_QHP is set to YES.
QHG_LOCATION = QHG_LOCATION =
@@ -1490,6 +1522,17 @@ TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO EXT_LINKS_IN_WINDOW = NO
# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg
# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see
# https://inkscape.org) to generate formulas as SVG images instead of PNGs for
# the HTML output. These images will generally look nicer at scaled resolutions.
# Possible values are: png (the default) and svg (looks nicer but requires the
# pdf2svg or inkscape tool).
# The default value is: png.
# This tag requires that the tag GENERATE_HTML is set to YES.
HTML_FORMULA_FORMAT = png
# Use this tag to change the font size of LaTeX formulas included as images in # Use this tag to change the font size of LaTeX formulas included as images in
# the HTML documentation. When you change the font size after a successful # the HTML documentation. When you change the font size after a successful
# doxygen run you need to manually remove any form_*.png images from the HTML # doxygen run you need to manually remove any form_*.png images from the HTML
@@ -1529,7 +1572,7 @@ USE_MATHJAX = NO
# When MathJax is enabled you can set the default output format to be used for # When MathJax is enabled you can set the default output format to be used for
# the MathJax output. See the MathJax site (see: # the MathJax output. See the MathJax site (see:
# http://docs.mathjax.org/en/latest/output.html) for more details. # http://docs.mathjax.org/en/v2.7-latest/output.html) for more details.
# Possible values are: HTML-CSS (which is slower, but has the best # Possible values are: HTML-CSS (which is slower, but has the best
# compatibility), NativeMML (i.e. MathML) and SVG. # compatibility), NativeMML (i.e. MathML) and SVG.
# The default value is: HTML-CSS. # The default value is: HTML-CSS.
@@ -1545,7 +1588,7 @@ MATHJAX_FORMAT = HTML-CSS
# Content Delivery Network so you can quickly see the result without installing # Content Delivery Network so you can quickly see the result without installing
# MathJax. However, it is strongly recommended to install a local copy of # MathJax. However, it is strongly recommended to install a local copy of
# MathJax from https://www.mathjax.org before deployment. # MathJax from https://www.mathjax.org before deployment.
# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/. # The default value is: https://cdn.jsdelivr.net/npm/mathjax@2.
# This tag requires that the tag USE_MATHJAX is set to YES. # This tag requires that the tag USE_MATHJAX is set to YES.
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
@@ -1559,7 +1602,8 @@ MATHJAX_EXTENSIONS =
# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
# of code that will be used on startup of the MathJax code. See the MathJax site # of code that will be used on startup of the MathJax code. See the MathJax site
# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an # (see:
# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
# example see the documentation. # example see the documentation.
# This tag requires that the tag USE_MATHJAX is set to YES. # This tag requires that the tag USE_MATHJAX is set to YES.
@@ -1606,7 +1650,8 @@ SERVER_BASED_SEARCH = NO
# #
# Doxygen ships with an example indexer (doxyindexer) and search engine # Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library # (doxysearch.cgi) which are based on the open source search engine library
# Xapian (see: https://xapian.org/). # Xapian (see:
# https://xapian.org/).
# #
# See the section "External Indexing and Searching" for details. # See the section "External Indexing and Searching" for details.
# The default value is: NO. # The default value is: NO.
@@ -1619,8 +1664,9 @@ EXTERNAL_SEARCH = NO
# #
# Doxygen ships with an example indexer (doxyindexer) and search engine # Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library # (doxysearch.cgi) which are based on the open source search engine library
# Xapian (see: https://xapian.org/). See the section "External Indexing and # Xapian (see:
# Searching" for details. # https://xapian.org/). See the section "External Indexing and Searching" for
# details.
# This tag requires that the tag SEARCHENGINE is set to YES. # This tag requires that the tag SEARCHENGINE is set to YES.
SEARCHENGINE_URL = SEARCHENGINE_URL =
@@ -1715,7 +1761,7 @@ COMPACT_LATEX = NO
# The default value is: a4. # The default value is: a4.
# This tag requires that the tag GENERATE_LATEX is set to YES. # This tag requires that the tag GENERATE_LATEX is set to YES.
PAPER_TYPE = a4wide PAPER_TYPE = a4
# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
# that should be included in the LaTeX output. The package can be specified just # that should be included in the LaTeX output. The package can be specified just
@@ -1784,9 +1830,11 @@ LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES PDF_HYPERLINKS = YES
# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate # If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as
# the PDF file directly from the LaTeX files. Set this option to YES, to get a # specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX
# higher quality PDF documentation. # files. Set this option to YES, to get a higher quality PDF documentation.
#
# See also section LATEX_CMD_NAME for selecting the engine.
# The default value is: YES. # The default value is: YES.
# This tag requires that the tag GENERATE_LATEX is set to YES. # This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -2299,10 +2347,32 @@ UML_LOOK = NO
# but if the number exceeds 15, the total amount of fields shown is limited to # but if the number exceeds 15, the total amount of fields shown is limited to
# 10. # 10.
# Minimum value: 0, maximum value: 100, default value: 10. # Minimum value: 0, maximum value: 100, default value: 10.
# This tag requires that the tag HAVE_DOT is set to YES. # This tag requires that the tag UML_LOOK is set to YES.
UML_LIMIT_NUM_FIELDS = 10 UML_LIMIT_NUM_FIELDS = 10
# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and
# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS
# tag is set to YES, doxygen will add type and arguments for attributes and
# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen
# will not generate fields with class member information in the UML graphs. The
# class diagrams will look similar to the default class diagrams but using UML
# notation for the relationships.
# Possible values are: NO, YES and NONE.
# The default value is: NO.
# This tag requires that the tag UML_LOOK is set to YES.
DOT_UML_DETAILS = NO
# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters
# to display on a single line. If the actual line length exceeds this threshold
# significantly it will wrapped across multiple lines. Some heuristics are apply
# to avoid ugly line breaks.
# Minimum value: 0, maximum value: 1000, default value: 17.
# This tag requires that the tag HAVE_DOT is set to YES.
DOT_WRAP_THRESHOLD = 17
# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and # If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
# collaboration graphs will show the relations between templates and their # collaboration graphs will show the relations between templates and their
# instances. # instances.
@@ -2492,9 +2562,11 @@ DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES GENERATE_LEGEND = YES
# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot # If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate
# files that are used to generate the various graphs. # files that are used to generate the various graphs.
#
# Note: This setting is not only used for dot files but also for msc and
# plantuml temporary files.
# The default value is: YES. # The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
DOT_CLEANUP = YES DOT_CLEANUP = YES
+3536 -1399
View File
File diff suppressed because it is too large Load Diff
+29 -28
View File
@@ -2,48 +2,49 @@
bison \- GNU Project parser generator (yacc replacement) bison \- GNU Project parser generator (yacc replacement)
[description] [description]
.I Bison The
is a parser generator in the style of .B bison
.IR yacc (1). parser generator inputs grammars in the style of
It should be upwardly compatible with input files designed .BR yacc (1)
for and outputs parsers for those grammers.
.IR yacc .
.PP .PP
Input files should follow the Input files should follow the
.I yacc .B yacc
convention of ending in convention of ending in
.BR .y . .IR .y .
Unlike Unlike
.IR yacc , .BR yacc ,
the generated files do not have fixed names, but instead use the prefix the generated files do not have fixed names, but instead use the prefix
of the input file. of the input file.
Moreover, if you need to put Moreover, if you need to put C++
.I C++ code in the input file, you can end its name by a C++-like extension
code in the input file, you can end his name by a C++-like extension .RI ( .ypp
(.ypp or .y++), then bison will follow your extension to name the or
output file (.cpp or .c++). .IR .y++ ),
and then
.B bison
will follow your extension to name the
output file
.RI ( .cpp
or
.IR .c++ ).
For instance, a grammar description file named For instance, a grammar description file named
.B parse.yxx .I parse.yxx
would produce the generated parser in a file named would produce the generated parser in a file named
.BR parse.tab.cxx , .IR parse.tab.cxx ,
instead of instead of
.IR yacc 's .BR yacc 's
.B y.tab.c .IR y.tab.c .
or old
.I Bison
version's
.BR parse.tab.c .
.PP .PP
This description of the options that can be given to This description of the options that can be given to
.I bison .B bison
is adapted from the node is adapted from the node
.B Invocation .B Invocation
in the in the Bison manual, which should be taken as authoritative.
.B bison.texi
manual, which should be taken as authoritative.
.PP .PP
.I Bison The
supports both traditional single-letter options and mnemonic long .B bison
command supports both traditional single-letter options and mnemonic long
option names. Long option names are indicated with option names. Long option names are indicated with
.B \-\- .B \-\-
instead of instead of
+23
View File
@@ -0,0 +1,23 @@
%union
{
int ival;
const char *sval;
}
%token <ival> NUM
%nterm <ival> exp
%token <sval> STR
%nterm <sval> useless
%left '+' '-'
%left '*'
%%
exp:
exp '+' exp
| exp '-' exp
| exp '*' exp
| exp '/' exp
| NUM
;
useless: STR;
+13
View File
@@ -0,0 +1,13 @@
%%
stmt:
expr
| if_stmt
;
if_stmt:
"if" expr "then" stmt
| "if" expr "then" stmt "else" stmt
;
expr:
"identifier"
+505
View File
@@ -0,0 +1,505 @@
@c The GNU Free Documentation License.
@center Version 1.3, 3 November 2008
@c This file is intended to be included within another document,
@c hence no sectioning command or @node.
@display
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
@uref{https://fsf.org/}
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@enumerate 0
@item
PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document @dfn{free} in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of ``copyleft'', which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
@item
APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The ``Document'', below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as ``you''. You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A ``Modified Version'' of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A ``Secondary Section'' is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The ``Invariant Sections'' are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The ``Cover Texts'' are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A ``Transparent'' copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not ``Transparent'' is called ``Opaque''.
Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, La@TeX{} input
format, SGML or XML using a publicly available
DTD, and standard-conforming simple HTML,
PostScript or PDF designed for human modification. Examples
of transparent image formats include PNG, XCF and
JPG@. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, SGML or
XML for which the DTD and/or processing tools are
not generally available, and the machine-generated HTML,
PostScript or PDF produced by some word processors for
output purposes only.
The ``Title Page'' means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
The ``publisher'' means any person or entity that distributes copies
of the Document to the public.
A section ``Entitled XYZ'' means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as ``Acknowledgements'',
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
@item
VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
@item
COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
@item
MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
@enumerate A
@item
Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
@item
List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
@item
State on the Title page the name of the publisher of the
Modified Version, as the publisher.
@item
Preserve all the copyright notices of the Document.
@item
Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
@item
Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
@item
Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
@item
Include an unaltered copy of this License.
@item
Preserve the section Entitled ``History'', Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled ``History'' in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
@item
Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the ``History'' section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
@item
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.
@item
Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
@item
Delete any section Entitled ``Endorsements''. Such a section
may not be included in the Modified Version.
@item
Do not retitle any existing section to be Entitled ``Endorsements'' or
to conflict in title with any Invariant Section.
@item
Preserve any Warranty Disclaimers.
@end enumerate
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled ``Endorsements'', provided it contains
nothing but endorsements of your Modified Version by various
parties---for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
@item
COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled ``History''
in the various original documents, forming one section Entitled
``History''; likewise combine any sections Entitled ``Acknowledgements'',
and any sections Entitled ``Dedications''. You must delete all
sections Entitled ``Endorsements.''
@item
COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
@item
AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
@item
TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled ``Acknowledgements'',
``Dedications'', or ``History'', the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
@item
TERMINATION
You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense, or distribute it is void, and
will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.
@item
FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{https://www.gnu.org/licenses/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation. If the Document
specifies that a proxy can decide which future versions of this
License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the
Document.
@item
RELICENSING
``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works. A
public wiki that anybody can edit is an example of such a server. A
``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the
site means any set of copyrightable works thus published on the MMC
site.
``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.
``Incorporate'' means to publish or republish a Document, in whole or
in part, as part of another Document.
An MMC is ``eligible for relicensing'' if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole
or in part into the MMC, (1) had no cover texts or invariant sections,
and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.
@end enumerate
@page
@heading ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
@smallexample
@group
Copyright (C) @var{year} @var{your name}.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end group
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with@dots{}Texts.''@: line with this:
@smallexample
@group
with the Invariant Sections being @var{list their titles}, with
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
being @var{list}.
@end group
@end smallexample
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:
+1 -1
View File
@@ -3,7 +3,7 @@ digraph "reduce.y"
node [fontname=courier shape=box] node [fontname=courier shape=box]
edge [fontname=courier] edge [fontname=courier]
1 [label="State 1\n 3 a: \"0\" . [\".\"]\l 4 b: \"0\" . [\";\"]\l"] 1 [label="State 1\n 3 a: \"0\" [\".\"]\l 4 b: \"0\" [\";\"]\l"]
1 -> "1R3" [label="" style=solid] 1 -> "1R3" [label="" style=solid]
"1R3" [style=filled shape=diamond fillcolor=yellowgreen label="R3"] "1R3" [style=filled shape=diamond fillcolor=yellowgreen label="R3"]
1 -> "1R4" [label="[\";\"]" style=solid] 1 -> "1R4" [label="[\";\"]" style=solid]
+2 -2
View File
@@ -1,7 +1,7 @@
.------------------. .------------------.
| State 1 | | State 1 |
| 3 a: "0" . [";"] | | 3 a: "0" [";"] |
| 4 b: "0" . ["."] | | 4 b: "0" ["."] |
`------------------' `------------------'
/ \ / \
/ \ ["."] / \ ["."]
+2 -2
View File
@@ -3,7 +3,7 @@ digraph "shift.y"
node [fontname=courier shape=box] node [fontname=courier shape=box]
edge [fontname=courier] edge [fontname=courier]
3 [label="State 3\n 1 exp: a . \".\"\l"] 3 [label="State 3\n 1 exp: a \".\"\l"]
3 -> 6 [style=solid label="\".\""] 3 -> 6 [style=solid label="\".\""]
6 [label="State 6\n 1 exp: a \".\" .\l"] 6 [label="State 6\n 1 exp: a \".\" \l"]
} }
+2 -2
View File
@@ -1,6 +1,6 @@
.----------------. .----------------.
| State 3 | | State 3 |
| 1 exp: a . ";" | | 1 exp: a ";" |
`----------------' `----------------'
| |
| ";" | ";"
@@ -8,5 +8,5 @@
v v
.----------------. .----------------.
| State 6 | | State 6 |
| 1 exp: a ";" . | | 1 exp: a ";" |
`----------------' `----------------'
+10 -10
View File
@@ -1,35 +1,35 @@
// Generated by GNU Bison 2.6.90. // Generated by GNU Bison 2.6.90.
// Report bugs to <[email protected]>. // Report bugs to <[email protected]>.
// Home page: <http://www.gnu.org/software/bison/>. // Home page: <https://www.gnu.org/software/bison/>.
digraph "/tmp/fo.y" digraph "example.y"
{ {
node [fontname = courier, shape = box, colorscheme = paired6] node [fontname = courier, shape = box, colorscheme = paired6]
edge [fontname = courier] edge [fontname = courier]
0 [label="State 0\n\l 0 $accept: . exp $end\l 1 exp: . a \";\"\l 2 | . b \".\"\l 3 a: . \"0\"\l 4 b: . \"0\"\l"] 0 [label="State 0\n\l 0 $accept: exp $end\l 1 exp: a \";\"\l 2 | b \".\"\l 3 a: \"0\"\l 4 b: \"0\"\l"]
0 -> 1 [style=solid label="\"0\""] 0 -> 1 [style=solid label="\"0\""]
0 -> 2 [style=dashed label="exp"] 0 -> 2 [style=dashed label="exp"]
0 -> 3 [style=dashed label="a"] 0 -> 3 [style=dashed label="a"]
0 -> 4 [style=dashed label="b"] 0 -> 4 [style=dashed label="b"]
1 [label="State 1\n\l 3 a: \"0\" . [\";\"]\l 4 b: \"0\" . [\".\"]\l"] 1 [label="State 1\n\l 3 a: \"0\" [\";\"]\l 4 b: \"0\" [\".\"]\l"]
1 -> "1R3" [style=solid] 1 -> "1R3" [style=solid]
"1R3" [label="R3", fillcolor=3, shape=diamond, style=filled] "1R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
1 -> "1R4" [label="[\".\"]", style=solid] 1 -> "1R4" [label="[\".\"]", style=solid]
"1R4" [label="R4", fillcolor=3, shape=diamond, style=filled] "1R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
2 [label="State 2\n\l 0 $accept: exp . $end\l"] 2 [label="State 2\n\l 0 $accept: exp $end\l"]
2 -> 5 [style=solid label="$end"] 2 -> 5 [style=solid label="$end"]
3 [label="State 3\n\l 1 exp: a . \";\"\l"] 3 [label="State 3\n\l 1 exp: a \";\"\l"]
3 -> 6 [style=solid label="\";\""] 3 -> 6 [style=solid label="\";\""]
4 [label="State 4\n\l 2 exp: b . \".\"\l"] 4 [label="State 4\n\l 2 exp: b \".\"\l"]
4 -> 7 [style=solid label="\".\""] 4 -> 7 [style=solid label="\".\""]
5 [label="State 5\n\l 0 $accept: exp $end .\l"] 5 [label="State 5\n\l 0 $accept: exp $end \l"]
5 -> "5R0" [style=solid] 5 -> "5R0" [style=solid]
"5R0" [label="Acc", fillcolor=1, shape=diamond, style=filled] "5R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
6 [label="State 6\n\l 1 exp: a \";\" .\l"] 6 [label="State 6\n\l 1 exp: a \";\" \l"]
6 -> "6R1" [style=solid] 6 -> "6R1" [style=solid]
"6R1" [label="R1", fillcolor=3, shape=diamond, style=filled] "6R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
7 [label="State 7\n\l 2 exp: b \".\" .\l"] 7 [label="State 7\n\l 2 exp: b \".\" \l"]
7 -> "7R2" [style=solid] 7 -> "7R2" [style=solid]
"7R2" [label="R2", fillcolor=3, shape=diamond, style=filled] "7R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
} }
+5
View File
@@ -0,0 +1,5 @@
%token ID
%%
s: a ID
a: expr
expr: %empty | expr ID ','
+75 -60
View File
@@ -1,5 +1,5 @@
## Copyright (C) 2001-2003, 2005-2015, 2018-2020 Free Software ## Copyright (C) 2001-2003, 2005-2015, 2018-2022, 2025-2026 Free
## Foundation, Inc. ## Software Foundation, Inc.
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -12,7 +12,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
AM_MAKEINFOFLAGS = \ AM_MAKEINFOFLAGS = \
--no-split \ --no-split \
@@ -20,71 +20,71 @@ AM_MAKEINFOFLAGS = \
--set-customization-variable=AVOID_MENU_REDUNDANCY=true \ --set-customization-variable=AVOID_MENU_REDUNDANCY=true \
--set-customization-variable=ICONS=true --set-customization-variable=ICONS=true
info_TEXINFOS = doc/bison.texi info_TEXINFOS = %D%/bison.texi
doc_bison_TEXINFOS = \ %C%_bison_TEXINFOS = \
$(CROSS_OPTIONS_TEXI) \ $(CROSS_OPTIONS_TEXI) \
doc/fdl.texi \ %D%/fdl.texi \
doc/gpl-3.0.texi \ %D%/gpl-3.0.texi \
doc/relocatable.texi %D%/relocatable.texi
# Cannot express dependencies directly on file names because of Automake. # Cannot express dependencies directly on file names because of Automake.
# Obfuscate with a variable. # Obfuscate with a variable.
doc_bison = doc/bison %C%_bison = %D%/bison
$(doc_bison).dvi: $(FIGS_GV:.gv=.eps) $(%C%_bison).dvi: $(FIGS_GV:.gv=.eps)
$(doc_bison).info: $(FIGS_GV:.gv=.txt) $(%C%_bison).info: $(FIGS_GV:.gv=.txt)
$(doc_bison).pdf: $(FIGS_GV:.gv=.pdf) $(%C%_bison).pdf: $(FIGS_GV:.gv=.pdf)
$(doc_bison).html: $(FIGS_GV:.gv=.svg) $(%C%_bison).html: $(FIGS_GV:.gv=.svg)
TEXI2DVI = texi2dvi --build-dir=doc/bison.t2d -I doc TEXI2DVI = texi2dvi --build-dir=%D%/bison.t2d -I %D%
CLEANDIRS += doc/bison.t2d CLEANDIRS += %D%/bison.t2d
MOSTLYCLEANFILES += $(top_srcdir)/doc/*.tmp MOSTLYCLEANFILES += $(top_srcdir)/%D%/*.tmp
CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl
CROSS_OPTIONS_TEXI = $(top_srcdir)/doc/cross-options.texi CROSS_OPTIONS_TEXI = $(top_srcdir)/%D%/cross-options.texi
$(CROSS_OPTIONS_TEXI): doc/bison.help $(CROSS_OPTIONS_PL) $(CROSS_OPTIONS_TEXI): %D%/bison.help $(CROSS_OPTIONS_PL)
# Create $@~ which is the previous contents. Don't use 'mv' here so # Create $@~ which is the previous contents. Don't use 'mv' here so
# that even if we are interrupted, the file is still available for # that even if we are interrupted, the file is still available for
# diff in the next run. Note that $@ might not exist yet. # diff in the next run. Note that $@ might not exist yet.
$(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~ $(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~
$(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp $(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp
$(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \ $(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \
<$(top_srcdir)/doc/bison.help >$@.tmp <$(top_srcdir)/%D%/bison.help >$@.tmp
$(AM_V_at)diff -u $@~ $@.tmp || true $(AM_V_at)diff -u $@~ $@.tmp || true
$(AM_V_at)mv $@.tmp $@ $(AM_V_at)mv $@.tmp $@
MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI) MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
# Fix Info's @code in @deftype # Fix Info's @code in @deftype
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html # https://lists.gnu.org/r/help-texinfo/2019-11/msg00004.html
all: $(srcdir)/$(doc_bison).info.bak all-local: $(srcdir)/$(%C%_bison).info.bak
$(srcdir)/$(doc_bison).info.bak: $(srcdir)/$(doc_bison).info $(srcdir)/$(%C%_bison).info.bak: $(srcdir)/$(%C%_bison).info
$(AM_V_GEN) $(PERL) -pi.bak -0777 \ $(AM_V_GEN) $(PERL) -pi.bak -0777 \
-e 's{(^ --.*\n(?: {10}.*\n)*)}' \ -e 's{(^ --.*\n(?: {10}.*\n)*)}' \
-e '{' \ -e '{' \
-e ' $$def = $$1;' \ -e ' $$def = $$1;' \
-e ' $$def =~ s/|//g;' \ -e ' $$def =~ s/|//g;' \
-e ' $$def;' \ -e ' $$def;' \
-e '}gem;' $(srcdir)/$(doc_bison).info -e '}gem;' $(srcdir)/$(%C%_bison).info
@ touch $@ @ touch $@
EXTRA_DIST += $(srcdir)/$(doc_bison).info.bak EXTRA_DIST += $(srcdir)/$(%C%_bison).info.bak
MAINTAINERCLEANFILES += $(srcdir)/$(doc_bison).info.bak MAINTAINERCLEANFILES += $(srcdir)/$(%C%_bison).info.bak
## ---------- ## ## ---------- ##
## Ref card. ## ## Ref card. ##
## ---------- ## ## ---------- ##
EXTRA_DIST += doc/refcard.tex EXTRA_DIST += %D%/refcard.tex
CLEANFILES += doc/refcard.pdf CLEANFILES += %D%/refcard.pdf
doc/refcard.pdf: doc/refcard.tex %D%/refcard.pdf: %D%/refcard.tex
$(AM_V_GEN) cd doc && pdftex $(abs_top_srcdir)/doc/refcard.tex $(AM_V_GEN) cd %D% && pdftex $(abs_top_srcdir)/%D%/refcard.tex
## ---------------- ## ## ---------------- ##
## doc/bison.help. ## ## %D%/bison.help. ##
## ---------------- ## ## ---------------- ##
# Some of our targets (cross-options.texi, bison.1) use "bison --help". # Some of our targets (cross-options.texi, bison.1) use "bison --help".
@@ -106,18 +106,19 @@ doc/refcard.pdf: doc/refcard.tex
# compilations of cross-options.texi and bison.1. At the cost of # compilations of cross-options.texi and bison.1. At the cost of
# repeated builds of bison.help. # repeated builds of bison.help.
EXTRA_DIST += $(top_srcdir)/doc/bison.help EXTRA_DIST += $(top_srcdir)/%D%/bison.help
if ! CROSS_COMPILING if ! CROSS_COMPILING
MAINTAINERCLEANFILES += $(top_srcdir)/doc/bison.help MAINTAINERCLEANFILES += $(top_srcdir)/%D%/bison.help
$(top_srcdir)/doc/bison.help: src/bison$(EXEEXT) $(top_srcdir)/%D%/bison.help: src/bison$(EXEEXT)
$(AM_V_GEN)LC_ALL=C tests/bison --version >doc/bison.help.tmp $(AM_V_GEN)$(MKDIR_P) %D%
$(AM_V_at) LC_ALL=C tests/bison --version >%D%/bison.help.tmp
$(AM_V_at) LC_ALL=C tests/bison --help | \ $(AM_V_at) LC_ALL=C tests/bison --help | \
## Avoid depending on the path to Bison. ## Avoid depending on the path to Bison.
sed -e 's,^Usage: .*/bison \[OPTION\],Usage: bison [OPTION],g' \ sed -e 's,^Usage: .*/bison \[OPTION],Usage: bison [OPTION],g' \
## Avoid variations in the output depending on whether we are ## Avoid variations in the output depending on whether we are
## on a glibc system. ## on a glibc system.
-e '/translation bugs/d' >>doc/bison.help.tmp -e '/translation bugs/d' >>%D%/bison.help.tmp
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change doc/bison.help.tmp $@ $(AM_V_at)$(top_srcdir)/build-aux/move-if-change %D%/bison.help.tmp $@
endif ! CROSS_COMPILING endif ! CROSS_COMPILING
@@ -125,34 +126,48 @@ endif ! CROSS_COMPILING
## Man Pages. ## ## Man Pages. ##
## ----------- ## ## ----------- ##
dist_man_MANS = $(top_srcdir)/doc/bison.1 dist_man_MANS = $(top_srcdir)/%D%/bison.1
EXTRA_DIST += $(dist_man_MANS:.1=.x) EXTRA_DIST += $(dist_man_MANS:.1=.x)
MAINTAINERCLEANFILES += $(dist_man_MANS) MAINTAINERCLEANFILES += $(dist_man_MANS)
# Differences to ignore when comparing the man page (the date). # Differences to ignore when comparing man pages (the date).
remove_time_stamp = \ remove_time_stamp = \
sed 's/^\(\.TH[^"]*"[^"]*"[^"]*\)"[^"]*"/\1/' sed 's/^\(\.TH[^"]*"[^"]*"[^"]*\)"[^"]*"/\1/'
# Depend on configure to get version number changes. # Depend on configure to get version number changes.
if ! CROSS_COMPILING if ! CROSS_COMPILING
MAN_DEPS = doc/bison.help doc/bison.x $(top_srcdir)/configure MAN_DEPS = %D%/bison.help %D%/bison.x $(top_srcdir)/configure
endif endif
$(top_srcdir)/doc/bison.1: $(MAN_DEPS) # If we don't have help2man, just touch the target. Maintainers must
$(AM_V_GEN)$(HELP2MAN) \ # have the real thing, so if there's a .git directory, fail hard.
--include=$(top_srcdir)/doc/bison.x \ #
--output=$@.tmp tests/bison # We shouldn't need this, but on some OS the timestamps in the tarball
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \ # leave us no choice. See
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \ # https://lists.gnu.org/r/bug-bison/2020-05/msg00055.html.
touch $@; \ $(top_srcdir)/%D%/bison.1: $(MAN_DEPS)
else \ $(AM_V_GEN)if $(HELP2MAN) --version >/dev/null 2>&1; then \
mv $@.tmp $@; \ $(HELP2MAN) \
--include=$(top_srcdir)/%D%/bison.x \
--output=$@.tmp tests/bison && \
{ $(remove_time_stamp) $@ >$@a.tmp || true; } && \
$(remove_time_stamp) $@.tmp >$@b.tmp && \
if diff $@a.tmp $@b.tmp >/dev/null 2>&1; then \
touch $@; \
else \
mv $@.tmp $@; \
fi && \
rm -f $@*.tmp; \
elif test -d $(srcdir)/.git; then \
echo >&2 "ERROR: $@: help2man is needed"; \
exit 1; \
else \
touch $@; \
fi fi
$(AM_V_at)rm -f $@*.tmp
if ENABLE_YACC if ENABLE_YACC
nodist_man_MANS = doc/yacc.1 nodist_man_MANS = %D%/yacc.1
endif endif
## ----------------------------- ## ## ----------------------------- ##
@@ -161,8 +176,8 @@ endif
CLEANFILES += $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg) CLEANFILES += $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
FIGS_GV = \ FIGS_GV = \
doc/figs/example.gv \ %D%/figs/example.gv \
doc/figs/example-reduce.gv doc/figs/example-shift.gv %D%/figs/example-reduce.gv %D%/figs/example-shift.gv
EXTRA_DIST += \ EXTRA_DIST += \
$(FIGS_GV) $(FIGS_GV:.gv=.txt) \ $(FIGS_GV) $(FIGS_GV:.gv=.txt) \
$(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg) $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
@@ -193,8 +208,8 @@ DOXYGEN = doxygen
doc: html doc: html
html-local: doc/Doxyfile html-local: %D%/Doxyfile
$(AM_V_GEN) $(DOXYGEN) doc/Doxyfile $(AM_V_GEN) $(DOXYGEN) %D%/Doxyfile
edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \ edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
-e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \ -e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
@@ -202,11 +217,11 @@ edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
-e 's,@top_builddir\@,$(top_builddir),g' \ -e 's,@top_builddir\@,$(top_builddir),g' \
-e 's,@top_srcdir\@,$(top_srcdir),g' -e 's,@top_srcdir\@,$(top_srcdir),g'
EXTRA_DIST += doc/Doxyfile.in EXTRA_DIST += %D%/Doxyfile.in
CLEANFILES += doc/Doxyfile CLEANFILES += %D%/Doxyfile
# Sed is used to generate Doxyfile from Doxyfile.in instead of # Sed is used to generate Doxyfile from Doxyfile.in instead of
# configure, because the former is way faster than the latter. # configure, because the former is way faster than the latter.
doc/Doxyfile: $(top_srcdir)/doc/Doxyfile.in %D%/Doxyfile: $(top_srcdir)/%D%/Doxyfile.in
$(AM_V_GEN) $(edit) $(top_srcdir)/doc/Doxyfile.in >doc/Doxyfile $(AM_V_GEN) $(edit) $(top_srcdir)/%D%/Doxyfile.in >%D%/Doxyfile
CLEANDIRS += doc/html CLEANDIRS += %D%/html
+3 -3
View File
@@ -19,8 +19,8 @@
\def\finalout{\overfullrule=0pt} \def\finalout{\overfullrule=0pt}
%\finalout %\finalout
% Copyright (c) 1998, 2001, 2009--2015, 2018--2020 Free Software % Copyright (c) 1998, 2001, 2009--2015, 2018--2022, 2025--2026 Free
% Foundation, Inc. % Software Foundation, Inc.
% %
% This file is part of Bison. % This file is part of Bison.
% %
@@ -35,7 +35,7 @@
% GNU General Public License for more details. % GNU General Public License for more details.
% %
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>. % along with this program. If not, see <https://www.gnu.org/licenses/>.
% %
% This file is intended to be processed by plain TeX (TeX82). % This file is intended to be processed by plain TeX (TeX82).
% %
+10
View File
@@ -0,0 +1,10 @@
%%
sequence:
%empty
| maybeword
| sequence "word"
;
maybeword:
%empty
| "word"
;
+4 -3
View File
@@ -5,14 +5,15 @@ yacc \- GNU Project parser generator
.B yacc .B yacc
[\fIOPTION\fR]... \fIFILE\fR [\fIOPTION\fR]... \fIFILE\fR
.SH DESCRIPTION .SH DESCRIPTION
.I Yacc The program
.B yacc
(Yet Another Compiler Compiler) is a parser generator. This (Yet Another Compiler Compiler) is a parser generator. This
version is a simple wrapper around version is a simple wrapper around
.IR bison (1). .BR bison (1).
It passes option It passes option
\fB\-y\fR, \fB\-\-yacc\fR \fB\-y\fR, \fB\-\-yacc\fR
to activate the upward compatibility mode. See to activate the upward compatibility mode. See
.IR bison (1) .BR bison (1)
for more information. for more information.
.SH AUTHOR .SH AUTHOR
Written by Paul Eggert. Written by Paul Eggert.
-38
View File
@@ -1,38 +0,0 @@
* bench.pl
A primitive Perl script to run benches. Currently its only bench is
the usual calculator: it has a lightweight processing part (but not
null), so it is really emphasizing the cost of the whole parsing
(including scanning and I/O).
Set the envvars BISON and CC to the programs and flags you want to
use. They default to bison and gcc. To run a non-installed bison
from a tarball built in _build, I suggest the following.
BISON=_build/tests/bison CC='gcc -O2' ./bench.pl
(The _build/tests/bison wrapper makes sure that _build/src/bison will
use the tarballs' skeletons, not those already installed as a
straightforward use of _build/src/bison would.)
--
Copyright (C) 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Local Variables:
mode: outline
End:
+37
View File
@@ -0,0 +1,37 @@
# bench.pl
A primitive Perl script to run benches. Currently its only bench is the
usual calculator: it has a lightweight processing part (but not null), so it
is really emphasizing the cost of the whole parsing (including scanning and
I/O).
Set the envvars `BISON` and `CC` to the programs and flags you want to use.
They default to `bison` and `gcc`. To run a non-installed bison from a
tarball built in _build, I suggest the following.
BISON=_build/tests/bison CC='gcc -O2' ./bench.pl
(The `_build/tests/bison` wrapper makes sure that `_build/src/bison` will
use the tarballs' skeletons, not those already installed as a
straightforward use of `_build/src/bison` would.)
<!--
Local Variables:
mode: markdown
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2006, 2009-2015, 2018-2022, 2025-2026 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
-->
+372 -216
View File
File diff suppressed because one or more lines are too long
+5 -4
View File
@@ -1,5 +1,5 @@
## Copyright (C) 2006, 2008-2015, 2018-2020 Free Software Foundation, ## Copyright (C) 2006, 2008-2015, 2018-2022, 2025-2026 Free Software
## Inc. ## Foundation, Inc.
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -12,6 +12,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
nodist_noinst_SCRIPTS = etc/bench.pl dist_noinst_DATA = %D%/README.md
nodist_noinst_SCRIPTS = %D%/bench.pl
+13
View File
@@ -0,0 +1,13 @@
*.c
*.cc
*.class
*.h
*.hh
!/c++/glr/ast.hh
*.java
*.ll
/c/bistromathic/bistromathic
/c/calc/calc
/c/glr/c++-types
/c/lexcalc/lexcalc
/c/pushcalc/calc
+1 -1
View File
@@ -17,7 +17,7 @@ fill-column: 76
ispell-dictionary: "american" ispell-dictionary: "american"
End: End:
Copyright (C) 2018-2020 Free Software Foundation, Inc. Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or under the terms of the GNU Free Documentation License, Version 1.3 or
+4
View File
@@ -1 +1,5 @@
/glr/c++-types
/simple
/simple.yy /simple.yy
/variant
/variant-11
+2 -2
View File
@@ -11,8 +11,8 @@ variant-11: CXXFLAGS = -std=c++11
all: $(PROGS) all: $(PROGS)
%.cc %.hh: %.yy %.cc %.hh %.html %.gv: %.yy
$(BISON) $(BISONFLAGS) -o $*.cc $< $(BISON) $(BISONFLAGS) --html --graph -o $*.cc $<
%: %.cc %: %.cc
$(CXX) $(CXXFLAGS) -o$@ $< $(CXX) $(CXXFLAGS) -o$@ $<
+15 -6
View File
@@ -8,13 +8,13 @@ afterwards.
## simple.yy - Simple example in C++14 ## simple.yy - Simple example in C++14
A very simple example in C++, based on variants and symbol constructors. A very simple example in C++, based on variants and symbol constructors.
Variants allow to use any C++ type as semantic value type, and symbol Variants allow to use any C++ type as semantic value type, and symbol
constructors ensure consistency between declared token type and effective constructors ensure consistency between declared token kind and effective
semantic value. semantic value.
Run as `./simple`. Run as `./simple`.
Extracted from the documentation: "A Simple C++ Example". Extracted from the documentation: [A Simple C++
https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html Example](https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html).
## variant.yy - Self-contained example in C++98 ## variant.yy - Self-contained example in C++98
A variation of simple.yy, in C++98. A variation of simple.yy, in C++98.
@@ -36,8 +36,17 @@ starting point for a clean parser in C++. The previous examples are better
introductory examples, and the C examples are also useful introductory introductory examples, and the C examples are also useful introductory
examples. examples.
Extracted from the documentation: "A Complete C++ Example". Extracted from the documentation: [A Complete C++
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html Example](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html).
## glr
This example demonstrates the use of GLR parsers to handle (local)
ambiguities in the C++ language. See the node "Merging GLR Parses" in
Bison's documentation.
It uses (Bison) variants to store objects as semantic values. It also
demonstrates custom error messages in C++.
<!--- <!---
@@ -46,7 +55,7 @@ fill-column: 76
ispell-dictionary: "american" ispell-dictionary: "american"
End: End:
Copyright (C) 2018-2020 Free Software Foundation, Inc. Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or under the terms of the GNU Free Documentation License, Version 1.3 or
-17
View File
@@ -1,19 +1,2 @@
/*.o
/*.tmp
/.deps
/calc++ /calc++
/calc++.cc
/calc++.exe
/calc.stamp
/driver.cc
/driver.hh
/location.hh
/parser.cc
/parser.hh
/parser.output
/parser.stamp
/parser.yy /parser.yy
/position.hh
/scanner.cc
/scanner.ll
/stack.hh
+2 -7
View File
@@ -5,12 +5,11 @@ BASE = calc++
BISON = bison BISON = bison
CXX = g++ CXX = g++
FLEX = flex FLEX = flex
XSLTPROC = xsltproc
all: $(BASE) all: $(BASE)
%.cc %.hh %.xml %.gv: %.yy %.cc %.hh %.html %.gv: %.yy
$(BISON) $(BISONFLAGS) --xml --graph=$*.gv -o $*.cc $< $(BISON) $(BISONFLAGS) --html --graph -o $*.cc $<
%.cc: %.ll %.cc: %.ll
$(FLEX) $(FLEXFLAGS) -o$@ $< $(FLEX) $(FLEXFLAGS) -o$@ $<
@@ -29,10 +28,6 @@ run: $(BASE)
@echo "Type arithmetic expressions. Quit with ctrl-d." @echo "Type arithmetic expressions. Quit with ctrl-d."
./$< - ./$< -
html: parser.html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \ CLEANFILES = \
$(BASE) *.o \ $(BASE) *.o \
parser.hh parser.cc parser.output parser.xml parser.html parser.gv location.hh \ parser.hh parser.cc parser.output parser.xml parser.html parser.gv location.hh \
+4 -4
View File
@@ -5,9 +5,9 @@ saw the traditional implementation in C, please first read
examples/c/lexcalc, which can be seen as a C precursor of this example. examples/c/lexcalc, which can be seen as a C precursor of this example.
Read the corresponding chapter in the documentation: "A Complete C++ Read the corresponding chapter in the documentation: "A Complete C++
Example". It is also available on line (maybe with a different version of Example". It is also available [on
Bison): line](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html)
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html (maybe with a different version of Bison).
To use it, copy this directory into some work directory, and run `make` to To use it, copy this directory into some work directory, and run `make` to
compile the executable, and try it. It is a simple calculator which accepts compile the executable, and try it. It is a simple calculator which accepts
@@ -36,7 +36,7 @@ fill-column: 76
ispell-dictionary: "american" ispell-dictionary: "american"
End: End:
Copyright (C) 2018-2020 Free Software Foundation, Inc. Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or under the terms of the GNU Free Documentation License, Version 1.3 or
+26 -3
View File
@@ -1,6 +1,7 @@
#! /bin/sh #! /bin/sh
# Copyright (C) 2005-2015, 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2005-2015, 2018-2022, 2025-2026 Free Software
# Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,7 +14,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF cat >input <<EOF
toto := 1 toto := 1
@@ -44,11 +45,33 @@ EOF
run 0 9 run 0 9
cat >input <<EOF
1 +
EOF
run 1 'err: -:2.1: syntax error, unexpected end of file, expecting ( or identifier or number'
# Check handling of tabs.
cat >input <<EOF
*1
EOF
run 1 'err: -:1.9: syntax error, unexpected *, expecting ( or identifier or number'
cat >input <<EOF
*2
EOF
run 1 'err: -:1.9: syntax error, unexpected *, expecting ( or identifier or number'
cat >input <<EOF
*3
EOF
run 1 'err: -:1.9: syntax error, unexpected *, expecting ( or identifier or number'
# LAC finds many more tokens.
cat >input <<EOF cat >input <<EOF
a := 1 a := 1
d := a + b * c d := a + b * c
EOF EOF
run 1 'err: -:3.1: syntax error, unexpected end of file, expecting ( or identifier or number' run 1 'err: -:3.1: syntax error, unexpected end of file'
cat >input <<EOF cat >input <<EOF
+5 -5
View File
@@ -1,5 +1,5 @@
## Copyright (C) 2005-2006, 2008-2015, 2018-2020 Free Software ## Copyright (C) 2005-2006, 2008-2015, 2018-2022, 2025-2026 Free
## Foundation, Inc. ## Software Foundation, Inc.
## ##
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -12,13 +12,12 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
## ------------------- ## ## ------------------- ##
## Parser generation. ## ## Parser generation. ##
## ------------------- ## ## ------------------- ##
%D%/parser.stamp: $(dependencies)
SUFFIXES += .yy .stamp SUFFIXES += .yy .stamp
.yy.stamp: .yy.stamp:
$(AM_V_YACC)rm -f $@ $(AM_V_YACC)rm -f $@
@@ -26,12 +25,13 @@ SUFFIXES += .yy .stamp
$(AM_V_at)$(YACCCOMPILE) -o $*.cc $< $(AM_V_at)$(YACCCOMPILE) -o $*.cc $<
$(AM_V_at)mv -f $@.tmp $@ $(AM_V_at)mv -f $@.tmp $@
%D%/parser.stamp: $(dependencies)
$(calcxx_sources_generated): %D%/parser.stamp $(calcxx_sources_generated): %D%/parser.stamp
@test -f $@ || rm -f %D%/parser.stamp @test -f $@ || rm -f %D%/parser.stamp
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/parser.stamp @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/parser.stamp
CLEANFILES += \ CLEANFILES += \
$(calcxx_sources_generated) \ $(calcxx_sources_generated) \
%D%/parser.dot \ %D%/parser.gv \
%D%/parser.output \ %D%/parser.output \
%D%/parser.stamp \ %D%/parser.stamp \
%D%/scanner.cc %D%/scanner.cc
+23
View File
@@ -0,0 +1,23 @@
# This Makefile is designed to be simple and readable. It does not
# aim at portability. It requires GNU Make.
BASE = c++-types
BISON = bison
all: $(BASE)
%.c %.h %.html %.gv: %.y
$(BISON) $(BISONFLAGS) --header --html --graph -o $*.c $<
$(BASE): $(BASE).o
$(CC) $(CFLAGS) -o $@ $^
run: $(BASE)
@echo "Type C++ declarations or expressions. Quit with ctrl-d."
./$<
CLEANFILES = \
$(BASE) *.o $(BASE).[ch] $(BASE).output $(BASE).xml $(BASE).html $(BASE).gv
clean:
rm -f $(CLEANFILES)
+27
View File
@@ -0,0 +1,27 @@
# glr
This example demonstrates the use of GLR parsers to handle (local)
ambiguities in the C++ language. See the node "Merging GLR Parses" in
Bison's documentation.
It uses (Bison) variants to store objects as semantic values. It also
demonstrates custom error messages in C++.
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2020-2022, 2025-2026 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the "GNU Free
Documentation License" file as part of this distribution.
--->
+173
View File
@@ -0,0 +1,173 @@
/*
Copyright (C) 2020-2022, 2025-2026 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cstddef> // nullptr_t
#include <iostream>
#include <memory>
// Type erasure 101 <https://stackoverflow.com/a/26199467/1353549>.
class NodeInterface;
class Node
{
public:
Node (const Node& node) = default;
Node (Node&& node) = default;
Node () = default;
~Node () = default;
template <typename T,
// SFINAE block using this ctor as a copy/move ctor:
std::enable_if_t<!std::is_same<Node, std::decay_t<T>>::value, int>* = nullptr>
Node (T&& t);
Node& operator= (const Node& node) = default;
Node& operator= (Node&& node) = default;
explicit operator bool () const
{
return impl_ != nullptr;
}
std::ostream& print (std::ostream& o) const;
std::shared_ptr<NodeInterface> impl_;
};
static std::ostream&
operator<< (std::ostream& o, const Node &node)
{
return node.print (o);
}
class NodeInterface
{
public:
virtual ~NodeInterface () = default;
virtual std::ostream& print (std::ostream& o) const = 0;
};
std::ostream& Node::print (std::ostream& o) const
{
if (impl_)
impl_->print (o);
return o;
}
template <typename T,
std::enable_if_t<!std::is_same<std::nullptr_t, std::decay_t<T>>::value, int>* = nullptr>
struct NodeImpl : public NodeInterface
{
template <typename U>
explicit NodeImpl (U&& u)
: t{std::forward<U> (u)}
{}
virtual ~NodeImpl () = default;
virtual std::ostream& print (std::ostream& o) const
{
return o << t;
}
T t;
};
template <typename T,
std::enable_if_t<!std::is_same<Node, std::decay_t<T>>::value, int>*>
Node::Node (T&& t)
: impl_ (new NodeImpl<std::decay_t<T>>{std::forward<T> (t)})
{}
class Nterm
{
public:
Nterm (std::string form,
Node child0 = Node (), Node child1 = Node (), Node child2 = Node ())
: form_ (std::move (form))
{
children_[0] = child0;
children_[1] = child1;
children_[2] = child2;
}
friend std::ostream& operator<< (std::ostream& o, const Nterm& t)
{
o << t.form_;
if (t.children_[0])
{
o << '(' << t.children_[0];
if (t.children_[1])
o << ", " << t.children_[1];
if (t.children_[2])
o << ", " << t.children_[2];
o << ')';
}
return o;
}
private:
std::string form_;
Node children_[3];
};
class Term
{
public:
Term (std::string text)
: text_ (std::move (text))
{}
friend std::ostream& operator<< (std::ostream& o, const Term& t)
{
return o << t.text_;
}
private:
std::string text_;
};
#ifdef TEST
int main ()
{
Node n0;
std::cout << n0 << '\n';
Node n;
n = n0;
std::cout << n0 << '\n';
Term t1 = Term ("T");
std::cout << t1 << '\n';
n = t1;
std::cout << n << '\n';
std::cout << Nterm ("+", t1, t1) << '\n';
auto n1
= Nterm ("<OR>",
Nterm ("<declare>", Term ("T"), Term ("x")),
Nterm ("<cast>", Term ("x"), Term ("T")));
std::cout << n1 << '\n';
n = n1;
std::cout << n1 << '\n';
}
#endif
+50
View File
@@ -0,0 +1,50 @@
#! /bin/sh
# Copyright (C) 2020-2022, 2025-2026 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF
z + q;
T x;
T x = y;
x = y;
EOF
run 0 "\
1.0-5: +(z, q)
3.0-3: <declare>(T, x)
5.0-7: <init-declare>(T, x, y)
7.0-5: =(x, y)"
cat >input <<EOF
T (x) + y;
T (x);
T (y) = z + q;
T (y y) = z + q;
z + q;
EOF
run 0 "\
1.0-9: +(<cast>(x, T), y)
3.0-5: <OR>(<declare>(T, x), <cast>(x, T))
5.0-13: <OR>(<init-declare>(T, y, +(z, q)), =(<cast>(y, T), +(z, q)))
7.0-15: <error>
9.0-5: +(z, q)
err: 7.5: syntax error on token identifier (expected = or + or ))"
+257
View File
@@ -0,0 +1,257 @@
/* -*- C++ -*-
Copyright (C) 2020-2022, 2025-2026 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* Simplified C++ Type and Expression Grammar.
Written by Paul Hilfinger for Bison's test suite. */
%require "3.8"
%glr-parser
%skeleton "glr2.cc"
%define parse.assert
%define api.token.constructor
%header
%locations
%debug
// Custom error messages.
%define parse.error custom
%code requires
{
#include "ast.hh"
}
%define api.value.type variant
%code
{
#include <cassert>
#include <cctype>
#include <fstream>
#include <cstring>
// Merge two semantic values.
static Node
stmt_merge (const Node& x0, const Node& x1);
// Fetch a token.
static yy::parser::symbol_type
yylex ();
}
%expect-rr 1
%type <Node> TYPENAME ID stmt expr decl declarator
%printer { yyo << $$; } <Node>
%token
TYPENAME "typename"
ID "identifier"
SEMICOLON ";"
EQUAL "="
PLUS "+"
LPAREN "("
RPAREN ")"
%right "="
%left "+"
%%
prog : %empty
| prog stmt { std::cout << @2 << ": " << $2 << '\n'; }
;
stmt : expr ";" %merge <stmt_merge> { $$ = $1; }
| decl %merge <stmt_merge>
| error ";" { $$ = Nterm ("<error>"); }
;
expr : ID
| TYPENAME "(" expr ")" { $$ = Nterm ("<cast>", $3, $1); }
| expr "+" expr { $$ = Nterm ("+", $1, $3); }
| expr "=" expr { $$ = Nterm ("=", $1, $3); }
;
decl : TYPENAME declarator ";"
{ $$ = Nterm ("<declare>", $1, $2); }
| TYPENAME declarator "=" expr ";"
{ $$ = Nterm ("<init-declare>", $1, $2, $4); }
;
declarator
: ID
| "(" declarator ")" { $$ = $2; }
;
%%
std::istream* input = nullptr;
yy::parser::location_type loc;
/*---------.
| Parser. |
`---------*/
// Generate a custom error message.
void
yy::parser::report_syntax_error (const context& ctx) const
{
std::cerr << ctx.location () << ": syntax error";
if (!ctx.lookahead ().empty ())
std::cerr << " on token " << ctx.lookahead ().name ();
{
enum { TOKENMAX = 10 };
symbol_kind_type expected[TOKENMAX];
int n = ctx.expected_tokens (expected, TOKENMAX);
if (0 < n)
{
for (int i = 0; i < n; ++i)
std::cerr << (i == 0 ? " (expected " : " or ")
<< symbol_name (expected[i]);
std::cerr << ')';
}
}
std::cerr << '\n';
}
// Report the error to the user.
void
yy::parser::error (const location_type& l, const std::string& m)
{
std::cerr << l << ": " << m << '\n';
}
// Fetch the next token.
static yy::parser::symbol_type
yylex ()
{
while (true)
{
loc.step ();
loc += 1;
assert (!input->eof ());
switch (int c = input->get ())
{
case EOF:
return yy::parser::make_YYEOF (loc);
case '\t':
loc.end.column = (loc.end.column + 7) & ~7;
loc.step ();
break;
case ' ': case '\f':
loc.step ();
break;
case '\n':
loc.lines (1);
loc.end.column = 0;
loc.step ();
break;
case '+':
return yy::parser::make_PLUS (loc);
case '=':
return yy::parser::make_EQUAL (loc);
case '(':
return yy::parser::make_LPAREN (loc);
case ')':
return yy::parser::make_RPAREN (loc);
case ';':
return yy::parser::make_SEMICOLON (loc);
default:
if (isalpha (c))
{
std::string form;
do
{
form += static_cast<char> (c);
loc += 1;
c = input->get ();
}
while (isalnum (c) || c == '_');
input->unget ();
loc -= 1;
if (isupper (static_cast <unsigned char> (form[0])))
return yy::parser::make_TYPENAME (Term (form), loc);
else
return yy::parser::make_ID (Term (form), loc);
}
else
{
auto msg = "invalid character: " + std::string(1, static_cast<char> (c));
throw yy::parser::syntax_error (loc, msg);
}
}
}
}
// Merge two semantic values as an AST including both alternatives.
static Node
stmt_merge (const Node& x0, const Node& x1)
{
return Nterm ("<OR>", x0, x1);
}
/*-------.
| Main. |
`-------*/
// Parse `file` using parser `parse`.
int
process (yy::parser& parse, const std::string& file)
{
bool is_stdin = file == "-" || file.empty ();
if (is_stdin)
input = &std::cin;
else
input = new std::ifstream (file.c_str ());
loc.initialize (nullptr, 1, 0);
int status = parse ();
if (!is_stdin)
delete input;
return status;
}
int
main (int argc, char **argv)
{
yy::parser parse;
if (getenv ("YYDEBUG"))
parse.set_debug_level (1);
bool ran = false;
for (int i = 1; i < argc; ++i)
// Enable parse traces on option -p.
if (strcmp (argv[i], "-p") == 0)
parse.set_debug_level (1);
else
{
int status = process (parse, argv[i]);
ran = true;
if (!status)
return status;
}
if (!ran)
{
int status = process (parse, "");
if (!status)
return status;
}
return 0;
}
+52
View File
@@ -0,0 +1,52 @@
## Copyright (C) 2020-2022, 2025-2026 Free Software Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
glrxxdir = $(docdir)/%D%
## ----------- ##
## c++-types. ##
## ----------- ##
%D%/c++-types.stamp: $(dependencies)
$(nodist_%C%_c___types_SOURCES): %D%/c++-types.stamp
@test -f $@ || rm -f %D%/c++-types.stamp
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/c++-types.stamp
CLEANFILES += \
$(nodist_%C%_c___types_SOURCES) \
%D%/c++-types.stamp \
%D%/c++-types.output \
%D%/location.hh
CLEANDIRS += %D%/*.dSYM
## -------------------- ##
## Building & testing. ##
## -------------------- ##
# Avoid using BUILT_SOURCES which is too global.
$(%C%_c___types_OBJECTS): $(cxx_types_sources_generated)
if ENABLE_CXX14
check_PROGRAMS += %D%/c++-types
dist_%C%_c___types_SOURCES = \
%D%/ast.hh
nodist_%C%_c___types_SOURCES = \
%D%/c++-types.cc \
%D%/c++-types.hh
# Don't use gnulib's system headers.
%C%_c___types_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_c___types_CXXFLAGS = $(CXX14_CXXFLAGS) $(WARN_CXXFLAGS_TEST)
TESTS += %D%/c++-types.test
endif ENABLE_CXX14
EXTRA_DIST += %D%/c++-types.yy %D%/c++-types.test
+4 -3
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2018-2020 Free Software Foundation, Inc. ## Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
## ##
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
@@ -11,10 +11,11 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <https://www.gnu.org/licenses/>.
cxxdir = $(docdir)/%D% cxxdir = $(docdir)/%D%
include %D%/calc++/local.mk include %D%/calc++/local.mk
include %D%/glr/local.mk
## -------- ## ## -------- ##
## Simple. ## ## Simple. ##
@@ -29,7 +30,7 @@ simple_extracted = %D%/simple.yy
simple_sources = $(simple_extracted) simple_sources = $(simple_extracted)
extracted += $(simple_extracted) extracted += $(simple_extracted)
if ENABLE_CXX14 if ENABLE_CXX11
check_PROGRAMS += %D%/simple check_PROGRAMS += %D%/simple
nodist_%C%_simple_SOURCES = $(simple_sources) nodist_%C%_simple_SOURCES = $(simple_sources)
+2 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Copyright (C) 2018-2020 Free Software Foundation, Inc. # Copyright (C) 2018-2022, 2025-2026 Free Software Foundation, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
: >input : >input
run 0 "{I have numbers for you., 1, 2, 3, And that's all!}" 4 run 0 "{I have numbers for you., 1, 2, 3, And that's all!}" 4

Some files were not shown because too many files have changed in this diff Show More