Compare commits

..
483 Commits
Author SHA1 Message Date
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
294 changed files with 17108 additions and 5462 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 .*$"
+1 -1
View File
@@ -1 +1 @@
3.6.93
3.7.90
+82 -39
View File
@@ -44,12 +44,15 @@ jobs:
- git fetch --unshallow || true
- 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
- ./configure --enable-gcc-warnings || { cat config.log && false; }
- make -j2
- make -j2 dist-xz
# Can help understanding why we get "dirty" tarballs.
- git status
- git diff
- dist=$(echo bison*.xz)
# Unfortunately we cannot deterministically know the name of the tarball without the full
@@ -70,55 +73,57 @@ jobs:
# Start with three completely different environments, to get errors asap.
- name: "GCC 10 -O3"
- name: "GCC 11 -O3"
stage: check
os: linux
dist: bionic
addons: &gcc10
addons: &gcc11
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-10
packages: g++-11
env:
- CC=gcc-10
- CXX=g++-10
- 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 10 libc++ and ASAN part 1"
- name: "Clang 11 libc++ and ASAN part 1"
stage: check
os: linux
dist: bionic
addons: &clang10
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-10 main'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-10
- libc++-10-dev
- libc++abi-10-dev
- 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-10 -fsanitize=address'
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
- CC='clang-11 -fsanitize=address'
- CXX='clang++-11 -fsanitize=address -stdlib=libc++'
- PART=1
- name: "Clang 10 libc++ and ASAN part 2"
- name: "Clang 11 libc++ and ASAN part 2"
stage: check
os: linux
dist: bionic
addons: *clang10
addons: *clang11
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-10 -fsanitize=address'
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
- 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
@@ -127,7 +132,7 @@ jobs:
- CC=icc
- CXX=icpc
install:
- source /opt/intel/inteloneapi/compiler/latest/env/vars.sh
- source /opt/intel/oneapi/compiler/latest/env/vars.sh
addons:
apt:
sources:
@@ -136,19 +141,19 @@ jobs:
packages:
- intel-oneapi-icc
- name: "ARM64: GCC 10 -O2 part 1"
- name: "ARM64: GCC 11 -O2 part 1"
stage: check
os: linux
arch: arm64
dist: bionic
addons: *gcc10
addons: *gcc11
env:
- CC=gcc-10
- CXX=g++-10
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "PPC64le: GCC 10 -O2 part 1"
- name: "PPC64le: GCC 11 -O2 part 1"
stage: check
os: linux
arch: ppc64le
@@ -158,22 +163,22 @@ jobs:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-10
packages: g++-11
env:
- CC=gcc-10
- CXX=g++-10
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
- name: "s390x: GCC 10 -O2 part 1"
- name: "s390x: GCC 11 -O2 part 1"
stage: check
os: linux
arch: s390x
dist: bionic
addons: *gcc10
addons: *gcc11
env:
- CC=gcc-10
- CXX=g++-10
- CC=gcc-11
- CXX=g++-11
- CONFIGUREFLAGS='CFLAGS=-O2 CXXFLAGS=-O2'
- PART=1
@@ -181,7 +186,24 @@ jobs:
## GCC. ##
## ----- ##
- name: "GCC 9 with sanitizers part 1"
- 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
os: linux
dist: bionic
@@ -192,12 +214,12 @@ jobs:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-9
env:
- CC='gcc-9 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CXX='g++-9 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CONFIGUREFLAGS='CFLAGS=-O1 CXXFLAGS=-O1'
- CC=gcc-9
- CXX=g++-9
- PART=1
- name: "GCC 8"
# With glr2.cc, we run out of time with the full test suite.
- name: "GCC 8 part 1"
stage: check
os: linux
dist: bionic
@@ -207,6 +229,7 @@ jobs:
env:
- CC=gcc-8
- CXX=g++-8
- PART=1
- name: "GCC 7"
stage: check
@@ -295,7 +318,28 @@ jobs:
## Clang. ##
## ------- ##
- name: "Clang 9 -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
@@ -313,9 +357,8 @@ jobs:
env:
- CC='clang-9'
- CXX='clang++-9 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- name: "Clang 8"
- name: "Clang 8 and libc++"
stage: check
os: linux
dist: bionic
@@ -329,7 +372,7 @@ jobs:
- CC=clang-8
- CXX='clang++-8 -stdlib=libc++'
- name: "Clang 7"
- name: "Clang 7 and libc++"
stage: check
os: linux
dist: bionic
+2 -2
View File
@@ -24,7 +24,7 @@ and nasty bugs.
-----
Copyright (C) 1998-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 1998-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -39,4 +39,4 @@ 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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
+4 -4
View File
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
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
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.
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.
@@ -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,
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
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
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
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>.
+209 -210
View File
File diff suppressed because it is too large Load Diff
+11 -3
View File
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in.
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2001-2015, 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = -I m4
@@ -76,6 +76,13 @@ include tests/local.mk
clean-local:
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
# 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
@@ -133,9 +140,10 @@ gen-ChangeLog:
$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -o $@ -E $<
.PHONY: codespell
CODESPELL = codespell
codespell:
$(AM_V_GEN) cd $(srcdir) \
&& codespell \
&& $(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)
+254 -8
View File
@@ -1,5 +1,248 @@
GNU Bison NEWS
* Noteworthy changes in release 3.7.91 (2021-09-02) [beta]
Portability issues in the test suite and in C++ skeletons.
* Noteworthy changes in release 3.7.90 (2021-08-13) [beta]
** Backward incompatible changes
In conformance with the recommendations of the Graphviz team
(https://marc.info/?l=graphviz-devel&m=129418103126092), `-g`/`--graph`
now generates a *.gv file by default, instead of *.dot. A transition
started in Bison 3.4.
To comply with the latest POSIX standard, in Yacc compatibility mode
(options `-y`/`--yacc`) Bison now generates prototypes for yyerror and
yylex. In some situations, this is breaking compatibility: if the user
has already declared these functions but with some differences (e.g., to
declare them as static, or to use specific attributes), the generated
parser will fail to compile. To disable these prototypes, #define yyerror
(to `yyerror`), and likewise for yylex.
** Deprecated features
Support for the YYPRINT macro is removed. It worked only with yacc.c and
only for tokens. It was obsoleted by %printer, introduced in Bison 1.50
(November 2002).
It has always been recommended to prefer `%define api.value.type foo` to
`#define YYSTYPE foo`. The latter is supported in C for compatibility
with Yacc, but not in C++. Warnings are now issued if `#define YYSTYPE`
is used in C++, and eventually support will be removed.
In C++ code, prefer value_type to semantic_type to denote the semantic
value type, which is specified by the `api.value.type` %define variable.
** New features
*** A skeleton for the D programming language
The "lalr1.d" skeleton is now officially part of Bison.
It was originally contributed by Oliver Mangold, based on Paolo Bonzini's
lalr1.java, and was improved by H. S. Teoh. Adela Vais then took over
maintenance and invested a lot of efforts to complete, test and document
it.
It now supports all the bells and whistles of the other deterministic
parsers, which include: pull/push interfaces, verbose and custom error
messages, lookahead correction, token constructors, internationalization,
locations, printers, token and symbol prefixes, etc.
Two examples demonstrate the D parsers: a basic one (examples/d/simple),
and an advanced one (examples/d/calc).
*** Option -H, --header and directive %header
The option `-H`/`--header` supersedes the option `--defines`, and the
directive %header supersedes %defines. Both `--defines` and `%defines`
are, of course, maintained for backward compatibility.
*** Option --html
Since version 2.4 Bison can be used to generate HTML reports. However it
was a two-step process: first bison must be invoked with option `--xml`,
and then xsltproc must be run to the convert the XML reports into HTML.
The new option `--html` combines these steps. The xsltproc program must
be available.
*** A C++ native GLR parser
A new version of the C++ GLR parser was added: "glr2.cc". It generates
"true C++11", instead of a C++ wrapper around a C parser as does the
existing "glr.cc" parser. As a first significant consequence, it supports
`%define api.value.type variant`, contrary to glr.cc.
It should be upward compatible in terms of interface, feature and
performance to "glr.cc". To try it out, simply use
%skeleton "glr2.cc"
It will eventually replace "glr.cc". However we need user feedback on
this skeleton. _Please_ report your results and comments about it.
*** Counterexamples
Counterexamples now show the rule numbers, and always show ε for rules
with an empty right-hand side. For instance
exp
↳ 1: e1 e2 "a"
↳ 3: ε • ↳ 1: ε
instead of
exp
↳ e1 e2 "a"
↳ • ↳ ε
*** Lookahead correction in Java
The Java skeleton (lalr1.java) now supports LAC, via the `parse.lac`
%define variable.
*** Abort parsing for memory exhaustion (C)
User actions may now use `YYNOMEM` (similar to `YYACCEPT` and `YYABORT`)
to abort the current parse with memory exhaustion.
*** Printing locations in debug traces (C)
The `YYLOCATION_PRINT(File, Loc)` macro prints a location. It is defined
when (i) locations are enabled, (ii) the default type for locations is
used, (iii) debug traces are enabled, and (iv) `YYLOCATION_PRINT` is not
already defined.
Users may define `YYLOCATION_PRINT` to cover other cases.
*** GLR traces
There were no debug traces for deferred calls to user actions. They are
logged now.
* Noteworthy changes in release 3.7.6 (2021-03-08) [stable]
** Bug fixes
*** Reused Push Parsers
When a push-parser state structure is used for multiple parses, it was
possible for some state to leak from one run into the following one.
*** Fix Table Generation
In some very rare conditions, when there are many useless tokens, it was
possible to generate incorrect parsers.
* Noteworthy changes in release 3.7.5 (2021-01-24) [stable]
** Bug fixes
*** Counterexample Generation
In some cases counterexample generation could crash. This is fixed.
*** Fix Table Generation
In some very rare conditions, when there are many useless tokens, it was
possible to generate incorrect parsers.
*** GLR parsers now support %merge together with api.value.type=union.
*** C++ parsers use noexcept in more places.
*** Generated parsers avoid some warnings about signedness issues.
*** C-language parsers now avoid warnings from pedantic clang.
*** C-language parsers now work around quirks of HP-UX 11.23 (2003).
* Noteworthy changes in release 3.7.4 (2020-11-14) [stable]
** Bug fixes
*** Bug fixes in yacc.c
In Yacc mode, all the tokens are defined twice: once as an enum, and then
as a macro. YYEMPTY was missing its macro.
*** Bug fixes in lalr1.cc
The lalr1.cc skeleton used to emit internal assertions (using YY_ASSERT)
even when the `parse.assert` %define variable is not enabled. It no
longer does.
The private internal macro YY_ASSERT now obeys the `api.prefix` %define
variable.
When there is a very large number of tokens, some assertions could be long
enough to hit arbitrary limits in Visual C++. They have been rewritten to
work around this limitation.
** Changes
The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
skeleton) used to be defined to 1. It is now defined to the version of
Bison as an integer (e.g., 30704 for version 3.7.4).
* Noteworthy changes in release 3.7.3 (2020-10-13) [stable]
** Bug fixes
Fix concurrent build issues.
The bison executable is no longer linked uselessly against libreadline.
Fix incorrect use of yytname in glr.cc.
* Noteworthy changes in release 3.7.2 (2020-09-05) [stable]
This release of Bison fixes all known bugs reported for Bison in MITRE's
Common Vulnerabilities and Exposures (CVE) system. These vulnerabilities
are only about bison-the-program itself, not the generated code.
Although these bugs are typically irrelevant to how Bison is used, they
are worth fixing if only to give users peace of mind.
There is no known vulnerability in the generated parsers.
** Bug fixes
Fix concurrent build issues (introduced in Bison 3.5).
Push parsers always use YYMALLOC/YYFREE (no direct calls to malloc/free).
Fix portability issues of the test suite, and of bison itself.
Some unlikely crashes found by fuzzing have been fixed. This is only
about bison itself, not the generated parsers.
* Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
** Bug fixes
Crash when a token alias contains a NUL byte.
Portability issues with libtextstyle.
Portability issues of Bison itself with MSVC.
** Changes
Improvements and fixes in the documentation.
More precise location about symbol type redefinitions.
* Noteworthy changes in release 3.7 (2020-07-23) [stable]
** Deprecated features
@@ -179,7 +422,7 @@ GNU Bison NEWS
parse errors, since `yynerrs` was also reset. This can be especially
troublesome when used in autocompletion, since a parser with error
recovery would suggest (irrelevant) expected tokens even if there were
failure.
failures.
Now the parser state can be examined when parsing is finished. The parser
state is reset when starting a new parse.
@@ -537,7 +780,8 @@ GNU Bison NEWS
\005) with incorrect styling. Fixes for similar issues with unexpectedly
short lines (e.g., the file was changed between parsing and diagnosing).
Several unlikely crashes found by fuzzing have been fixed.
Some unlikely crashes found by fuzzing have been fixed. This is only
about bison itself, not the generated parsers.
* Noteworthy changes in release 3.5.2 (2020-02-13) [stable]
@@ -659,7 +903,7 @@ GNU Bison NEWS
Also, because string aliases need not be defined, typos such as "baz"
instead of "bar" will be not reported.
The option -Wdangling-alias catches these situations. On
The option `-Wdangling-alias` catches these situations. On
%token BAR "bar"
%type <ival> foo "foo"
@@ -675,7 +919,7 @@ GNU Bison NEWS
| foo: "baz" {}
| ^~~~~
The -Wall option does not (yet?) include -Wdangling-alias.
The `-Wall` option does not (yet?) include `-Wdangling-alias`.
*** Better POSIX Yacc compatibility diagnostics
@@ -3297,7 +3541,7 @@ GNU Bison NEWS
inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is
used. For a more detailed discussion, see:
http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html
https://lists.gnu.org/r/bison-patches/2009-12/msg00024.html
The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
deterministic parsers in C will continue to implement it. However,
@@ -4053,7 +4297,7 @@ GNU Bison NEWS
error token. The new behavior has long been the documented behavior,
and has long been required by POSIX. For more details, please see
Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
<http://lists.gnu.org/archive/html/bug-bison/2002-05/msg00038.html>.
<https://lists.gnu.org/r/bug-bison/2002-05/msg00038.html>.
** Traces
Popped tokens and nonterminals are now reported.
@@ -4451,7 +4695,7 @@ LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak
LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues
LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw
LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num
LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE
LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE CVE
LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
LocalWords: noexcept constexpr ispell american deprecations backend Teoh
@@ -4462,6 +4706,8 @@ LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
LocalWords: autocompletion bistromathic submessages Cayuela lexcalc hoc
LocalWords: yytoken YYUNDEF YYerror basename Automake's UTF ifdef ffile
LocalWords: gotos readline Imbimbo Wcounterexamples Wcex Nonunifying rcex
LocalWords: Vais xsltproc YYNOMEM YYLOCATION signedness YYBISON MITRE's
LocalWords: libreadline YYMALLOC YYFREE MSVC redefinitions
Local Variables:
ispell-dictionary: "american"
@@ -4469,7 +4715,7 @@ mode: outline
fill-column: 76
End:
Copyright (C) 1995-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 1995-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Parser Generator.
+2 -2
View File
@@ -36,7 +36,7 @@ to the bison package.
-----
Copyright (C) 2002, 2005, 2009-2015, 2018-2020 Free Software Foundation,
Copyright (C) 2002, 2005, 2009-2015, 2018-2021 Free Software Foundation,
Inc.
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.
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/>.
+16 -7
View File
@@ -7,7 +7,7 @@ simple desk calculators to complex programming languages.
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
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.
Bison and the parsers it generates are portable, they do not require any
@@ -27,7 +27,7 @@ Bison from the git repo. Roughly, run:
then proceed with the usual `configure && make` steps.
## Build from tarball
See the [INSTALL file](INSTALL] for generic compilation and installation
See the [INSTALL file](INSTALL) for generic compilation and installation
instructions.
Bison requires GNU m4 1.4.6 or later. See
@@ -42,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
`--color` and `--style` options.
To use them, install the libtextstyle library before configuring Bison. It
is available from https://alpha.gnu.org/gnu/gettext/, for instance
https://alpha.gnu.org/pub/gnu/gettext/libtextstyle-0.20.5.tar.gz.
To use them, install the libtextstyle library, 0.20.5 or newer, before
configuring Bison. It is available from https://alpha.gnu.org/gnu/gettext/,
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:
- always, yes: Enable colors.
@@ -61,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`
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
If you pass `--enable-relocatable` to `configure`, Bison is relocatable.
@@ -78,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
system, neither are installed if ngettext is not supported, even if
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.
# Questions
@@ -111,7 +120,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2020 Free
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018-2021 Free
Software Foundation, Inc.
This file is part of GNU bison, the GNU Compiler Compiler.
+2 -2
View File
@@ -12,7 +12,7 @@ the problems you encounter.
-----
Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation,
Copyright (C) 2002, 2004, 2009-2015, 2018-2021 Free Software Foundation,
Inc.
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.
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/>.
+123 -54
View File
@@ -2,7 +2,7 @@ This file attempts to describe the rules to use when hacking Bison.
Don't put this file into the distribution.
Everything related to the development of Bison is on Savannah:
http://savannah.gnu.org/projects/bison/.
https://savannah.gnu.org/projects/bison/.
Working from the Repository
@@ -19,21 +19,21 @@ 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
tools we depend upon, including:
- Autoconf <http://www.gnu.org/software/autoconf/>
- Automake <http://www.gnu.org/software/automake/>
- Flex <http://www.gnu.org/software/flex/>
- Gettext <http://www.gnu.org/software/gettext/>
- Gperf <http://www.gnu.org/software/gperf/>
- Graphviz <http://www.graphviz.org>
- Gzip <http://www.gnu.org/software/gzip/>
- Help2man <http://www.gnu.org/software/help2man/>
- Perl <http://www.cpan.org/>
- Rsync <http://samba.anu.edu.au/rsync/>
- Tar <http://www.gnu.org/software/tar/>
- Texinfo <http://www.gnu.org/software/texinfo/>
- Autoconf <https://www.gnu.org/software/autoconf/>
- Automake <https://www.gnu.org/software/automake/>
- Flex <https://www.gnu.org/software/flex/>
- Gettext <https://www.gnu.org/software/gettext/>
- Gperf <https://www.gnu.org/software/gperf/>
- Graphviz <https://www.graphviz.org>
- Gzip <https://www.gnu.org/software/gzip/>
- Help2man <https://www.gnu.org/software/help2man/>
- Perl <https://www.cpan.org/>
- Rsync <https://rsync.samba.org/>
- 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
your architecture.
Valgrind <https://www.valgrind.org/> is also highly recommended, if it
supports your architecture.
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
@@ -57,7 +57,7 @@ might be needed.
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
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
particular it uses gnulib, the GNU portability library. To ask Git to
@@ -139,7 +139,7 @@ Register your changes.
For a suggestion of what gnulib commit might be stable enough for a formal
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:
- m4/m4.m4
@@ -246,7 +246,7 @@ 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 ">="
(http://www.gelato.unsw.edu.au/archives/git/0505/4507.html).
<https://public-inbox.org/git/7vfyw7yebj.fsf_-_@assigned-by-dhcp.cox.net/>.
### Bison
Follow the GNU Coding Standards.
@@ -325,7 +325,7 @@ about the C standard introducing such a name.
#### C++
Follow the [C++ Core
Guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
The [Google ones](https://google.github.io/styleguide/cppguide.html) may be
interesting too.
@@ -346,12 +346,14 @@ 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.
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".
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.
@@ -386,6 +388,11 @@ In examples/, there is a number of ready-to-use examples (see
suites run by `make check`. The test results are in local `*.log` files
(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, in tests/, is written on top of GNU Autotest, which is
part of Autoconf. Run `info autoconf 'Using Autotest'` to read the
@@ -399,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.
#### 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
be very time consuming when checking repeatedly or on slower setups. This
can be sped up in two ways:
The default is for `make check-tests` to run all tests sequentially. This
can be very time consuming when checking repeatedly or on slower setups.
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
it, so you may simply run
When using GNU Make, TESTSUITEFLAGS defaults to the -jN passed to it, so you
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
with AT_KEYWORDS([[category]]). Categories include:
- c++, for c++ parsers
- deprec, for tests concerning deprecated constructs.
- glr, for glr parsers
- java, for java parsers
- report, for automaton dumps
2. Running only the tests of a certain category. See
[tests/README.md](tests/README.md#keywords) for the list of categories.
To get a list of all the tests (and their keywords for -k), run
@@ -428,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:
$ make check-local TESTSUITEFLAGS='-k c++'
$ make check-tests TESTSUITEFLAGS='-k c++'
Both can be combined.
$ make check-local TESTSUITEFLAGS='-j8 -k c++'
$ make check-tests TESTSUITEFLAGS='-j8 -k c++'
To rerun the tests that failed:
@@ -462,28 +464,55 @@ Use the `javaexec.sh` script. For instance to run the parser of test case
## Using Sanitizers
Address sanitizer (ASAN) and undefined-behavior sanitizer (UBSAN) are very
useful. Here's one way to set ASAN up with GCC 10 on Mac Ports
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' \
CFLAGS='-ggdb' \
CXX='g++-mp-10.0 -fsanitize=address' \
CXXFLAGS='-ggdb' \
LDFLAGS='-L/opt/local/lib'
```
$ ./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
```
$ 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
```
$ make check-local 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
This target uses valgrind both to check bison, and the generated parsers.
@@ -512,7 +541,7 @@ release:
- Maybe build with -DGNULIB_POSIXCHECK, which suggests gnulib modules that
can fix portability issues. See if you really want to pay attention to
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.
@@ -560,6 +589,46 @@ re-run the tests, run:
make check
## Docker
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:
```
docker run -v /tmp:/tmp -it ubuntu:xenial
```
This way, the host and guest machines share `/tmp`.
### GCC 4.6
On Ubuntu Xenial.
```
apt-get update
apt-get install software-properties-common
apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
apt-get update
apt-get install -y gcc-4.6 g++-4.6 m4 make
```
## Stow
If you want to install several versions of Bison using GNU Stow, do
something like this:
```
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
```
Release Procedure
=================
@@ -569,7 +638,7 @@ bootstrapped.
<!--
Copyright (C) 2002-2005, 2007-2015, 2018-2020 Free Software Foundation,
Copyright (C) 2002-2005, 2007-2015, 2018-2021 Free Software Foundation,
Inc.
This file is part of GNU Bison.
@@ -585,7 +654,7 @@ 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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Local Variables:
mode: markdown
+6 -2
View File
@@ -34,6 +34,7 @@ Bob Rossi [email protected]
Brandon Lucia [email protected]
Brooks Moses [email protected]
Bruce Lilly [email protected]
Bruno Belanyi [email protected]
Bruno Haible [email protected]
Charles-Henri de Boysson [email protected]
Christian Burger [email protected]
@@ -106,9 +107,11 @@ Keith Browne [email protected]
Ken Moffat [email protected]
Kiyoshi Kanazawa [email protected]
Lars Maier [email protected]
Lars Wendler [email protected]
László Várady [email protected]
Laurent Mascherpa [email protected]
Lie Yan [email protected]
Maarten De Braekeleer [email protected]
Magnus Fromreide [email protected]
Marc Autret [email protected]
Marc Mendiola [email protected]
@@ -185,6 +188,7 @@ Simon Sobisch [email protected]
Stefano Lattarini [email protected]
Stephen Cameron [email protected]
Steve Murphy [email protected]
Suhwan Song [email protected]
Sum Wu [email protected]
Théophile Ranquet [email protected]
Thiru Ramakrishnan [email protected]
@@ -234,7 +238,7 @@ End:
-----
Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2000-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Parser Generator.
@@ -249,4 +253,4 @@ 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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
+170 -47
View File
@@ -1,4 +1,42 @@
* Bison 3.7
* Soon
** 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):
@@ -48,13 +86,6 @@ Unless we play it dumb (little structure).
- promote YYEOF rather than EOF.
*** D
- is there a way to attach yysymbol_name to the enum itself? As we did
in Java.
- It would be better to have TokenKind as return value. Can we use
reflection to support both output types?
** YYerror
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
@@ -65,10 +96,6 @@ enough.
*** calc.at
Stop hard-coding "Calc". Adjust local.at (look for FIXME).
** A dev warning for b4_
Maybe we should check for m4_ and b4_ leaking out of the m4 processing, as
Autoconf does. It would have caught overquotation issues.
** doc
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
@@ -88,7 +115,7 @@ push parsers on top of pull parser. Which is currently not relevant, since
push parsers are measurably slower.
** %define parse.error formatted
How about pushing bistromathics' yyreport_syntax_error as another standard
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:
@@ -156,10 +183,48 @@ Les catégories d'avertissements incluent :
Line -1 and -3 should mention CATEGORIE, not CATEGORY.
* Bison 3.8
** Rewrite glr.cc
Get rid of scaffolding in glr.c.
* 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)
Maybe we could expand unit rules (or "injections", see
https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
@@ -202,18 +267,54 @@ 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
"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.
*** complain.*
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.
*** ritem
states/nstates, rules/nrules, ..., ritem/nritems
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
@@ -231,9 +332,8 @@ and older C++ compilers. Currently the code defaults to defining it to
define it to the same type as the C ptrdiff_t type.
* Completion
Several features are not available in all the backends.
Several features are not available in all the back-ends.
- lac: D, Java (easy)
- push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
- token constructors: Java, C, D (a bit difficult)
- glr: D, Java (super difficult)
@@ -248,9 +348,6 @@ $ ./tests/testsuite -l | grep errors | sed q
38: input.at:1730 errors
* Short term
** Get rid of YYPRINT and b4_toknum
Besides yytoknum is wrong when api.token.raw is defined.
** Better design for diagnostics
The current implementation of diagnostics is ad hoc, it grew organically.
It works as a series of calls to several functions, with dependency of the
@@ -301,7 +398,7 @@ opposite side we have some use of \l, which is graphviz-specific, in what
should be generic code.
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.
Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
@@ -368,23 +465,6 @@ It would be a very nice source of inspiration for the other languages.
Valentin Tolmer is working on this.
** 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
** Single stack
Merging the three stacks in lalr1.cc simplified the code, prompted for
@@ -437,6 +517,9 @@ https://github.com/scfc/bison-php/blob/master/data/lalr1.php
https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
** Multiple start symbols
Revert a70e75b8a41755ab96ab211a0ea111ac68a4aadd.
Revert tests: disable "Multistart reports".
Would be very useful when parsing closely related languages. The idea is to
declare several start symbols, for instance
@@ -458,12 +541,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
corresponding parse function.
*** Number of useless symbols
AT_TEST(
[[%start exp;
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]])
We should say "1 nonterminal": the other one is $accept, which should not
participate in the count.
*** 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
This is a popular demand. We already made many changes in the parser that
should make this reasonably easy to implement.
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,
because I don't want a % equivalent to #include (which we all learned to
@@ -472,11 +570,11 @@ them together, paying attention to keep separate bits separated, in pseudo
name spaces.
** 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
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
We should find a means to provide an access to values deep in the
@@ -579,15 +677,40 @@ to bison. If you're interested, I'll work on a patch.
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:
mode: outline
coding: utf-8
fill-column: 76
ispell-dictionary: "american"
End:
-----
Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2020 Free Software
Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2021 Free Software
Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+37 -8
View File
@@ -1,10 +1,10 @@
#! /bin/sh
# Print a version string.
scriptversion=2020-04-13.15; # UTC
scriptversion=2021-04-11.09; # UTC
# Bootstrap this package from checked-out sources.
# Copyright (C) 2003-2020 Free Software Foundation, Inc.
# Copyright (C) 2003-2021 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
@@ -47,7 +47,7 @@ PERL="${PERL-perl}"
me=$0
default_gnulib_url=git://git.sv.gnu.org/gnulib
default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git
usage() {
cat <<EOF
@@ -71,7 +71,9 @@ Options:
--no-git do not use git to update gnulib. Requires that
--gnulib-srcdir point to a correct gnulib snapshot
--skip-po do not download po files
EOF
bootstrap_print_option_usage_hook
cat <<EOF
If the file $me.conf exists in the same directory as this script, its
contents are read as shell variables to configure the bootstrap.
@@ -113,6 +115,12 @@ Running without arguments will suffice in most cases.
EOF
}
copyright_year=`echo "$scriptversion" | sed -e 's/[^0-9].*//'`
copyright="Copyright (C) ${copyright_year} Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law."
# warnf_ FORMAT-STRING ARG1...
warnf_ ()
{
@@ -154,6 +162,18 @@ gnulib_files=
: ${AUTOPOINT=autopoint}
: ${AUTORECONF=autoreconf}
# A function to be called for each unrecognized option. Returns 0 if
# the option in $1 has been processed by the function. Returns 1 if
# the option has not been processed by the function. Override it via
# your own definition in bootstrap.conf
bootstrap_option_hook() { return 1; }
# A function to be called in order to print the --help information
# corresponding to user-defined command-line options.
bootstrap_print_option_usage_hook() { :; }
# A function to be called right after gnulib-tool is run.
# Override it via your own definition in bootstrap.conf.
bootstrap_post_import_hook() { :; }
@@ -170,7 +190,7 @@ po_download_command_format=\
https://translationproject.org/latest/%s/"
# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
# fall back to the package name (1st argument with munging)
# fall back to the package name (1st argument with munging).
extract_package_name='
/^AC_INIT(\[*/{
s///
@@ -187,8 +207,11 @@ extract_package_name='
p
}
'
package=$(sed -n "$extract_package_name" configure.ac) \
|| die 'cannot find package name in configure.ac'
package=$(${AUTOCONF:-autoconf} --trace AC_INIT:\$4 configure.ac 2>/dev/null)
if test -z "$package"; then
package=$(sed -n "$extract_package_name" configure.ac) \
|| die 'cannot find package name in configure.ac'
fi
gnulib_name=lib$package
build_aux=build-aux
@@ -320,6 +343,12 @@ do
--help)
usage
exit;;
--version)
set -e
echo "bootstrap $scriptversion"
echo "$copyright"
exit 0
;;
--gnulib-srcdir=*)
GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
--skip-po)
@@ -335,7 +364,7 @@ do
--no-git)
use_git=false;;
*)
die "$option: unknown option";;
bootstrap_option_hook $option || die "$option: unknown option";;
esac
done
+7 -4
View File
@@ -1,6 +1,6 @@
# Bootstrap configuration.
# Copyright (C) 2006-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2006-2015, 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# gnulib modules used by this package.
gnulib_modules='
@@ -22,11 +22,12 @@ gnulib_modules='
calloc-posix close closeout config-h c-strcase
configmake
dirname
error extensions
error execute extensions
fdl fopen-safer fstrcmp
getopt-gnu
gettext-h git-version-gen gitlog-to-changelog
gpl-3.0 intprops inttypes isnan javacomp-script
hash-map
javaexec-script
ldexpl
libtextstyle-optional
@@ -45,6 +46,8 @@ gnulib_modules='
relocatable-prog relocatable-script
rename
spawn-pipe stdbool stpcpy stpncpy strdup-posix strerror strverscmp
sys_ioctl
termios
timevar
unicodeio unistd unistd-safer unlink unlocked-io
update-copyright unsetenv verify
@@ -56,7 +59,7 @@ gnulib_modules='
xconcat-filename
xhash
xlist
xmemdup0
xmap xmemdup0
xstrndup
fprintf-posix printf-posix snprintf-posix sprintf-posix
+5 -5
View File
@@ -1,6 +1,7 @@
/announce-gen
/compile
/config.guess
/config.libpath
/config.rpath
/config.rpath~
/config.sub
@@ -11,20 +12,19 @@
/gitlog-to-changelog
/gnu-web-doc-update
/gnupload
/install-reloc
/install-sh
/javacomp.sh.in
/javaexec.sh.in
/libtool-reloc
/mdate-sh
/missing
/prefix-gnulib-mk
/reloc-ldflags
/relocatable.sh.in
/test-driver
/texinfo.tex
/update-copyright
/useless-if-before-free
/vc-list-files
/ylwrap
/config.libpath
/install-reloc
/reloc-ldflags
/relocatable.sh.in
/libtool-reloc
+2 -2
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2012-2015, 2018-2021 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
@@ -11,7 +11,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Valgrind suppression file for Bison.
+2 -2
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2012-2015, 2018-2021 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
@@ -11,7 +11,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Valgrind suppression file for Bison.
+1 -1
View File
@@ -2,7 +2,7 @@
# Generate a release announcement message.
# Copyright (C) 2007-2020 Free Software Foundation, Inc.
# Copyright (C) 2007-2021 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
+2 -2
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc.
## Copyright (C) 2000-2015, 2018-2021 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
@@ -11,7 +11,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
EXTRA_DIST += \
build-aux/Darwin.valgrind \
+2 -2
View File
@@ -3,7 +3,7 @@
# Update b4_copyright invocations or b4_copyright_years definitions to
# include the current year.
# Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2009-2015, 2018-2021 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
@@ -16,7 +16,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use warnings;
+2 -2
View File
@@ -2,7 +2,7 @@
# 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-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use warnings;
+1 -1
View File
@@ -2,7 +2,7 @@
# Update expectations in an Autotest test suite.
# Copyright (C) 2019-2020 Free Software Foundation, Inc.
# Copyright (C) 2019-2021 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
+5 -3
View File
@@ -1,5 +1,5 @@
## Customize maint.mk -*- makefile -*-
## Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
## Copyright (C) 2008-2015, 2018-2021 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
@@ -12,7 +12,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
# Update version, then recompile so that tests/bison --version be
# up-to-date, then compile our parser again with our up-to-date bison.
@@ -126,7 +126,7 @@ _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
_space_before_paren_exempt =? \\n\\$$
_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.
sc_space_before_open_paren:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
@@ -156,6 +156,8 @@ exclude = \
$(call exclude, \
bindtextdomain=^lib/main.c$$ \
cast_of_argument_to_free=^src/muscle-tab.c$$ \
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]$$ \
program_name=^lib/main.c$$ \
+12 -13
View File
@@ -1,6 +1,6 @@
# Configure template for GNU Bison. -*-Autoconf-*-
#
# Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2001-2015, 2018-2021 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
@@ -13,14 +13,9 @@
# 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/>.
# 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
# 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])
AC_PREREQ([2.71])
m4_pattern_forbid([^_?(gl_[A-Z]|AX_|BISON_)])
m4_pattern_allow([^BISON_USE_NLS$])
@@ -29,7 +24,7 @@ AC_INIT([GNU Bison],
[[email protected]],
[],
[https://www.gnu.org/software/bison/])
AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2020])
AC_SUBST([PACKAGE_COPYRIGHT_YEAR], [2021])
AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR],
[The copyright year for this package])
@@ -54,12 +49,15 @@ AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([lib/config.h:lib/config.in.h])
# Checks for the compiler.
AC_PROG_CC_STDC
AC_PROG_CC
AC_PROG_CXX
# Gnulib (early checks).
gl_EARLY
# We want ostream_printf and hyperlink support.
gl_LIBTEXTSTYLE_OPTIONAL([0.20.5])
# Gnulib uses '#pragma GCC diagnostic push' to silence some
# warnings, but older gcc doesn't support this.
AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
@@ -81,7 +79,8 @@ BISON_CXXSTD([03])
BISON_CXXSTD([11])
BISON_CXXSTD([14])
BISON_CXXSTD([17])
BISON_CXXSTD([2a])
BISON_CXXSTD([20])
BISON_CXXSTD([2b])
AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x])
AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x])
AC_LANG_POP([C++])
@@ -130,7 +129,7 @@ if test "$enable_gcc_warnings" = yes; then
warn_common='-Wall -Wextra
-Wcast-align -Wchar-subscripts
-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
-Wpointer-arith -Wshadow -Wstrict-aliasing
-Wwrite-strings
@@ -248,7 +247,7 @@ AM_CONDITIONAL([ENABLE_JAVA], [test x"$CONF_JAVAC" != x && test x"$CONF_JAVA" !=
AC_ARG_ENABLE([yacc],
[AC_HELP_STRING([--disable-yacc],
[AS_HELP_STRING([--disable-yacc],
[do not build a yacc command or an -ly library])],
, [enable_yacc=yes])
AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes])
+25 -5
View File
@@ -73,15 +73,29 @@ 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
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
### `b4_symbol(NUM, FIELD)`
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,
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.
FIELD can be:
- `has_id`: 0 or 1
Whether the symbol has an `id`.
@@ -142,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.
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,
its type.
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
- `printer`: string
- `printer_file`: string
@@ -187,7 +207,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2002, 2008-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2002, 2008-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of GNU Bison.
@@ -202,6 +222,6 @@ 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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
+1 -1
View File
@@ -1,5 +1,5 @@
/* Default styling rules for Bison when doing terminal output.
Copyright (C) 2019-2020 Free Software Foundation, Inc.
Copyright (C) 2019-2021 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
+3 -3
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2002, 2005-2015, 2018-2020 Free Software Foundation,
## Copyright (C) 2002, 2005-2015, 2018-2021 Free Software Foundation,
## Inc.
## This program is free software: you can redistribute it and/or modify
@@ -12,7 +12,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
dist_pkgdata_DATA = \
data/README.md \
@@ -28,6 +28,7 @@ dist_skeletons_DATA = \
data/skeletons/c.m4 \
data/skeletons/glr.c \
data/skeletons/glr.cc \
data/skeletons/glr2.cc \
data/skeletons/java-skel.m4 \
data/skeletons/java.m4 \
data/skeletons/lalr1.cc \
@@ -40,7 +41,6 @@ dist_skeletons_DATA = \
# Experimental support for the D language.
dist_skeletons_DATA += \
data/skeletons/README-D.txt \
data/skeletons/d-skel.m4 \
data/skeletons/d.m4 \
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. */
TokenKind 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 unions (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
+67 -34
View File
@@ -2,7 +2,7 @@
# Language-independent M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation,
# Copyright (C) 2002, 2004-2015, 2018-2021 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -49,7 +49,7 @@ m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
# 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])
@@ -74,7 +74,7 @@ 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/>.])
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
part or all of the Bison parser skeleton and distribute that work
@@ -261,6 +261,13 @@ m4_define([b4_fatal_at],
[b4_error([[fatal]], $@)dnl
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. ##
@@ -332,14 +339,14 @@ number is the opposite. If YYTABLE_NINF, syntax error.]])
$1([check], [b4_check])
$1([stos], [b4_stos],
[[YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM.]])
[[YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
state STATE-NUM.]])
$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],
[[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.]])
])
@@ -391,9 +398,9 @@ m4_define([b4_$3_if],
# b4_FLAG_if(IF-TRUE, IF-FALSE)
# -----------------------------
# 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([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([token_table]) # Whether yytoken_table is demanded.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
@@ -402,7 +409,7 @@ b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
# b4_glr_cc_if([IF-TRUE], [IF-FALSE])
# -----------------------------------
m4_define([b4_glr_cc_if],
[m4_if(b4_skeleton, ["glr.cc"], $@)])
[m4_if(m4_bregexp(b4_skeleton, [^"glr.cc"$]), [0], $@)])
## --------- ##
@@ -465,17 +472,35 @@ m4_case([$1],
# 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)
# ---------------------
# Fetch FIELD of symbol #NUM (or "orig NUM"). Fail if undefined.
# Fetch FIELD of symbol #NUM (or "orig NUM", or "empty"). Fail if undefined.
#
# If FIELD = id, prepend the token prefix.
m4_define([b4_symbol],
[m4_case([$2],
[id], [b4_symbol_token_kind([$1])],
[kind_base], [b4_symbol_kind_base([$1])],
[kind], [b4_symbol_kind([$1])],
[_b4_symbol($@)])])
[m4_if([$1], [empty], [b4_symbol([-2], [$2])],
[$1], [eof], [b4_symbol([0], [$2])],
[$1], [error], [b4_symbol([1], [$2])],
[$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)
@@ -537,7 +562,7 @@ m4_defn([b4_actions_])[]dnl
break;
}dnl
],
[YYUSE (m4_default([$2], [yykind]));])dnl
[b4_use(m4_default([$2], [yykind]));])dnl
m4_popdef([b4_actions_])dnl
])
@@ -633,11 +658,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.
m4_define([b4_type_foreach],
[m4_map([$1], m4_defn([b4_type_names]))])
[m4_map_sep([$1], [$2], m4_defn([b4_type_names]))])
@@ -953,15 +978,18 @@ m4_define([b4_percent_define_flag_if],
# For example:
#
# 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],
[_b4_percent_define_ifdef([$1], [],
[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[)], [[]])])])
[_b4_percent_define_define($@)])])
# b4_percent_define_if_define(NAME, [VARIABLE = NAME])
@@ -971,11 +999,12 @@ m4_define([b4_percent_define_default],
# to '_'.
m4_define([_b4_percent_define_if_define],
[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
[b4_percent_define_flag_if(m4_default([$2], [$1]),
[$3], [$4])])])
[b4_percent_define_default([m4_default([$2], [$1])], [[false]])dnl
b4_percent_define_flag_if(m4_default([$2], [$1]),
[$3], [$4])])])
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])
@@ -1110,14 +1139,18 @@ m4_define([b4_parse_error_bmatch],
# b4_union_if([IF-UNION-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]])
b4_percent_define_ifdef([[api.value.type]],
[m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
[m4_case(b4_percent_define_get([[api.value.type]]), [variant],
[m4_define([b4_variant_flag], [[1]])])])])
[m4_case(b4_percent_define_get([[api.value.type]]),
[union], [m4_define([b4_union_flag], [[1]])],
[variant], [m4_define([b4_variant_flag], [[1]])])])])
b4_define_flag_if([union])
b4_define_flag_if([variant])
+2 -2
View File
@@ -2,7 +2,7 @@
# C++ skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software
# Copyright (C) 2006-2007, 2009-2015, 2018-2021 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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/>.
# 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_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])])
+30 -25
View File
@@ -2,7 +2,7 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Sanity checks, before defaults installed by c.m4.
b4_percent_define_ifdef([[api.value.union.name]],
@@ -109,7 +109,6 @@ b4_percent_define_default([[api.filename.type]], [[const std::string]])
# 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([[global_tokens_and_yystype]], [[false]])
b4_percent_define_default([[define_location_comparison]],
[m4_if(b4_percent_define_get([[filename_type]]),
[std::string], [[true]], [[false]])])
@@ -193,7 +192,7 @@ m4_define([b4_declare_symbol_enum],
[[enum symbol_kind_type
{
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
]b4_symbol(-2, kind_base)[ = -2,
]b4_symbol(empty, kind_base)[ = -2,
]b4_symbol_foreach([ b4_symbol_enum])dnl
[ };]])
@@ -207,16 +206,16 @@ m4_define([b4_declare_symbol_enum],
# b4_value_type_declare
# ---------------------
# Declare semantic_type.
# Declare value_type.
m4_define([b4_value_type_declare],
[b4_value_type_setup[]dnl
[ /// Symbol semantic values.
]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
[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]]),
[union\|union-directive],
[[ union semantic_type
[[ union value_type
{
]b4_user_union_members[
};]])])dnl
@@ -228,11 +227,16 @@ m4_define([b4_value_type_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],
[[#ifndef ]b4_api_PREFIX[STYPE
]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
typedef ]b4_api_PREFIX[STYPE semantic_type;
#endif]b4_locations_if([
]b4_value_type_declare[
#endif
/// Backward compatibility (Bison 3.8).
typedef value_type semantic_type;]b4_locations_if([
/// Symbol locations.
typedef b4_percent_define_get([[api.location.type]],
[[location]]) location_type;])[
@@ -321,15 +325,16 @@ m4_define([b4_symbol_type_define],
/// Copy constructor.
basic_symbol (const basic_symbol& that);]b4_variant_if([[
/// Constructor for valueless symbols, and symbols from each type.
]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
/// Constructors for typed symbols.
]b4_type_foreach([b4_basic_symbol_constructor_define], [
])], [[
/// Constructor for valueless symbols.
basic_symbol (typename Base::kind_type t]b4_locations_if([,
YY_MOVE_REF (location_type) l])[);
/// Constructor for symbols with semantic value.
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])[);
]])[
/// Destroy the symbol.
@@ -339,7 +344,7 @@ m4_define([b4_symbol_type_define],
}
/// Destroy contents, and record that is empty.
void clear ()
void clear () YY_NOEXCEPT
{]b4_variant_if([[
// User destructor.
symbol_kind_type yykind = this->kind ();
@@ -390,7 +395,7 @@ m4_define([b4_symbol_type_define],
void move (basic_symbol& s);
/// The semantic value.
semantic_type value;]b4_locations_if([
value_type value;]b4_locations_if([
/// The location.
location_type location;])[
@@ -423,7 +428,7 @@ m4_define([b4_symbol_type_define],
by_kind (kind_type t);
/// Record that this symbol is empty.
void clear ();
void clear () YY_NOEXCEPT;
/// Steal the symbol kind from \a that.
void move (by_kind& that);
@@ -453,7 +458,7 @@ m4_define([b4_symbol_type_define],
symbol_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
])[};
]])
@@ -487,7 +492,7 @@ m4_define([b4_public_types_define],
template <typename Base>
]b4_parser_class[::basic_symbol<Base>::basic_symbol (]b4_join(
[typename Base::kind_type t],
[YY_RVREF (semantic_type) v],
[YY_RVREF (value_type) v],
b4_locations_if([YY_RVREF (location_type) l]))[)
: Base (t)
, value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([
@@ -507,7 +512,7 @@ m4_define([b4_public_types_define],
bool
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
{
return this->kind () == ]b4_symbol(-2, kind)[;
return this->kind () == ]b4_symbol(empty, kind)[;
}
template <typename Base>
@@ -523,7 +528,7 @@ m4_define([b4_public_types_define],
// by_kind.
]b4_inline([$1])b4_parser_class[::by_kind::by_kind ()
: kind_ (]b4_symbol(-2, kind)[)
: kind_ (]b4_symbol(empty, kind)[)
{}
#if 201103L <= YY_CPLUSPLUS
@@ -543,9 +548,9 @@ m4_define([b4_public_types_define],
{}
]b4_inline([$1])[void
]b4_parser_class[::by_kind::clear ()
]b4_parser_class[::by_kind::clear () YY_NOEXCEPT
{
kind_ = ]b4_symbol(-2, kind)[;
kind_ = ]b4_symbol(empty, kind)[;
}
]b4_inline([$1])[void
@@ -571,7 +576,7 @@ m4_define([b4_public_types_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.
m4_define([b4_token_constructor_define], [])
@@ -600,7 +605,7 @@ m4_define([b4_yytranslate_define],
if (t <= 0)
return symbol_kind::]b4_symbol_prefix[YYEOF;
else if (t <= code_max)
return YY_CAST (symbol_kind_type, translate_table[t]);
return static_cast <symbol_kind_type> (translate_table[t]);
else
return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
}
+2 -2
View File
@@ -2,7 +2,7 @@
# 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-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# _b4_comment(TEXT, OPEN, CONTINUE, END)
+2 -2
View File
@@ -2,7 +2,7 @@
# C skeleton dispatching for Bison.
# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software
# Copyright (C) 2006-2007, 2009-2015, 2018-2021 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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/>.
# 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_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])])
+108 -63
View File
@@ -2,7 +2,7 @@
# C M4 Macros for Bison.
# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation,
# Copyright (C) 2002, 2004-2015, 2018-2021 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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
# api.push-pull.
m4_define([b4_identification],
[[/* Identify Bison output. */
#define YYBISON 1
[[/* Identify Bison output, and Bison version. */
#define YYBISON ]b4_version[
/* Bison version. */
#define YYBISON_VERSION "]b4_version["
/* Bison version string. */
#define YYBISON_VERSION "]b4_version_string["
/* Skeleton name. */
#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
@@ -107,27 +107,32 @@ b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]])
## Pure/impure interfaces. ##
## ------------------------ ##
# b4_lex_formals
# --------------
# b4_yylex_formals
# ----------------
# All the yylex formal arguments.
# b4_lex_param arrives quoted twice, but we want to keep only one level.
m4_define([b4_lex_formals],
[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl
b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl
m4_define([b4_yylex_formals],
[b4_pure_if([[[b4_api_PREFIX[STYPE *yylvalp]], [[&yylval]]][]dnl
b4_locations_if([, [b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param)])
# b4_lex
# ------
# b4_yylex
# --------
# Call yylex.
m4_define([b4_lex],
[b4_function_call([yylex], [int], b4_lex_formals)])
m4_define([b4_yylex],
[b4_function_call([yylex], [int], b4_yylex_formals)])
# 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
@@ -158,13 +163,20 @@ m4_popdef([$2])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])
# --------------------------------
# '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_ifvaln([$1], [ YYUSE ([$1]);])dnl
b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl
b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
[m4_ifvaln([$1], [ b4_use([$1]);])dnl
b4_locations_if([m4_ifvaln([$2], [ b4_use([$2]);])])dnl
b4_parse_param_for([Decl], [Formal], [ b4_use(Formal);
])dnl
])
@@ -242,6 +254,18 @@ typedef int_least16_t yytype_int16;
typedef short yytype_int16;
#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__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
@@ -366,14 +390,16 @@ dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings.
&& ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
|| (defined _MSC_VER && 1900 <= _MSC_VER)))
# define _Noreturn [[noreturn]]
# elif (!defined __cplusplus \
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|| (defined __apple_build_version__ \
? 6000000 <= __apple_build_version__ \
: 3 < __clang_major__ + (5 <= __clang_minor__))))
# elif ((!defined __cplusplus || defined __clang__) \
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|| (!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. */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
|| 0x5110 <= __SUNPRO_C)
# define _Noreturn __attribute__ ((__noreturn__))
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
# define _Noreturn __declspec (noreturn)
@@ -384,17 +410,23 @@ dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings.
]])[/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
# define YY_USE(E) ((void) (E))
#else
# define YYUSE(E) /* empty */
# define YY_USE(E) /* empty */
#endif
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* 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 ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# endif
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
@@ -474,7 +506,7 @@ m4_define([b4_null], [YY_NULLPTR])
# -------------------------------------------------------------
# Define "yy<TABLE-NAME>" whose contents is CONTENT.
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[[]] =
{
$2
@@ -493,7 +525,7 @@ static const b4_int_type_for([$2]) yy$1[[]] =
m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]])
m4_define([b4_symbol(-2, tag)], [[No symbol.]])
m4_if(b4_symbol(0, id), [YYEOF],
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]])
@@ -509,10 +541,11 @@ m4_define([b4_token_define],
# ----------------
# Output the definition of the tokens.
m4_define([b4_token_defines],
[b4_any_token_visible_if([/* Token kinds. */
m4_join([
[[/* Token kinds. */
#define ]b4_symbol(empty, [id])[ -2
]m4_join([
], b4_symbol_map([b4_token_define]))
])])
])
# b4_token_enum(TOKEN-NUM)
@@ -537,7 +570,7 @@ m4_define([b4_token_enums],
# define ]b4_api_PREFIX[TOKENTYPE
enum ]b4_api_prefix[tokentype
{
]b4_symbol([-2], [id])[ = -2,
]b4_symbol(empty, [id])[ = -2,
]b4_symbol_foreach([b4_token_enum])dnl
[ };
typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t;
@@ -587,7 +620,7 @@ m4_define([b4_declare_symbol_enum],
[[/* Symbol kind. */
enum yysymbol_kind_t
{
]b4_symbol([-2], kind_base)[ = -2,
]b4_symbol(empty, [kind_base])[ = -2,
]b4_symbol_foreach([b4_symbol_enum])dnl
[};
typedef enum yysymbol_kind_t yysymbol_kind_t;
@@ -629,6 +662,14 @@ m4_define([b4_formal],
[$1])
# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
# ------------------------------------------------------------
# Declare the function NAME.
m4_define([b4_function_declare],
[$2 $1 (b4_formals(m4_shift2($@)));[]dnl
])
## --------------------- ##
## Calling C functions. ##
@@ -728,13 +769,6 @@ yy_symbol_value_print (FILE *yyo,
]b4_parse_param_use([yyoutput], [yylocationp])dnl
[ if (!yyvaluep)
return;]
dnl glr.c does not feature yytoknum.
m4_if(b4_skeleton, ["yacc.c"],
[[# ifdef YYPRINT
if (yykind < YYNTOKENS)
YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
# endif
]])dnl
b4_percent_code_get([[pre-printer]])dnl
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
b4_symbol_actions([printer])
@@ -755,7 +789,7 @@ yy_symbol_print (FILE *yyo,
YYFPRINTF (yyo, "%s %s (",
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
]b4_locations_if([ YYLOCATION_PRINT (yyo, yylocationp);
YYFPRINTF (yyo, ": ");
])dnl
[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl
@@ -942,7 +976,7 @@ struct ]b4_api_PREFIX[LTYPE
# 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.
m4_define([b4_declare_yylstype],
[b4_value_type_define[]b4_locations_if([
@@ -1012,17 +1046,24 @@ m4_define([b4_yylloc_default_define],
#endif
]])
# b4_yy_location_print_define
# ---------------------------
# Define YY_LOCATION_PRINT.
m4_define([b4_yy_location_print_define],
# b4_yylocation_print_define
# --------------------------
# Define YYLOCATION_PRINT.
m4_define([b4_yylocation_print_define],
[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
we won't break user code: when these are the locations we know. */
# ifndef YY_LOCATION_PRINT
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
# ifndef YYLOCATION_PRINT
# 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. */
@@ -1050,19 +1091,23 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
res += YYFPRINTF (yyo, "-%d", end_col);
}
return res;
}
}
# define YY_LOCATION_PRINT(File, Loc) \
yy_location_print_ (File, &(Loc))
# define YYLOCATION_PRINT yy_location_print_
/* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc))
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# define YYLOCATION_PRINT(File, Loc) ((void) 0)
/* 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 YY_LOCATION_PRINT */]],
[[/* This macro is provided for backward compatibility. */
# ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif]])
# endif /* !defined YYLOCATION_PRINT */]])
])
# b4_yyloc_default
+2 -2
View File
@@ -2,7 +2,7 @@
# D skeleton dispatching for Bison.
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2018-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [b4_complain([%%glr-parser not supported for D])])
b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])])
+289 -34
View File
@@ -2,7 +2,7 @@
# D language support for Bison
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2018-2021 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
@@ -15,27 +15,36 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# _b4_comment(TEXT, OPEN, CONTINUE, END)
# --------------------------------------
# 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])
m4_include(b4_skeletonsdir/[c-like.m4])
# b4_comment(TEXT, [PREFIX])
# --------------------------
# Put TEXT in comment. Prefix all the output lines with PREFIX.
m4_define([b4_comment],
[_b4_comment([$1], [$2/* ], [$2 ], [ */])])
# b4_symbol_action(SYMBOL-NUM, ACTION)
# ------------------------------------
# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
m4_define([b4_symbol_action],
[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)
@@ -58,6 +67,23 @@ m4_define([b4_percent_define_get3],
[m4_ifval(m4_quote(b4_percent_define_get([$1])),
[$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)
# ---------------------------
@@ -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.final], [final ])dnl
[class ]b4_parser_class[]dnl
b4_percent_define_get3([api.parser.extends], [ extends ])dnl
b4_percent_define_get3([api.parser.implements], [ implements ])])
b4_percent_define_if_get2([api.parser.extends], [api.parser.implements], [ : ])dnl
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)
@@ -103,12 +131,12 @@ m4_define([b4_location_type_if],
# b4_identification
# -----------------
m4_define([b4_identification],
[/** Version number for the Bison executable that generated this parser. */
public static immutable string yy_bison_version = "b4_version";
[[/** Version number for the Bison executable that generated this parser. */
public static immutable string yy_bison_version = "]b4_version_string[";
/** 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[;
]])
## ------------ ##
@@ -153,6 +181,7 @@ private static immutable b4_int_type_for([$2])[[]] yy$1_ =
## ------------- ##
m4_define([b4_symbol(-2, id)], [[YYEMPTY]])
b4_percent_define_default([[api.token.raw]], [[true]])
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# ---------------------------------------
@@ -167,19 +196,49 @@ m4_define([b4_token_enum],
m4_define([b4_token_enums],
[/* Token kinds. */
public enum TokenKind {
]b4_symbol_kind([-2])[ = -2,
]b4_symbol(empty, id)[ = -2,
b4_symbol_foreach([b4_token_enum])dnl
}
])
# b4_symbol_translate(STRING)
# ---------------------------
# 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_percent_define_default([[api.symbol.prefix]], [[S_]])
# b4_symbol_kind(NUM)
# -------------------
m4_define([b4_symbol_kind],
@@ -204,16 +263,46 @@ m4_define([b4_symbol_enum],
# to use a signed type, which matters for yytoken.
m4_define([b4_declare_symbol_enum],
[[ /* Symbol kinds. */
public enum SymbolKind
struct SymbolKind
{
]b4_symbol(-2, kind_base)[ = -2, /* No symbol. */
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(W)(W sink) const
if (isOutputRange!(W, char))
{
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[
@};]])[
put(sink, yy_sname[yycode_]);
}
}
]])
# b4-case(ID, CODE, [COMMENTS])
# b4_case(ID, CODE, [COMMENTS])
# -----------------------------
m4_define([b4_case], [ case $1:m4_ifval([$3], [ b4_comment([$3])])
$2
@@ -240,6 +329,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]))
## ---------------- ##
## 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. ##
## ----------------- ##
@@ -286,7 +478,7 @@ m4_define([b4_lhs_location],
# Expansion of @POS, where the current rule has RULE-LENGTH symbols
# on RHS.
m4_define([b4_rhs_location],
[yystack.locationAt ([$1], [$2])])
[yystack.locationAt (b4_subtract($@))])
# b4_lex_param
@@ -371,3 +563,66 @@ m4_define([b4_var_decls],
], [$@])])
m4_define([b4_var_decl],
[ 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])[
}
]])
+166 -143
View File
@@ -1,8 +1,8 @@
-*- C -*-
# -*- C -*-
# GLR skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# If we are loaded by glr.cc, do not override c++.m4 definitions by
@@ -32,7 +32,9 @@ m4_if(b4_skeleton, ["glr.c"],
m4_define_default([b4_stack_depth_max], [10000])
m4_define_default([b4_stack_depth_init], [200])
# Included header.
b4_percent_define_default([[api.header.include]],
[["@basename(]b4_spec_header_file[@)"]])
## ------------------------ ##
## Pure/impure interfaces. ##
@@ -122,7 +124,7 @@ m4_define([b4_rhs_data],
# --------------------------------------------------
# Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
m4_define([b4_rhs_value],
[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3], [$4])])
[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yyval], [$3], [$4])])
@@ -145,13 +147,22 @@ m4_define([b4_rhs_location],
[(b4_rhs_data([$1], [$2]).yyloc)])
# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
# ---------------------------------------------------
m4_define([b4_call_merger],
[b4_case([$1],
[ b4_symbol_if([$3], [has_type],
[yy0->b4_symbol($3, slot) = $2 (*yy0, *yy1);],
[*yy0 = $2 (*yy0, *yy1);])])])
## -------------- ##
## Declarations. ##
## -------------- ##
# b4_shared_declarations
# ----------------------
# Declaration that might either go into the header (if --defines)
# Declaration that might either go into the header (if --header)
# or open coded in the parser body. glr.cc has its own definition.
m4_if(b4_skeleton, ["glr.c"],
[m4_define([b4_shared_declarations],
@@ -185,10 +196,10 @@ int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)],
# glr.cc produces its own header.
b4_glr_cc_if([],
[b4_defines_if(
[b4_header_if(
[b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C],
[2002-2015, 2018-2020])[
[2002-2015, 2018-2021])[
]b4_cpp_guard_open([b4_spec_mapped_header_file])[
]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[
@@ -202,7 +213,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C],
b4_output_begin([b4_parser_file_name])
b4_copyright([Skeleton implementation for Bison GLR parsers in C],
[2002-2015, 2018-2020])[
[2002-2015, 2018-2021])[
/* C GLR parser skeleton written by Paul Hilfinger. */
]b4_disclaimer[
@@ -215,7 +226,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
]m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */
#define yyparse ]b4_prefix[parse
#define ]b4_glr_cc_if([yy_parse_impl], [yyparse])[ ]b4_prefix[]b4_glr_cc_if([_parse_impl], [parse])[
#define yylex ]b4_prefix[lex
#define yyerror ]b4_prefix[error
#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[
@@ -228,8 +239,8 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_cast_define[
]b4_null_define[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations])[
]b4_header_if([[#include ]b4_percent_define_get([[api.header.include]])],
[b4_shared_declarations])[
]b4_glr_cc_if([b4_glr_cc_setup],
[b4_declare_symbol_enum])[
@@ -431,7 +442,7 @@ int yychar;])[
enum { YYENOMEM = -2 };
typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
typedef enum { yyok, yyaccept, yyabort, yyerr, yynomem } YYRESULTTAG;
#define YYCHK(YYE) \
do { \
@@ -496,10 +507,11 @@ typedef struct yySemanticOption yySemanticOption;
typedef union yyGLRStackItem yyGLRStackItem;
typedef struct yyGLRStack yyGLRStack;
struct yyGLRState {
struct yyGLRState
{
/** Type tag: always true. */
yybool yyisState;
/** Type tag for yysemantics. If true, yysval applies, otherwise
/** Type tag for yysemantics. If true, yyval applies, otherwise
* yyfirstVal applies. */
yybool yyresolved;
/** Number of corresponding LALR(1) machine state. */
@@ -514,24 +526,26 @@ struct yyGLRState {
* yynext. */
yySemanticOption* yyfirstVal;
/** Semantic value for this state. */
YYSTYPE yysval;
YYSTYPE yyval;
} yysemantics;]b4_locations_if([[
/** Source location for this state. */
YYLTYPE yyloc;]])[
};
struct yyGLRStateSet {
struct yyGLRStateSet
{
yyGLRState** yystates;
/** During nondeterministic operation, yylookaheadNeeds tracks which
* stacks have actually needed the current lookahead. During deterministic
* operation, yylookaheadNeeds[0] is not maintained since it would merely
* duplicate yychar != ]b4_symbol(-2, id)[. */
* duplicate yychar != ]b4_symbol(empty, id)[. */
yybool* yylookaheadNeeds;
YYPTRDIFF_T yysize;
YYPTRDIFF_T yycapacity;
};
struct yySemanticOption {
struct yySemanticOption
{
/** Type tag: always false. */
yybool yyisState;
/** Rule number for this reduction */
@@ -637,6 +651,13 @@ yysymbol_name (yysymbol_kind_t yysymbol)
}]])[
#endif
/** Left-hand-side symbol for rule #YYRULE. */
static inline yysymbol_kind_t
yylhsNonterm (yyRuleNum yyrule)
{
return YY_CAST (yysymbol_kind_t, yyr1[yyrule]);
}
#if ]b4_api_PREFIX[DEBUG
# ifndef YYFPRINTF
@@ -662,7 +683,7 @@ yysymbol_name (yysymbol_kind_t yysymbol)
YY_IGNORE_USELESS_CAST_END \
} while (0)
]b4_yy_location_print_define[
]b4_yylocation_print_define[
]b4_yy_symbol_print_define[
@@ -676,6 +697,16 @@ yysymbol_name (yysymbol_kind_t yysymbol)
} \
} while (0)
static inline void
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk,
yyRuleNum yyrule]b4_user_formals[);
# define YY_REDUCE_PRINT(Args) \
do { \
if (yydebug) \
yy_reduce_print Args; \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
@@ -689,6 +720,7 @@ static void yypdumpstack (yyGLRStack* yystackp)
# define YY_DPRINTF(Args) do {} while (yyfalse)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
# define YY_REDUCE_PRINT(Args)
#endif /* !]b4_api_PREFIX[DEBUG */
@@ -791,9 +823,9 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
#endif
yyvsp[i].yystate.yyresolved = s->yyresolved;
if (s->yyresolved)
yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
yyvsp[i].yystate.yysemantics.yyval = s->yysemantics.yyval;
else
/* The effect of using yysval or yyloc (in an immediate rule) is
/* The effect of using yyval or yyloc (in an immediate rule) is
* undefined. */
yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[
yyvsp[i].yystate.yyloc = s->yyloc;]])[
@@ -809,14 +841,14 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
{
yysymbol_kind_t yytoken;
]b4_parse_param_use()dnl
[ if (*yycharp == ]b4_symbol(-2, id)[)
[ if (*yycharp == ]b4_symbol(empty, id)[)
{
YY_DPRINTF ((stderr, "Reading a token\n"));]b4_glr_cc_if([[
#if YY_EXCEPTIONS
try
{
#endif // YY_EXCEPTIONS
*yycharp = ]b4_lex[;
*yycharp = ]b4_yylex[;
#if YY_EXCEPTIONS
}
catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
@@ -827,14 +859,14 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
// Map errors caught in the scanner to the undefined token,
// so that error handling is started. However, record this
// with this special value of yychar.
*yycharp = ]b4_symbol(1, id)[;
*yycharp = ]b4_symbol(error, id)[;
}
#endif // YY_EXCEPTIONS]], [[
*yycharp = ]b4_lex[;]])[
*yycharp = ]b4_yylex[;]])[
}
if (*yycharp <= ]b4_symbol(0, [id])[)
if (*yycharp <= ]b4_symbol(eof, [id])[)
{
*yycharp = ]b4_symbol(0, [id])[;
*yycharp = ]b4_symbol(eof, [id])[;
yytoken = ]b4_symbol_prefix[YYEOF;
YY_DPRINTF ((stderr, "Now at end of input.\n"));
}
@@ -866,28 +898,31 @@ yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
* and top stack item YYVSP. YYLVALP points to place to put semantic
* value ($$), and yylocp points to place for location information
* (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
* yyerr for YYERROR, yyabort for YYABORT. */
* yyerr for YYERROR, yyabort for YYABORT, yynomem for YYNOMEM. */
static YYRESULTTAG
yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
yyGLRStack* yystackp,
yyuserAction (yyRuleNum yyrule, int yyrhslen, yyGLRStackItem* yyvsp,
yyGLRStack* yystackp, YYPTRDIFF_T yyk,
YYSTYPE* yyvalp]b4_locuser_formals[)
{
yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR;
int yylow;
const yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR;
int yylow = 1;
]b4_parse_param_use([yyvalp], [yylocp])dnl
[ YYUSE (yyrhslen);
[ YY_USE (yyk);
YY_USE (yyrhslen);
# undef yyerrok
# define yyerrok (yystackp->yyerrState = 0)
# undef YYACCEPT
# define YYACCEPT return yyaccept
# undef YYABORT
# define YYABORT return yyabort
# undef YYNOMEM
# define YYNOMEM return yynomem
# undef YYERROR
# define YYERROR return yyerrok, yyerr
# undef YYRECOVERING
# define YYRECOVERING() (yystackp->yyerrState != 0)
# undef yyclearin
# define yyclearin (yychar = ]b4_symbol(-2, id)[)
# define yyclearin (yychar = ]b4_symbol(empty, id)[)
# undef YYFILL
# define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal)
# undef YYBACKUP
@@ -895,21 +930,23 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
yyerrok, yyerr
yylow = 1;
if (yyrhslen == 0)
*yyvalp = yyval_default;
else
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yyval;]b4_locations_if([[
/* Default location. */
YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
]])[]b4_glr_cc_if([[
yystackp->yyerror_range[1].yystate.yyloc = *yylocp;]])[
/* If yyk == -1, we are running a deferred action on a temporary
stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
so pretend the stack is "normal". */
YY_REDUCE_PRINT ((yynormal || yyk == -1, yyvsp, yyk, yyrule]b4_user_args[));]b4_glr_cc_if([[
#if YY_EXCEPTIONS
typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error;
try
{
#endif // YY_EXCEPTIONS]])[
switch (yyn)
switch (yyrule)
{
]b4_user_actions[
default: break;
@@ -924,11 +961,13 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
YYERROR;
}
#endif // YY_EXCEPTIONS]])[
YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), yyvalp, yylocp);
return yyok;
# undef yyerrok
# undef YYABORT
# undef YYACCEPT
# undef YYNOMEM
# undef YYERROR
# undef YYBACKUP
# undef yyclearin
@@ -939,8 +978,8 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
static void
yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
{
YYUSE (yy0);
YYUSE (yy1);
YY_USE (yy0);
YY_USE (yy1);
switch (yyn)
{
@@ -965,7 +1004,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
{
if (yys->yyresolved)
yydestruct (yymsg, yy_accessing_symbol (yys->yylrState),
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
&yys->yysemantics.yyval]b4_locuser_args([&yys->yyloc])[);
else
{
#if ]b4_api_PREFIX[DEBUG
@@ -992,13 +1031,6 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
}
}
/** Left-hand-side symbol for rule #YYRULE. */
static inline yysymbol_kind_t
yylhsNonterm (yyRuleNum yyrule)
{
return YY_CAST (yysymbol_kind_t, yyr1[yyrule]);
}
#define yypact_value_is_default(Yyn) \
]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[
@@ -1032,7 +1064,7 @@ static inline int
yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts)
{
int yyindex = yypact[yystate] + yytoken;
if (yytoken == ]b4_symbol(1, kind)[)
if (yytoken == ]b4_symbol(error, kind)[)
{
// This is the error token.
*yyconflicts = yyconfl;
@@ -1119,7 +1151,7 @@ yyaddDeferredAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyGLRState* yystate,
yynewOption->yyloc = yylloc;])[
}
else
yynewOption->yyrawchar = ]b4_symbol(-2, id)[;
yynewOption->yyrawchar = ]b4_symbol(empty, id)[;
yynewOption->yynext = yystate->yysemantics.yyfirstVal;
yystate->yysemantics.yyfirstVal = yynewOption;
@@ -1340,7 +1372,7 @@ yyglrShift (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState,
yynewState->yyposn = yyposn;
yynewState->yyresolved = yytrue;
yynewState->yypred = yystackp->yytops.yystates[yyk];
yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
yynewState->yysemantics.yyval = *yyvalp;]b4_locations_if([
yynewState->yyloc = *yylocp;])[
yystackp->yytops.yystates[yyk] = yynewState;
@@ -1368,14 +1400,7 @@ yyglrShiftDefer (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState,
yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
}
#if !]b4_api_PREFIX[DEBUG
# define YY_REDUCE_PRINT(Args)
#else
# define YY_REDUCE_PRINT(Args) \
do { \
if (yydebug) \
yy_reduce_print Args; \
} while (0)
#if ]b4_api_PREFIX[DEBUG
/*----------------------------------------------------------------------.
| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
@@ -1398,7 +1423,7 @@ yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk,
YY_FPRINTF ((stderr, " $%d = ", yyi + 1));
yy_symbol_print (stderr,
yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].yystate.yylrState),
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval]b4_locations_if([,
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yyval]b4_locations_if([,
&]b4_rhs_location(yynrhs, yyi + 1))[]dnl
b4_user_args[);
if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
@@ -1429,8 +1454,7 @@ yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
yystackp->yynextFree -= yynrhs;
yystackp->yyspaceLeft += yynrhs;
yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
YY_REDUCE_PRINT ((yytrue, yyrhs, yyk, yyrule]b4_user_args[));
return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, yyk,
yyvalp]b4_locuser_args[);
}
else
@@ -1449,9 +1473,8 @@ yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
}
yyupdateSplit (yystackp, yys);
yystackp->yytops.yystates[yyk] = yys;
YY_REDUCE_PRINT ((yyfalse, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
yystackp, yyvalp]b4_locuser_args[);
yystackp, yyk, yyvalp]b4_locuser_args[);
}
}
@@ -1474,21 +1497,20 @@ yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
{
YYSTYPE yysval;]b4_locations_if([[
YYSTYPE yyval;]b4_locations_if([[
YYLTYPE yyloc;]])[
YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yyval]b4_locuser_args([&yyloc])[);
if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
YY_DPRINTF ((stderr,
"Parse on stack %ld rejected by rule %d (line %d).\n",
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1]));
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule]));
if (yyflag != yyok)
return yyflag;
YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), &yysval, &yyloc);
yyglrShift (yystackp, yyk,
yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
yylhsNonterm (yyrule)),
yyposn, &yysval]b4_locations_if([, &yyloc])[);
yyposn, &yyval]b4_locations_if([, &yyloc])[);
}
else
{
@@ -1508,7 +1530,7 @@ yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
YY_DPRINTF ((stderr,
"Reduced stack %ld by rule %d (line %d); action deferred. "
"Now in state %d.\n",
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1],
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule],
yynewLRState));
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
@@ -1619,12 +1641,12 @@ yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
else if (yys0->yyresolved)
{
yys1->yyresolved = yytrue;
yys1->yysemantics.yysval = yys0->yysemantics.yysval;
yys1->yysemantics.yyval = yys0->yysemantics.yyval;
}
else if (yys1->yyresolved)
{
yys0->yyresolved = yytrue;
yys0->yysemantics.yysval = yys1->yysemantics.yysval;
yys0->yysemantics.yyval = yys1->yysemantics.yyval;
}
else
{
@@ -1678,8 +1700,8 @@ yypreference (yySemanticOption* y0, yySemanticOption* y1)
return 0;
}
static YYRESULTTAG yyresolveValue (yyGLRState* yys,
yyGLRStack* yystackp]b4_user_formals[);
static YYRESULTTAG
yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[);
/** Resolve the previous YYN states starting at and including state YYS
@@ -1735,7 +1757,7 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
yylloc = yyopt->yyloc;])[
yyflag = yyuserAction (yyopt->yyrule, yynrhs,
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
yystackp, yyvalp]b4_locuser_args[);
yystackp, -1, yyvalp]b4_locuser_args[);
yychar = yychar_current;
yylval = yylval_current;]b4_locations_if([
yylloc = yylloc_current;])[
@@ -1795,8 +1817,8 @@ static YYRESULTTAG
yyreportAmbiguity (yySemanticOption* yyx0,
yySemanticOption* yyx1]b4_pure_formals[)
{
YYUSE (yyx0);
YYUSE (yyx1);
YY_USE (yyx0);
YY_USE (yyx1);
#if ]b4_api_PREFIX[DEBUG
YY_FPRINTF ((stderr, "Ambiguity detected.\n"));
@@ -1870,7 +1892,7 @@ yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
yySemanticOption* yybest = yyoptionList;
yySemanticOption** yypp;
yybool yymerge = yyfalse;
YYSTYPE yysval;
YYSTYPE yyval;
YYRESULTTAG yyflag;]b4_locations_if([
YYLTYPE *yylocp = &yys->yyloc;])[
@@ -1914,33 +1936,33 @@ yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
{
yySemanticOption* yyp;
int yyprec = yydprec[yybest->yyrule];
yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args[);
if (yyflag == yyok)
for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext)
{
if (yyprec == yydprec[yyp->yyrule])
{
YYSTYPE yysval_other;]b4_locations_if([
YYSTYPE yyval_other;]b4_locations_if([
YYLTYPE yydummy;])[
yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
yyflag = yyresolveAction (yyp, yystackp, &yyval_other]b4_locuser_args([&yydummy])[);
if (yyflag != yyok)
{
yydestruct ("Cleanup: discarding incompletely merged value for",
yy_accessing_symbol (yys->yylrState),
&yysval]b4_locuser_args[);
&yyval]b4_locuser_args[);
break;
}
yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
yyuserMerge (yymerger[yyp->yyrule], &yyval, &yyval_other);
}
}
}
else
yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args([yylocp])[);
if (yyflag == yyok)
{
yys->yyresolved = yytrue;
yys->yysemantics.yysval = yysval;
yys->yysemantics.yyval = yyval;
}
else
yys->yysemantics.yyfirstVal = YY_NULLPTR;
@@ -1965,18 +1987,24 @@ yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
return yyok;
}
/** Called when returning to deterministic operation to clean up the extra
* stacks. */
static void
yycompressStack (yyGLRStack* yystackp)
{
yyGLRState* yyp, *yyq, *yyr;
/* yyr is the state after the split point. */
yyGLRState *yyr;
if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR)
return;
for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
yyp != yystackp->yysplitPoint;
yyr = yyp, yyp = yyq, yyq = yyp->yypred)
yyp->yypred = yyr;
{
yyGLRState *yyp, *yyq;
for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
yyp != yystackp->yysplitPoint;
yyr = yyp, yyp = yyq, yyq = yyp->yypred)
yyp->yypred = yyr;
}
yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
yystackp->yynextFree = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yysplitPoint) + 1;
@@ -2110,7 +2138,7 @@ yypcontext_expected_tokens (const yyGLRStack* yystackp,
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (!yyarg)
@@ -2122,7 +2150,7 @@ yypcontext_expected_tokens (const yyGLRStack* yystackp,
}
}
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = ]b4_symbol(-2, kind)[;
yyarg[0] = ]b4_symbol(empty, kind)[;
return yycount;
}]])[
@@ -2140,19 +2168,19 @@ yypcontext_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED;
static yysymbol_kind_t
yypcontext_token (const yyGLRStack *yystackp)
{
YYUSE (yystackp);
yysymbol_kind_t yytoken = yychar == ]b4_symbol(-2, id)[ ? ]b4_symbol(-2, kind)[ : YYTRANSLATE (yychar);
YY_USE (yystackp);
yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar);
return yytoken;
}
]b4_locations_if([[/* The location of the lookahead of this context. */
static YYLTYPE *
static const YYLTYPE *
yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED;
static YYLTYPE *
static const YYLTYPE *
yypcontext_location (const yyGLRStack *yystackp)
{
YYUSE (yystackp);
YY_USE (yystackp);
return &yylloc;
}]])],
[detailed\|verbose],
@@ -2160,7 +2188,7 @@ yypcontext_location (const yyGLRStack *yystackp)
yy_syntax_error_arguments (const yyGLRStack* yystackp,
yysymbol_kind_t yyarg[], int yyargn)
{
yysymbol_kind_t yytoken = yychar == ]b4_symbol(-2, id)[ ? ]b4_symbol(-2, kind)[ : YYTRANSLATE (yychar);
yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar);
/* Actual size of YYARG. */
int yycount = 0;
/* There are many possibilities here to consider:
@@ -2176,12 +2204,7 @@ yy_syntax_error_arguments (const yyGLRStack* yystackp,
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.]b4_lac_if([[
In the first two cases, it might appear that the current syntax
error should have been detected in the previous state when yy_lac
was invoked. However, at that time, there might have been a
different syntax error that discarded a different initial context
during error recovery, leaving behind the current lookahead.]], [[
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
@@ -2189,9 +2212,9 @@ yy_syntax_error_arguments (const yyGLRStack* yystackp,
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.]])[
accepted due to an error action in a later state.
*/
if (yytoken != ]b4_symbol(-2, kind)[)
if (yytoken != ]b4_symbol(empty, kind)[)
{
int yyn;
if (yyarg)
@@ -2318,9 +2341,9 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
{
yysymbol_kind_t yytoken;
int yyj;
if (yychar == ]b4_symbol(0, [id])[)
if (yychar == ]b4_symbol(eof, [id])[)
yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
if (yychar != ]b4_symbol(-2, id)[)
if (yychar != ]b4_symbol(empty, id)[)
{]b4_locations_if([[
/* We throw away the lookahead, but the error range
of the shifted error token must take it into account. */
@@ -2332,7 +2355,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
yytoken = YYTRANSLATE (yychar);
yydestruct ("Error: discarding",
yytoken, &yylval]b4_locuser_args([&yylloc])[);
yychar = ]b4_symbol(-2, id)[;
yychar = ]b4_symbol(empty, id)[;
}
yytoken = ]b4_yygetToken_call[;
yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
@@ -2370,8 +2393,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
int yyj = yypact[yys->yylrState];
if (! yypact_value_is_default (yyj))
{
yyj += ]b4_symbol(1, kind)[;
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(1, kind)[
yyj += ]b4_symbol(error, kind)[;
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, kind)[
&& yyisShiftAction (yytable[yyj]))
{
/* Shift the error token. */
@@ -2399,20 +2422,16 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
}
#define YYCHK1(YYE) \
do { \
switch (YYE) { \
case yyok: \
break; \
case yyabort: \
goto yyabortlab; \
case yyaccept: \
goto yyacceptlab; \
case yyerr: \
goto yyuser_error; \
default: \
goto yybuglab; \
} \
#define YYCHK1(YYE) \
do { \
switch (YYE) { \
case yyok: break; \
case yyabort: goto yyabortlab; \
case yyaccept: goto yyacceptlab; \
case yyerr: goto yyuser_error; \
case yynomem: goto yyexhaustedlab; \
default: goto yybuglab; \
} \
} while (0)
/*----------.
@@ -2420,7 +2439,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
`----------*/
int
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
]b4_glr_cc_if([yy_parse_impl], [yyparse])[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
{
int yyresult;
yyGLRStack yystack;
@@ -2429,7 +2448,7 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
YY_DPRINTF ((stderr, "Starting parse\n"));
yychar = ]b4_symbol(-2, id)[;
yychar = ]b4_symbol(empty, id)[;
yylval = yyval_default;]b4_locations_if([
yylloc = yyloc_default;])[
]m4_ifdef([b4_initial_action], [
@@ -2483,7 +2502,7 @@ b4_dollar_popdef])[]dnl
if (yyisShiftAction (yyaction))
{
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
yychar = ]b4_symbol(-2, id)[;
yychar = ]b4_symbol(empty, id)[;
yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
if (0 < yystack.yyerrState)
@@ -2494,7 +2513,7 @@ b4_dollar_popdef])[]dnl
yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
/* Issue an error message unless the scanner already
did. */
if (yychar != ]b4_symbol(1, id)[)
if (yychar != ]b4_symbol(error, id)[)
yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error;
}
@@ -2510,7 +2529,7 @@ b4_dollar_popdef])[]dnl
YYPTRDIFF_T yys;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(-2, id)[;
yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(empty, id)[;
/* yyprocessOneStack returns one of three things:
@@ -2548,11 +2567,11 @@ b4_dollar_popdef])[]dnl
/* If any yyglrShift call fails, it will fail after shifting. Thus,
a copy of yylval will already be on stack 0 in the event of a
failure in the following loop. Thus, yychar is set to ]b4_symbol(-2, id)[
failure in the following loop. Thus, yychar is set to ]b4_symbol(empty, id)[
before the loop to make sure the user destructor for yylval isn't
called twice. */
yytoken_to_shift = YYTRANSLATE (yychar);
yychar = ]b4_symbol(-2, id)[;
yychar = ]b4_symbol(empty, id)[;
yyposn += 1;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
{
@@ -2565,7 +2584,7 @@ b4_dollar_popdef])[]dnl
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
yyglrShift (&yystack, yys, yyaction, yyposn,
&yylval]b4_locations_if([, &yylloc])[);
YY_DPRINTF ((stderr, "Stack %ld now in state #%d\n",
YY_DPRINTF ((stderr, "Stack %ld now in state %d\n",
YY_CAST (long, yys),
yystack.yytops.yystates[yys]->yylrState));
}
@@ -2586,7 +2605,7 @@ b4_dollar_popdef])[]dnl
yyacceptlab:
yyresult = 0;
goto yyreturn;
goto yyreturnlab;
yybuglab:
YY_ASSERT (yyfalse);
@@ -2594,15 +2613,15 @@ b4_dollar_popdef])[]dnl
yyabortlab:
yyresult = 1;
goto yyreturn;
goto yyreturnlab;
yyexhaustedlab:
yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
yyresult = 2;
goto yyreturn;
goto yyreturnlab;
yyreturn:
if (yychar != ]b4_symbol(-2, id)[)
yyreturnlab:
if (yychar != ]b4_symbol(empty, id)[)
yydestruct ("Cleanup: discarding lookahead",
YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
@@ -2640,6 +2659,7 @@ b4_dollar_popdef])[]dnl
/* DEBUGGING ONLY */
#if ]b4_api_PREFIX[DEBUG
/* Print *YYS and its predecessors. */
static void
yy_yypstack (yyGLRState* yys)
{
@@ -2651,22 +2671,25 @@ yy_yypstack (yyGLRState* yys)
YY_FPRINTF ((stderr, "%d@@%ld", yys->yylrState, YY_CAST (long, yys->yyposn)));
}
/* Print YYS (possibly NULL) and its predecessors. */
static void
yypstates (yyGLRState* yyst)
yypstates (yyGLRState* yys)
{
if (yyst == YY_NULLPTR)
if (yys == YY_NULLPTR)
YY_FPRINTF ((stderr, "<null>"));
else
yy_yypstack (yyst);
yy_yypstack (yys);
YY_FPRINTF ((stderr, "\n"));
}
/* Print the stack #YYK. */
static void
yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk)
{
yypstates (yystackp->yytops.yystates[yyk]);
}
/* Print all the stacks. */
static void
yypdumpstack (yyGLRStack* yystackp)
{
+43 -43
View File
@@ -1,6 +1,6 @@
# C++ GLR skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This skeleton produces a C++ class that encapsulates a C glr parser.
@@ -78,7 +78,7 @@ m4_define([b4_yy_symbol_print_define],
static void
yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken,
const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[,
const ]b4_namespace_ref::b4_parser_class[::value_type *yyvaluep]b4_locations_if([[,
const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[)
{
]b4_parse_param_use[]dnl
@@ -144,7 +144,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
int
]b4_parser_class[::parse ()
{
return ::yyparse (*this]b4_user_args[);
return ::yy_parse_impl (*this]b4_user_args[);
}
#if ]b4_api_PREFIX[DEBUG
@@ -154,25 +154,25 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
void
]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
{]b4_locations_if([[
YYUSE (yylocationp);]])[
YYUSE (yyvaluep);
YY_USE (yylocationp);]])[
YY_USE (yyvaluep);
std::ostream& yyo = debug_stream ();
std::ostream& yyoutput = yyo;
YYUSE (yyoutput);
YY_USE (yyoutput);
]b4_symbol_actions([printer])[
}
void
]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
{
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << yytname[yykind] << " ("]b4_locations_if([[
<< ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[
<< *yylocationp << ": "]])[;
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
*yycdebug_ << ')';
@@ -221,15 +221,33 @@ m4_define([b4_define_symbol_kind],
# Setup redirections for glr.c: Map the names used in c.m4 to the ones used
# in c++.m4.
m4_define([b4_glr_cc_setup],
[[#undef ]b4_symbol(-2, [id])[
#define ]b4_symbol(-2, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(-2, [id])[
#undef ]b4_symbol(0, [id])[
#define ]b4_symbol(0, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[
#undef ]b4_symbol(1, [id])[
#define ]b4_symbol(1, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(1, [id])[
[[]b4_attribute_define[
]b4_null_define[
// This skeleton is based on C, yet compiles it as C++.
// So expect warnings about C style casts.
#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's
// -pedantic reports as being a C++11 extension.
#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \
&& defined __clang__ && 4 <= __clang_major__
# pragma clang diagnostic ignored "-Wc++11-long-long"
#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[::semantic_type
# 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
@@ -252,9 +270,9 @@ m4_define([b4_undef_symbol_kind],
# -----------------
# Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup],
[[#undef ]b4_symbol(-2, [id])[
#undef ]b4_symbol(0, [id])[
#undef ]b4_symbol(1, [id])[
[[#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
@@ -263,7 +281,7 @@ b4_symbol_foreach([b4_undef_symbol_kind])dnl
# b4_shared_declarations(hh|cc)
# -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh)
# 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
@@ -277,24 +295,6 @@ b4_percent_code_get([[requires]])[
[[# include ]b4_location_include])[
]b4_variant_if([b4_variant_includes])[
]b4_attribute_define[
]b4_null_define[
// This skeleton is based on C, yet compiles it as C++.
// So expect warnings about C style casts.
#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's
// -pedantic reports as being a C++11 extension.
#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \
&& defined __clang__ && 4 <= __clang_major__
# pragma clang diagnostic ignored "-Wc++11-long-long"
#endif
// Whether we are compiled with exception support.
#ifndef YY_EXCEPTIONS
# if defined __GNUC__ && !defined __EXCEPTIONS
@@ -355,14 +355,14 @@ b4_percent_code_get([[requires]])[
/// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[
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;
/// \brief Report a symbol on the debug stream.
/// \param yykind The symbol kind.
/// \param yyvaluep Its semantic value.]b4_locations_if([[
/// \param yylocationp Its location.]])[
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;
private:
/// Debug stream.
@@ -378,10 +378,10 @@ b4_percent_code_get([[requires]])[
]m4_popdef([b4_parse_param])dnl
])[
]b4_defines_if(
]b4_header_if(
[b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[
[2002-2015, 2018-2021])[
// C++ GLR parser skeleton written by Akim Demaille.
]b4_disclaimer[
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2,7 +2,7 @@
# Java skeleton dispatching for Bison.
# Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation,
# Copyright (C) 2007, 2009-2015, 2018-2021 Free Software Foundation,
# Inc.
# This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
b4_glr_if( [b4_complain([%%glr-parser not supported for Java])])
b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])])
+6 -6
View File
@@ -2,7 +2,7 @@
# Java language support for Bison
# Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2007-2015, 2018-2021 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
@@ -15,7 +15,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[c-like.m4])
@@ -71,12 +71,12 @@ m4_define([b4_lexer_if],
# b4_identification
# -----------------
m4_define([b4_identification],
[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "b4_version";
[[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "]b4_version_string[";
/** Name of the skeleton that generated this parser. */
public static final String bisonSkeleton = b4_skeleton;
])
public static final String bisonSkeleton = ]b4_skeleton[;
]])
## ------------ ##
+69 -57
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -13,15 +13,14 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[c++.m4])
# api.value.type=variant is valid.
m4_define([b4_value_type_setup_variant])
# Check the value of %define parse.lac, where LAC stands for lookahead
# correction.
# parse.lac
b4_percent_define_default([[parse.lac]], [[none]])
b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]])
b4_define_flag_if([lac])
@@ -146,21 +145,21 @@ b4_dollar_popdef[]dnl
])])
# b4_lex
# ------
# b4_yylex
# --------
# Call yylex.
m4_define([b4_lex],
m4_define([b4_yylex],
[b4_token_ctor_if(
[b4_function_call([yylex],
[symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
[b4_function_call([yylex], [int],
[b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl
b4_locations_if([, [[location*], [&yyla.location]]])dnl
[[value_type *], [&yyla.value]][]dnl
b4_locations_if([, [[location_type *], [&yyla.location]]])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
m4_pushdef([b4_copyright_years],
[2002-2015, 2018-2020])
[2002-2015, 2018-2021])
m4_define([b4_parser_class],
[b4_percent_define_get([[api.parser.class]])])
@@ -174,7 +173,7 @@ b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])])
# b4_shared_declarations(hh|cc)
# -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh)
# Declaration that might either go into the header (if --header, $1 = hh)
# or in the implementation file.
m4_define([b4_shared_declarations],
[b4_percent_code_get([[requires]])[
@@ -271,9 +270,9 @@ m4_define([b4_shared_declarations],
{
public:
context (const ]b4_parser_class[& yyparser, const symbol_type& yyla);
const symbol_type& lookahead () const { return yyla_; }
symbol_kind_type token () const { return yyla_.kind (); }]b4_locations_if([[
const location_type& location () const { return yyla_.location; }
const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[
const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
]])[
/// Put in YYARG at most YYARGN of the expected tokens, and return the
/// number of tokens stored in YYARG. If YYARG is null, return the
@@ -307,11 +306,11 @@ m4_define([b4_shared_declarations],
/// Stored state numbers (used for stacks).
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type;
]b4_parse_error_bmatch(
[custom], [[
[custom], [[
/// Report a syntax error
/// \param yyctx the context in which the error occurred.
void report_syntax_error (const context& yyctx) const;]],
[detailed\|verbose], [[
[detailed\|verbose], [[
/// The arguments of the error message.
int yy_syntax_error_arguments_ (const context& yyctx,
symbol_kind_type yyarg[], int yyargn) const;
@@ -408,7 +407,7 @@ m4_define([b4_shared_declarations],
void move (by_state& that);
/// The symbol kind (corresponding to \a state).
/// \a ]b4_symbol(-2, kind)[ when empty.
/// \a ]b4_symbol(empty, kind)[ when empty.
symbol_kind_type kind () const YY_NOEXCEPT;
/// The state number used to denote an empty symbol.
@@ -494,16 +493,21 @@ m4_define([b4_shared_declarations],
]b4_namespace_close[
]b4_percent_code_get([[provides]])[
]])
]])[
## -------------- ##
## Output files. ##
## -------------- ##
b4_defines_if(
[b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
[
# ------------- #
# Header file. #
# ------------- #
]b4_header_if([[
]b4_output_begin([b4_spec_header_file])[
]b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])[
/**
** \file ]b4_spec_mapped_header_file[
** Define the ]b4_namespace_ref[::parser class.
@@ -516,10 +520,14 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
]b4_shared_declarations(hh)[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[
]b4_output_end[
]])
]])[
b4_output_begin([b4_parser_file_name])[
# --------------------- #
# Implementation file. #
# --------------------- #
]b4_output_begin([b4_parser_file_name])[
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[
]b4_disclaimer[
]b4_percent_code_get([[top]])[]dnl
@@ -530,7 +538,7 @@ m4_if(b4_prefix, [yy], [],
]b4_user_pre_prologue[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations([cc])])[
]b4_user_post_prologue[
@@ -597,7 +605,7 @@ m4_if(b4_prefix, [yy], [],
#else // !]b4_api_PREFIX[DEBUG
# define YYCDEBUG if (false) std::cerr
# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE (Symbol)
# define YY_SYMBOL_PRINT(Title, Symbol) YY_USE (Symbol)
# define YY_REDUCE_PRINT(Rule) static_cast<void> (0)
# define YY_STACK_PRINT() static_cast<void> (0)
@@ -665,7 +673,7 @@ m4_if(b4_prefix, [yy], [],
]b4_parser_class[::by_state::kind () const YY_NOEXCEPT
{
if (state == empty_state)
return ]b4_symbol(-2, kind)[;
return ]b4_symbol(empty, kind)[;
else
return YY_CAST (symbol_kind_type, yystos_[+state]);
}
@@ -690,7 +698,7 @@ m4_if(b4_prefix, [yy], [],
b4_symbol_variant([that.kind ()],
[value], [move], [YY_MOVE (that.value)])])[
// that is emptied.
that.kind_ = ]b4_symbol(-2, kind)[;
that.kind_ = ]b4_symbol(empty, kind)[;
}
#if YY_CPLUSPLUS < 201103L
@@ -736,7 +744,7 @@ m4_if(b4_prefix, [yy], [],
]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const
{
std::ostream& yyoutput = yyo;
YYUSE (yyoutput);
YY_USE (yyoutput);
if (yysym.empty ())
yyo << "empty symbol";
else
@@ -851,8 +859,8 @@ m4_if(b4_prefix, [yy], [],
/// The return value of parse ().
int yyresult;]b4_lac_if([[
/// Discard the LAC context in case there still is one left from a
/// previous invocation.
// Discard the LAC context in case there still is one left from a
// previous invocation.
yy_lac_discard_ ("init");]])[
#if YY_EXCEPTIONS
@@ -904,9 +912,9 @@ b4_dollar_popdef])[]dnl
try
#endif // YY_EXCEPTIONS
{]b4_token_ctor_if([[
symbol_type yylookahead (]b4_lex[);
symbol_type yylookahead (]b4_yylex[);
yyla.move (yylookahead);]], [[
yyla.kind_ = yytranslate_ (]b4_lex[);]])[
yyla.kind_ = yytranslate_ (]b4_yylex[);]])[
}
#if YY_EXCEPTIONS
catch (const syntax_error& yyexc)
@@ -919,13 +927,13 @@ b4_dollar_popdef])[]dnl
}
YY_SYMBOL_PRINT ("Next token is", yyla);
if (yyla.kind () == ]b4_symbol(1, kind)[)
if (yyla.kind () == ]b4_symbol(error, kind)[)
{
// The scanner already issued an error message, process directly
// to error recovery. But do not keep the error token as
// lookahead, it is too special and may lead us to an endless
// loop in error recovery. */
yyla.kind_ = ]b4_symbol(2, kind)[;
yyla.kind_ = ]b4_symbol(undef, kind)[;
goto yyerrlab1;
}
@@ -935,7 +943,7 @@ b4_dollar_popdef])[]dnl
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ())
{]b4_lac_if([[
if (!yy_lac_establish_ (yyla.kind ()))
goto yyerrlab;]])[
goto yyerrlab;]])[
goto yydefault;
}
@@ -946,7 +954,7 @@ b4_dollar_popdef])[]dnl
if (yy_table_value_is_error_ (yyn))
goto yyerrlab;]b4_lac_if([[
if (!yy_lac_establish_ (yyla.kind ()))
goto yyerrlab;
goto yyerrlab;
]])[
yyn = -yyn;
goto yyreduce;
@@ -979,11 +987,11 @@ b4_dollar_popdef])[]dnl
yylen = yyr2_[yyn];
{
stack_symbol_type yylhs;
yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([
yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([[
/* Variants are always initialized to an empty instance of the
correct type. The default '$$ = $1' action is NOT applied
when using variants. */
b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [
]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [[
/* If YYLEN is nonzero, implement the default value of the
action: '$$ = $1'. Otherwise, use the top of the stack.
@@ -993,7 +1001,7 @@ b4_dollar_popdef])[]dnl
if (yylen)
yylhs.value = yystack_@{yylen - 1@}.value;
else
yylhs.value = yystack_@{0@}.value;])[
yylhs.value = yystack_@{0@}.value;]])[
]b4_locations_if([dnl
[
// Default location.
@@ -1062,7 +1070,7 @@ b4_dollar_popdef])[]dnl
error, discard it. */
// Return failure if at end of input.
if (yyla.kind () == ]b4_symbol(0, kind)[)
if (yyla.kind () == ]b4_symbol(eof, kind)[)
YYABORT;
else if (!yyla.empty ())
{
@@ -1103,9 +1111,9 @@ b4_dollar_popdef])[]dnl
yyn = yypact_[+yystack_[0].state];
if (!yy_pact_value_is_default_ (yyn))
{
yyn += ]b4_symbol(1, kind)[;
yyn += ]b4_symbol(error, kind)[;
if (0 <= yyn && yyn <= yylast_
&& yycheck_[yyn] == ]b4_symbol(1, kind)[)
&& yycheck_[yyn] == ]b4_symbol(error, kind)[)
{
yyn = yytable_[yyn];
if (0 < yyn)
@@ -1297,8 +1305,8 @@ b4_dollar_popdef])[]dnl
for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
{
symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
if (yysym != ]b4_symbol(1, kind)[
&& yysym != ]b4_symbol(2, kind)[
if (yysym != ]b4_symbol(error, kind)[
&& yysym != ]b4_symbol(undef, kind)[
&& yyparser_.yy_lac_check_ (yysym))
{
if (!yyarg)
@@ -1309,18 +1317,18 @@ b4_dollar_popdef])[]dnl
yyarg[yycount++] = yysym;
}
}]], [[
int yyn = yypact_[+yyparser_.yystack_[0].state];
const int yyn = yypact_[+yyparser_.yystack_[0].state];
if (!yy_pact_value_is_default_ (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
const int yyxbegin = yyn < 0 ? -yyn : 0;
// Stay within bounds of both yycheck and yytname.
int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
const int yychecklim = yylast_ - yyn + 1;
const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
{
if (!yyarg)
@@ -1333,11 +1341,13 @@ b4_dollar_popdef])[]dnl
}
]])[
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = ]b4_symbol(-2, kind)[;
yyarg[0] = ]b4_symbol(empty, kind)[;
return yycount;
}
]])b4_lac_if([[
]])[
]b4_lac_if([[
bool
]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const
{
@@ -1442,7 +1452,9 @@ b4_dollar_popdef])[]dnl
follows. If no initial context is currently established for the
current lookahead, then check if that lookahead can eventually be
shifted if syntactic actions continue from the current context. */
if (!yy_lac_established_)
if (yy_lac_established_)
return true;
else
{
#if ]b4_api_PREFIX[DEBUG
YYCDEBUG << "LAC: initial context established for "
@@ -1451,12 +1463,11 @@ b4_dollar_popdef])[]dnl
yy_lac_established_ = true;
return yy_lac_check_ (yytoken);
}
return true;
}
// Discard any previous initial lookahead context.
void
]b4_parser_class[::yy_lac_discard_ (const char* evt)
]b4_parser_class[::yy_lac_discard_ (const char* event)
{
/* Discard any previous initial lookahead context because of Event,
which may be a lookahead change or an invalidation of the currently
@@ -1472,11 +1483,12 @@ b4_dollar_popdef])[]dnl
if (yy_lac_established_)
{
YYCDEBUG << "LAC: initial context discarded due to "
<< evt << '\n';
<< event << '\n';
yy_lac_established_ = false;
}
}]])b4_parse_error_bmatch([detailed\|verbose], [[
}]])[
]b4_parse_error_bmatch([detailed\|verbose], [[
int
]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx,
symbol_kind_type yyarg[], int yyargn) const
+668 -265
View File
File diff suppressed because it is too large Load Diff
+299 -106
View File
@@ -1,6 +1,6 @@
# Java skeleton for Bison -*- autoconf -*-
# Java skeleton for Bison -*- java -*-
# Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2007-2015, 2018-2021 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
@@ -13,11 +13,11 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[java.m4])
b4_defines_if([b4_complain([%defines does not make sense in Java])])
b4_header_if([b4_complain([%header/%defines does not make sense in Java])])
m4_define([b4_symbol_no_destructor_assert],
[b4_symbol_if([$1], [has_destructor],
@@ -25,7 +25,10 @@ m4_define([b4_symbol_no_destructor_assert],
[%destructor does not make sense in Java])])])
b4_symbol_foreach([b4_symbol_no_destructor_assert])
# Setup some macros for api.push-pull.
## --------------- ##
## api.push-pull. ##
## --------------- ##
b4_percent_define_default([[api.push-pull]], [[pull]])
b4_percent_define_check_values([[[[api.push-pull]],
[[pull]], [[push]], [[both]]]])
@@ -52,7 +55,8 @@ b4_use_push_for_pull_if([
# Define a macro to encapsulate the parse state variables. This
# allows them to be defined either in parse() when doing pull parsing,
# or as class instance variable when doing push parsing.
m4_define([b4_define_state],[[
m4_define([b4_define_state],
[[
/* Lookahead token kind. */
int yychar = YYEMPTY_;
/* Lookahead symbol kind. */
@@ -74,17 +78,31 @@ m4_define([b4_define_state],[[
/* Semantic value of the lookahead. */
]b4_yystype[ yylval = null;
]])[
]])
]b4_output_begin([b4_parser_file_name])[
# parse.lac
b4_percent_define_default([[parse.lac]], [[none]])
b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]])
b4_define_flag_if([lac])
m4_define([b4_lac_flag],
[m4_if(b4_percent_define_get([[parse.lac]]),
[none], [[0]], [[1]])])
## ------------- ##
## Parser File. ##
## ------------- ##
b4_output_begin([b4_parser_file_name])[
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
[2007-2015, 2018-2020])[
[2007-2015, 2018-2021])[
]b4_disclaimer[
]b4_percent_define_ifdef([api.package], [package b4_percent_define_get([api.package]);[
]])[
]b4_user_pre_prologue[
]b4_user_post_prologue[
import java.text.MessageFormat;
import java.util.ArrayList;
]b4_percent_code_get([[imports]])[
/**
* A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
@@ -157,11 +175,11 @@ import java.text.MessageFormat;
* <code>]b4_position_type[</code> should override the <code>equals</code>
* method.
*/
public String toString () {
public String toString() {
if (begin.equals (end))
return begin.toString ();
return begin.toString();
else
return begin.toString () + "-" + end.toString ();
return begin.toString() + "-" + end.toString();
}
}
@@ -181,8 +199,8 @@ import java.text.MessageFormat;
*/
public interface Lexer {
]b4_token_enums[
/** Deprecated, use ]b4_symbol(0, id)[ instead. */
public static final int EOF = ]b4_symbol(0, id)[;
/** Deprecated, use ]b4_symbol(eof, id)[ instead. */
public static final int EOF = ]b4_symbol(eof, id)[;
]b4_pull_if([b4_locations_if([[
/**
* Method to retrieve the beginning position of the last scanned token.
@@ -226,7 +244,7 @@ import java.text.MessageFormat;
*
* @@param ctx The context of the error.
*/
void reportSyntaxError (][Context ctx);
void reportSyntaxError(Context ctx);
]])[
}
@@ -247,10 +265,12 @@ import java.text.MessageFormat;
/**
* Instantiates the Bison-generated parser.
*/
public ]b4_parser_class (b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[
public ]b4_parser_class[(]b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[
{
]b4_percent_code_get([[init]])[
this.yylexer = new YYLexer (]b4_lex_param_call[);
]b4_percent_code_get([[init]])[]b4_lac_if([[
this.yylacStack = new ArrayList<Integer>();
this.yylacEstablished = false;]])[
this.yylexer = new YYLexer(]b4_lex_param_call[);
]b4_parse_param_cons[
}
]])[
@@ -259,9 +279,11 @@ import java.text.MessageFormat;
* Instantiates the Bison-generated parser.
* @@param yylexer The scanner that will supply tokens to the parser.
*/
]b4_lexer_if([[protected]], [[public]]) b4_parser_class[ (]b4_parse_param_decl([[Lexer yylexer]])[)]b4_maybe_throws([b4_init_throws])[
]b4_lexer_if([[protected]], [[public]]) b4_parser_class[(]b4_parse_param_decl([[Lexer yylexer]])[)]b4_maybe_throws([b4_init_throws])[
{
]b4_percent_code_get([[init]])[
]b4_percent_code_get([[init]])[]b4_lac_if([[
this.yylacStack = new ArrayList<Integer>();
this.yylacEstablished = false;]])[
this.yylexer = yylexer;
]b4_parse_param_cons[
}
@@ -272,13 +294,13 @@ import java.text.MessageFormat;
/**
* The <tt>PrintStream</tt> on which the debugging output is printed.
*/
public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
public final java.io.PrintStream getDebugStream() { return yyDebugStream; }
/**
* Set the <tt>PrintStream</tt> on which the debug output is printed.
* @@param s The stream that is used for debugging output.
*/
public final void setDebugStream (java.io.PrintStream s) { yyDebugStream = s; }
public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
private int yydebug = 0;
@@ -286,14 +308,14 @@ import java.text.MessageFormat;
* Answer the verbosity of the debugging output; 0 means that all kinds of
* output from the parser are suppressed.
*/
public final int getDebugLevel () { return yydebug; }
public final int getDebugLevel() { return yydebug; }
/**
* Set the verbosity of the debugging output; 0 means that all kinds of
* output from the parser are suppressed.
* @@param level The verbosity level for debugging output.
*/
public final void setDebugLevel (int level) { yydebug = level; }
public final void setDebugLevel(int level) { yydebug = level; }
]])[
private int yynerrs = 0;
@@ -301,7 +323,7 @@ import java.text.MessageFormat;
/**
* The number of syntax errors so far.
*/
public final int getNumberOfErrors () { return yynerrs; }
public final int getNumberOfErrors() { return yynerrs; }
/**
* Print an error message via the lexer.
@@ -330,9 +352,14 @@ import java.text.MessageFormat;
yylexer.yyerror(new ]b4_location_type[ (pos), msg);
}]])[
]b4_parse_trace_if([[
protected final void yycdebug (String s) {
protected final void yycdebugNnl(String s) {
if (0 < yydebug)
yyDebugStream.println (s);
yyDebugStream.print(s);
}
protected final void yycdebug(String s) {
if (0 < yydebug)
yyDebugStream.println(s);
}]])[
private final class YYStack {
@@ -343,65 +370,63 @@ import java.text.MessageFormat;
public int size = 16;
public int height = -1;
public final void push (int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
height++;
if (size == height)
{
int[] newStateStack = new int[size * 2];
System.arraycopy (stateStack, 0, newStateStack, 0, height);
stateStack = newStateStack;]b4_locations_if([[
]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
System.arraycopy (locStack, 0, newLocStack, 0, height);
locStack = newLocStack;]])
if (size == height) {
int[] newStateStack = new int[size * 2];
System.arraycopy(stateStack, 0, newStateStack, 0, height);
stateStack = newStateStack;]b4_locations_if([[
]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
System.arraycopy(locStack, 0, newLocStack, 0, height);
locStack = newLocStack;]])
b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
System.arraycopy (valueStack, 0, newValueStack, 0, height);
valueStack = newValueStack;
b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
System.arraycopy(valueStack, 0, newValueStack, 0, height);
valueStack = newValueStack;
size *= 2;
}
size *= 2;
}
stateStack[height] = state;]b4_locations_if([[
locStack[height] = loc;]])[
valueStack[height] = value;
}
public final void pop () {
pop (1);
public final void pop() {
pop(1);
}
public final void pop (int num) {
public final void pop(int num) {
// Avoid memory leaks... garbage collection is a white lie!
if (0 < num) {
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);]b4_locations_if([[
java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);]b4_locations_if([[
java.util.Arrays.fill(locStack, height - num + 1, height + 1, null);]])[
}
height -= num;
}
public final int stateAt (int i) {
public final int stateAt(int i) {
return stateStack[height - i];
}
]b4_locations_if([[
public final ]b4_location_type[ locationAt (int i) {
public final ]b4_location_type[ locationAt(int i) {
return locStack[height - i];
}
]])[
public final ]b4_yystype[ valueAt (int i) {
public final ]b4_yystype[ valueAt(int i) {
return valueStack[height - i];
}
// Print the state stack on the debug stream.
public void print (java.io.PrintStream out) {
public void print(java.io.PrintStream out) {
out.print ("Stack now");
for (int i = 0; i <= height; i++)
{
out.print (' ');
out.print (stateStack[i]);
}
out.println ();
for (int i = 0; i <= height; i++) {
out.print(' ');
out.print(stateStack[i]);
}
out.println();
}
}
@@ -458,8 +483,7 @@ import java.text.MessageFormat;
* @@param yystate the current state
* @@param yysym the nonterminal to push on the stack
*/
private int yyLRGotoState (int yystate, int yysym)
{
private int yyLRGotoState(int yystate, int yysym) {
int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate;
if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate)
return yytable_[yyr];
@@ -536,7 +560,12 @@ import java.text.MessageFormat;
/* @@$. */
]b4_location_type[ yyloc;]])[
]b4_push_if([],[[
]b4_define_state[]b4_parse_trace_if([[
]b4_define_state[
]b4_lac_if([[
// Discard the LAC context in case there still is one left from a
// previous invocation.
yylacDiscard("init");]])[
]b4_parse_trace_if([[
yycdebug ("Starting parse");]])[
yyerrstatus_ = 0;
yynerrs = 0;
@@ -614,14 +643,14 @@ b4_dollar_popdef[]dnl
yySymbolPrint("Next token is", yytoken,
yylval]b4_locations_if([, yylloc])[);]])[
if (yytoken == ]b4_symbol(1, kind)[)
if (yytoken == ]b4_symbol(error, kind)[)
{
// The scanner already issued an error message, process directly
// to error recovery. But do not keep the error token as
// lookahead, it is too special and may lead us to an endless
// loop in error recovery. */
yychar = Lexer.]b4_symbol(2, id)[;
yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[
yychar = Lexer.]b4_symbol(undef, id)[;
yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
yyerrloc = yylloc;]])[
label = YYERRLAB1;
}
@@ -630,19 +659,24 @@ b4_dollar_popdef[]dnl
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken.getCode();
if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode())
if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) {]b4_lac_if([[
if (!yylacEstablish(yystack, yytoken)) {
label = YYERRLAB;
} else]])[
label = YYDEFAULT;
}
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
if (yyTableValueIsError (yyn))
if (yyTableValueIsError(yyn)) {
label = YYERRLAB;
else
{
yyn = -yyn;
label = YYREDUCE;
}
}]b4_lac_if([[ else if (!yylacEstablish(yystack, yytoken)) {
label = YYERRLAB;
}]])[ else {
yyn = -yyn;
label = YYREDUCE;
}
}
else
@@ -660,7 +694,8 @@ b4_dollar_popdef[]dnl
--yyerrstatus_;
yystate = yyn;
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
yystack.push(yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[
yylacDiscard("shift");]])[
label = YYNEWSTATE;
}
}
@@ -683,7 +718,7 @@ b4_dollar_popdef[]dnl
case YYREDUCE:
yylen = yyr2_[yyn];
label = yyaction(yyn, yystack, yylen);
yystate = yystack.stateAt (0);
yystate = yystack.stateAt(0);
break;
/*------------------------------------.
@@ -696,7 +731,7 @@ b4_dollar_popdef[]dnl
++yynerrs;
if (yychar == YYEMPTY_)
yytoken = null;
yyreportSyntaxError (new Context (yystack, yytoken]b4_locations_if([[, yylloc]])[));
yyreportSyntaxError(new Context(this, yystack, yytoken]b4_locations_if([[, yylloc]])[));
}
]b4_locations_if([[
yyerrloc = yylloc;]])[
@@ -705,10 +740,10 @@ b4_dollar_popdef[]dnl
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= Lexer.]b4_symbol(0, id)[)
if (yychar <= Lexer.]b4_symbol(eof, id)[)
{
/* Return failure if at end of input. */
if (yychar == Lexer.]b4_symbol(0, id)[)
if (yychar == Lexer.]b4_symbol(eof, id)[)
]b4_push_if([{label = YYABORT; break;}], [return false;])[
}
else
@@ -729,7 +764,7 @@ b4_dollar_popdef[]dnl
this YYERROR. */
yystack.pop (yylen);
yylen = 0;
yystate = yystack.stateAt (0);
yystate = yystack.stateAt(0);
label = YYERRLAB1;
break;
@@ -745,9 +780,9 @@ b4_dollar_popdef[]dnl
yyn = yypact_[yystate];
if (!yyPactValueIsDefault (yyn))
{
yyn += ]b4_symbol(1, kind)[.getCode();
yyn += ]b4_symbol(error, kind)[.getCode();
if (0 <= yyn && yyn <= YYLAST_
&& yycheck_[yyn] == ]b4_symbol(1, kind)[.getCode())
&& yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode())
{
yyn = yytable_[yyn];
if (0 < yyn)
@@ -763,7 +798,7 @@ b4_dollar_popdef[]dnl
]b4_locations_if([[
yyerrloc = yystack.locationAt (0);]])[
yystack.pop ();
yystate = yystack.stateAt (0);]b4_parse_trace_if([[
yystate = yystack.stateAt(0);]b4_parse_trace_if([[
if (0 < yydebug)
yystack.print (yyDebugStream);]])[
}
@@ -779,7 +814,8 @@ b4_dollar_popdef[]dnl
yyloc = yylloc (yystack, 2);
yystack.pop (2);]])[
/* Shift the error token. */]b4_parse_trace_if([[
/* Shift the error token. */]b4_lac_if([[
yylacDiscard("error recovery");]])[]b4_parse_trace_if([[
yySymbolPrint("Shifting", SymbolKind.get(yystos_[yyn]),
yylval]b4_locations_if([, yyloc])[);]])[
@@ -815,7 +851,9 @@ b4_dollar_popdef[]dnl
this.yyn = 0;
this.yylen = 0;
this.yystate = 0;
this.yystack = new YYStack ();
this.yystack = new YYStack();]b4_lac_if([[
this.yylacStack = new ArrayList<Integer>();
this.yylacEstablished = false;]])[
this.label = YYNEWSTATE;
/* Error handling. */
@@ -875,23 +913,22 @@ b4_dollar_popdef[]dnl
* Information needed to get the list of expected tokens and to forge
* a syntax error diagnostic.
*/
public static final class Context
{
Context (YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[)
{
public static final class Context {
Context(]b4_parser_class[ parser, YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[) {
yyparser = parser;
yystack = stack;
yytoken = token;]b4_locations_if([[
yylocation = loc;]])[
}
private ]b4_parser_class[ yyparser;
private YYStack yystack;
/**
* The symbol kind of the lookahead token.
*/
public final SymbolKind getToken ()
{
public final SymbolKind getToken() {
return yytoken;
}
@@ -900,8 +937,7 @@ b4_dollar_popdef[]dnl
/**
* The location of the lookahead.
*/
public final ]b4_location_type[ getLocation ()
{
public final ]b4_location_type[ getLocation() {
return yylocation;
}
@@ -914,16 +950,34 @@ b4_dollar_popdef[]dnl
* YYARG is null, return the number of expected tokens (guaranteed to
* be less than YYNTOKENS).
*/
int getExpectedTokens (SymbolKind yyarg[], int yyargn)
{
int getExpectedTokens(SymbolKind yyarg[], int yyargn) {
return getExpectedTokens (yyarg, 0, yyargn);
}
int getExpectedTokens (SymbolKind yyarg[], int yyoffset, int yyargn)
{
int yycount = yyoffset;
int yyn = yypact_[this.yystack.stateAt (0)];
if (!yyPactValueIsDefault (yyn))
int getExpectedTokens(SymbolKind yyarg[], int yyoffset, int yyargn) {
int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[
// Execute LAC once. We don't care if it is successful, we
// only do it for the sake of debugging output.
if (!yyparser.yylacEstablished)
yyparser.yylacCheck(yystack, yytoken);
]])[
for (int yyx = 0; yyx < YYNTOKENS_; ++yyx)
{
SymbolKind yysym = SymbolKind.get(yyx);
if (yysym != ]b4_symbol(error, kind)[
&& yysym != ]b4_symbol(undef, kind)[
&& yyparser.yylacCheck(yystack, yysym))
{
if (yyarg == null)
yycount += 1;
else if (yycount == yyargn)
return 0;
else
yyarg[yycount++] = yysym;
}
}]], [[
int yyn = yypact_[this.yystack.stateAt(0)];
if (!yyPactValueIsDefault(yyn))
{
/* Start YYX at -YYN if negative to avoid negative
indexes in YYCHECK. In other words, skip the first
@@ -934,7 +988,7 @@ b4_dollar_popdef[]dnl
int yychecklim = YYLAST_ - yyn + 1;
int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[.getCode()
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[.getCode()
&& !yyTableValueIsError(yytable_[yyx + yyn]))
{
if (yyarg == null)
@@ -944,17 +998,158 @@ b4_dollar_popdef[]dnl
else
yyarg[yycount++] = SymbolKind.get(yyx);
}
}
}]])[
if (yyarg != null && yycount == yyoffset && yyoffset < yyargn)
yyarg[yycount] = null;
return yycount - yyoffset;
}
}
]b4_lac_if([[
/** Check the lookahead yytoken.
* \returns true iff the token will be eventually shifted.
*/
boolean yylacCheck(YYStack yystack, SymbolKind yytoken)
{
// Logically, the yylacStack's lifetime is confined to this function.
// Clear it, to get rid of potential left-overs from previous call.
yylacStack.clear();
// Reduce until we encounter a shift and thereby accept the token.
yycdebugNnl("LAC: checking lookahead " + yytoken.getName() + ":");
int lacTop = 0;
while (true)
{
int topState = (yylacStack.isEmpty()
? yystack.stateAt(lacTop)
: yylacStack.get(yylacStack.size() - 1));
int yyrule = yypact_[topState];
if (yyPactValueIsDefault(yyrule)
|| (yyrule += yytoken.getCode()) < 0 || YYLAST_ < yyrule
|| yycheck_[yyrule] != yytoken.getCode())
{
// Use the default action.
yyrule = yydefact_[+topState];
if (yyrule == 0) {
yycdebug(" Err");
return false;
}
}
else
{
// Use the action from yytable.
yyrule = yytable_[yyrule];
if (yyTableValueIsError(yyrule)) {
yycdebug(" Err");
return false;
}
if (0 < yyrule) {
yycdebug(" S" + yyrule);
return true;
}
yyrule = -yyrule;
}
// By now we know we have to simulate a reduce.
yycdebugNnl(" R" + (yyrule - 1));
// Pop the corresponding number of values from the stack.
{
int yylen = yyr2_[yyrule];
// First pop from the LAC stack as many tokens as possible.
int lacSize = yylacStack.size();
if (yylen < lacSize) {
// yylacStack.setSize(lacSize - yylen);
for (/* Nothing */; 0 < yylen; yylen -= 1) {
yylacStack.remove(yylacStack.size() - 1);
}
yylen = 0;
} else if (lacSize != 0) {
yylacStack.clear();
yylen -= lacSize;
}
// Only afterwards look at the main stack.
// We simulate popping elements by incrementing lacTop.
lacTop += yylen;
}
// Keep topState in sync with the updated stack.
topState = (yylacStack.isEmpty()
? yystack.stateAt(lacTop)
: yylacStack.get(yylacStack.size() - 1));
// Push the resulting state of the reduction.
int state = yyLRGotoState(topState, yyr1_[yyrule]);
yycdebugNnl(" G" + state);
yylacStack.add(state);
}
}
/** Establish the initial context if no initial context currently exists.
* \returns true iff the token will be eventually shifted.
*/
boolean yylacEstablish(YYStack yystack, SymbolKind yytoken) {
/* Establish the initial context for the current lookahead if no initial
context is currently established.
We define a context as a snapshot of the parser stacks. We define
the initial context for a lookahead as the context in which the
parser initially examines that lookahead in order to select a
syntactic action. Thus, if the lookahead eventually proves
syntactically unacceptable (possibly in a later context reached via a
series of reductions), the initial context can be used to determine
the exact set of tokens that would be syntactically acceptable in the
lookahead's place. Moreover, it is the context after which any
further semantic actions would be erroneous because they would be
determined by a syntactically unacceptable token.
yylacEstablish should be invoked when a reduction is about to be
performed in an inconsistent state (which, for the purposes of LAC,
includes consistent states that don't know they're consistent because
their default reductions have been disabled).
For parse.lac=full, the implementation of yylacEstablish is as
follows. If no initial context is currently established for the
current lookahead, then check if that lookahead can eventually be
shifted if syntactic actions continue from the current context. */
if (yylacEstablished) {
return true;
} else {
yycdebug("LAC: initial context established for " + yytoken.getName());
yylacEstablished = true;
return yylacCheck(yystack, yytoken);
}
}
/** Discard any previous initial lookahead context because of event.
* \param event the event which caused the lookahead to be discarded.
* Only used for debbuging output. */
void yylacDiscard(String event) {
/* Discard any previous initial lookahead context because of Event,
which may be a lookahead change or an invalidation of the currently
established initial context for the current lookahead.
The most common example of a lookahead change is a shift. An example
of both cases is syntax error recovery. That is, a syntax error
occurs when the lookahead is syntactically erroneous for the
currently established initial context, so error recovery manipulates
the parser stacks to try to find a new initial context in which the
current lookahead is syntactically acceptable. If it fails to find
such a context, it discards the lookahead. */
if (yylacEstablished) {
yycdebug("LAC: initial context discarded due to " + event);
yylacEstablished = false;
}
}
/** The stack for LAC.
* Logically, the yylacStack's lifetime is confined to the function
* yylacCheck. We just store it as a member of this class to hold
* on to the memory and to avoid frequent reallocations.
*/
ArrayList<Integer> yylacStack;
/** Whether an initial LAC context was established. */
boolean yylacEstablished;
]])[
]b4_parse_error_bmatch(
[detailed\|verbose], [[
private int yysyntaxErrorArguments (Context yyctx, SymbolKind[] yyarg, int yyargn)
{
private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) {
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action,
then the only way this function was invoked is if the
@@ -1032,8 +1227,7 @@ b4_dollar_popdef[]dnl
* Whether the given <code>yypact_</code> value indicates a defaulted state.
* @@param yyvalue the value to check
*/
private static boolean yyPactValueIsDefault (int yyvalue)
{
private static boolean yyPactValueIsDefault(int yyvalue) {
return yyvalue == yypact_ninf_;
}
@@ -1042,8 +1236,7 @@ b4_dollar_popdef[]dnl
* value indicates a syntax error.
* @@param yyvalue the value to check
*/
private static boolean yyTableValueIsError (int yyvalue)
{
private static boolean yyTableValueIsError(int yyvalue) {
return yyvalue == yytable_ninf_;
}
@@ -1072,7 +1265,7 @@ b4_dollar_popdef[]dnl
/* The symbols being reduced. */
for (int yyi = 0; yyi < yynrhs; yyi++)
yySymbolPrint(" $" + (yyi + 1) + " =",
SymbolKind.get(yystos_[yystack.stateAt (yynrhs - (yyi + 1))]),
SymbolKind.get(yystos_[yystack.stateAt(yynrhs - (yyi + 1))]),
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
b4_rhs_location(yynrhs, yyi + 1)])[);
}]])[
@@ -1089,11 +1282,11 @@ b4_dollar_popdef[]dnl
// Last valid token kind.
int code_max = ]b4_code_max[;
if (t <= 0)
return ]b4_symbol(0, kind)[;
return ]b4_symbol(eof, kind)[;
else if (t <= code_max)
return SymbolKind.get(yytranslate_table_[t]);
else
return ]b4_symbol(2, kind)[;
return ]b4_symbol(undef, kind)[;
}
]b4_integral_parser_table_define([translate_table], [b4_translate])[
]])[
+14 -11
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -13,17 +13,10 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_pushdef([b4_copyright_years],
[2002-2015, 2018-2020])
# 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])])])])
[2002-2015, 2018-2021])
# b4_location_file
@@ -32,7 +25,7 @@ b4_defines_if([b4_required_version_if([302], [],
# if we want this file.
b4_percent_define_check_file([b4_location_file],
[[api.location.file]],
b4_defines_if([[location.hh]]))
b4_header_if([[location.hh]]))
# b4_location_include
# -------------------
@@ -54,6 +47,16 @@ m4_ifdef([b4_location_file],
])
# 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
# ------------------
+4 -4
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -13,14 +13,14 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# b4_stack_file
# -------------
# Name of the file containing the stack class, if we want this file.
b4_defines_if([b4_required_version_if([302], [],
[m4_define([b4_stack_file], [stack.hh])])])
b4_header_if([b4_required_version_if([30200], [],
[m4_define([b4_stack_file], [stack.hh])])])
# b4_stack_define
+131 -69
View File
@@ -1,6 +1,6 @@
# C++ skeleton for Bison
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2002-2015, 2018-2021 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
@@ -13,13 +13,20 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## --------- ##
## variant. ##
## --------- ##
# b4_assert
# ---------
# The name of YY_ASSERT.
m4_define([b4_assert],
[b4_api_PREFIX[]_ASSERT])
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
# ------------------------------------------------
# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
@@ -71,12 +78,12 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl
# -------------------
# The needed includes for variants support.
m4_define([b4_variant_includes],
[b4_parse_assert_if([[#include <typeinfo>]])[
#ifndef YY_ASSERT
[b4_parse_assert_if([[#include <typeinfo>
#ifndef ]b4_assert[
# include <cassert>
# define YY_ASSERT assert
# define ]b4_assert[ assert
#endif
]])
]])])
@@ -87,45 +94,45 @@ m4_define([b4_variant_includes],
# b4_value_type_declare
# ---------------------
# Define semantic_type.
# Define value_type.
m4_define([b4_value_type_declare],
[[ /// A buffer to store and retrieve objects.
///
/// Sort of a variant, but does not keep track of the nature
/// of the stored data, since that knowledge is available
/// via the current parser state.
class semantic_type
class value_type
{
public:
/// Type of *this.
typedef semantic_type self_type;
typedef value_type self_type;
/// Empty construction.
semantic_type () YY_NOEXCEPT
: yybuffer_ ()]b4_parse_assert_if([
value_type () YY_NOEXCEPT
: yyraw_ ()]b4_parse_assert_if([
, yytypeid_ (YY_NULLPTR)])[
{}
/// Construct and fill.
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))])[
{
YY_ASSERT (sizeof (T) <= size);
{]b4_parse_assert_if([[
]b4_assert[ (sizeof (T) <= size);]])[
new (yyas_<T> ()) T (YY_MOVE (t));
}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
semantic_type (const self_type&) = delete;
value_type (const self_type&) = delete;
/// Non copyable.
self_type& operator= (const self_type&) = delete;
#endif
/// Destruction, allowed only if empty.
~semantic_type () YY_NOEXCEPT
~value_type () YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
]b4_assert[ (!yytypeid_);
])[}
# if 201103L <= YY_CPLUSPLUS
@@ -133,10 +140,10 @@ m4_define([b4_value_type_declare],
template <typename T, typename... U>
T&
emplace (U&&... u)
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (std::forward <U>(u)...);
}
# else
@@ -144,10 +151,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace ()
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T ();
}
@@ -155,10 +162,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace (const T& t)
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (t);
}
# endif
@@ -185,10 +192,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
as () YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -196,10 +203,10 @@ m4_define([b4_value_type_declare],
template <typename T>
const T&
as () const YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -214,9 +221,9 @@ m4_define([b4_value_type_declare],
template <typename T>
void
swap (self_type& that) YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == *that.yytypeid_);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[
std::swap (as<T> (), that.as<T> ());
}
@@ -267,7 +274,7 @@ m4_define([b4_value_type_declare],
private:
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
semantic_type (const self_type&);
value_type (const self_type&);
/// Non copyable.
self_type& operator= (const self_type&);
#endif
@@ -277,7 +284,7 @@ m4_define([b4_value_type_declare],
T*
yyas_ () YY_NOEXCEPT
{
void *yyp = yybuffer_.yyraw;
void *yyp = yyraw_;
return static_cast<T*> (yyp);
}
@@ -286,7 +293,7 @@ m4_define([b4_value_type_declare],
const T*
yyas_ () const YY_NOEXCEPT
{
const void *yyp = yybuffer_.yyraw;
const void *yyp = yyraw_;
return static_cast<const T*> (yyp);
}
@@ -301,10 +308,10 @@ m4_define([b4_value_type_declare],
union
{
/// Strongest alignment constraints.
long double yyalign_me;
long double yyalign_me_;
/// A buffer large enough to store any of the semantic values.
char yyraw[size];
} yybuffer_;]b4_parse_assert_if([
char yyraw_[size];
};]b4_parse_assert_if([
/// Whether the content is built: if defined, the name of the stored type.
const std::type_info *yytypeid_;])[
@@ -388,18 +395,74 @@ m4_define([_b4_token_maker_define],
])])
m4_define([_b4_type_clause],
[b4_symbol_if([$1], [is_token],
[b4_symbol_if([$1], [has_id],
[tok == token::b4_symbol([$1], [id])],
[tok == b4_symbol([$1], [code])])])])
# b4_token_kind(SYMBOL-NUM)
# -------------------------
# Some tokens don't have an ID.
m4_define([b4_token_kind],
[b4_symbol_if([$1], [has_id],
[token::b4_symbol([$1], [id])],
[b4_symbol([$1], [code])])])
# _b4_token_constructor_define(SYMBOL-NUM...)
# -------------------------------------------
# Define a unique make_symbol for all the SYMBOL-NUM (they
# _b4_tok_in(SYMBOL-NUM, ...)
# ---------------------------
# 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.
m4_define([_b4_token_constructor_define],
m4_define([_b4_symbol_constructor_define],
[m4_ifval(_b4_includes_tokens($@),
[[#if 201103L <= YY_CPLUSPLUS
symbol_type (]b4_join(
@@ -407,25 +470,24 @@ m4_define([_b4_token_constructor_define],
b4_symbol_if([$1], [has_type],
[b4_symbol([$1], [type]) v]),
b4_locations_if([location_type l]))[)
: super_type(]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [std::move (v)]),
b4_locations_if([std::move (l)]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
: super_type (]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [std::move (v)]),
b4_locations_if([std::move (l)]))[)
#else
symbol_type (]b4_join(
[int tok],
b4_symbol_if([$1], [has_type],
[const b4_symbol([$1], [type])& v]),
b4_locations_if([const location_type& l]))[)
: super_type(]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [v]),
b4_locations_if([l]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
: super_type (]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [v]),
b4_locations_if([l]))[)
#endif
{]b4_parse_assert_if([[
#if !defined _MSC_VER || defined __clang__
]b4_assert[ (]b4_tok_in($@)[);
#endif
]])[}
]])])
@@ -457,7 +519,7 @@ m4_define([b4_basic_symbol_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],
[ // Implementation of make_symbol for each symbol type.
[ // Implementation of make_symbol for each token kind.
b4_symbol_foreach([_b4_token_maker_define])])
+188 -80
View File
@@ -1,11 +1,11 @@
# -*- C -*-
# Yacc compatible skeleton for Bison
# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software
# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software
# Foundation, Inc.
m4_pushdef([b4_copyright_years],
[1984, 1989-1990, 2000-2015, 2018-2020])
[1984, 1989-1990, 2000-2015, 2018-2021])
# 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
@@ -18,10 +18,11 @@ m4_pushdef([b4_copyright_years],
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
m4_include(b4_skeletonsdir/[c.m4])
## ---------- ##
## api.pure. ##
## ---------- ##
@@ -101,6 +102,16 @@ m4_define([b4_yyerror_arg_loc_if],
[1], [m4_ifset([b4_parse_param], [$1])],
[2], [$1])])])
# b4_yyerror_formals
# ------------------
m4_define([b4_yyerror_formals],
[b4_pure_if([b4_locations_if([, [[const ]b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])[]dnl
m4_ifdef([b4_parse_param], [, b4_parse_param])[]dnl
,])dnl
[[const char *msg], [msg]]])
# b4_yyerror_args
# ---------------
# Arguments passed to yyerror: user args plus yylloc.
@@ -115,6 +126,16 @@ m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
## ----------------- ##
# b4_accept([SYMBOL-NUM])
# -----------------------
# Used in actions of the rules of accept, the initial symbol, to call
# YYACCEPT. If SYMBOL-NUM is specified, run "yyvalue->SLOT = $2;"
# before, using the slot of SYMBOL-NUM.
m4_define([b4_accept],
[m4_ifval([$1],
[b4_symbol_value(yyimpl->yyvalue, [$1]) = b4_rhs_value(2, 1, [$1]); ]) YYACCEPT])
# b4_lhs_value(SYMBOL-NUM, [TYPE])
# --------------------------------
# See README.
@@ -154,14 +175,61 @@ m4_define([b4_rhs_location],
## Declarations. ##
## -------------- ##
# _b4_declare_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM)
# ---------------------------------------------------------------------
# Define the return type of the parsing function for SYMBOL-NUM, and
# declare its parsing function.
m4_define([_b4_declare_sub_yyparse],
[[
// Return type when parsing one ]_b4_symbol($1, tag)[.
typedef struct
{]b4_symbol_if([$1], [has_type], [[
]_b4_symbol($1, type)[ yyvalue;]])[
int yystatus;
int yynerrs;
} ]b4_prefix[parse_]_b4_symbol($1, id)[_t;
// Parse one ]_b4_symbol($1, tag)[.
]b4_prefix[parse_]_b4_symbol($1, id)[_t ]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);
]])
# _b4_first_switching_token
# -------------------------
m4_define([b4_first], [$1])
m4_define([b4_second], [$2])
m4_define([_b4_first_switching_token],
[b4_second(b4_first(b4_start_symbols))])
# _b4_define_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM)
# --------------------------------------------------------------------
# Define the parsing function for START-SYMBOL-NUM.
m4_define([_b4_define_sub_yyparse],
[[
]b4_prefix[parse_]_b4_symbol($1, id)[_t
]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
{
]b4_prefix[parse_]_b4_symbol($1, id)[_t yyres;
yy_parse_impl_t yyimpl;
yyres.yystatus = yy_parse_impl (]b4_symbol($2, id)[, &yyimpl]m4_ifset([b4_parse_param],
[[, ]b4_args(b4_parse_param)])[);]b4_symbol_if([$1], [has_type], [[
yyres.yyvalue = yyimpl.yyvalue.]b4_symbol($1, slot)[;]])[
yyres.yynerrs = yyimpl.yynerrs;
return yyres;
}
]])
# b4_declare_scanner_communication_variables
# ------------------------------------------
# Declare the variables that are global, or local to YYPARSE if
# pure-parser.
m4_define([b4_declare_scanner_communication_variables], [[
/* Lookahead token kind. */
]m4_ifdef([b4_start_symbols], [],
[[/* Lookahead token kind. */
int yychar;
]])[
]b4_pure_if([[
/* The semantic value of the lookahead symbol. */
/* Default value used for initialization, for pacifying older GCCs
@@ -276,11 +344,14 @@ int ]b4_prefix[push_parse (]b4_prefix[pstate *ps]b4_pure_if([[,
void ]b4_prefix[pstate_delete (]b4_prefix[pstate *ps);
]])
# _b4_declare_yyparse
# -------------------
# When not the push parser.
m4_define([_b4_declare_yyparse],
[[int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);]])
[[int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);
]m4_ifdef([b4_start_symbols],
[m4_map([_b4_declare_sub_yyparse], m4_defn([b4_start_symbols]))])])
# b4_declare_yyparse
@@ -291,16 +362,32 @@ m4_define([b4_declare_yyparse],
])
# b4_declare_yyerror_and_yylex
# ----------------------------
# Comply with POSIX Yacc.
# <https://austingroupbugs.net/view.php?id=1388#c5220>
m4_define([b4_declare_yyerror_and_yylex],
[b4_yacc_if([[#if !defined ]b4_prefix[error && !defined ]b4_api_PREFIX[ERROR_IS_DECLARED
]b4_function_declare([b4_prefix[error]], void, b4_yyerror_formals)[
#endif
#if !defined ]b4_prefix[lex && !defined ]b4_api_PREFIX[LEX_IS_DECLARED
]b4_function_declare([b4_prefix[lex]], int, b4_yylex_formals)[
#endif
]])dnl
])
# b4_shared_declarations
# ----------------------
# Declaration that might either go into the header (if --defines)
# or open coded in the parser body.
# Declarations that might either go into the header (if --header)
# or into the implementation file.
m4_define([b4_shared_declarations],
[b4_cpp_guard_open([b4_spec_mapped_header_file])[
]b4_declare_yydebug[
]b4_percent_code_get([[requires]])[
]b4_token_enums_defines[
]b4_declare_yylstype[
]b4_declare_yyerror_and_yylex[
]b4_declare_yyparse[
]b4_percent_code_get([[provides]])[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[]dnl
@@ -330,13 +417,13 @@ m4_if(b4_spec_header_file, [y.tab.h], [],
## -------------- ##
b4_defines_if([[
b4_header_if([[
]b4_output_begin([b4_spec_header_file])[
]b4_copyright([Bison interface for Yacc-like parsers in C])[
]b4_disclaimer[
]b4_shared_declarations[
]b4_output_end[
]])# b4_defines_if
]])# b4_header_if
b4_output_begin([b4_parser_file_name])[
]b4_copyright([Bison implementation for Yacc-like parsers in C])[
@@ -641,15 +728,6 @@ yysymbol_name (yysymbol_kind_t yysymbol)
}]])[
#endif
#ifdef YYPRINT
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
(internal) symbol number NUM (which must be that of a token). */
static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
{
]b4_toknum[
};
#endif
#define YYPACT_NINF (]b4_pact_ninf[)
#define yypact_value_is_default(Yyn) \
@@ -665,18 +743,19 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
enum { YYENOMEM = -2 };
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = ]b4_symbol(-2, id)[)
#define yyclearin (yychar = ]b4_symbol(empty, id)[)
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
#define YYNOMEM goto yyexhaustedlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == ]b4_symbol(-2, id)[) \
if (yychar == ]b4_symbol(empty, id)[) \
{ \
yychar = (Token); \
yylval = (Value); \
@@ -693,8 +772,8 @@ enum { YYENOMEM = -2 };
while (0)
/* Backward compatibility with an undocumented macro.
Use ]b4_symbol(1, id)[ or ]b4_symbol(2, id)[. */
#define YYERRCODE ]b4_symbol(2, id)[
Use ]b4_symbol(error, id)[ or ]b4_symbol(undef, id)[. */
#define YYERRCODE ]b4_symbol(undef, id)[
]b4_locations_if([[
]b4_yylloc_default_define[
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
@@ -714,7 +793,7 @@ do { \
YYFPRINTF Args; \
} while (0)
]b4_yy_location_print_define[
]b4_yylocation_print_define[
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
do { \
@@ -925,7 +1004,7 @@ do { \
switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \
{ \
case YYENOMEM: \
goto yyexhaustedlab; \
YYNOMEM; \
case 1: \
goto yyerrlab; \
} \
@@ -1103,7 +1182,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
for (yyx = 0; yyx < YYNTOKENS; ++yyx)
{
yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
if (yysym != ]b4_symbol(1, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF)
if (yysym != ]b4_symbol(error, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF)
switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]],
[[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[))
{
@@ -1132,7 +1211,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (!yyarg)
@@ -1144,7 +1223,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
}
}]])[
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = ]b4_symbol(-2, kind)[;
yyarg[0] = ]b4_symbol(empty, kind)[;
return yycount;
}
@@ -1307,7 +1386,7 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx,
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.]])[
*/
if (yyctx->yytoken != ]b4_symbol(-2, kind)[)
if (yyctx->yytoken != ]b4_symbol(empty, kind)[)
{
int yyn;]b4_lac_if([[
YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
@@ -1453,7 +1532,7 @@ yypull_parse (yypstate *yyps]b4_user_formals[)
int yystatus;
do {
]b4_pure_if([[ YYSTYPE yylval;
int ]])[yychar = ]b4_lex[;
int ]])[yychar = ]b4_yylex[;
yystatus = yypush_parse (yyps]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[);
} while (yystatus == YYPUSH_MORE);
return yystatus;
@@ -1486,7 +1565,7 @@ yypstate_new (void)
yypstate *yyps;]b4_pure_if([], [[
if (yypstate_allocated)
return YY_NULLPTR;]])[
yyps = YY_CAST (yypstate *, malloc (sizeof *yyps));
yyps = YY_CAST (yypstate *, YYMALLOC (sizeof *yyps));
if (!yyps)
return YY_NULLPTR;]b4_pure_if([], [[
yypstate_allocated = 1;]])[
@@ -1515,7 +1594,7 @@ yypstate_delete (yypstate *yyps)
#endif]b4_lac_if([[
if (yyes != yyesa)
YYSTACK_FREE (yyes);]])[
free (yyps);]b4_pure_if([], [[
YYFREE (yyps);]b4_pure_if([], [[
yypstate_allocated = 0;]])[
}
}
@@ -1534,8 +1613,31 @@ yypush_parse (yypstate *yyps]b4_pure_if([[,
| yyparse. |
`----------*/
]m4_ifdef([b4_start_symbols],
[[// Extract data from the parser.
typedef struct
{
YYSTYPE yyvalue;
int yynerrs;
} yy_parse_impl_t;
// Run a full parse, using YYCHAR as switching token.
static int
yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[);
]m4_map([_b4_define_sub_yyparse], m4_defn([b4_start_symbols]))[
int
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
{
return yy_parse_impl (]b4_symbol(_b4_first_switching_token, id)[, YY_NULLPTR]m4_ifset([b4_parse_param],
[[, ]b4_args(b4_parse_param)])[);
}
static int
yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[)]],
[[int
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])])[
{]b4_pure_if([b4_declare_scanner_communication_variables
])b4_push_if([b4_pure_if([], [[
int yypushed_char = yychar;
@@ -1550,7 +1652,7 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
/* The return value of yyparse. */
int yyresult;
/* Lookahead symbol kind. */
yysymbol_kind_t yytoken = ]b4_symbol(-2, kind)[;
yysymbol_kind_t yytoken = ]b4_symbol(empty, kind)[;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;]b4_locations_if([[
@@ -1573,19 +1675,23 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
switch (yyps->yynew)
{
case 2:
yypstate_clear (yyps);
goto case_0;
case_0:
case 0:
yyn = yypact[yystate];
goto yyread_pushed_token;
case 2:
yypstate_clear (yyps);
break;
default:
break;
}]])[
YYDPRINTF ((stderr, "Starting parse\n"));
yychar = ]b4_symbol(-2, id)[; /* Cause a token to be read. */
]m4_ifdef([b4_start_symbols], [],
[[ yychar = ]b4_symbol(empty, id)[; /* Cause a token to be read. */
]])[
]m4_ifdef([b4_initial_action], [
b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [],
[b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl
@@ -1620,7 +1726,7 @@ yysetstate:
if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
goto yyexhaustedlab;
YYNOMEM;
#else
{
/* Get the current used size of the three stacks, in elements. */
@@ -1651,7 +1757,7 @@ yysetstate:
# else /* defined YYSTACK_RELOCATE */
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
goto yyexhaustedlab;
YYNOMEM;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
@@ -1662,7 +1768,7 @@ yysetstate:
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr)
goto yyexhaustedlab;
YYNOMEM;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([
YYSTACK_RELOCATE (yyls_alloc, yyls);])[
@@ -1686,8 +1792,9 @@ yysetstate:
}
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
]m4_ifdef([b4_start_symbols], [], [[
if (yystate == YYFINAL)
YYACCEPT;
YYACCEPT;]])[
goto yybackup;
@@ -1707,7 +1814,7 @@ yybackup:
/* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
if (yychar == ]b4_symbol(-2, id)[)
if (yychar == ]b4_symbol(empty, id)[)
{]b4_push_if([[
if (!yyps->yynew)
{]b4_use_push_for_pull_if([], [[
@@ -1729,23 +1836,23 @@ yyread_pushed_token:]])[
yylval = *yypushed_val;]b4_locations_if([[
if (yypushed_loc)
yylloc = *yypushed_loc;]])])], [[
yychar = ]b4_lex[;]])[
yychar = ]b4_yylex[;]])[
}
if (yychar <= ]b4_symbol(0, [id])[)
if (yychar <= ]b4_symbol(eof, [id])[)
{
yychar = ]b4_symbol(0, [id])[;
yytoken = ]b4_symbol(0, [kind])[;
yychar = ]b4_symbol(eof, [id])[;
yytoken = ]b4_symbol(eof, [kind])[;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else if (yychar == ]b4_symbol(1, [id])[)
else if (yychar == ]b4_symbol(error, [id])[)
{
/* The scanner already issued an error message, process directly
to error recovery. But do not keep the error token as
lookahead, it is too special and may lead us to an endless
loop in error recovery. */
yychar = ]b4_symbol(2, [id])[;
yytoken = ]b4_symbol(1, [kind])[;]b4_locations_if([[
yychar = ]b4_symbol(undef, [id])[;
yytoken = ]b4_symbol(error, [kind])[;]b4_locations_if([[
yyerror_range[1] = yylloc;]])[
goto yyerrlab1;
}
@@ -1768,9 +1875,9 @@ yyread_pushed_token:]])[
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;]b4_lac_if([[
goto yyerrlab;
yyn = -yyn;]b4_lac_if([[
YY_LAC_ESTABLISH;]])[
yyn = -yyn;
goto yyreduce;
}
@@ -1788,7 +1895,7 @@ yyread_pushed_token:]])[
*++yylsp = yylloc;])[
/* Discard the shifted token. */
yychar = ]b4_symbol(-2, id)[;]b4_lac_if([[
yychar = ]b4_symbol(empty, id)[;]b4_lac_if([[
YY_LAC_DISCARD ("shift");]])[
goto yynewstate;
@@ -1879,7 +1986,7 @@ yyreduce:
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == ]b4_symbol(-2, id)[ ? ]b4_symbol(-2, kind)[ : YYTRANSLATE (yychar);
yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
@@ -1889,11 +1996,11 @@ yyerrlab:
[[ {
yypcontext_t yyctx
= {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};]b4_lac_if([[
if (yychar != ]b4_symbol(-2, id)[)
if (yychar != ]b4_symbol(empty, id)[)
YY_LAC_ESTABLISH;]])[
if (yyreport_syntax_error (&yyctx]m4_ifset([b4_parse_param],
[[, ]b4_args(b4_parse_param)])[) == 2)
goto yyexhaustedlab;
[[, ]b4_args(b4_parse_param)])[) == 2)
YYNOMEM;
}]],
[simple],
[[ yyerror (]b4_yyerror_args[YY_("syntax error"));]],
@@ -1902,7 +2009,7 @@ yyerrlab:
= {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;]b4_lac_if([[
if (yychar != ]b4_symbol(-2, id)[)
if (yychar != ]b4_symbol(empty, id)[)
YY_LAC_ESTABLISH;]])[
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
if (yysyntax_error_status == 0)
@@ -1928,7 +2035,7 @@ yyerrlab:
}
yyerror (]b4_yyerror_args[yymsgp);
if (yysyntax_error_status == YYENOMEM)
goto yyexhaustedlab;
YYNOMEM;
}]])[
}
]b4_locations_if([[
@@ -1938,17 +2045,17 @@ yyerrlab:
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= ]b4_symbol(0, [id])[)
if (yychar <= ]b4_symbol(eof, [id])[)
{
/* Return failure if at end of input. */
if (yychar == ]b4_symbol(0, [id])[)
if (yychar == ]b4_symbol(eof, [id])[)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
yychar = ]b4_symbol(-2, id)[;
yychar = ]b4_symbol(empty, id)[;
}
}
@@ -1965,6 +2072,7 @@ yyerrorlab:
label yyerrorlab therefore never appears in user code. */
if (0)
YYERROR;
++yynerrs;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
@@ -1987,8 +2095,8 @@ yyerrlab1:
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += ]b4_symbol(1, kind)[;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(1, kind)[)
yyn += ]b4_symbol(error, kind)[;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(error, kind)[)
{
yyn = yytable[yyn];
if (0 < yyn)
@@ -2032,7 +2140,7 @@ yyerrlab1:
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
goto yyreturnlab;
/*-----------------------------------.
@@ -2040,25 +2148,23 @@ yyacceptlab:
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
goto yyreturnlab;
#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
/*-----------------------------------------------------------.
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
`-----------------------------------------------------------*/
yyexhaustedlab:
yyerror (]b4_yyerror_args[YY_("memory exhausted"));
yyresult = 2;
goto yyreturn;
#endif
goto yyreturnlab;
/*-------------------------------------------------------.
| yyreturn -- parsing is finished, clean up and return. |
`-------------------------------------------------------*/
yyreturn:
if (yychar != ]b4_symbol(-2, id)[)
/*----------------------------------------------------------.
| yyreturnlab -- parsing is finished, clean up and return. |
`----------------------------------------------------------*/
yyreturnlab:
if (yychar != ]b4_symbol(empty, id)[)
{
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
@@ -2092,7 +2198,9 @@ yypushreturn:]], [[
YYSTACK_FREE (yyes);]])])[
]b4_parse_error_bmatch([detailed\|verbose],
[[ if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);]])[
YYSTACK_FREE (yymsg);]])[]m4_ifdef([b4_start_symbols], [[
if (yyimpl)
yyimpl->yynerrs = yynerrs;]])[
return yyresult;
}
]b4_push_if([b4_parse_state_variable_macros([b4_macro_undef])])[
+3 -3
View File
@@ -3,7 +3,7 @@
<!--
bison.xsl - common templates for Bison XSLT.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -18,12 +18,12 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="1.0"
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
name="bison:symbolByName"
+3 -3
View File
@@ -3,7 +3,7 @@
<!--
xml2dot.xsl - transform Bison XML Report into DOT.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -18,14 +18,14 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>.
-->
<xsl:stylesheet version="1.0"
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:output method="text" encoding="UTF-8" indent="no"/>
+3 -3
View File
@@ -3,7 +3,7 @@
<!--
xml2text.xsl - transform Bison XML Report into plain text.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -18,14 +18,14 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>.
-->
<xsl:stylesheet version="1.0"
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:output method="text" encoding="UTF-8" indent="no"/>
+4 -4
View File
@@ -3,7 +3,7 @@
<!--
xml2html.xsl - transform Bison XML Report into XHTML.
Copyright (C) 2007-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -18,7 +18,7 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Written by Wojciech Polak <polak@gnu.org>.
-->
@@ -26,7 +26,7 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"/>
@@ -88,7 +88,7 @@
<xsl:apply-templates select="bison-xml-report"/>
<xsl:text>&#10;&#10;</xsl:text>
<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>
XML Automaton Report.<br />
<!-- default copying notice -->
+3 -3
View File
@@ -22,15 +22,15 @@
/bison.ps
/cross-options.texi
/fdl.texi
/figs/*.eps
/figs/*.svg
/gendocs_template
/gendocs_template_min
/gpl-3.0.texi
/refcard.dvi
/refcard.log
/refcard.ps
/relocatable.texi
/stamp-vti
/version.texi
/yacc.1
/relocatable.texi
/figs/*.eps
/figs/*.svg
+119 -52
View File
@@ -1,4 +1,4 @@
# Doxyfile 1.8.18
# Doxyfile 1.9.1
# This file describes the settings to be used by the documentation system
# 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.
# 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
# could be handy for archiving the generated documentation or if some version
# 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
# 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
# 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
# documentation from any documented member that it re-implements.
# The default value is: YES.
@@ -305,7 +313,10 @@ OPTIMIZE_OUTPUT_SLICE = NO
# 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
# 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 =
@@ -439,6 +450,19 @@ TYPEDEF_HIDES_STRUCT = NO
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
#---------------------------------------------------------------------------
@@ -502,6 +526,13 @@ EXTRACT_LOCAL_METHODS = 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
# undocumented members inside documented classes or files. If set to NO these
# members will be included in the various overviews, but no documentation
@@ -539,11 +570,18 @@ HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
# names in lower-case letters. If set to YES, upper-case letters are also
# allowed. This is useful if you have classes or files whose names only differ
# in case and if your file system supports case sensitive file names. Windows
# (including Cygwin) ands Mac users are advised to set this option to NO.
# With the correct setting of option CASE_SENSE_NAMES doxygen will better be
# able to match the capabilities of the underlying filesystem. In case the
# filesystem is case sensitive (i.e. it supports files in the same directory
# whose names only differ in casing), the option must be set to YES to properly
# 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.
CASE_SENSE_NAMES = YES
@@ -782,7 +820,10 @@ WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
# 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.
WARN_AS_ERROR = NO
@@ -819,8 +860,8 @@ INPUT = @top_srcdir@/src \
# 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
# 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
# possible encodings.
# documentation (see:
# https://www.gnu.org/software/libiconv/) for the list of possible encodings.
# The default value is: UTF-8.
INPUT_ENCODING = UTF-8
@@ -833,13 +874,15 @@ INPUT_ENCODING = UTF-8
# need to set EXTENSION_MAPPING for the extension otherwise the files are not
# 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,
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
# *.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
# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd,
# *.vhdl, *.ucf, *.qsf and *.ice.
# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
# *.ucf, *.qsf and *.ice.
FILE_PATTERNS = *.c \
*.h \
@@ -1069,13 +1112,6 @@ VERBATIM_HEADERS = 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
# 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
@@ -1246,10 +1282,11 @@ HTML_INDEX_NUM_ENTRIES = 100
# 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
# environment (see: https://developer.apple.com/xcode/), introduced with OSX
# 10.5 (Leopard). To create a documentation set, doxygen will generate a
# Makefile in the HTML output directory. Running make will produce the docset in
# that directory and running make install will install the docset in
# environment (see:
# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
# create a documentation set, doxygen will generate a Makefile in the HTML
# 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
# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
# genXcode/_index.html for more information.
@@ -1291,8 +1328,8 @@ DOCSET_PUBLISHER_NAME = Publisher
# 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
# 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
# Windows.
# (see:
# 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
# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
@@ -1322,7 +1359,7 @@ CHM_FILE =
HHC_LOCATION =
# 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.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
@@ -1367,7 +1404,8 @@ QCH_FILE =
# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
# 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.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1375,8 +1413,8 @@ QHP_NAMESPACE = org.doxygen.Project
# 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
# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
# folders).
# Folders (see:
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders).
# The default value is: doc.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1384,16 +1422,16 @@ QHP_VIRTUAL_FOLDER = doc
# 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
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
# filters).
# Filters (see:
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_NAME =
# 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
# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
# filters).
# Filters (see:
# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_ATTRS =
@@ -1405,9 +1443,9 @@ QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS =
# The QHG_LOCATION tag can be used to specify the location of Qt's
# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
# generated .qhp file.
# The QHG_LOCATION tag can be used to specify the location (absolute path
# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to
# run qhelpgenerator on the generated .qhp file.
# This tag requires that the tag GENERATE_QHP is set to YES.
QHG_LOCATION =
@@ -1488,8 +1526,8 @@ EXT_LINKS_IN_WINDOW = NO
# 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 tool.
# 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.
@@ -1534,7 +1572,7 @@ USE_MATHJAX = NO
# When MathJax is enabled you can set the default output format to be used for
# 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
# compatibility), NativeMML (i.e. MathML) and SVG.
# The default value is: HTML-CSS.
@@ -1564,7 +1602,8 @@ MATHJAX_EXTENSIONS =
# 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
# (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.
# This tag requires that the tag USE_MATHJAX is set to YES.
@@ -1611,7 +1650,8 @@ SERVER_BASED_SEARCH = NO
#
# Doxygen ships with an example indexer (doxyindexer) and search engine
# (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.
# The default value is: NO.
@@ -1624,8 +1664,9 @@ EXTERNAL_SEARCH = NO
#
# Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library
# Xapian (see: https://xapian.org/). See the section "External Indexing and
# Searching" for details.
# Xapian (see:
# https://xapian.org/). See the section "External Indexing and Searching" for
# details.
# This tag requires that the tag SEARCHENGINE is set to YES.
SEARCHENGINE_URL =
@@ -1789,9 +1830,11 @@ LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
# the PDF file directly from the LaTeX files. Set this option to YES, to get a
# higher quality PDF documentation.
# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as
# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX
# 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.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -2304,10 +2347,32 @@ UML_LOOK = NO
# but if the number exceeds 15, the total amount of fields shown is limited to
# 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
# 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
# collaboration graphs will show the relations between templates and their
# instances.
@@ -2497,9 +2562,11 @@ DOT_MULTI_TARGETS = NO
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.
#
# Note: This setting is not only used for dot files but also for msc and
# plantuml temporary files.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
DOT_CLEANUP = YES
+1124 -482
View File
File diff suppressed because it is too large Load Diff
View File
+1 -1
View File
@@ -1,6 +1,6 @@
// Generated by GNU Bison 2.6.90.
// Report bugs to <[email protected]>.
// Home page: <http://www.gnu.org/software/bison/>.
// Home page: <https://www.gnu.org/software/bison/>.
digraph "example.y"
{
+4 -4
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2001-2003, 2005-2015, 2018-2020 Free Software
## Copyright (C) 2001-2003, 2005-2015, 2018-2021 Free Software
## Foundation, Inc.
## This program is free software: you can redistribute it and/or modify
@@ -12,7 +12,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
AM_MAKEINFOFLAGS = \
--no-split \
@@ -56,8 +56,8 @@ MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
# Fix Info's @code in @deftype
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html
all: $(srcdir)/$(%C%_bison).info.bak
# https://lists.gnu.org/r/help-texinfo/2019-11/msg00004.html
all-local: $(srcdir)/$(%C%_bison).info.bak
$(srcdir)/$(%C%_bison).info.bak: $(srcdir)/$(%C%_bison).info
$(AM_V_GEN) $(PERL) -pi.bak -0777 \
-e 's{(^ --.*\n(?: {10}.*\n)*)}' \
+2 -2
View File
@@ -19,7 +19,7 @@
\def\finalout{\overfullrule=0pt}
%\finalout
% Copyright (c) 1998, 2001, 2009--2015, 2018--2020 Free Software
% Copyright (c) 1998, 2001, 2009--2015, 2018--2021 Free Software
% Foundation, Inc.
%
% This file is part of Bison.
@@ -35,7 +35,7 @@
% 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/>.
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%
% This file is intended to be processed by plain TeX (TeX82).
%
+1 -1
View File
@@ -22,7 +22,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2006, 2009-2015, 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+45 -33
View File
@@ -1,6 +1,6 @@
#! /usr/bin/perl -w
# Copyright (C) 2006, 2008-2015, 2018-2020 Free Software Foundation,
# Copyright (C) 2006, 2008-2015, 2018-2021 Free Software Foundation,
# Inc.
#
# This file is part of Bison, the GNU Compiler Compiler.
@@ -16,7 +16,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
=head1 NAME
@@ -185,13 +185,13 @@ my $verbose = 1;
=over 4
=item C<verbose($level, $message)>
=item C<verbose ($level, $message)>
Report the C<$message> is C<$level> E<lt>= C<$verbose>.
=cut
sub verbose($$)
sub verbose ($$)
{
my ($level, $message) = @_;
print STDERR $message
@@ -201,13 +201,13 @@ sub verbose($$)
######################################################################
=item C<directives($bench, @directive)>
=item C<directives ($bench, @directive)>
Format the list of directives for Bison for bench named C<$bench>.
=cut
sub directives($@)
sub directives ($@)
{
my ($bench, @directive) = @_;
my $res = "/* Directives for bench '$bench'. */\n";
@@ -218,6 +218,27 @@ sub directives($@)
######################################################################
=item C<is_pure (@directive)>
Whether api.pure is set.
=cut
sub is_pure (@)
{
my (@directive) = @_;
for my $dir (@directive)
{
if ($dir =~ /\A%define api.pure/)
{
return 1;
}
}
return 0;
}
######################################################################
=item C<generate_grammar_triangular ($base, $max, @directive)>
Create a large triangular grammar which looks like :
@@ -389,18 +410,14 @@ sub generate_grammar_calc ($$@)
%define api.value.type union
$directives
%{
%code provides {
static int power (int base, int exponent);
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
static void yyerror (const char *s);
#if YYPURE
static int yylex (YYSTYPE* yylvalp);
#else
static int yylex (void);
#endif
%}
static int yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]});
}
/* Bison Declarations */
%token
@@ -467,12 +484,7 @@ yyerror (const char *s)
}
static int
#if YYPURE
# define yylval (*yylvalp)
yylex (YYSTYPE* yylvalp)
#else
yylex (void)
#endif
yylex (@{[is_pure (@directive) ? "YYSTYPE *yylvalp" : "void"]})
{
int c;
@@ -498,7 +510,7 @@ yylex (void)
case '5': case '6': case '7': case '8': case '9':
{
int nchars = 0;
int n = sscanf (input - 1, "%d%n", &yylval.NUM, &nchars);
int n = sscanf (input - 1, "%d%n", &@{[is_pure (@directive) ? "yylvalp->" : "yylval."]}NUM, &nchars);
assert (n == 1);
input += nchars - 1;
return NUM;
@@ -506,7 +518,7 @@ yylex (void)
default:
yyerror ("error: invalid character");
return yylex ();
return yylex (@{[is_pure (@directive) ? "yylvalp" : ""]});
}
}
EOF
@@ -569,7 +581,7 @@ sub generate_grammar_list ($$@)
or die;
print $out <<EOF;
%language "C++"
%defines
%header
%locations
$directives
@@ -592,10 +604,10 @@ $directives
// Prototype of the yylex function providing subsequent tokens.
static
#if USE_TOKEN_CTOR
yy::parser::symbol_type yylex();
yy::parser::symbol_type yylex ();
#else
yy::parser::token_type yylex(yy::parser::semantic_type* yylvalp,
yy::parser::location_type* yyllocp);
yy::parser::token_type yylex (yy::parser::semantic_type *yylvalp,
yy::parser::location_type *yyllocp);
#endif
// Conversion to string.
@@ -618,8 +630,8 @@ EOF
print $out <<'EOF';
%token <std::string> TEXT
%token <int> NUMBER
%printer { std::cerr << "Number: " << $$; } <int>
%printer { std::cerr << "Text: " << $$; } <std::string>
%printer { yyo << "Number: " << $$; } <int>
%printer { yyo << "Text: " << $$; } <std::string>
%type <std::string> text result
%%
@@ -641,8 +653,8 @@ EOF
%union {int ival; std::string* sval;}
%token <sval> TEXT
%token <ival> NUMBER
%printer { std::cerr << "Number: " << $$; } <ival>
%printer { std::cerr << "Text: " << *$$; } <sval>
%printer { yyo << "Number: " << $$; } <ival>
%printer { yyo << "Text: " << *$$; } <sval>
%type <sval> text result
%%
@@ -664,10 +676,10 @@ EOF
static
#if USE_TOKEN_CTOR
yy::parser::symbol_type yylex()
yy::parser::symbol_type yylex ()
#else
yy::parser::token_type yylex(yy::parser::semantic_type* yylvalp,
yy::parser::location_type* yyllocp)
yy::parser::token_type yylex (yy::parser::semantic_type *yylvalp,
yy::parser::location_type *yyllocp)
#endif
{
typedef yy::parser::location_type location_type;
@@ -1060,7 +1072,7 @@ sub help ($)
{
my ($verbose) = @_;
use Pod::Usage;
# See <URL:http://perldoc.perl.org/pod2man.html#NOTES>.
# See <URL:https://perldoc.perl.org/pod2man.html#NOTES>.
pod2usage( { -message => "Bench Bison parsers",
-exitval => 0,
-verbose => $verbose,
+2 -2
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2006, 2008-2015, 2018-2020 Free Software Foundation,
## Copyright (C) 2006, 2008-2015, 2018-2021 Free Software Foundation,
## Inc.
## This program is free software: you can redistribute it and/or modify
@@ -12,7 +12,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
dist_noinst_DATA = %D%/README.md
nodist_noinst_SCRIPTS = %D%/bench.pl
+1 -1
View File
@@ -17,7 +17,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2018-2021 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
+2 -2
View File
@@ -11,8 +11,8 @@ variant-11: CXXFLAGS = -std=c++11
all: $(PROGS)
%.cc %.hh: %.yy
$(BISON) $(BISONFLAGS) -o $*.cc $<
%.cc %.hh %.html %.gv: %.yy
$(BISON) $(BISONFLAGS) --html --graph -o $*.cc $<
%: %.cc
$(CXX) $(CXXFLAGS) -o$@ $<
+1 -1
View File
@@ -46,7 +46,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2018-2021 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
+2 -7
View File
@@ -5,12 +5,11 @@ BASE = calc++
BISON = bison
CXX = g++
FLEX = flex
XSLTPROC = xsltproc
all: $(BASE)
%.cc %.hh %.xml %.gv: %.yy
$(BISON) $(BISONFLAGS) --xml --graph=$*.gv -o $*.cc $<
%.cc %.hh %.html %.gv: %.yy
$(BISON) $(BISONFLAGS) --html --graph -o $*.cc $<
%.cc: %.ll
$(FLEX) $(FLEXFLAGS) -o$@ $<
@@ -29,10 +28,6 @@ run: $(BASE)
@echo "Type arithmetic expressions. Quit with ctrl-d."
./$< -
html: parser.html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \
$(BASE) *.o \
parser.hh parser.cc parser.output parser.xml parser.html parser.gv location.hh \
+1 -1
View File
@@ -36,7 +36,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2018-2021 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
+2 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2005-2015, 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2005-2015, 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF
toto := 1
+4 -4
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2005-2006, 2008-2015, 2018-2020 Free Software
## Copyright (C) 2005-2006, 2008-2015, 2018-2021 Free Software
## Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
@@ -12,13 +12,12 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
## ------------------- ##
## Parser generation. ##
## ------------------- ##
%D%/parser.stamp: $(dependencies)
SUFFIXES += .yy .stamp
.yy.stamp:
$(AM_V_YACC)rm -f $@
@@ -26,12 +25,13 @@ SUFFIXES += .yy .stamp
$(AM_V_at)$(YACCCOMPILE) -o $*.cc $<
$(AM_V_at)mv -f $@.tmp $@
%D%/parser.stamp: $(dependencies)
$(calcxx_sources_generated): %D%/parser.stamp
@test -f $@ || rm -f %D%/parser.stamp
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/parser.stamp
CLEANFILES += \
$(calcxx_sources_generated) \
%D%/parser.dot \
%D%/parser.gv \
%D%/parser.output \
%D%/parser.stamp \
%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)
+24
View File
@@ -0,0 +1,24 @@
# 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.
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2020-2021 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-2021 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-2021 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, unexpected identifier, expecting = or + or )"
+220
View File
@@ -0,0 +1,220 @@
/* -*- C++ -*-
Copyright (C) 2020-2021 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
// Nice error messages with details.
%define parse.error detailed
%code requires
{
#include "ast.hh"
}
%define api.value.type variant
%code
{
#include <cassert>
#include <cctype>
#include <fstream>
#include <cstring>
static Node
stmt_merge (const Node& x0, const Node& x1);
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;
// An error reporting function.
void
yy::parser::error (const location_type& l, const std::string& m)
{
std::cerr << l << ": " << m << '\n';
}
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);
}
}
}
}
static Node
stmt_merge (const Node& x0, const Node& x1)
{
return Nterm ("<OR>", x0, x1);
}
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-2021 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-2021 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
@@ -11,10 +11,11 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
cxxdir = $(docdir)/%D%
include %D%/calc++/local.mk
include %D%/glr/local.mk
## -------- ##
## Simple. ##
@@ -29,7 +30,7 @@ simple_extracted = %D%/simple.yy
simple_sources = $(simple_extracted)
extracted += $(simple_extracted)
if ENABLE_CXX14
if ENABLE_CXX11
check_PROGRAMS += %D%/simple
nodist_%C%_simple_SOURCES = $(simple_sources)
+2 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
: >input
run 0 "{I have numbers for you., 1, 2, 3, And that's all!}" 4
+2 -2
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2008-2015, 2018-2021 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
@@ -12,7 +12,7 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
%require "3.2"
+2 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
# Copyright (C) 2018-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
: >input
run 0 "{I have three numbers for you., 1, 2, 3, And that's all!}"
+2 -2
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2015, 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2008-2015, 2018-2021 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
@@ -12,7 +12,7 @@
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/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
%require "3.2"
+2 -2
View File
@@ -60,7 +60,7 @@ This example demonstrates best practices when using Bison.
push-parser API to feed the parser with the incoming tokens.
- It features an interactive command line with completion based on the
parser state, based on `yyexpected_tokens`.
- It uses Bison's standard catalogue for internationalization of generated
- It uses Bison's standard catalog for internationalization of generated
messages.
- It uses a custom syntax error with location, lookahead correction and
token internationalization.
@@ -81,7 +81,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2018-2021 Free Software Foundation, Inc.
This file is part of GNU bison, the GNU Compiler Compiler.
+3 -8
View File
@@ -3,14 +3,13 @@
BASE = bistromathic
BISON = bison
XSLTPROC = xsltproc
# We need to find the headers and libs for readline (and possibly intl).
# You probably need to customize this for your own environment.
CPPFLAGS = -I/opt/local/include
LDFLAGS = -L/opt/local/lib
# Find the translation catalogue for Bison's generated messagess.
# Find the translation catalog for Bison's generated messagess.
BISON_LOCALEDIR = $(shell $(BISON) $(BISON_FLAGS) --print-localedir)
CPPFLAGS += -DENABLE_NLS -DBISON_LOCALEDIR='"$(BISON_LOCALEDIR)"'
@@ -18,8 +17,8 @@ LIBS = -lreadline -lm # In some environments, -lintl is needed.
all: $(BASE)
%.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
%.c %.h %.html %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --header --html --graph -o $*.c $<
$(BASE): parse.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
@@ -28,10 +27,6 @@ run: $(BASE)
@echo "Type bistromathic expressions. Quit with ctrl-d."
./$<
html: $(BASE).html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \
$(BASE) *.o \
parse.[ch] parse.output parse.xml parse.html parse.gv
+2 -2
View File
@@ -9,7 +9,7 @@ This example demonstrates best practices when using Bison.
push-parser API to feed the parser with the incoming tokens.
- It features an interactive command line with completion based on the
parser state, based on `yyexpected_tokens`.
- It uses Bison's standard catalogue for internationalization of generated
- It uses Bison's standard catalog for internationalization of generated
messages.
- It uses a custom syntax error with location, lookahead correction and
token internationalization.
@@ -32,7 +32,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2020 Free Software Foundation, Inc.
Copyright (C) 2020-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+21 -14
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2020 Free Software Foundation, Inc.
# Copyright (C) 2020-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Users may customize the behavior of readline, which might break our
# expected results.
@@ -251,29 +251,29 @@ err: Next token is token ) (1.4: )
err: Shifting token ) (1.4: )
err: Entering state 20
err: Stack now 0 2 10 20
err: Reducing stack by rule 15 (line 151):
err: Reducing stack by rule XX (line XXX):
err: $1 = token ( (1.1: )
err: $2 = token error (1.2-3: )
err: $3 = token ) (1.4: )
err: -> $$ = nterm exp (1.1-4: 666)
err: Entering state 7
err: Stack now 0 7
err: Entering state 8
err: Stack now 0 8
err: Return for a new token:
err: Reading a token
err: Now at end of input.
err: LAC: initial context established for end of file
err: LAC: checking lookahead end of file: R2 G8 S19
err: Reducing stack by rule 2 (line 126):
err: LAC: checking lookahead end of file: R2 G7 S14
err: Reducing stack by rule XX (line XXX):
err: $1 = nterm exp (1.1-4: 666)
err: -> $$ = nterm input (1.1-4: )
err: Entering state 8
err: Stack now 0 8
err: Entering state 7
err: Stack now 0 7
err: Now at end of input.
err: Shifting token end of file (1.5: )
err: LAC: initial context discarded due to shift
err: Entering state 19
err: Stack now 0 8 19
err: Stack now 0 8 19
err: Entering state 14
err: Stack now 0 7 14
err: Stack now 0 7 14
err: Cleanup: popping token end of file (1.5: )
err: Cleanup: popping nterm input (1.1-4: )' -p
@@ -306,10 +306,17 @@ esac
sed -e 's/\\t/ /g' >input <<EOF
(1+\t\t
EOF
run 0 '> (1+
# Nuke the possible trailing white spaces in the effective output.
# This is to cope with some readlines that pad all the suggestions
# with white spaces (for alignment), including the last one on a line.
#
# See for instance <https://trac.macports.org/ticket/59927#comment:48>
# and its test-suite.log:
# <https://trac.macports.org/attachment/ticket/59927/bison-3.7.6-test-10.13.test-suite.log>
run -t 0 '> (1+
( - atan cos exp ln number sin sqrt
> (1+
> ''
>
err: 1.4: syntax error: expected - or ( or number or function or variable before end of file
err: 1 | (1+
err: | ^'
+2 -2
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2020 Free Software Foundation, Inc.
## Copyright (C) 2020-2021 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
@@ -11,7 +11,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
bistromathicdir = $(docdir)/%D%
+38 -14
View File
@@ -1,6 +1,6 @@
/* Parser and scanner for bistromathic. -*- C -*-
Copyright (C) 2019-2020 Free Software Foundation, Inc.
Copyright (C) 2019-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -15,7 +15,7 @@
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/>. */
along with this program. If not, see <https://www.gnu.org/licenses/>. */
%require "3.7"
@@ -37,7 +37,7 @@
# define YYENABLE_NLS 1
# include <libintl.h>
// Unless specified otherwise, we expect bistromathic's own
// catalogue to be installed in the same tree as Bison's catalogue.
// catalog to be installed in the same tree as Bison's catalog.
# ifndef LOCALEDIR
# define LOCALEDIR BISON_LOCALEDIR
# endif
@@ -87,13 +87,17 @@
yytoken_kind_t
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
const user_context *uctx);
void yyerror (YYLTYPE *loc, const user_context *uctx,
void yyerror (const YYLTYPE *loc, const user_context *uctx,
char const *format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
}
// Emitted in the implementation file.
%code {
// Print *LOC on OUT.
static void location_print (FILE *out, YYLTYPE const * const loc);
#define YYLOCATION_PRINT location_print
#if defined ENABLE_NLS && ENABLE_NLS
# define _(Msgid) gettext (Msgid)
#else
@@ -117,13 +121,13 @@
// with TOK_ (e.g., TOK_EOF).
%define api.token.prefix {TOK_}
// Customized syntax error messages (see yyreport_syntax_error).
// Customized syntax error messages (see yyreport_syntax_error)...
%define parse.error custom
// with locations.
// ... with locations...
%locations
// and accurate list of expected tokens.
// ... and accurate list of expected tokens.
%define parse.lac full
// Generate the parser description file (calc.output).
@@ -187,7 +191,7 @@ exp:
{
if ($r == 0)
{
yyerror (&@$, uctx, "error: division by zero");
yyerror (&@$, uctx, _("error: division by zero"));
YYERROR;
}
else
@@ -269,6 +273,26 @@ symbol_count (void)
}
/*------------.
| Locations. |
`------------*/
// Print *LOC on OUT. Do it in a compact way, that avoids redundancy.
static void
location_print (FILE *out, YYLTYPE const * const loc)
{
fprintf (out, "%d.%d", loc->first_line, loc->first_column);
int end_col = 0 != loc->last_column ? loc->last_column - 1 : 0;
if (loc->first_line < loc->last_line)
fprintf (out, "-%d.%d", loc->last_line, end_col);
else if (loc->first_column < end_col)
fprintf (out, "-%d", end_col);
}
/*----------.
| Scanner. |
`----------*/
@@ -345,7 +369,7 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
// Stray characters.
default:
yyerror (yylloc, uctx, "syntax error: invalid character: %c", c);
yyerror (yylloc, uctx, _("syntax error: invalid character: %c"), c);
return TOK_YYerror;
}
}
@@ -403,7 +427,7 @@ yyreport_syntax_error (const yypcontext_t *ctx, const user_context *uctx)
// %@: location.
if (format[0] == '%' && format[1] == '@')
{
YY_LOCATION_PRINT (stderr, *loc);
YYLOCATION_PRINT (stderr, loc);
format += 2;
}
// %u: unexpected token.
@@ -442,12 +466,12 @@ yyreport_syntax_error (const yypcontext_t *ctx, const user_context *uctx)
// Called by yyparse on error.
void yyerror (YYLTYPE *loc, const user_context *uctx, char const *format, ...)
void yyerror (const YYLTYPE *loc, const user_context *uctx, char const *format, ...)
{
if (uctx->silent)
return;
YY_LOCATION_PRINT (stderr, *loc);
YYLOCATION_PRINT (stderr, loc);
fputs (": ", stderr);
va_list args;
va_start (args, format);
@@ -638,10 +662,10 @@ main (int argc, char const* argv[])
#if defined ENABLE_NLS && ENABLE_NLS
// Set up internationalization.
setlocale (LC_ALL, "");
// Use Bison's standard translation catalogue for error messages
// Use Bison's standard translation catalog for error messages
// (the generated messages).
bindtextdomain ("bison-runtime", BISON_LOCALEDIR);
// The translation catalogue of bistromathic is actually included in
// The translation catalog of bistromathic is actually included in
// Bison's. In your own project, use the name of your project.
bindtextdomain ("bison", LOCALEDIR);
textdomain ("bison");
+2 -7
View File
@@ -3,12 +3,11 @@
BASE = calc
BISON = bison
XSLTPROC = xsltproc
all: $(BASE)
%.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
%.c %.h %.html %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --header --html --graph -o $*.c $<
$(BASE): $(BASE).o
$(CC) $(CFLAGS) -o $@ $^
@@ -17,10 +16,6 @@ run: $(BASE)
@echo "Type arithmetic expressions. Quit with ctrl-d."
./$<
html: $(BASE).html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \
$(BASE) *.o $(BASE).[ch] $(BASE).output $(BASE).xml $(BASE).html $(BASE).gv
+1 -1
View File
@@ -9,7 +9,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2019-2020 Free Software Foundation, Inc.
Copyright (C) 2019-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
+2 -2
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2019-2020 Free Software Foundation, Inc.
# Copyright (C) 2019-2021 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
@@ -13,7 +13,7 @@
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
cat >input <<EOF
1+2*3
+2 -2
View File
@@ -1,4 +1,4 @@
## Copyright (C) 2019-2020 Free Software Foundation, Inc.
## Copyright (C) 2019-2021 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
@@ -11,7 +11,7 @@
## 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/>.
## along with this program. If not, see <https://www.gnu.org/licenses/>.
calcdir = $(docdir)/%D%
+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 %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --header --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)
+24
View File
@@ -0,0 +1,24 @@
# 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.
<!---
Local Variables:
fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2020-2021 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.
--->
+47
View File
@@ -0,0 +1,47 @@
#! /bin/sh
# Copyright (C) 2020-2021 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;
T (x) + y;
T (x);
T (y) = z + q;
T (y y) = z + q;
z + q;
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)
9.0-9: +(<cast>(x, T), y)
11.0-5: <OR>(<declare>(T, x), <cast>(x, T))
13.0-13: <OR>(<init-declare>(T, y, +(z, q)), =(<cast>(y, T), +(z, q)))
15.0-15: <error>
17.0-5: +(z, q)
err: 15.5: syntax error, unexpected identifier, expecting '=' or '+' or ')'"
+340
View File
@@ -0,0 +1,340 @@
/* -*- C -*-
Copyright (C) 2020-2021 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. */
%define api.pure
%header
%define api.header.include {"c++-types.h"}
%locations
%debug
/* Nice error messages with details. */
%define parse.error detailed
%code requires
{
union Node {
struct {
int isNterm;
int parents;
} nodeInfo;
struct {
int isNterm; /* 1 */
int parents;
char const *form;
union Node *children[3];
} nterm;
struct {
int isNterm; /* 0 */
int parents;
char *text;
} term;
};
typedef union Node Node;
}
%define api.value.type union
%code
{
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static Node *new_nterm (char const *, Node *, Node *, Node *);
static Node *new_term (char *);
static void free_node (Node *);
static char *node_to_string (const Node *);
static void node_print (FILE *, const Node *);
static Node *stmt_merge (YYSTYPE x0, YYSTYPE x1);
static void yyerror (YYLTYPE const * const loc, const char *msg);
static yytoken_kind_t yylex (YYSTYPE *lval, YYLTYPE *lloc);
}
%expect-rr 1
%token
TYPENAME "typename"
ID "identifier"
%right '='
%left '+'
%glr-parser
%type <Node *> stmt expr decl declarator TYPENAME ID
%destructor { free_node ($$); } <Node *>
%printer { node_print (yyo, $$); } <Node *>
%%
prog : %empty
| prog stmt {
YYLOCATION_PRINT (stdout, &@2);
fputs (": ", stdout);
node_print (stdout, $2);
putc ('\n', stdout);
fflush (stdout);
free_node ($2);
}
;
stmt : expr ';' %merge <stmt_merge> { $$ = $1; }
| decl %merge <stmt_merge>
| error ';' { $$ = new_nterm ("<error>", NULL, NULL, NULL); }
;
expr : ID
| TYPENAME '(' expr ')'
{ $$ = new_nterm ("<cast>(%s, %s)", $3, $1, NULL); }
| expr '+' expr { $$ = new_nterm ("+(%s, %s)", $1, $3, NULL); }
| expr '=' expr { $$ = new_nterm ("=(%s, %s)", $1, $3, NULL); }
;
decl : TYPENAME declarator ';'
{ $$ = new_nterm ("<declare>(%s, %s)", $1, $2, NULL); }
| TYPENAME declarator '=' expr ';'
{ $$ = new_nterm ("<init-declare>(%s, %s, %s)", $1,
$2, $4); }
;
declarator
: ID
| '(' declarator ')' { $$ = $2; }
;
%%
/* A C error reporting function. */
static void
yyerror (YYLTYPE const * const loc, const char *msg)
{
YYLOCATION_PRINT (stderr, loc);
fprintf (stderr, ": %s\n", msg);
}
/* The input file. */
FILE * input = NULL;
yytoken_kind_t
yylex (YYSTYPE *lval, YYLTYPE *lloc)
{
static int lineNum = 1;
static int colNum = 0;
while (1)
{
int c;
assert (!feof (input));
c = getc (input);
switch (c)
{
case EOF:
return 0;
case '\t':
colNum = (colNum + 7) & ~7;
break;
case ' ': case '\f':
colNum += 1;
break;
case '\n':
lineNum += 1;
colNum = 0;
break;
default:
{
yytoken_kind_t tok;
lloc->first_line = lloc->last_line = lineNum;
lloc->first_column = colNum;
if (isalpha (c))
{
char buffer[256];
unsigned i = 0;
do
{
buffer[i++] = (char) c;
colNum += 1;
assert (i != sizeof buffer - 1);
c = getc (input);
}
while (isalnum (c) || c == '_');
ungetc (c, input);
buffer[i++] = 0;
if (isupper ((unsigned char) buffer[0]))
{
tok = TYPENAME;
lval->TYPENAME = new_term (strcpy (malloc (i), buffer));
}
else
{
tok = ID;
lval->ID = new_term (strcpy (malloc (i), buffer));
}
}
else
{
colNum += 1;
tok = c;
}
lloc->last_column = colNum;
return tok;
}
}
}
}
static Node *
new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
{
Node *res = malloc (sizeof *res);
res->nterm.isNterm = 1;
res->nterm.parents = 0;
res->nterm.form = form;
res->nterm.children[0] = child0;
if (child0)
child0->nodeInfo.parents += 1;
res->nterm.children[1] = child1;
if (child1)
child1->nodeInfo.parents += 1;
res->nterm.children[2] = child2;
if (child2)
child2->nodeInfo.parents += 1;
return res;
}
static Node *
new_term (char *text)
{
Node *res = malloc (sizeof *res);
res->term.isNterm = 0;
res->term.parents = 0;
res->term.text = text;
return res;
}
static void
free_node (Node *node)
{
if (!node)
return;
node->nodeInfo.parents -= 1;
/* Free only if 0 (last parent) or -1 (no parents). */
if (node->nodeInfo.parents > 0)
return;
if (node->nodeInfo.isNterm == 1)
{
free_node (node->nterm.children[0]);
free_node (node->nterm.children[1]);
free_node (node->nterm.children[2]);
}
else
free (node->term.text);
free (node);
}
static char *
node_to_string (const Node *node)
{
char *res;
if (!node)
{
res = malloc (1);
res[0] = 0;
}
else if (node->nodeInfo.isNterm == 1)
{
char *child0 = node_to_string (node->nterm.children[0]);
char *child1 = node_to_string (node->nterm.children[1]);
char *child2 = node_to_string (node->nterm.children[2]);
res = malloc (strlen (node->nterm.form) + strlen (child0)
+ strlen (child1) + strlen (child2) + 1);
sprintf (res, node->nterm.form, child0, child1, child2);
free (child2);
free (child1);
free (child0);
}
else
res = strdup (node->term.text);
return res;
}
static void
node_print (FILE *out, const Node *n)
{
char *str = node_to_string (n);
fputs (str, out);
free (str);
}
static Node *
stmt_merge (YYSTYPE x0, YYSTYPE x1)
{
return new_nterm ("<OR>(%s, %s)", x0.stmt, x1.stmt, NULL);
}
static int
process (const char *file)
{
int is_stdin = !file || strcmp (file, "-") == 0;
if (is_stdin)
input = stdin;
else
input = fopen (file, "r");
assert (input);
int status = yyparse ();
if (!is_stdin)
fclose (input);
return status;
}
int
main (int argc, char **argv)
{
if (getenv ("YYDEBUG"))
yydebug = 1;
int ran = 0;
for (int i = 1; i < argc; ++i)
// Enable parse traces on option -p.
if (strcmp (argv[i], "-p") == 0)
yydebug = 1;
else
{
int status = process (argv[i]);
ran = 1;
if (!status)
return status;
}
if (!ran)
{
int status = process (NULL);
if (!status)
return status;
}
return 0;
}
+34
View File
@@ -0,0 +1,34 @@
## Copyright (C) 2020-2021 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/>.
glrdir = $(docdir)/%D%
## ----------- ##
## c++-types. ##
## ----------- ##
check_PROGRAMS += %D%/c++-types
TESTS += %D%/c++-types.test
EXTRA_DIST += %D%/c++-types.test
nodist_%C%_c___types_SOURCES = %D%/c++-types.y
%D%/c++-types.c: $(dependencies)
# Don't use gnulib's system headers.
%C%_c___types_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_c___types_CFLAGS = $(TEST_CFLAGS)
dist_glr_DATA = %D%/c++-types.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/c++-types.[ch] %D%/c++-types.output
CLEANDIRS += %D%/*.dSYM
+2 -7
View File
@@ -4,12 +4,11 @@
BASE = lexcalc
BISON = bison
FLEX = flex
XSLTPROC = xsltproc
all: $(BASE)
%.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
%.c %.h %.html %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --header --html --graph -o $*.c $<
%.c: %.l
$(FLEX) $(FLEXFLAGS) -o$@ $<
@@ -22,10 +21,6 @@ run: $(BASE)
@echo "Type arithmetic expressions. Quit with ctrl-d."
./$<
html: parse.html
%.html: %.xml
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
CLEANFILES = \
$(BASE) *.o \
parse.[ch] parse.output parse.xml parse.html parse.gv \
+1 -1
View File
@@ -11,7 +11,7 @@ fill-column: 76
ispell-dictionary: "american"
End:
Copyright (C) 2018-2020 Free Software Foundation, Inc.
Copyright (C) 2018-2021 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.

Some files were not shown because too many files have changed in this diff Show More