Compare commits

...
90 Commits
Author SHA1 Message Date
Akim Demaille 2a069f22c6 version 3.6.4
* NEWS: Record release date.
2020-06-15 20:18:50 +02:00
Akim Demaille 3f4ffea6f2 glr.cc: don't leak glr.c/glr.cc scaffolding to the user
Until we have a decent reimplementation of glr.cc, we have to use
tricks to shoehorn C++ symbols to the C engine of glr.c.  Some of them
are done via #define.  Unfortunately in Bison 3.6 some of these we
done in the header file, which broke valid user code.

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

* data/skeletons/glr.cc: Stop playing tricks with b4_pre_epilogue.
(b4_glr_cc_setup, b4_glr_cc_cleanup): New.
Much cleaner way to instal glr.cc's scaffolding around glr.c.
* data/skeletons/glr.c: Adjust to use them.
2020-06-15 20:18:47 +02:00
Akim Demaille 508ac09939 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-03 07:52:30 +02:00
Akim Demaille 0535d2a608 version 3.6.3
* NEWS: Record release date.
2020-06-03 07:31:43 +02:00
Akim Demaille 52ce2a008b build: check -Wmissing-prototypes
pstate_clear is lacking a prototype.
Reported by Ryan
https://lists.gnu.org/r/bug-bison/2020-05/msg00101.html

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

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

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

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

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

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

* examples/c/bistromathic/parse.y, examples/c/reccalc/scan.l: Fix
warnings.
* doc/bison.texi: Discard scanf's return value to defeat
-Werror=unused-result.
2020-06-01 08:29:53 +02:00
Akim Demaille 12f4091de4 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 18:02:44 +02:00
Akim Demaille 8ece778cb8 c++: fix printing of state number on streams
Avoid this kind of display:

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

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 18:02:24 +02:00
Akim Demaille f80890c4bb fix generated comments
In Bison 3.6.2, the comments with brackets lose their brackets, for
improper m4 quotation.

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

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

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

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

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

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

we generate

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

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

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

* data/skeletons/c-like.m4 (_b4_comment): Escape comment delimiters in
comments.
* tests/input.at (Torturing the Scanner): Check thes cases.
* tests/m4.at: New.
2020-05-17 08:28:12 +02:00
Akim Demaille 6a28e6d412 todo: update 2020-05-15 07:18:15 +02:00
Akim Demaille f4495da337 examples: use markdown hyperlinks
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/README.md: here.
2020-05-14 07:26:55 +02:00
Akim Demaille dbaed0bbf2 tests: don't use == to compare const char *...
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00091.html

* tests/c++.at: here.
2020-05-14 07:26:34 +02:00
Akim Demaille 78c7fb6460 gnulib: update 2020-05-14 07:25:09 +02:00
Akim Demaille da29809969 news: update 2020-05-10 17:32:28 +02:00
Akim Demaille 87e4895189 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-10 14:47:51 +02:00
Akim Demaille 01e3f45f83 version 3.6.1
* NEWS: Record release date.
2020-05-10 14:28:24 +02:00
Akim Demaille 091943f265 c++: style: reorder generated code
The implementation of yy::parser::symbol_name is emitted even before
the implementation of yy::parser::parser.  This makes little sense.

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

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

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

* data/skeletons/yacc.c: Don't use // comments.
2020-05-09 17:05:03 +02:00
Akim Demaille 0c77d69721 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-05-08 10:15:38 +02:00
Akim Demaille 307fcdee00 version 3.6
* NEWS: Record release date.
2020-05-08 09:57:14 +02:00
Akim Demaille d26d10ad6c examples: beware of portability issue on Windows
Reported by Jannick.
https://lists.gnu.org/r/bug-bison/2020-05/msg00040.html
https://lists.gnu.org/r/bug-bison/2020-05/msg00066.html

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

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

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

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

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

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

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

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

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

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

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

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

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

    $ cat bistro.test
    if true; then
    fi

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

which relies on several private implementation details.

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

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

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

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

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

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

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

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

* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/variant.hh: Delete the copy-ctor and the copy operator.
2020-05-01 06:52:04 +02:00
Akim Demaille fb1d76d9a9 yacc.c: avoid the use of a temporary
* data/skeletons/yacc.c: Use YYLLOC_DEFAULT directly with the final
destination.
2020-04-30 08:07:55 +02:00
Akim Demaille a61bc3f9f8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-04-29 09:07:50 +02:00
74 changed files with 1477 additions and 761 deletions
+1 -1
View File
@@ -1 +1 @@
3.5.90
3.6.3
+58 -40
View File
@@ -46,7 +46,7 @@ jobs:
- ./bootstrap
- ./configure --enable-gcc-warnings || { cat config.log && false; }
- make -j2
- make -j2 dist
- make -j2 dist-xz
# Can help understanding why we get "dirty" tarballs.
- git status
- dist=$(echo bison*.xz)
@@ -69,53 +69,53 @@ jobs:
# Start with three completely different environments, to get errors asap.
- name: "GCC 9 -O3"
- name: "GCC 10 -O3"
stage: check
os: linux
dist: bionic
addons: &gcc9
addons: &gcc10
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-9
packages: g++-10
env:
- CC=gcc-9
- CXX=g++-9
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
# ASAN is time consuming, and we timeout the 50min granted by
# Travis if we run all the tests in one go. Run in two parts.
- name: "Clang 9 libc++ and ASAN part 1"
- name: "Clang 10 libc++ and ASAN part 1"
stage: check
os: linux
dist: bionic
addons: &clang9
addons: &clang10
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-9
- libc++-9-dev
- libc++abi-9-dev
- clang-10
- libc++-10-dev
- libc++abi-10-dev
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-9 -fsanitize=address'
- CXX='clang++-9 -fsanitize=address -stdlib=libc++'
- CC='clang-10 -fsanitize=address'
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
- PART=1
- name: "Clang 9 libc++ and ASAN part 2"
- name: "Clang 10 libc++ and ASAN part 2"
stage: check
os: linux
dist: bionic
addons: *clang9
addons: *clang10
env:
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
- CC='clang-9 -fsanitize=address'
- CXX='clang++-9 -fsanitize=address -stdlib=libc++'
- CC='clang-10 -fsanitize=address'
- CXX='clang++-10 -fsanitize=address -stdlib=libc++'
- PART=2
- name: "ICC"
@@ -135,46 +135,41 @@ jobs:
packages:
- intel-oneapi-icc
## ------- ##
## First. ##
## ------- ##
# Start with three completely different environments, to get
# errors asap.
- name: "ARM64: GCC 9 -O3 part 1"
- name: "ARM64: GCC 10 -O3 part 1"
stage: check
os: linux
arch: arm64
dist: bionic
addons: *gcc9
addons: *gcc10
env:
- CC=gcc-9
- CXX=g++-9
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- PART=1
# GCC10 on PPC seems to be buggy.
# E.g., https://travis-ci.org/github/akimd/bison/jobs/687812428.
- name: "PPC64le: GCC 9 part 1"
stage: check
os: linux
arch: ppc64le
dist: bionic
addons: *gcc9
addons: *gcc10
env:
- CC=gcc-9
- CXX=g++-9
- CONFIGUREFLAGS='CFLAGS=-O3 CXXFLAGS=-O3'
- PART=1
- name: "s390x: GCC 9 part 1"
- name: "s390x: GCC 10 part 1"
stage: check
os: linux
arch: s390x
dist: bionic
addons: *gcc9
addons: *gcc10
env:
- CC=gcc-9
- CXX=g++-9
- CC=gcc-10
- CXX=g++-10
- CONFIGUREFLAGS='CFLAGS=-O3 CXXFLAGS=-O3'
- PART=1
@@ -182,15 +177,19 @@ jobs:
## GCC. ##
## ----- ##
- name: "GCC 8 with sanitizers part 1"
- name: "GCC 9 with sanitizers part 1"
stage: check
os: linux
dist: bionic
addons:
apt:
packages: g++-8
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages: g++-9
env:
- CC='gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer'
- CXX='g++-8 -fsanitize=undefined,address -fno-omit-frame-pointer'
- 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'
- PART=1
@@ -292,7 +291,27 @@ jobs:
## Clang. ##
## ------- ##
- name: "Clang 8 -O3"
- name: "Clang 9 -O3"
stage: check
os: linux
dist: bionic
addons:
apt:
sources:
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
- sourceline: 'ppa:ubuntu-toolchain-r/test'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang-9
- libc++-9-dev
- libc++abi-9-dev
env:
- CC='clang-9'
- CXX='clang++-9 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- name: "Clang 8"
stage: check
os: linux
dist: bionic
@@ -305,7 +324,6 @@ jobs:
env:
- CC=clang-8
- CXX='clang++-8 -stdlib=libc++'
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
- name: "Clang 7"
stage: check
+4
View File
@@ -127,3 +127,7 @@ gen-ChangeLog:
--since=$(gen_start_date) > $$cl.tmp && \
mv -f $$cl.tmp $$cl; \
fi
# Useful to debug.
.c.i:
$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -o $@ -E $<
+82 -48
View File
@@ -1,27 +1,49 @@
GNU Bison NEWS
* Noteworthy changes in release 3.5.91 (2020-04-29) [stable]
* Noteworthy changes in release 3.6.4 (2020-06-15) [stable]
** Bug fixes
In glr.cc some internal macros leaked in the user's code, and could damage
access to the token kinds.
* Noteworthy changes in release 3.6.3 (2020-06-03) [stable]
** Bug fixes
Incorrect comments in the generated parsers.
Warnings in push parsers (yacc.c).
Incorrect display of gotos in LAC traces (lalr1.cc).
* Noteworthy changes in release 3.6.2 (2020-05-17) [stable]
** Bug fixes
Some tests were fixed.
When token aliases contain comment delimiters:
%token FOO "/* foo */"
bison used to emit "nested" comments, which is invalid C.
* Noteworthy changes in release 3.6.1 (2020-05-10) [stable]
** Bug fixes
Restored ANSI-C compliance in yacc.c.
GNU readline portability issues.
In C++, yy::parser::symbol_name is now a public member, as was intended.
** New features
*** Returning the error token
In C++, yy::parser::symbol_type now has a public name() member function.
When the scanner returns an invalid token or the undefined token
(YYUNDEF), the parser generates an error message and enters error
recovery. Because of that error message, most scanners that find lexical
errors generate an error message, and then ignore the invalid input
without entering the error-recovery.
The scanners may now return YYerror, the error token, to enter the
error-recovery mode without triggering an additional error message. See
the bistromathic for an example.
*** The bistromathic features internationalization
Its way to build the error message is more general and is easy to use in
other projects.
* Noteworthy changes in release 3.5.90 (2020-04-18) [beta]
* Noteworthy changes in release 3.6 (2020-05-08) [stable]
** Backward incompatible changes
@@ -126,6 +148,18 @@ GNU Bison NEWS
It makes little sense to use this feature without enabling LAC (lookahead
correction).
*** Returning the error token
When the scanner returns an invalid token or the undefined token
(YYUNDEF), the parser generates an error message and enters error
recovery. Because of that error message, most scanners that find lexical
errors generate an error message, and then ignore the invalid input
without entering the error-recovery.
The scanners may now return YYerror, the error token, to enter the
error-recovery mode without triggering an additional error message. See
the bistromathic for an example.
*** Deep overhaul of the symbol and token kinds
To avoid the confusion with types in programming languages, we now refer
@@ -213,8 +247,8 @@ GNU Bison NEWS
*** Examples
There are now two examples in examples/java: a very simple calculator, and
one that tracks locations to provide accurate error messages.
There are now examples/java: a very simple calculator, and a more complete
one (push-parser, location tracking, and debug traces).
The lexcalc example (a simple example in C based on Flex and Bison) now
also demonstrates location tracking.
@@ -2545,7 +2579,7 @@ GNU Bison NEWS
Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
halts in the middle of its course.
* Changes in version 2.5 (2011-05-14):
* Noteworthy changes in release 2.5 (2011-05-14)
** Grammar symbol names can now contain non-initial dashes:
@@ -2900,7 +2934,7 @@ GNU Bison NEWS
This bug has been fixed.
* Changes in version 2.4.3 (2010-08-05):
* Noteworthy changes in release 2.4.3 (2010-08-05)
** Bison now obeys -Werror and --warnings=error for warnings about
grammar rules that are useless in the parser due to conflicts.
@@ -2920,7 +2954,7 @@ GNU Bison NEWS
** Minor documentation fixes.
* Changes in version 2.4.2 (2010-03-20):
* Noteworthy changes in release 2.4.2 (2010-03-20)
** Some portability problems that resulted in failures and livelocks
in the test suite on some versions of at least Solaris, AIX, HP-UX,
@@ -3014,7 +3048,7 @@ GNU Bison NEWS
message translations were not installed although supported by the
host system.
* Changes in version 2.4.1 (2008-12-11):
* Noteworthy changes in release 2.4.1 (2008-12-11)
** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
declarations have been fixed.
@@ -3039,7 +3073,7 @@ GNU Bison NEWS
** A few minor improvements to the Bison manual.
* Changes in version 2.4 (2008-11-02):
* Noteworthy changes in release 2.4 (2008-11-02)
** %language is an experimental feature.
@@ -3054,7 +3088,7 @@ GNU Bison NEWS
** Several bugs in the C++ skeleton and the experimental Java skeleton have been
fixed.
* Changes in version 2.3b (2008-05-27):
* Noteworthy changes in release 2.3b (2008-05-27)
** The quotes around NAME that used to be required in the following directive
are now deprecated:
@@ -3240,7 +3274,7 @@ GNU Bison NEWS
** The nonfunctional --no-parser, -n, and %no-parser options have been
completely removed from Bison.
* Changes in version 2.3a, 2006-09-13:
* Noteworthy changes in release 2.3a (2006-09-13)
** Instead of %union, you can define and use your own union type
YYSTYPE if your grammar contains at least one <type> tag.
@@ -3354,7 +3388,7 @@ GNU Bison NEWS
The old spelling still works, but is not documented and may be removed
in a future release.
* Changes in version 2.3, 2006-06-05:
* Noteworthy changes in release 2.3 (2006-06-05)
** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING",
for compatibility with LALR(1) grammars.
@@ -3362,7 +3396,7 @@ GNU Bison NEWS
** It is now documented that any definition of YYSTYPE or YYLTYPE should
be to a type name that does not contain parentheses or brackets.
* Changes in version 2.2, 2006-05-19:
* Noteworthy changes in release 2.2 (2006-05-19)
** The distribution terms for all Bison-generated parsers now permit
using the parsers in nonfree programs. Previously, this permission
@@ -3444,7 +3478,7 @@ GNU Bison NEWS
** DJGPP support added.
* Changes in version 2.1, 2005-09-16:
* Noteworthy changes in release 2.1 (2005-09-16)
** The C++ lalr1.cc skeleton supports %lex-param.
@@ -3470,7 +3504,7 @@ GNU Bison NEWS
print 'syntax error, unexpected number' instead of 'syntax error,
unexpected "number"'.
* Changes in version 2.0, 2004-12-25:
* Noteworthy changes in release 2.0 (2004-12-25)
** Possibly-incompatible changes
@@ -3533,7 +3567,7 @@ GNU Bison NEWS
- Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
* Changes in version 1.875, 2003-01-01:
* Noteworthy changes in release 1.875 (2003-01-01)
** The documentation license has been upgraded to version 1.2
of the GNU Free Documentation License.
@@ -3653,7 +3687,7 @@ GNU Bison NEWS
ago, but nobody noticed until we recently asked someone to try
building Bison with a K&R C compiler.
* Changes in version 1.75, 2002-10-14:
* Noteworthy changes in release 1.75 (2002-10-14)
** Bison should now work on 64-bit hosts.
@@ -3684,7 +3718,7 @@ GNU Bison NEWS
was incorrectly rejected: $1 is defined in the second midrule
action, and is equal to the $$ of the first midrule action.
* Changes in version 1.50, 2002-10-04:
* Noteworthy changes in release 1.50 (2002-10-04)
** GLR parsing
The declaration
@@ -3828,7 +3862,7 @@ GNU Bison NEWS
** GNU M4 is now required when using Bison.
* Changes in version 1.35, 2002-03-25:
* Noteworthy changes in release 1.35 (2002-03-25)
** C Skeleton
Some projects use Bison's C parser with C++ compilers, and define
@@ -3843,7 +3877,7 @@ GNU Bison NEWS
This kludge also addresses some C++ problems when the stack was
extended.
* Changes in version 1.34, 2002-03-12:
* Noteworthy changes in release 1.34 (2002-03-12)
** File name clashes are detected
$ bison foo.y -d -o foo.x
@@ -3863,7 +3897,7 @@ GNU Bison NEWS
** Fix test suite portability problems.
* Changes in version 1.33, 2002-02-07:
* Noteworthy changes in release 1.33 (2002-02-07)
** Fix C++ issues
Groff could not be compiled for the definition of size_t was lacking
@@ -3872,7 +3906,7 @@ GNU Bison NEWS
** Catch invalid @n
As is done with $n.
* Changes in version 1.32, 2002-01-23:
* Noteworthy changes in release 1.32 (2002-01-23)
** Fix Yacc output file names
@@ -3880,7 +3914,7 @@ GNU Bison NEWS
** Italian, Dutch translations
* Changes in version 1.31, 2002-01-14:
* Noteworthy changes in release 1.31 (2002-01-14)
** Many Bug Fixes
@@ -3967,7 +4001,7 @@ GNU Bison NEWS
** --output
New, aliasing "--output-file".
* Changes in version 1.30, 2001-10-26:
* Noteworthy changes in release 1.30 (2001-10-26)
** "--defines" and "--graph" have now an optional argument which is the
output file name. "-d" and "-g" do not change; they do not take any
@@ -3978,7 +4012,7 @@ GNU Bison NEWS
** Portability fixes.
* Changes in version 1.29, 2001-09-07:
* Noteworthy changes in release 1.29 (2001-09-07)
** The output file does not define const, as this caused problems when used
with common autoconfiguration schemes. If you still use ancient compilers
@@ -4013,7 +4047,7 @@ GNU Bison NEWS
** @$
Automatic location tracking.
* Changes in version 1.28, 1999-07-06:
* Noteworthy changes in release 1.28 (1999-07-06)
** Should compile better now with K&R compilers.
@@ -4023,12 +4057,12 @@ GNU Bison NEWS
** There is now a FAQ.
* Changes in version 1.27:
* Noteworthy changes in release 1.27
** The make rule which prevented bison.simple from being created on
some systems has been fixed.
* Changes in version 1.26:
* Noteworthy changes in release 1.26
** Bison now uses Automake.
@@ -4045,7 +4079,7 @@ GNU Bison NEWS
** Generated parsers should now work even on operating systems which do
not provide alloca().
* Changes in version 1.25, 1995-10-16:
* Noteworthy changes in release 1.25 (1995-10-16)
** Errors in the input grammar are not fatal; Bison keeps reading
the grammar file, and reports all the errors found in it.
@@ -4070,7 +4104,7 @@ the parser engine; a project can now use its own parser engine.
The actions go into a separate file called NAME.act, in the form of
a switch statement body.
* Changes in version 1.23:
* Noteworthy changes in release 1.23
The user can define YYPARSE_PARAM as the name of an argument to be
passed into yyparse. The argument should have type void *. It should
@@ -4079,11 +4113,11 @@ by casting it to the proper pointer type.
Line numbers in output file corrected.
* Changes in version 1.22:
* Noteworthy changes in release 1.22
--help option added.
* Changes in version 1.20:
* Noteworthy changes in release 1.20
Output file does not redefine const for C++.
+4
View File
@@ -20,6 +20,7 @@ Anthony Heading [email protected]
Antonio Silva Correia [email protected]
Arnold Robbins [email protected]
Art Haas [email protected]
Arthur Schwarz [email protected]
Askar Safin [email protected]
Balázs Scheidler [email protected]
Baron Schwartz [email protected]
@@ -57,6 +58,7 @@ Derek M. Jones [email protected]
Di-an Jan [email protected]
Dick Streefland [email protected]
Didier Godefroy [email protected]
Don Macpherson [email protected]
Efi Fogel [email protected]
Enrico Scholz [email protected]
Eric Blake [email protected]
@@ -154,11 +156,13 @@ Petr Machata [email protected]
Pho [email protected]
Piotr Gackiewicz [email protected]
Piotr Marcińczyk [email protected]
Pramod Kumbhar [email protected]
Quentin Hocquet [email protected]
Quoc Peyrot [email protected]
R Blake [email protected]
Raja R Harinath [email protected]
Ralf Wildenhues [email protected]
Ryan [email protected]
Rich Wilson [email protected]
Richard Stallman [email protected]
Rici Lake [email protected]
+94 -9
View File
@@ -1,4 +1,18 @@
* Bison 3.6
* Bison 3.7
** glr.cc
Get rid of global_tokens_and_yystype.
** Bistromathic
- Hitting tab on a line with a syntax error is ugly
- Be robust to existing ~/.inputrc
- How about not evaluating incomplete lines when the text is not finished
(as shells do).
** Doc
*** api.header.include
** Questions
*** Java
- Should i18n be part of the Lexer? Currently it's a static method of
@@ -25,13 +39,9 @@ should be updated to not use YYERRCODE. Returning an undef token is good
enough.
** Java
*** Examples
Have an example with a push parser. Use autocompletion in that case.
*** calc.at
Stop hard-coding "Calc". Adjust local.at (look for FIXME).
* Bison 3.7
** Counter example generation
See https://github.com/akimd/bison/pull/15.
@@ -71,8 +81,79 @@ a bad feature. On the other hand, that would make it much harder to sit
push parsers on top of pull parser. Which is currently not relevant, since
push parsers are measurably slower.
** %define parse.error formatted
How about pushing bistromathics' 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:
const char *
error_format_string (int argc)
{
switch (argc)
{
default: /* Avoid compiler warnings. */
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
// "unexpected token", and '%0e', '%1e'... are expected tokens
// at this point.
//
// For instance on the expression "1 + * 2", you'd get
//
// 1.5: syntax error: expected - or ( or number or function or variable before *
case 2: return _("%@: syntax error: expected %0e before %u");
case 3: return _("%@: syntax error: expected %0e or %1e before %u");
case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
}
}
The message would have to be generated in a string, and pushed to yyerror.
Which will be a pain in the neck in yacc.c.
If we want to do that, we should think very carefully about the syntax of
the format string.
** yyclearin does not invoke the lookahead token's %destructor
https://lists.gnu.org/r/bug-bison/2018-02/msg00000.html
Rici:
> Modifying yyclearin so that it calls yydestruct seems like the simplest
> solution to this issue, but it is conceivable that such a change would
> break programs which already perform some kind of workaround in order to
> destruct the lookahead symbol. So it might be necessary to use some kind of
> compatibility %define, or to create a new replacement macro with a
> different name such as yydiscardin.
>
> At a minimum, the fact that yyclearin does not invoke the %destructor
> should be highlighted in the documentation, since it is not at all obvious.
** Issues in i18n
Les catégories d'avertissements incluent :
conflicts-sr conflits S/R (activé par défaut)
conflicts-rr conflits R/R (activé par défaut)
dangling-alias l'alias chaîne n'est pas attaché à un symbole
deprecated construction obsolète
empty-rule règle vide sans %empty
midrule-values valeurs de règle intermédiaire non définies ou inutilisées
precedence priorité et associativité inutiles
yacc incompatibilités avec POSIX Yacc
other tous les autres avertissements (activé par défaut)
all tous les avertissements sauf « dangling-alias » et « yacc »
no-CATEGORY désactiver les avertissements dans CATEGORIE
none désactiver tous les avertissements
error[=CATEGORY] traiter les avertissements comme des erreurs
Line -1 and -3 should mention CATEGORIE, not CATEGORY.
* Bison 3.8
** Rewrite glr.cc
Get rid of scaffolding in glr.c.
** 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.,
@@ -146,10 +227,10 @@ define it to the same type as the C ptrdiff_t type.
* Completion
Several features are not available in all the backends.
- push parsers: glr.c, glr.cc, lalr1.cc
- lac: D, Java
- glr: D, Java
- token constructors: Java, C, D
- 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)
* Bugs
** Autotest has quotation issues
@@ -353,8 +434,12 @@ LORIA, INRIA Nancy - Grand Est, Nancy, France
** More languages?
Well, only if there is really some demand for it.
*** PHP
https://github.com/scfc/bison-php/blob/master/data/lalr1.php
*** Python
https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
** Multiple start symbols
Would be very useful when parsing closely related languages. The idea is to
declare several start symbols, for instance
+7
View File
@@ -73,6 +73,11 @@ def diff_to_re(match):
is_diff = True
to.append(l)
if is_diff:
# Do not run s//SOMETHING/g (with an emty pattern), that won't
# work well...
if frm == []:
trace("no from for", match.group(1))
return
frm = "\n".join(frm)
to = "\n".join(to)
subst[frm] = to
@@ -112,4 +117,6 @@ def process(logfile):
for logfile in args.logs:
trace("FILE:", logfile)
if os.path.isdir(logfile):
logfile = os.path.join(logfile, 'testsuite.log')
process(logfile)
+1 -1
View File
@@ -51,7 +51,7 @@ gnulib_dir = $(srcdir)/gnulib
bootstrap-tools = autoconf,automake,flex,gettext,gnulib
announcement_Cc_ = \
[email protected], [email protected], bison-patches@gnu.org, \
[email protected], bison-announce@gnu.org, \
[email protected]
update-copyright: update-b4-copyright update-package-copyright-year
+14 -7
View File
@@ -36,10 +36,8 @@ AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT_YEAR], [$PACKAGE_COPYRIGHT_YEAR],
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
# We use Automake 1.14's %D% and %C%.
#
# When we move to Automake 1.16, simplify examples/c/reccalc/local.mk.
# Our CI runs on Xenial, which has only Automake 1.15.
# Our CI build the packages on Bionic, which has only Automake 1.15.
#
# We want gnits strictness only when rolling a stable release. For
# release candidates, we use version strings like 2.4.3_rc1, but gnits
@@ -47,7 +45,7 @@ AC_CONFIG_MACRO_DIR([m4])
# releases, we want to be able run make dist without being required to
# add a bogus NEWS entry. In that case, the version string
# automatically contains a dash, which we also let disable gnits.
AM_INIT_AUTOMAKE([1.14 dist-xz nostdinc
AM_INIT_AUTOMAKE([1.15 dist-lzip dist-xz nostdinc
color-tests parallel-tests
silent-rules]
m4_bmatch(m4_defn([AC_PACKAGE_VERSION]), [[-_]],
@@ -137,7 +135,9 @@ if test "$enable_gcc_warnings" = yes; then
-Wpointer-arith -Wshadow
-Wwrite-strings
-wr188 -wr2259 -wr3179'
warn_c='-Wbad-function-cast -Wstrict-prototypes'
warn_c='-Wbad-function-cast
-Wmissing-prototypes
-Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept -Wold-style-cast -Wundefined-func-template
-Wweak-vtables'
# Warnings for the test suite only.
@@ -261,9 +261,9 @@ if ! "$LEX_IS_FLEX" || test "X$LEX" = X:; then
AC_MSG_WARN([bypassing lex because flex is required])
LEX=:
fi
AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX])
AM_CONDITIONAL([FLEX_WORKS], [$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT])
AM_CONDITIONAL([FLEX_CXX_WORKS],
[$LEX_IS_FLEX && test $bison_cv_cxx_works = yes])
[$LEX_IS_FLEX && $FLEX_SUPPORTS_HEADER_OPT && test $bison_cv_cxx_works = yes])
AC_PROG_YACC
AC_PROG_RANLIB
AC_PROG_GNU_M4
@@ -332,6 +332,13 @@ AC_MSG_RESULT([$suppfile])
# Whether we cannot run the compiled bison.
AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
# Build bistromathic if we have the lib and both readline/readline.h
# and readline/history.h.
AM_CONDITIONAL([ENABLE_BISTROMATHIC],
[test "$gl_cv_lib_readline" != no &&
test "$ac_cv_header_readline_readline_h" = yes &&
test "$ac_cv_header_readline_history_h" = yes])
AM_MISSING_PROG([AUTOM4TE], [autom4te])
# Needed by tests/atlocal.in.
AC_SUBST([GCC])
+1
View File
@@ -34,6 +34,7 @@ dist_skeletons_DATA = \
data/skeletons/lalr1.java \
data/skeletons/location.cc \
data/skeletons/stack.hh \
data/skeletons/traceon.m4 \
data/skeletons/variant.hh \
data/skeletons/yacc.c
+21
View File
@@ -19,6 +19,27 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...)
# ----------------------------------------------
# m4 equivalent of
#
# $_ = STRING;
# s/RE1/SUBST1/g;
# s/RE2/SUBST2/g;
# ...
#
# Really similar to m4_bpatsubsts, but behaves properly with quotes.
# See m4.at's "Generating Comments". Super inelegant, but so far, I
# did not find any better solution.
m4_define([b4_gsub],
[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]],
[$2], [$3]),
[$4], [$5]),
[$6], [$7])])
## ---------------- ##
## Identification. ##
## ---------------- ##
+38 -3
View File
@@ -259,14 +259,14 @@ m4_define([b4_public_types_declare],
struct token
{
]b4_token_enums[
/// Backward compatibility alias.
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype;
};
/// Token kind, as returned by yylex.
typedef token::yytokentype token_kind_type;
/// Backward compatibility alias.
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type token_type;
/// Symbol kinds.
@@ -357,7 +357,30 @@ m4_define([b4_symbol_type_define],
Base::clear ();
}
/// Backward compatibility.
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of this symbol.
const char *name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of this symbol.
std::string name () const YY_NOEXCEPT
{
return ]b4_parser_class[::symbol_name (this->kind ());
}]])[
/// Backward compatibility (Bison 3.6).
symbol_kind_type type_get () const YY_NOEXCEPT;
/// Whether empty.
@@ -409,11 +432,17 @@ m4_define([b4_symbol_type_define],
/// \a empty when empty.
symbol_kind_type kind () const YY_NOEXCEPT;
/// Backward compatibility (Bison 3.6).
symbol_kind_type type_get () const YY_NOEXCEPT;
/// The symbol kind.
/// \a ]b4_symbol_prefix[YYEMPTY when empty.
symbol_kind_type kind_;
};
/// Backward compatibility for a private implementation detail (Bison 3.6).
typedef by_kind by_type;
/// "External" symbols: returned by the scanner.
struct symbol_type : basic_symbol<by_kind>
{]b4_variant_if([[
@@ -531,6 +560,12 @@ m4_define([b4_public_types_define],
{
return kind_;
}
]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
]])
+7 -1
View File
@@ -17,15 +17,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://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]).
# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close
# the comments before its end.
#
# Prefix all the output lines with PREFIX.
m4_define([_b4_comment],
[$2[]m4_bpatsubst(m4_expand([[$1]]), [
[$2[]b4_gsub(m4_expand([$1]),
[[*]/], [*\\/],
[/[*]], [/\\*],
[
\(.\)], [
$3\1])$4])
+49 -1
View File
@@ -205,7 +205,11 @@ m4_define([b4_c99_int_type],
# Define private types suitable for holding small integers in C99 or later.
m4_define([b4_c99_int_type_define],
[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl
[/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
[#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */
@@ -261,6 +265,50 @@ typedef int yytype_uint16;
#endif]])
# b4_sizes_types_define
# ---------------------
# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM,
# and YYSIZEOF.
m4_define([b4_sizes_types_define],
[[#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
]])
# b4_int_type_for(NAME)
# ---------------------
# Return a narrow int type able to handle numbers ranging from
+57 -55
View File
@@ -230,7 +230,9 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations])[
]b4_declare_symbol_enum[
]b4_glr_cc_if([b4_glr_cc_setup],
[b4_declare_symbol_enum])[
/* Default (constant) value used for initialization for null
right-hand sides. Unlike the standard yacc.c template, here we set
@@ -249,6 +251,7 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
#include <string.h>
]b4_c99_int_type_define[
]b4_sizes_types_define[
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
@@ -277,9 +280,6 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
# define YYREALLOC realloc
#endif
#define YYSIZEMAX \
(PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
#ifdef __cplusplus
typedef bool yybool;
# define yytrue true
@@ -507,7 +507,7 @@ struct yyGLRState {
/** Preceding state in this stack */
yyGLRState* yypred;
/** Source position of the last token produced by my symbol */
ptrdiff_t yyposn;
YYPTRDIFF_T yyposn;
union {
/** First in a chain of alternative reductions producing the
* nonterminal corresponding to this state, threaded through
@@ -527,8 +527,8 @@ struct yyGLRStateSet {
* operation, yylookaheadNeeds[0] is not maintained since it would merely
* duplicate yychar != ]b4_symbol(-2, id)[. */
yybool* yylookaheadNeeds;
ptrdiff_t yysize;
ptrdiff_t yycapacity;
YYPTRDIFF_T yysize;
YYPTRDIFF_T yycapacity;
};
struct yySemanticOption {
@@ -568,7 +568,7 @@ struct yyGLRStack {
YYJMP_BUF yyexception_buffer;
yyGLRStackItem* yyitems;
yyGLRStackItem* yynextFree;
ptrdiff_t yyspaceLeft;
YYPTRDIFF_T yyspaceLeft;
yyGLRState* yysplitPoint;
yyGLRState* yylastDeleted;
yyGLRStateSet yytops;
@@ -680,7 +680,7 @@ yysymbol_name (yysymbol_kind_t yysymbol)
multiple parsers can coexist. */
int yydebug;
static void yypstack (yyGLRStack* yystackp, ptrdiff_t yyk)
static void yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk)
YY_ATTRIBUTE_UNUSED;
static void yypdumpstack (yyGLRStack* yystackp)
YY_ATTRIBUTE_UNUSED;
@@ -696,7 +696,7 @@ static void yypdumpstack (yyGLRStack* yystackp)
[simple],
[[]],
[[#ifndef yystrlen
# define yystrlen(S) (YY_CAST (ptrdiff_t, strlen (S)))
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
#endif
]b4_parse_error_bmatch(
@@ -731,12 +731,12 @@ yystpcpy (char *yydest, const char *yysrc)
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static ptrdiff_t
static YYPTRDIFF_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
ptrdiff_t yyn = 0;
YYPTRDIFF_T yyn = 0;
char const *yyp = yystr;
for (;;)
@@ -1104,7 +1104,7 @@ yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
* alternative actions for YYSTATE. Assumes that YYRHS comes from
* stack #YYK of *YYSTACKP. */
static void
yyaddDeferredAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyGLRState* yystate,
yyaddDeferredAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyGLRState* yystate,
yyGLRState* yyrhs, yyRuleNum yyrule)
{
yySemanticOption* yynewOption =
@@ -1136,14 +1136,14 @@ yyinitStateSet (yyGLRStateSet* yyset)
yyset->yycapacity = 16;
yyset->yystates
= YY_CAST (yyGLRState**,
YYMALLOC (YY_CAST (size_t, yyset->yycapacity)
YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity)
* sizeof yyset->yystates[0]));
if (! yyset->yystates)
return yyfalse;
yyset->yystates[0] = YY_NULLPTR;
yyset->yylookaheadNeeds
= YY_CAST (yybool*,
YYMALLOC (YY_CAST (size_t, yyset->yycapacity)
YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity)
* sizeof yyset->yylookaheadNeeds[0]));
if (! yyset->yylookaheadNeeds)
{
@@ -1152,7 +1152,7 @@ yyinitStateSet (yyGLRStateSet* yyset)
}
memset (yyset->yylookaheadNeeds,
0,
YY_CAST (size_t, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]);
YY_CAST (YYSIZE_T, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]);
return yytrue;
}
@@ -1165,14 +1165,14 @@ static void yyfreeStateSet (yyGLRStateSet* yyset)
/** Initialize *YYSTACKP to a single empty stack, with total maximum
* capacity for all stacks of YYSIZE. */
static yybool
yyinitGLRStack (yyGLRStack* yystackp, ptrdiff_t yysize)
yyinitGLRStack (yyGLRStack* yystackp, YYPTRDIFF_T yysize)
{
yystackp->yyerrState = 0;
yynerrs = 0;
yystackp->yyspaceLeft = yysize;
yystackp->yyitems
= YY_CAST (yyGLRStackItem*,
YYMALLOC (YY_CAST (size_t, yysize)
YYMALLOC (YY_CAST (YYSIZE_T, yysize)
* sizeof yystackp->yynextFree[0]));
if (!yystackp->yyitems)
return yyfalse;
@@ -1198,9 +1198,9 @@ yyexpandGLRStack (yyGLRStack* yystackp)
{
yyGLRStackItem* yynewItems;
yyGLRStackItem* yyp0, *yyp1;
ptrdiff_t yynewSize;
ptrdiff_t yyn;
ptrdiff_t yysize = yystackp->yynextFree - yystackp->yyitems;
YYPTRDIFF_T yynewSize;
YYPTRDIFF_T yyn;
YYPTRDIFF_T yysize = yystackp->yynextFree - yystackp->yyitems;
if (YYMAXDEPTH - YYHEADROOM < yysize)
yyMemoryExhausted (yystackp);
yynewSize = 2*yysize;
@@ -1208,7 +1208,7 @@ yyexpandGLRStack (yyGLRStack* yystackp)
yynewSize = YYMAXDEPTH;
yynewItems
= YY_CAST (yyGLRStackItem*,
YYMALLOC (YY_CAST (size_t, yynewSize)
YYMALLOC (YY_CAST (YYSIZE_T, yynewSize)
* sizeof yynewItems[0]));
if (! yynewItems)
yyMemoryExhausted (yystackp);
@@ -1273,7 +1273,7 @@ yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
/** Invalidate stack #YYK in *YYSTACKP. */
static inline void
yymarkStackDeleted (yyGLRStack* yystackp, ptrdiff_t yyk)
yymarkStackDeleted (yyGLRStack* yystackp, YYPTRDIFF_T yyk)
{
if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
@@ -1297,7 +1297,7 @@ yyundeleteLastStack (yyGLRStack* yystackp)
static inline void
yyremoveDeletes (yyGLRStack* yystackp)
{
ptrdiff_t yyi, yyj;
YYPTRDIFF_T yyi, yyj;
yyi = yyj = 0;
while (yyj < yystackp->yytops.yysize)
{
@@ -1330,8 +1330,8 @@ yyremoveDeletes (yyGLRStack* yystackp)
* state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
* value *YYVALP and source location *YYLOCP. */
static inline void
yyglrShift (yyGLRStack* yystackp, ptrdiff_t yyk, yy_state_t yylrState,
ptrdiff_t yyposn,
yyglrShift (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState,
YYPTRDIFF_T yyposn,
YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
{
yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
@@ -1351,8 +1351,8 @@ yyglrShift (yyGLRStack* yystackp, ptrdiff_t yyk, yy_state_t yylrState,
* state YYLRSTATE, at input position YYPOSN, with the (unresolved)
* semantic value of YYRHS under the action for YYRULE. */
static inline void
yyglrShiftDefer (yyGLRStack* yystackp, ptrdiff_t yyk, yy_state_t yylrState,
ptrdiff_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
yyglrShiftDefer (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState,
YYPTRDIFF_T yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
{
yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
YY_ASSERT (yynewState->yyisState);
@@ -1382,7 +1382,7 @@ yyglrShiftDefer (yyGLRStack* yystackp, ptrdiff_t yyk, yy_state_t yylrState,
`----------------------------------------------------------------------*/
static inline void
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, ptrdiff_t yyk,
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk,
yyRuleNum yyrule]b4_user_formals[)
{
int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
@@ -1415,7 +1415,7 @@ yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, ptrdiff_t yyk,
* and *YYLOCP to the computed location (if any). Return value is as
* for userAction. */
static inline YYRESULTTAG
yydoAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
YYSTYPE* yyvalp]b4_locuser_formals[)
{
int yynrhs = yyrhsLength (yyrule);
@@ -1467,10 +1467,10 @@ yydoAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
* added to the options for the existing state's semantic value.
*/
static inline YYRESULTTAG
yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
yybool yyforceEval]b4_user_formals[)
{
ptrdiff_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
YYPTRDIFF_T yyposn = yystackp->yytops.yystates[yyk]->yyposn;
if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
{
@@ -1492,7 +1492,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
}
else
{
ptrdiff_t yyi;
YYPTRDIFF_T yyi;
int yyn;
yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
yy_state_t yynewLRState;
@@ -1534,8 +1534,8 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
return yyok;
}
static ptrdiff_t
yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
static YYPTRDIFF_T
yysplitStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk)
{
if (yystackp->yysplitPoint == YY_NULLPTR)
{
@@ -1544,8 +1544,8 @@ yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
}
if (yystackp->yytops.yycapacity <= yystackp->yytops.yysize)
{
ptrdiff_t state_size = sizeof yystackp->yytops.yystates[0];
ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
YYPTRDIFF_T state_size = YYSIZEOF (yystackp->yytops.yystates[0]);
YYPTRDIFF_T half_max_capacity = YYSIZE_MAXIMUM / 2 / state_size;
if (half_max_capacity < yystackp->yytops.yycapacity)
yyMemoryExhausted (yystackp);
yystackp->yytops.yycapacity *= 2;
@@ -1554,7 +1554,7 @@ yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
yyGLRState** yynewStates
= YY_CAST (yyGLRState**,
YYREALLOC (yystackp->yytops.yystates,
(YY_CAST (size_t, yystackp->yytops.yycapacity)
(YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity)
* sizeof yynewStates[0])));
if (yynewStates == YY_NULLPTR)
yyMemoryExhausted (yystackp);
@@ -1565,7 +1565,7 @@ yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
yybool* yynewLookaheadNeeds
= YY_CAST (yybool*,
YYREALLOC (yystackp->yytops.yylookaheadNeeds,
(YY_CAST (size_t, yystackp->yytops.yycapacity)
(YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity)
* sizeof yynewLookaheadNeeds[0])));
if (yynewLookaheadNeeds == YY_NULLPTR)
yyMemoryExhausted (yystackp);
@@ -1996,8 +1996,8 @@ yycompressStack (yyGLRStack* yystackp)
}
static YYRESULTTAG
yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
ptrdiff_t yyposn]b4_pure_formals[)
yyprocessOneStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk,
YYPTRDIFF_T yyposn]b4_pure_formals[)
{
while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
{
@@ -2040,7 +2040,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
for (/* nothing */; *yyconflicts; yyconflicts += 1)
{
YYRESULTTAG yyflag;
ptrdiff_t yynewStack = yysplitStack (yystackp, yyk);
YYPTRDIFF_T yynewStack = yysplitStack (yystackp, yyk);
YY_DPRINTF ((stderr, "Splitting off stack %ld from %ld.\n",
YY_CAST (long, yynewStack), YY_CAST (long, yyk)));
yyflag = yyglrReduce (yystackp, yynewStack,
@@ -2121,6 +2121,8 @@ yypcontext_expected_tokens (const yyGLRStack* yystackp,
yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
}
}
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = ]b4_symbol(-2, kind)[;
return yycount;
}]])[
@@ -2228,7 +2230,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
one per "expected"). */
yysymbol_kind_t yyarg[YYARGS_MAX];
/* Cumulated lengths of YYARG. */
ptrdiff_t yysize = 0;
YYPTRDIFF_T yysize = 0;
/* Actual size of YYARG. */
int yycount
@@ -2259,11 +2261,11 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
int yyi;
for (yyi = 0; yyi < yycount; ++yyi)
{
ptrdiff_t yysz
YYPTRDIFF_T yysz
= ]b4_parse_error_case(
[verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]],
[[yystrlen (yysymbol_name (yyarg[yyi]))]]);[
if (YYSIZEMAX - yysize < yysz)
if (YYSIZE_MAXIMUM - yysize < yysz)
yysize_overflow = yytrue;
else
yysize += yysz;
@@ -2271,7 +2273,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
}
if (!yysize_overflow)
yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (size_t, yysize)));
yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (YYSIZE_T, yysize)));
if (yymsg)
{
@@ -2348,7 +2350,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
/* Reduce to one stack. */
{
ptrdiff_t yyk;
YYPTRDIFF_T yyk;
for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
break;
@@ -2423,7 +2425,7 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
int yyresult;
yyGLRStack yystack;
yyGLRStack* const yystackp = &yystack;
ptrdiff_t yyposn;
YYPTRDIFF_T yyposn;
YY_DPRINTF ((stderr, "Starting parse\n"));
@@ -2505,7 +2507,7 @@ b4_dollar_popdef])[]dnl
while (yytrue)
{
yysymbol_kind_t yytoken_to_shift;
ptrdiff_t yys;
YYPTRDIFF_T yys;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(-2, id)[;
@@ -2612,8 +2614,8 @@ b4_dollar_popdef])[]dnl
yyGLRState** yystates = yystack.yytops.yystates;
if (yystates)
{
ptrdiff_t yysize = yystack.yytops.yysize;
ptrdiff_t yyk;
YYPTRDIFF_T yysize = yystack.yytops.yysize;
YYPTRDIFF_T yyk;
for (yyk = 0; yyk < yysize; yyk += 1)
if (yystates[yyk])
{
@@ -2660,7 +2662,7 @@ yypstates (yyGLRState* yyst)
}
static void
yypstack (yyGLRStack* yystackp, ptrdiff_t yyk)
yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk)
{
yypstates (yystackp->yytops.yystates[yyk]);
}
@@ -2705,7 +2707,7 @@ yypdumpstack (yyGLRStack* yystackp)
YY_FPRINTF ((stderr, "Tops:"));
{
ptrdiff_t yyi;
YYPTRDIFF_T yyi;
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
YY_FPRINTF ((stderr, "%ld: %ld; ", YY_CAST (long, yyi),
YYINDEX (yystackp->yytops.yystates[yyi])));
@@ -2731,7 +2733,7 @@ m4_if(b4_prefix, [yy], [],
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])])[
]m4_ifdef([b4_pre_epilogue], [b4_pre_epilogue])[]dnl This is a hack for glr.cc. To remove when we have a better glr.cc.
b4_percent_code_get([[epilogue]])[]dnl
]b4_glr_cc_if([b4_glr_cc_cleanup])[
]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
b4_output_end
+49 -30
View File
@@ -105,12 +105,6 @@ yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
])[const char* msg);]])[
]b4_percent_define_flag_if([[global_tokens_and_yystype]], [],
[m4_define([b4_pre_epilogue],
[[/* The user is using the C++ token kind, not the C one. */
#undef ]b4_symbol(0, [id])
])])[
# Hijack the epilogue to define implementations (yyerror, parser member
# functions etc.).
]m4_append([b4_epilogue],
@@ -222,6 +216,53 @@ b4_namespace_close[]dnl
])
# b4_glr_cc_setup
# ---------------
# 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])[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
#define ]b4_symbol_prefix[YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY
#define ]b4_symbol_prefix[YYerror ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYerror
#define ]b4_symbol_prefix[YYEOF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF
#define ]b4_symbol_prefix[YYUNDEF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
]])
# b4_glr_cc_cleanup
# -----------------
# Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup],
[b4_percent_define_flag_if([[global_tokens_and_yystype]], [],
[[#undef ]b4_symbol(-2, [id])[
#undef ]b4_symbol(0, [id])[
#undef ]b4_symbol(1, [id])[
]])[
#undef ]b4_api_PREFIX[STYPE
#undef ]b4_api_PREFIX[LTYPE
#undef ]b4_symbol_prefix[YYEMPTY
#undef ]b4_symbol_prefix[YYerror
#undef ]b4_symbol_prefix[YYEOF
#undef ]b4_symbol_prefix[YYUNDEF
]])
# b4_shared_declarations(hh|cc)
# -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh)
@@ -339,33 +380,11 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
])[
]b4_namespace_close[
]dnl Map the name used in c.m4 to the one used in c++.m4.
[#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])[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
#endif
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
#endif
]m4_define([b4_declare_symbol_enum],
[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
#define ]b4_symbol_prefix[YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY
#define ]b4_symbol_prefix[YYerror ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYerror
#define ]b4_symbol_prefix[YYEOF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF
#define ]b4_symbol_prefix[YYUNDEF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
]])[
]b4_percent_code_get([[provides]])[
]m4_popdef([b4_parse_param])dnl
])
])[
b4_defines_if(
]b4_defines_if(
[b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[
+115 -96
View File
@@ -204,6 +204,13 @@ m4_define([b4_shared_declarations],
]b4_parser_class[ (]b4_parse_param_decl[);
virtual ~]b4_parser_class[ ();
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
]b4_parser_class[ (const ]b4_parser_class[&) = delete;
/// Non copyable.
]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete;
#endif
/// Parse. An alias for parse ().
/// \returns 0 iff parsing succeeded.
int operator() ();
@@ -234,6 +241,23 @@ m4_define([b4_shared_declarations],
/// Report a syntax error.
void error (const syntax_error& err);
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static std::string symbol_name (symbol_kind_type yysymbol);]])[
]b4_token_constructor_define[
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
class context
@@ -255,10 +279,13 @@ m4_define([b4_shared_declarations],
};
]])[
private:
/// This class is not copyable.
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
]b4_parser_class[ (const ]b4_parser_class[&);
]b4_parser_class[& operator= (const ]b4_parser_class[&);]b4_lac_if([[
/// Non copyable.
]b4_parser_class[& operator= (const ]b4_parser_class[&);
#endif
]b4_lac_if([[
/// Check the lookahead yytoken.
/// \returns true iff the token will be eventually shifted.
bool yy_lac_check_ (symbol_kind_type yytoken) const;
@@ -307,26 +334,14 @@ m4_define([b4_shared_declarations],
static symbol_kind_type yytranslate_ (int t);
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);
/// For a symbol, its name in clear.
static const char* const yytname_[];
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static std::string symbol_name (symbol_kind_type yysymbol);
/// Convert the symbol name \a n to a form suitable for a diagnostic.
[[ /// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *yystr);
/// For a symbol, its name in clear.
@@ -464,6 +479,7 @@ m4_define([b4_shared_declarations],
};
]b4_parse_param_vars[
]b4_percent_code_get([[yy_bison_internal_hook]])[
};
]b4_token_ctor_if([b4_yytranslate_define([$1])[
@@ -597,83 +613,6 @@ m4_if(b4_prefix, [yy], [],
#define YYRECOVERING() (!!yyerrstatus_)
]b4_namespace_open[
]b4_parse_error_bmatch([custom\|detailed],
[[ const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
static const char *const yy_sname[] =
{
]b4_symbol_names[
};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
{
]b4_translatable[
};
return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
? _(yy_sname[yysymbol])
: yy_sname[yysymbol]);]], [[
return yy_sname[yysymbol];]])[
}
]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytname_[yysymbol];
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
std::string
]b4_parser_class[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
std::string
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytnamerr_ (yytname_[yysymbol]);
}
]])[
/// Build a parser object.
]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)
#if ]b4_api_PREFIX[DEBUG
@@ -805,7 +744,7 @@ m4_if(b4_prefix, [yy], [],
{
symbol_kind_type yykind = yysym.kind ();
yyo << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << symbol_name (yykind) << " ("]b4_locations_if([
<< ' ' << yysym.name () << " ("]b4_locations_if([
<< yysym.location << ": "])[;
]b4_symbol_actions([printer])[
yyo << ')';
@@ -1257,8 +1196,86 @@ b4_dollar_popdef])[]dnl
{
error (]b4_join(b4_locations_if([yyexc.location]),
[[yyexc.what ()]])[);
}]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
}
]b4_parse_error_bmatch([custom\|detailed],
[[ const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
static const char *const yy_sname[] =
{
]b4_symbol_names[
};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
{
]b4_translatable[
};
return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
? _(yy_sname[yysymbol])
: yy_sname[yysymbol]);]], [[
return yy_sname[yysymbol];]])[
}
]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytname_[yysymbol];
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
std::string
]b4_parser_class[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
std::string
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytnamerr_ (yytname_[yysymbol]);
}
]])[
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
// ]b4_parser_class[::context.
]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla)
: yyparser_ (yyparser)
@@ -1316,6 +1333,8 @@ b4_dollar_popdef])[]dnl
}
}
]])[
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = symbol_kind::]b4_symbol(-2, kind)[;
return yycount;
}
@@ -1392,7 +1411,7 @@ b4_dollar_popdef])[]dnl
: yylac_stack_.back ());
// Push the resulting state of the reduction.
state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]);
YYCDEBUG << " G" << state;
YYCDEBUG << " G" << int (state);
yylac_stack_.push_back (state);
}
}
+96 -100
View File
@@ -121,7 +121,7 @@ import java.text.MessageFormat;
* Locations represent a part of the input through the beginning
* and ending positions.
*/
public class ]b4_location_type[ {
public static class ]b4_location_type[ {
/**
* The first, inclusive, position in the range.
*/
@@ -182,25 +182,24 @@ import java.text.MessageFormat;
]b4_token_enums[
/** Deprecated, use ]b4_symbol(0, id)[ instead. */
public static final int EOF = ]b4_symbol(0, id)[;
]b4_locations_if([[
]b4_pull_if([b4_locations_if([[
/**
* Method to retrieve the beginning position of the last scanned token.
* @@return the position at which the last scanned token starts.
*/
]b4_position_type[ getStartPos ();
]b4_position_type[ getStartPos();
/**
* Method to retrieve the ending position of the last scanned token.
* @@return the first position beyond the last scanned token.
*/
]b4_position_type[ getEndPos ();]])[
]b4_position_type[ getEndPos();]])[
/**
* Method to retrieve the semantic value of the last scanned token.
* @@return the semantic value of the last scanned token.
*/
]b4_yystype[ getLVal ();
]b4_yystype[ getLVal();
/**
* Entry point for the scanner. Returns the token identifier corresponding
@@ -208,24 +207,25 @@ import java.text.MessageFormat;
* ]b4_locations_if([and beginning/ending positions ])[of the token.
* @@return the token identifier corresponding to the next token.
*/
int yylex ()]b4_maybe_throws([b4_lex_throws])[;
int yylex()]b4_maybe_throws([b4_lex_throws])[;
]])[
/**
* Entry point for error reporting. Emits an error
* ]b4_locations_if([referring to the given location ])[in a user-defined way.
* Emit an error]b4_locations_if([ referring to the given location])[in a user-defined way.
*
*]b4_locations_if([[ @@param loc The location of the element to which the
* error message is related]])[
* error message is related.]])[
* @@param msg The string for the error message.
*/
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);
void yyerror(]b4_locations_if([b4_location_type[ loc, ]])[String msg);
]b4_parse_error_bmatch(
[custom], [[
/**
* Build and emit a syntax error message.
* Build and emit a "syntax error" message in a user-defined way.
*
* @@param ctx The context of the error.
*/
void reportSyntaxError (][Context yyctx);
void reportSyntaxError (][Context ctx);
]])[
}
@@ -307,9 +307,8 @@ import java.text.MessageFormat;
*]b4_locations_if([[ Use a <code>null</code> location.]])[
* @@param msg The error message.
*/
public final void yyerror (String msg)
{
yylexer.yyerror (]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
public final void yyerror(String msg) {
yylexer.yyerror(]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
}
]b4_locations_if([[
/**
@@ -317,9 +316,8 @@ import java.text.MessageFormat;
* @@param loc The location associated with the message.
* @@param msg The error message.
*/
public final void yyerror (]b4_location_type[ loc, String msg)
{
yylexer.yyerror (loc, msg);
public final void yyerror(]b4_location_type[ loc, String msg) {
yylexer.yyerror(loc, msg);
}
/**
@@ -327,9 +325,8 @@ import java.text.MessageFormat;
* @@param pos The position associated with the message.
* @@param msg The error message.
*/
public final void yyerror (]b4_position_type[ pos, String msg)
{
yylexer.yyerror (new ]b4_location_type[ (pos), msg);
public final void yyerror(]b4_position_type[ pos, String msg) {
yylexer.yyerror(new ]b4_location_type[ (pos), msg);
}]])[
]b4_parse_trace_if([[
protected final void yycdebug (String s) {
@@ -469,7 +466,7 @@ import java.text.MessageFormat;
return yydefgoto_[yysym - YYNTOKENS_];
}
private int yyaction (int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[
private int yyaction(int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[
{
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'. Otherwise, use the top of the stack.
@@ -477,10 +474,10 @@ import java.text.MessageFormat;
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. */
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);]b4_locations_if([[
]b4_location_type[ yyloc = yylloc (yystack, yylen);]])[]b4_parse_trace_if([[
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0);]b4_locations_if([[
]b4_location_type[ yyloc = yylloc(yystack, yylen);]])[]b4_parse_trace_if([[
yyReducePrint (yyn, yystack);]])[
yyReducePrint(yyn, yystack);]])[
switch (yyn)
{
@@ -488,13 +485,13 @@ import java.text.MessageFormat;
default: break;
}]b4_parse_trace_if([[
yySymbolPrint ("-> $$ =", SymbolKind.get (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
yySymbolPrint("-> $$ =", SymbolKind.get(yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
yystack.pop (yylen);
yystack.pop(yylen);
yylen = 0;
/* Shift the result of the reduction. */
int yystate = yyLRGotoState (yystack.stateAt (0), yyr1_[yyn]);
yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]);
yystack.push(yystate, yyval]b4_locations_if([, yyloc])[);
return YYNEWSTATE;
}
@@ -504,13 +501,14 @@ import java.text.MessageFormat;
`--------------------------------*/
private void yySymbolPrint(String s, SymbolKind yykind,
]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[)
{
yycdebug (s
+ (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ")
+ yykind.getName() + " ("]b4_locations_if([
+ yylocation + ": "])[
+ (yyvalue == null ? "(null)" : yyvalue.toString()) + ")");
]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[) {
if (0 < yydebug) {
yycdebug(s
+ (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ")
+ yykind.getName() + " ("]b4_locations_if([
+ yylocation + ": "])[
+ (yyvalue == null ? "(null)" : yyvalue.toString()) + ")");
}
}]])[
]b4_push_if([],[[
@@ -521,7 +519,7 @@ import java.text.MessageFormat;
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
* imply that there were no syntax errors.
*/
public boolean parse ()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
]b4_push_if([
/**
* Push Parse input from external lexer
@@ -532,7 +530,7 @@ import java.text.MessageFormat;
*
* @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
*/
public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
public int push_parse(int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
{]b4_locations_if([[
/* @@$. */
]b4_location_type[ yyloc;]])[
@@ -612,8 +610,8 @@ b4_dollar_popdef[]dnl
/* Convert token to internal form. */
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
yySymbolPrint ("Next token is", yytoken,
yylval]b4_locations_if([, yylloc])[);]])[
yySymbolPrint("Next token is", yytoken,
yylval]b4_locations_if([, yylloc])[);]])[
if (yytoken == SymbolKind.]b4_symbol_prefix[YYerror)
{
@@ -649,8 +647,8 @@ b4_dollar_popdef[]dnl
else
{
/* Shift the lookahead token. */]b4_parse_trace_if([[
yySymbolPrint ("Shifting", yytoken,
yylval]b4_locations_if([, yylloc])[);
yySymbolPrint("Shifting", yytoken,
yylval]b4_locations_if([, yylloc])[);
]])[
/* Discard the token being shifted. */
yychar = YYEMPTY_;
@@ -683,7 +681,7 @@ b4_dollar_popdef[]dnl
`-----------------------------*/
case YYREDUCE:
yylen = yyr2_[yyn];
label = yyaction (yyn, yystack, yylen);
label = yyaction(yyn, yystack, yylen);
yystate = yystack.stateAt (0);
break;
@@ -781,8 +779,8 @@ b4_dollar_popdef[]dnl
yystack.pop (2);]])[
/* Shift the error token. */]b4_parse_trace_if([[
yySymbolPrint ("Shifting", SymbolKind.get (yystos_[yyn]),
yylval]b4_locations_if([, yyloc])[);]])[
yySymbolPrint("Shifting", SymbolKind.get (yystos_[yyn]),
yylval]b4_locations_if([, yyloc])[);]])[
yystate = yyn;
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
@@ -833,7 +831,7 @@ b4_dollar_popdef[]dnl
this.push_parse_initialized = true;
}
]b4_locations_if([
]b4_locations_if([[
/**
* Push parse given input from an external lexer.
*
@@ -843,36 +841,32 @@ b4_dollar_popdef[]dnl
*
* @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
*/
public int push_parse (int yylextoken, b4_yystype yylexval, b4_position_type yylexpos)b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])
{
return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
public int push_parse(int yylextoken, ]b4_yystype[ yylexval, ]b4_position_type[ yylexpos)]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ {
return push_parse(yylextoken, yylexval, new ]b4_location_type[(yylexpos));
}
])[]])[
]])])[
]b4_both_if([[
/**
* Parse input from the scanner that was specified at object construction
* time. Return whether the end of the input was reached successfully.
* This version of parse () is defined only when api.push-push=both.
* This version of parse() is defined only when api.push-push=both.
*
* @@return <tt>true</tt> if the parsing succeeds. Note that this does not
* imply that there were no syntax errors.
*/
public boolean parse ()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
{
if (yylexer == null)
throw new NullPointerException("Null Lexer");
int status;
do {
int token = yylexer.yylex();
]b4_yystype[ lval = yylexer.getLVal();
]b4_locations_if([dnl
b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
yylexer.getEndPos ());])[]b4_locations_if([[
status = push_parse(token,lval,yyloc);]], [[
status = push_parse(token,lval);]])[
} while (status == YYPUSH_MORE);
return (status == YYACCEPT);
public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ {
if (yylexer == null)
throw new NullPointerException("Null Lexer");
int status;
do {
int token = yylexer.yylex();
]b4_yystype[ lval = yylexer.getLVal();]b4_locations_if([[
]b4_location_type[ yyloc = new ]b4_location_type[(yylexer.getStartPos(), yylexer.getEndPos());
status = push_parse(token, lval, yyloc);]], [[
status = push_parse(token, lval);]])[
} while (status == YYPUSH_MORE);
return status == YYACCEPT;
}
]])[
@@ -950,6 +944,8 @@ b4_dollar_popdef[]dnl
yyarg[yycount++] = SymbolKind.get (yyx);
}
}
if (yyarg != null && yycount == yyoffset && yyoffset < yyargn)
yyarg[yycount] = null;
return yycount - yyoffset;
}
}
@@ -996,39 +992,39 @@ b4_dollar_popdef[]dnl
}
]])[
/**
* Report a syntax error.
/**
* Build and emit a "syntax error" message in a user-defined way.
*
* @@param ctx The context of the error.
*/
private void yyreportSyntaxError (Context yyctx)
{]b4_parse_error_bmatch(
private void yyreportSyntaxError(Context yyctx) {]b4_parse_error_bmatch(
[custom], [[
yylexer.reportSyntaxError (yyctx);]],
yylexer.reportSyntaxError(yyctx);]],
[detailed\|verbose], [[
if (yyErrorVerbose)
{
final int argmax = 5;
SymbolKind[] yyarg = new SymbolKind[argmax];
int yycount = yysyntaxErrorArguments (yyctx, yyarg, argmax);
String[] yystr = new String[yycount];
for (int yyi = 0; yyi < yycount; ++yyi)
yystr[yyi] = yyarg[yyi].getName();
String yyformat;
switch (yycount)
{
default:
case 0: yyformat = ]b4_trans(["syntax error"])[; break;
case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break;
case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break;
case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break;
case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break;
case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break;
if (yyErrorVerbose) {
final int argmax = 5;
SymbolKind[] yyarg = new SymbolKind[argmax];
int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax);
String[] yystr = new String[yycount];
for (int yyi = 0; yyi < yycount; ++yyi) {
yystr[yyi] = yyarg[yyi].getName();
}
yyerror (]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat (yyformat).format (yystr));
return;
}
yyerror (]b4_locations_if([[yyctx.yylocation, ]])["syntax error");]],
String yyformat;
switch (yycount) {
default:
case 0: yyformat = ]b4_trans(["syntax error"])[; break;
case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break;
case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break;
case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break;
case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break;
case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break;
}
yyerror(]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat(yyformat).format(yystr));
} else {
yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[);
}]],
[simple], [[
yyerror (]b4_locations_if([[yyctx.yylocation, ]])["syntax error");]])[
yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[);]])[
}
/**
@@ -1074,10 +1070,10 @@ 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))]),
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
b4_rhs_location(yynrhs, yyi + 1)])[);
yySymbolPrint(" $" + (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)])[);
}]])[
/* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
+11
View File
@@ -41,6 +41,13 @@ m4_define([b4_stack_define],
: seq_ (n)
{}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
stack (const stack&) = delete;
/// Non copyable.
stack& operator= (const stack&) = delete;
#endif
/// Random access.
///
/// Index 0 returns the topmost element.
@@ -126,8 +133,12 @@ m4_define([b4_stack_define],
};
private:
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
stack (const stack&);
/// Non copyable.
stack& operator= (const stack&);
#endif
/// The wrapped container.
S seq_;
};
+2
View File
@@ -0,0 +1,2 @@
dnl GNU M4 treats -dV in a position-independent manner.
m4_debugmode(V)m4_traceon()dnl
+12 -2
View File
@@ -115,6 +115,13 @@ m4_define([b4_value_type_declare],
new (yyas_<T> ()) T (YY_MOVE (t));
}
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
semantic_type (const self_type&) = delete;
/// Non copyable.
self_type& operator= (const self_type&) = delete;
#endif
/// Destruction, allowed only if empty.
~semantic_type () YY_NOEXCEPT
{]b4_parse_assert_if([
@@ -258,9 +265,12 @@ m4_define([b4_value_type_declare],
}
private:
/// Prohibit blind copies.
self_type& operator= (const self_type&);
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
semantic_type (const self_type&);
/// Non copyable.
self_type& operator= (const self_type&);
#endif
/// Accessor to raw memory as \a T.
template <typename T>
+12 -51
View File
@@ -132,6 +132,7 @@ m4_define([b4_rhs_value],
# b4_lhs_location()
# -----------------
# Expansion of @$.
# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar".
m4_define([b4_lhs_location],
[(yyloc)])
@@ -140,6 +141,7 @@ m4_define([b4_lhs_location],
# ---------------------------------
# Expansion of @POS, where the current rule has RULE-LENGTH symbols
# on RHS.
# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar".
m4_define([b4_rhs_location],
[(yylsp@{b4_subtract([$2], [$1])@})])
@@ -401,50 +403,10 @@ m4_if(b4_api_prefix, [yy], [],
]b4_declare_symbol_enum[
]b4_user_post_prologue[
]b4_percent_code_get[]dnl
[#ifdef short
# undef short
#endif
]b4_percent_code_get[
]b4_c99_int_type_define[
#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
]b4_sizes_types_define[
/* Stored state numbers (used for stacks). */
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t;
@@ -826,9 +788,8 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&]b4_rhs_value(yynrhs, yyi + 1)[
]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
b4_user_args[);
&]b4_rhs_value(yynrhs, yyi + 1)[]b4_locations_if([,
&]b4_rhs_location(yynrhs, yyi + 1))[]b4_user_args[);
YYFPRINTF (stderr, "\n");
}
}
@@ -1197,6 +1158,8 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
}
}]])[
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = ]b4_symbol(-2, kind)[;
return yycount;
}
@@ -1517,7 +1480,7 @@ yypull_parse (yypstate *yyps]b4_user_formals[)
]b4_parse_state_variable_macros([b4_pstate_macro_define])[
/* Initialize the parser data structure. */
void
static void
yypstate_clear (yypstate *yyps)
{
]b4_initialize_parser_state_variables[
@@ -2016,7 +1979,7 @@ yyerrorlab:
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
// Pop stack until we find a state that shifts the error token.
/* Pop stack until we find a state that shifts the error token. */
for (;;)
{
yyn = yypact[yystate];
@@ -2052,10 +2015,8 @@ yyerrlab1:
YY_IGNORE_MAYBE_UNINITIALIZED_END
]b4_locations_if([[
yyerror_range[2] = yylloc;
/* Using YYLLOC is tempting, but would change the location of
the lookahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
*++yylsp = yyloc;]])[
++yylsp;
YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);]])[
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
+151 -84
View File
@@ -300,10 +300,7 @@ Bison Declarations
Parser C-Language Interface
* Parser Function:: How to call @code{yyparse} and what it returns.
* Push Parser Function:: How to call @code{yypush_parse} and what it returns.
* Pull Parser Function:: How to call @code{yypull_parse} and what it returns.
* Parser Create Function:: How to call @code{yypstate_new} and what it returns.
* Parser Delete Function:: How to call @code{yypstate_delete} and what it returns.
* Push Parser Interface:: How to create, use, and destroy push parsers.
* Lexical:: You must supply a function @code{yylex}
which reads tokens.
* Error Reporting:: Passing error messages to the user.
@@ -1882,6 +1879,7 @@ Here is the code for the lexical analyzer:
and tabs, and returns 0 for end-of-input. */
#include <ctype.h>
#include <stdlib.h>
@end group
@group
@@ -1898,7 +1896,8 @@ yylex (void)
if (c == '.' || isdigit (c))
@{
ungetc (c, stdin);
scanf ("%lf", &yylval);
if (scanf ("%lf", &yylval) != 1)
abort ();
return NUM;
@}
@end group
@@ -2369,9 +2368,9 @@ yylex (void)
@end group
@end example
Basically, the lexical analyzer performs the same processing as before:
it skips blanks and tabs, and reads numbers or single-character tokens.
In addition, it updates @code{yylloc}, the global variable (of type
Basically, the lexical analyzer performs the same processing as before: it
skips blanks and tabs, and reads numbers or single-character tokens. In
addition, it updates @code{yylloc}, the global variable (of type
@code{YYLTYPE}) containing the token's location.
Now, each time this function returns a token, the parser has its kind as
@@ -2731,7 +2730,8 @@ yylex (void)
if (c == '.' || isdigit (c))
@{
ungetc (c, stdin);
scanf ("%lf", &yylval.NUM);
if (scanf ("%lf", &yylval.NUM) != 1)
abort ();
return NUM;
@}
@end group
@@ -2758,10 +2758,10 @@ Bison generated a definition of @code{YYSTYPE} with a member named
if (bufsize <= i)
@{
bufsize = 2 * bufsize + 40;
symbuf = realloc (symbuf, bufsize);
symbuf = realloc (symbuf, (size_t) bufsize);
@}
/* Add this character to the buffer. */
symbuf[i++] = c;
symbuf[i++] = (char) c;
/* Get another character. */
c = getchar ();
@}
@@ -4505,12 +4505,17 @@ typedef struct YYLTYPE
@} YYLTYPE;
@end example
While default locations represent a range in the source file(s), this is not
a requirement. It could be a single point or just a line number, or even
more complex structures.
When @code{YYLTYPE} is not defined, at the beginning of the parsing, Bison
initializes all these fields to 1 for @code{yylloc}. To initialize
@code{yylloc} with a custom location type (or to chose a different
initialization), use the @code{%initial-action} directive. @xref{Initial
Action Decl}.
@node Actions and Locations
@subsection Actions and Locations
@cindex location actions
@@ -6132,7 +6137,7 @@ the @code{full} value was introduced in Bison 2.7
@deffn Directive {%define api.push-pull} @var{kind}
@itemize @bullet
@item Language(s): C (deterministic parsers only)
@item Language(s): C (deterministic parsers only), Java
@item Purpose: Request a pull parser, a push parser, or both.
@xref{Push Decl}.
@@ -6922,10 +6927,7 @@ in the grammar file, you are likely to run into trouble.
@menu
* Parser Function:: How to call @code{yyparse} and what it returns.
* Push Parser Function:: How to call @code{yypush_parse} and what it returns.
* Pull Parser Function:: How to call @code{yypull_parse} and what it returns.
* Parser Create Function:: How to call @code{yypstate_new} and what it returns.
* Parser Delete Function:: How to call @code{yypstate_delete} and what it returns.
* Push Parser Interface:: How to create, use, and destroy push parsers.
* Lexical:: You must supply a function @code{yylex}
which reads tokens.
* Error Reporting:: Passing error messages to the user.
@@ -7028,16 +7030,40 @@ void yyerror (YYLTYPE *llocp, int *randomness, const char *msg);
int yyparse (int *randomness);
@end example
@node Push Parser Function
@section The Push Parser Function @code{yypush_parse}
@findex yypush_parse
@node Push Parser Interface
@section Push Parser Interface
You call the function @code{yypush_parse} to parse a single token. This
@findex yypstate_new
You call the function @code{yypstate_new} to create a new parser instance.
This function is available if either the @samp{%define api.push-pull push}
or @samp{%define api.push-pull both} declaration is used. @xref{Push Decl}.
@deftypefun {yypstate*} yypstate_new (@code{void})
@anchor{yypstate_new}
Return a valid parser instance if there is memory available, 0 otherwise.
In impure mode, it will also return 0 if a parser instance is currently
allocated.
@end deftypefun
@findex yypstate_delete
You call the function @code{yypstate_delete} to delete a parser instance.
function is available if either the @samp{%define api.push-pull push} or
@samp{%define api.push-pull both} declaration is used.
@xref{Push Decl}.
@deftypefun void yypstate_delete (@code{yypstate *}@var{yyps})
@anchor{yypstate_delete}
Reclaim the memory associated with a parser instance. After this call, you
should no longer attempt to use the parser instance.
@end deftypefun
@findex yypush_parse
You call the function @code{yypush_parse} to parse a single token. This
function is available if either the @samp{%define api.push-pull push} or
@samp{%define api.push-pull both} declaration is used. @xref{Push Decl}.
@deftypefun int yypush_parse (@code{yypstate *}@var{yyps})
@anchor{yypush_parse}
The value returned by @code{yypush_parse} is the same as for @code{yyparse}
with the following exception: it returns @code{YYPUSH_MORE} if more input is
required to finish parsing the grammar.
@@ -7051,50 +7077,35 @@ reuse. For example, a calculator application which parses each input line
as an expression can just keep reusing the same @code{yyps} even if an input
was invalid.
@node Pull Parser Function
@section The Pull Parser Function @code{yypull_parse}
@findex yypull_parse
You call the function @code{yypull_parse} to parse the rest of the input
stream. This function is available if the @samp{%define api.push-pull both}
declaration is used.
@xref{Push Decl}.
declaration is used. @xref{Push Decl}.
@deftypefun int yypull_parse (@code{yypstate *}@var{yyps})
@anchor{yypull_parse}
The value returned by @code{yypull_parse} is the same as for @code{yyparse}.
The parser instance @code{yyps} may be reused for new parses.
@end deftypefun
@node Parser Create Function
@section The Parser Create Function @code{yystate_new}
@findex yypstate_new
@deftypefun int yypstate_expected_tokens (@code{const yypstate *}yyps, @code{yysymbol_kind_t} @var{argv}@code{[]}, @code{int} @var{argc})
Fill @var{argv} with the expected tokens, which never includes
@code{YYSYMBOL_YYEMPTY}, @code{YYSYMBOL_YYerror}, or
@code{YYSYMBOL_YYUNDEF}.
You call the function @code{yypstate_new} to create a new parser instance.
This function is available if either the @samp{%define api.push-pull push} or
@samp{%define api.push-pull both} declaration is used.
@xref{Push Decl}.
Never put more than @var{argc} elements into @var{argv}, and on success
return the number of tokens stored in @var{argv}. If there are more
expected tokens than @var{argc}, fill @var{argv} up to @var{argc} and return
0. If there are no expected tokens, also return 0, but set @code{argv[0]}
to @code{YYSYMBOL_YYEMPTY}.
@deftypefun {yypstate*} yypstate_new (@code{void})
The function will return a valid parser instance if there was memory available
or 0 if no memory was available.
In impure mode, it will also return 0 if a parser instance is currently
allocated.
When LAC is enabled, may return a negative number on errors,
such as @code{YYENOMEM} on memory exhaustion.
If @var{argv} is null, return the size needed to store all the possible
values, which is always less than @code{YYNTOKENS}.
@end deftypefun
@node Parser Delete Function
@section The Parser Delete Function @code{yystate_delete}
@findex yypstate_delete
You call the function @code{yypstate_delete} to delete a parser instance.
function is available if either the @samp{%define api.push-pull push} or
@samp{%define api.push-pull both} declaration is used.
@xref{Push Decl}.
@deftypefun void yypstate_delete (@code{yypstate *}@var{yyps})
This function will reclaim the memory associated with a parser instance.
After this call, you should no longer attempt to use the parser instance.
@end deftypefun
@node Lexical
@section The Lexical Analyzer Function @code{yylex}
@@ -7546,9 +7557,12 @@ Fill @var{argv} with the expected tokens, which never includes
@code{YYSYMBOL_YYUNDEF}.
Never put more than @var{argc} elements into @var{argv}, and on success
return the effective number of tokens stored in @var{argv}. Return 0 if
there are more than @var{argc} expected tokens, yet fill @var{argv} up to
@var{argc}. When LAC is enabled, may return a negative number on errors,
return the number of tokens stored in @var{argv}. If there are more
expected tokens than @var{argc}, fill @var{argv} up to @var{argc} and return
0. If there are no expected tokens, also return 0, but set @code{argv[0]}
to @code{YYSYMBOL_YYEMPTY}.
When LAC is enabled, may return a negative number on errors,
such as @code{YYENOMEM} on memory exhaustion.
If @var{argv} is null, return the size needed to store all the possible
@@ -7655,11 +7669,11 @@ recovery.
In either case, the rest of the action is not executed.
@end deffn
@deffn {Macro} YYEMPTY
@deffn {Value} YYEMPTY
Value stored in @code{yychar} when there is no lookahead token.
@end deffn
@deffn {Macro} YYEOF
@deffn {Value} YYEOF
Value stored in @code{yychar} when the lookahead is the end of the input
stream.
@end deffn
@@ -9645,10 +9659,10 @@ and understand the parser run-time traces (@pxref{Tracing}).
@node Understanding
@section Understanding Your Parser
As documented elsewhere (@pxref{Algorithm})
Bison parsers are @dfn{shift/reduce automata}. In some cases (much more
frequent than one would hope), looking at this automaton is required to
tune or simply fix a parser.
As documented elsewhere (@pxref{Algorithm}) Bison parsers are
@dfn{shift/reduce automata}. In some cases (much more frequent than one
would hope), looking at this automaton is required to tune or simply fix a
parser.
The textual file is generated when the options @option{--report} or
@option{--verbose} are specified, see @ref{Invocation}. Its name is made by
@@ -10604,6 +10618,26 @@ For compatibility with POSIX, the standard Bison distribution also contains
a shell script called @command{yacc} that invokes Bison with the @option{-y}
option.
@sp 1
The exit status of @command{bison} is:
@table @asis
@item 0 (success)
when there were no errors. Warnings, which are diagnostics about dubious
constructs, do not change the exit status, unless they are turned into
errors (@pxref{-Werror,,@option{-Werror}}).
@item 1 (failure)
when there were errors. No file was generated (except the reports generated
by @option{--verbose}, etc.). In particular, the output files that possibly
existed were not changed.
@item 63 (mismatch)
when @command{bison} does not meet the version requirements of the grammar
file. @xref{Require Decl}. No file was generated or changed.
@end table
@menu
* Bison Options:: All the options described in detail,
in alphabetical order by short options.
@@ -10997,6 +11031,7 @@ instance, @option{-Wno-yacc} will hide the warnings about
POSIX Yacc incompatibilities.
@item -Werror
@anchor{-Werror}
Turn enabled warnings for every @var{category} into errors, unless they are
explicitly disabled by @option{-Wno-error=@var{category}}.
@@ -12111,9 +12146,10 @@ Fill @var{argv} with the expected tokens, which never includes
@code{symbol_kind::S_YYUNDEF}.
Never put more than @var{argc} elements into @var{argv}, and on success
return the effective number of tokens stored in @var{argv}. Return 0 if
there are more than @var{argc} expected tokens, yet fill @var{argv} up to
@var{argc}.
return the number of tokens stored in @var{argv}. If there are more
expected tokens than @var{argc}, fill @var{argv} up to @var{argc} and return
0. If there are no expected tokens, also return 0, but set @code{argv[0]}
to @code{symbol_kind::S_YYEMPTY}.
If @var{argv} is null, return the size needed to store all the possible
values, which is always less than @code{YYNTOKENS}.
@@ -12121,6 +12157,8 @@ values, which is always less than @code{YYNTOKENS}.
@deftypemethod {parser} {const char *} symbol_name (@code{symbol_kind_t} @var{symbol}) @code{const}
The name of the symbol whose kind is @var{symbol}, possibly translated.
Returns a @code{std::string} when @code{parse.error} is @code{verbose}.
@end deftypemethod
A custom syntax error function looks as follows. This implementation is
@@ -12253,6 +12291,12 @@ applicable) location.
The kind of this symbol.
@end deftypemethod
@deftypemethod {symbol_type} {const char *} name () @code{const}
The name of the kind of this symbol.
Returns a @code{std::string} when @code{parse.error} is @code{verbose}.
@end deftypemethod
@sp 1
For each token kind, Bison generates named constructors as follows.
@@ -13001,9 +13045,6 @@ of the parser is always local to an instance of the parser class.
Therefore, all Java parsers are ``pure'', and the @code{%define api.pure}
directive does nothing when used in Java.
Push parsers are currently unsupported in Java and @code{%define
api.push-pull} have no effect.
GLR parsers are currently unsupported in Java. Do not use the
@code{glr-parser} directive.
@@ -13275,9 +13316,10 @@ Fill @var{argv} with the expected tokens, which never includes
@code{SymbolKind.S_YYERROR}, or @code{SymbolKind.S_YYUNDEF}.
Never put more than @var{argc} elements into @var{argv}, and on success
return the effective number of tokens stored in @var{argv}. Return 0 if
there are more than @var{argc} expected tokens, yet fill @var{argv} up to
@var{argc}.
return the number of tokens stored in @var{argv}. If there are more
expected tokens than @var{argc}, fill @var{argv} up to @var{argc} and return
0. If there are no expected tokens, also return 0, but set @code{argv[0]}
to @code{null}.
If @var{argv} is null, return the size needed to store all the possible
values, which is always less than @code{YYNTOKENS}.
@@ -13318,9 +13360,9 @@ changed using @code{%define api.location.type @{@var{class-name}@}}.
@end deftypemethod
@deftypemethod {Lexer} {int} yylex ()
Return the next token. Its type is the return value, its semantic
value and location are saved and returned by the their methods in the
interface.
Return the next token. Its type is the return value, its semantic value and
location are saved and returned by the their methods in the interface. Not
needed for push-only parsers.
Use @samp{%define lex_throws} to specify any uncaught exceptions.
Default is @code{java.io.IOException}.
@@ -13330,7 +13372,7 @@ Default is @code{java.io.IOException}.
@deftypemethodx {Lexer} {Position} getEndPos ()
Return respectively the first position of the last token that @code{yylex}
returned, and the first position beyond it. These methods are not needed
unless location tracking is active.
unless location tracking and pull parsing are active.
They should return new objects for each call, to avoid that all the symbol
share the same Position boundaries.
@@ -13340,7 +13382,8 @@ The return type can be changed using @code{%define api.position.type
@end deftypemethod
@deftypemethod {Lexer} {Object} getLVal ()
Return the semantic value of the last token that yylex returned.
Return the semantic value of the last token that yylex returned. Not needed
for push-only parsers.
The return type can be changed using @samp{%define api.value.type
@{@var{class-name}@}}.
@@ -14668,6 +14711,14 @@ is given a nonzero value, the parser will output information on input
symbols and parser action. @xref{Tracing}.
@end deffn
@deffn {Value} YYEMPTY
The pseudo token kind when there is no lookahead token.
@end deffn
@deffn {Value} YYEOF
The token kind denoting is the end of the input stream.
@end deffn
@deffn {Macro} yyerrok
Macro to cause parser to recover immediately to its normal mode
after a syntax error. @xref{Error Recovery}.
@@ -14717,8 +14768,8 @@ In semantic actions, it stores the location of the lookahead token.
@end deffn
@deffn {Type} YYLTYPE
Data type of @code{yylloc}; by default, a structure with four
members. @xref{Location Type}.
Data type of @code{yylloc}. By default in C, a structure with four members
(start/end line/column). @xref{Location Type}.
@end deffn
@deffn {Variable} yylval
@@ -14757,24 +14808,26 @@ Deprecated, use @code{%printer} instead (@pxref{Printer Decl}).
@deffn {Function} yypstate_delete
The function to delete a parser instance, produced by Bison in push mode;
call this function to delete the memory associated with a parser.
@xref{Parser Delete Function}. Does nothing when called with a null pointer.
@xref{yypstate_delete,,@code{yypstate_delete}}. Does nothing when called
with a null pointer.
@end deffn
@deffn {Function} yypstate_new
The function to create a parser instance, produced by Bison in push mode;
call this function to create a new parser.
@xref{Parser Create Function}.
@xref{yypstate_new,,@code{yypstate_new}}.
@end deffn
@deffn {Function} yypull_parse
The parser function produced by Bison in push mode; call this function to
parse the rest of the input stream.
@xref{Pull Parser Function}.
@xref{yypull_parse,,@code{yypull_parse}}.
@end deffn
@deffn {Function} yypush_parse
The parser function produced by Bison in push mode; call this function to
parse a single token. @xref{Push Parser Function}.
parse a single token.
@xref{yypush_parse,,@code{yypush_parse}}.
@end deffn
@deffn {Macro} YYRECOVERING
@@ -14822,6 +14875,10 @@ should not be confused with the @emph{symbol kinds}, used internally by the
parser.
@end deffn
@deffn {Value} YYUNDEF
The token kind denoting an unknown token.
@end deffn
@node Glossary
@appendix Glossary
@@ -14908,12 +14965,21 @@ A continuous flow of data between devices or programs.
@item Kind
``Token'' and ``symbol'' are each overloaded to mean either a grammar symbol
(kind) or all parse info (kind, value, location) associated with occurrences
of that grammar symbol from the input. To disambiguate, we use ``token
kind'' and ``symbol kind'' to mean both grammar symbols and the types that
represent them in a base programming language (C, C++, etc.). However, we
use ``token'' and ``symbol'' without the word ``kind'' to mean parsed
of that grammar symbol from the input. To disambiguate,
@itemize
@item
we use ``token kind'' and ``symbol kind'' to mean both grammar symbols and
the values that represent them in a base programming language (C, C++,
etc.). The names of the types of these values are typically
@code{token_kind_t}, or @code{token_kind_type}, or @code{TokenKind},
depending on the programming language.
@item
we use ``token'' and ``symbol'' without the word ``kind'' to mean parsed
occurrences, and we append the word ``type'' to refer to the types that
represent them in a base programming language.
@end itemize
In summary: When you see ``kind'', interpret ``symbol'' or ``token'' to mean
a @emph{grammar symbol}. When you don't see ``kind'' (including when you
@@ -15206,6 +15272,7 @@ London, Department of Computer Science, TR-00-12 (December 2000).
@c LocalWords: YYUNDEF SymbolKind yypcontext YYENOMEM TOKENMAX getBundle
@c LocalWords: ResourceBundle myResources getString getName getToken
@c LocalWords: getLocation getExpectedTokens reportSyntaxError bistromathic
@c LocalWords: TokenKind
@c Local Variables:
@c ispell-dictionary: "american"
+24 -10
View File
@@ -131,7 +131,7 @@ dist_man_MANS = $(top_srcdir)/%D%/bison.1
EXTRA_DIST += $(dist_man_MANS:.1=.x)
MAINTAINERCLEANFILES += $(dist_man_MANS)
# Differences to ignore when comparing the man page (the date).
# Differences to ignore when comparing man pages (the date).
remove_time_stamp = \
sed 's/^\(\.TH[^"]*"[^"]*"[^"]*\)"[^"]*"/\1/'
@@ -140,17 +140,31 @@ if ! CROSS_COMPILING
MAN_DEPS = %D%/bison.help %D%/bison.x $(top_srcdir)/configure
endif
# If we don't have help2man, just touch the target. Maintainers must
# have the real thing, so if there's a .git directory, fail hard.
#
# We shouldn't need this, but on some OS the timestamps in the tarball
# leave us no choice. See
# https://lists.gnu.org/r/bug-bison/2020-05/msg00055.html.
$(top_srcdir)/%D%/bison.1: $(MAN_DEPS)
$(AM_V_GEN)$(HELP2MAN) \
--include=$(top_srcdir)/%D%/bison.x \
--output=$@.tmp tests/bison
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \
touch $@; \
else \
mv $@.tmp $@; \
$(AM_V_GEN)if $(HELP2MAN) --version >/dev/null 2>&1; then \
$(HELP2MAN) \
--include=$(top_srcdir)/%D%/bison.x \
--output=$@.tmp tests/bison && \
{ $(remove_time_stamp) $@ >$@a.tmp || true; } && \
$(remove_time_stamp) $@.tmp >$@b.tmp && \
if diff $@a.tmp $@b.tmp >/dev/null 2>&1; then \
touch $@; \
else \
mv $@.tmp $@; \
fi && \
rm -f $@*.tmp; \
elif test -d $(srcdir)/.git; then \
echo >&2 "ERROR: $@: help2man is needed"; \
exit 1; \
else \
touch $@; \
fi
$(AM_V_at)rm -f $@*.tmp
if ENABLE_YACC
nodist_man_MANS = %D%/yacc.1
+4 -4
View File
@@ -13,8 +13,8 @@ semantic value.
Run as `./simple`.
Extracted from the documentation: "A Simple C++ Example".
https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html
Extracted from the documentation: [A Simple C++
Example](https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html).
## variant.yy - Self-contained example in C++98
A variation of simple.yy, in C++98.
@@ -36,8 +36,8 @@ starting point for a clean parser in C++. The previous examples are better
introductory examples, and the C examples are also useful introductory
examples.
Extracted from the documentation: "A Complete C++ Example".
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
Extracted from the documentation: [A Complete C++
Example](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html).
<!---
+3 -3
View File
@@ -5,9 +5,9 @@ saw the traditional implementation in C, please first read
examples/c/lexcalc, which can be seen as a C precursor of this example.
Read the corresponding chapter in the documentation: "A Complete C++
Example". It is also available on line (maybe with a different version of
Bison):
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
Example". It is also available [on
line](https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html)
(maybe with a different version of Bison).
To use it, copy this directory into some work directory, and run `make` to
compile the executable, and try it. It is a simple calculator which accepts
+1 -1
View File
@@ -139,7 +139,7 @@ namespace yy
int
main (int argc, const char *argv[])
{
if (2 <= argc && isdigit (*argv[1]))
if (2 <= argc && isdigit (static_cast<unsigned char> (*argv[1])))
{
auto maxl = strtol (argv[1], nullptr, 10);
max = INT_MIN <= maxl && maxl <= INT_MAX ? int(maxl) : 4;
+8 -8
View File
@@ -10,8 +10,8 @@ The first example is that of a simple double-precision Reverse Polish
Notation calculator (a calculator using postfix operators). This example
provides a good starting point, since operator precedence is not an issue.
Extracted from the documentation: "Reverse Polish Notation Calculator"
https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html
Extracted from the documentation: [Reverse Polish Notation
Calculator](https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html).
## calc - Simple Calculator
This example is slightly more complex than rpcalc: it features infix
@@ -24,18 +24,18 @@ A more complete C example: a multi-function calculator. More complex than
the previous example. Using precedence directives to support infix
operators.
Extracted from the documentation: "Multi-Function Calculator: mfcalc".
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
Extracted from the documentation: [Multi-Function Calculator:
mfcalc](https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html).
## lexcalc - calculator with Flex and Bison
The calculator with precedence directives and location tracking. It uses
Flex to generate the scanner.
## reccalc - recursive calculator with Flex and Bison
The example builds on top of the previous one to provide a reentrant parser.
Such parsers can be called concurrently in different threads, or even
recursively. To demonstrate this feature, expressions in parentheses are
tokenized as strings, and then recursively parsed from the parser. So
This example builds on top of the previous one to provide a reentrant
parser. Such parsers can be called concurrently in different threads, or
even recursively. To demonstrate this feature, expressions in parentheses
are tokenized as strings, and then recursively parsed from the parser. So
`(((1)+(2))*((3)+(4)))` uses eight parsers, with a depth of four.
## pushcalc - calculator implemented with a push parser
+2 -2
View File
@@ -5,7 +5,7 @@ BASE = bistromathic
BISON = bison
XSLTPROC = xsltproc
# We need to find the headers and libs for readline and intl.
# 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
@@ -14,7 +14,7 @@ LDFLAGS = -L/opt/local/lib
BISON_LOCALEDIR = $(shell $(BISON) $(BISON_FLAGS) --print-localedir)
CPPFLAGS += -DENABLE_NLS -DBISON_LOCALEDIR='"$(BISON_LOCALEDIR)"'
LIBS = -lreadline -lintl
LIBS = -lreadline -lm # In some environments, -lintl is needed.
all: $(BASE)
+3
View File
@@ -14,6 +14,9 @@ This example demonstrates best practices when using Bison.
- It supports debug traces with semantic values.
- It uses named references instead of the traditional $1, $2, etc.
To customize the interaction with bistromathic, see the GNU Readline user
manual (see `info rluserman`).
<!---
Local Variables:
fill-column: 76
+54 -11
View File
@@ -15,12 +15,47 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# macOS' version of readline does not repeat stdin on stdout in
# non-interactive mode.
if ! echo '1-1' | prog | grep '1-1' >/dev/null; then
strip_prompt=true
# Users may customize the behavior of readline, which might break our
# expected results.
INPUTRC=/dev/null
export INPUTRC
# Beware of portability issues of readline when not feeding it from a
# terminal.
#
# With recent versions of GNU Readline, input "1+2*3\n" gives
# "> 1+2*3\n7\n> \n"
#
# macOS' version does not display the prompt and does not repeat stdin
# on stdout, so input "1+2*3\n" gives "7\n" as output. Let's try to
# cope with this.
#
# On OpenBSD 6.5 the prompt is displayed, but the input is not
# repeated (!). So input "1+2*3\n" gives "> 7\n> \n" as output.
#
# On AIX, you get some escaping sequence before the prompt:
# "<ESC>[?1034h> 1+2*3". It appears to pass the terminfo capability
# "smm", to put the terminal in "meta mode": as if the user had hit
# META.
echo >perfect '> 0
0
> '
echo >ok '0'
echo '0' | prog >effective
echo "checking for readline output..."
if diff perfect effective; then
# Alles ist gut.
strip_prompt=false
elif diff ok effective; then
strip_prompt=true
else
skip "this is not the GNU Readline we expect"
fi
cat >input <<EOF
1+2*3
EOF
@@ -66,7 +101,7 @@ cat >input <<EOF
EOF
run 0 '> *
> ''
err: 1.1: syntax error: expected end of file or - or ( or exit or number or function or variable before *'
err: 1.1: syntax error: expected end of file or - or ( or exit or number or function etc., before *'
cat >input <<EOF
1 + 2 * * 3
@@ -227,14 +262,22 @@ err: Cleanup: popping nterm input (1.1-4: )' -p
# From now on, the differences between versions of GNU Readline are
# too painful to try to cope with.
if $strip_prompt; then
echo "SKIP: this is not the GNU Readline we expect"
if $exit; then
exit 0
else
exit 1
fi
echo "SKIP: this is not the GNU Readline we expect"
exit $status
fi
# On Windows10/MSYS2 the ^G coming from <tab> completion is not
# emitted the same way
# (https://lists.gnu.org/r/bug-bison/2020-05/msg00076.html).
echo "checking for kernel name... $(uname -s)"
case $(uname -s) in
(MSYS*)
echo "SKIP: this is Windows/MSYS"
exit $status
;;
esac
# Check completion after an operator.
sed -e 's/\\t/ /g' >input <<EOF
(1+\t\t
+14 -10
View File
@@ -19,19 +19,23 @@ bistromathicdir = $(docdir)/%D%
## Bistromathics. ##
## --------------- ##
check_PROGRAMS += %D%/bistromathic
TESTS += %D%/bistromathic.test
EXTRA_DIST += %D%/bistromathic.test
nodist_%C%_bistromathic_SOURCES = %D%/parse.y %D%/parse.h
%D%/parse.c: $(dependencies)
# Don't use gnulib's system headers.
%C%_bistromathic_CPPFLAGS = \
-DBISON_LOCALEDIR='"$(localdir)"' \
-DLOCALEDIR='"$(localdir)"' \
-I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_bistromathic_LDADD = -lm -lreadline $(LIBINTL)
if ENABLE_BISTROMATHIC
check_PROGRAMS += %D%/bistromathic
TESTS += %D%/bistromathic.test
nodist_%C%_bistromathic_SOURCES = %D%/parse.y
# Don't use gnulib's system headers.
%C%_bistromathic_CPPFLAGS = \
-DBISON_LOCALEDIR='"$(localdir)"' \
-DLOCALEDIR='"$(localdir)"' \
-I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_bistromathic_CFLAGS = $(TEST_CFLAGS)
%C%_bistromathic_LDADD = -lm $(LIBREADLINE) $(LIBINTL)
endif
EXTRA_DIST += %D%/bistromathic.test
dist_bistromathic_DATA = %D%/parse.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/parse.[ch] %D%/parse.output
CLEANDIRS += %D%/*.dSYM
+53 -23
View File
@@ -2,6 +2,7 @@
%code top {
#include <ctype.h> // isdigit
#include <locale.h> // LC_ALL
#include <math.h> // cos, sin, etc.
#include <stdarg.h> // va_start
#include <stdio.h> // printf
@@ -216,7 +217,7 @@ getsym (char const *name)
}
// How many symbols are registered.
int
static int
symbol_count (void)
{
int res = 0;
@@ -310,12 +311,12 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
`---------*/
const char *
static const char *
error_format_string (int argc)
{
switch (argc)
{
default: /* Avoid compiler warnings. */
default: // Avoid compiler warnings.
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
@@ -331,7 +332,7 @@ error_format_string (int argc)
case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e etc., before %u");
}
}
@@ -339,12 +340,15 @@ error_format_string (int argc)
int
yyreport_syntax_error (const yypcontext_t *ctx)
{
enum { ARGS_MAX = 7 };
enum { ARGS_MAX = 6 };
yysymbol_kind_t arg[ARGS_MAX];
int argsize = yypcontext_expected_tokens (ctx, arg, ARGS_MAX);
if (argsize < 0)
return argsize;
const char *format = error_format_string (1 + argsize);
const int too_many_expected_tokens = argsize == 0 && arg[0] != YYSYMBOL_YYEMPTY;
if (too_many_expected_tokens)
argsize = ARGS_MAX;
const char *format = error_format_string (1 + argsize + too_many_expected_tokens);
while (*format)
// %@: location.
@@ -361,7 +365,7 @@ yyreport_syntax_error (const yypcontext_t *ctx)
}
// %0e, %1e...: expected token.
else if (format[0] == '%'
&& isdigit (format[1])
&& isdigit ((unsigned char) format[1])
&& format[2] == 'e'
&& (format[1] - '0') < argsize)
{
@@ -392,12 +396,30 @@ void yyerror (YYLTYPE *loc, char const *format, ...)
}
// Return a newly allocated copy of at most N bytes of STRING. In
// other words, return a copy of the initial segment of length N of
// STRING.
static char *
xstrndup (const char *string, size_t n)
{
// len = strnlen (string, n), portably.
const char *end = memchr (string, '\0', n);
size_t len = end ? (size_t) (end - string) : n;
char *new = malloc (len + 1);
if (!new)
abort ();
new[len] = '\0';
return memcpy (new, string, len);
}
/*-----------.
| Readline. |
`-----------*/
// Parse (and execute) this line.
int process_line (YYLTYPE *lloc, const char *line)
static int
process_line (YYLTYPE *lloc, const char *line)
{
yypstate *ps = yypstate_new ();
int status = 0;
@@ -412,7 +434,8 @@ int process_line (YYLTYPE *lloc, const char *line)
}
// Get the list of possible tokens after INPUT was read.
int
// Returns a nonnegative.
static int
expected_tokens (const char *input,
int *tokens, int ntokens)
{
@@ -433,16 +456,18 @@ expected_tokens (const char *input,
// Then query for the accepted tokens at this point.
int res = yypstate_expected_tokens (ps, tokens, ntokens);
if (res < 0)
abort ();
yypstate_delete (ps);
return res;
}
/* Attempt to complete on the contents of TEXT. START and END bound the
region of rl_line_buffer that contains the word to complete. TEXT is
the word to complete. We can use the entire contents of rl_line_buffer
in case we want to do some simple parsing. Return the array of matches,
or NULL if there aren't any. */
char **
// Attempt to complete on the contents of TEXT. START and END bound
// the region of rl_line_buffer that contains the word to complete.
// TEXT is the word to complete. We can use the entire contents of
// rl_line_buffer in case we want to do some simple parsing. Return
// the array of matches, or NULL if there aren't any.
static char **
completion (const char *text, int start, int end)
{
YYDPRINTF ((stderr, "completion (\"%.*s[%.*s]%s\")\n",
@@ -452,14 +477,17 @@ completion (const char *text, int start, int end)
// Get list of token numbers.
int tokens[YYNTOKENS];
char *line = strndup (rl_line_buffer, start);
char *line = xstrndup (rl_line_buffer, (size_t) start);
int ntokens = expected_tokens (line, tokens, YYNTOKENS);
free (line);
// Build MATCHES, the list of possible completions.
const int len = strlen (text);
const size_t len = strlen (text);
// Need initial prefix and final NULL.
char **matches = calloc (ntokens + symbol_count () + 2, sizeof *matches);
char **matches
= calloc ((size_t) ntokens + (size_t) symbol_count () + 2, sizeof *matches);
if (!matches)
abort ();
int match = 1;
for (int i = 0; i < ntokens; ++i)
switch (tokens[i])
@@ -489,12 +517,12 @@ completion (const char *text, int start, int end)
matches[0] = strdup (text);
else
{
int lcplen = strlen (matches[1]);
size_t lcplen = strlen (matches[1]);
for (int i = 2; i < match && lcplen; ++i)
for (int j = 0; j < lcplen; ++j)
for (size_t j = 0; j < lcplen; ++j)
if (matches[1][j] != matches[i][j])
lcplen = j;
matches[0] = strndup (matches[1], lcplen);
matches[0] = xstrndup (matches[1], lcplen);
}
if (yydebug)
@@ -515,7 +543,8 @@ completion (const char *text, int start, int end)
return matches;
}
void init_readline (void)
static void
init_readline (void)
{
// Allow conditional parsing of the ~/.inputrc file.
rl_readline_name = "bistromathic";
@@ -534,7 +563,8 @@ void init_readline (void)
| Main. |
`-------*/
int main (int argc, char const* argv[])
int
main (int argc, char const* argv[])
{
#if defined ENABLE_NLS && ENABLE_NLS
// Set up internationalization.
+4 -2
View File
@@ -1,6 +1,7 @@
%code top {
#include <ctype.h> /* isdigit. */
#include <stdio.h> /* For printf, etc. */
#include <stdio.h> /* printf. */
#include <stdlib.h> /* abort. */
#include <string.h> /* strcmp. */
int yylex (void);
@@ -73,7 +74,8 @@ yylex (void)
if (c == '.' || isdigit (c))
{
ungetc (c, stdin);
scanf ("%lf", &yylval.NUM);
if (scanf ("%lf", &yylval.NUM) != 1)
abort ();
return NUM;
}
+1
View File
@@ -27,6 +27,7 @@ nodist_%C%_calc_SOURCES = %D%/calc.y
# Don't use gnulib's system headers.
%C%_calc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_calc_CFLAGS = $(TEST_CFLAGS)
dist_calc_DATA = %D%/calc.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/calc.[ch] %D%/calc.output %D%/scan.c
+2
View File
@@ -25,6 +25,8 @@ if FLEX_WORKS
nodist_%C%_lexcalc_SOURCES = %D%/parse.y %D%/parse.h %D%/scan.l
# Don't use gnulib's system headers.
%C%_lexcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
# Fighting warnings triggered by Flex is just too painful.
# %C%_lexcalc_CFLAGS = $(TEST_CFLAGS)
endif FLEX_WORKS
%D%/parse.c: $(dependencies)
+2 -2
View File
@@ -4,7 +4,7 @@
%option nodefault noinput nounput noyywrap
%{
#include <errno.h> /* errno, ERANGE */
#include <errno.h> /* errno, ERANGE */
#include <limits.h> /* INT_MIN */
#include <stdlib.h> /* strtol */
@@ -12,7 +12,7 @@
// Each time a rule is matched, advance the end cursor/position.
#define YY_USER_ACTION \
yylloc->last_column += yyleng;
yylloc->last_column += (int) yyleng;
// Move the first position onto the last.
#define LOCATION_STEP() \
+1
View File
@@ -31,6 +31,7 @@ nodist_%C%_mfcalc_SOURCES = $(mfcalc_sources)
%D%/mfcalc.c: $(dependencies)
# Don't use gnulib's system headers.
%C%_mfcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_mfcalc_CFLAGS = $(TEST_CFLAGS)
%C%_mfcalc_LDADD = -lm
dist_TESTS += %D%/mfcalc.test
+4 -3
View File
@@ -1,7 +1,7 @@
%code top {
#include <ctype.h> /* isdigit. */
#include <stdbool.h>
#include <stdio.h> /* For printf, etc. */
#include <stdio.h> /* printf. */
#include <stdlib.h> /* abort. */
#include <string.h> /* strcmp. */
}
@@ -81,7 +81,8 @@ yylex (YYSTYPE *yylval)
if (c == '.' || isdigit (c))
{
ungetc (c, stdin);
scanf ("%lf", &yylval->NUM);
if (scanf ("%lf", &yylval->NUM) != 1)
abort ();
return NUM;
}
+1
View File
@@ -27,6 +27,7 @@ nodist_%C%_calc_SOURCES = %D%/calc.y
# Don't use gnulib's system headers.
%C%_calc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
%C%_calc_CFLAGS = $(TEST_CFLAGS)
dist_pushcalc_DATA = %D%/calc.y %D%/Makefile %D%/README.md
CLEANFILES += %D%/calc.[ch] %D%/calc.output
+1 -1
View File
@@ -12,7 +12,7 @@ all: $(BASE)
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
%.c %.h: %.l
$(FLEX) $(FLEXFLAGS) -o$*.c --header-file=$*.h $<
$(FLEX) $(FLEXFLAGS) -o$*.c --header=$*.h $<
scan.o: parse.h
parse.o: scan.h
+5 -1
View File
@@ -26,6 +26,8 @@ if FLEX_WORKS
BUILT_SOURCES += $(nodist_%C%_reccalc_SOURCES)
# Don't use gnulib's system headers.
%C%_reccalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
# Fighting warnings triggered by Flex is just too painful.
# %C%_reccalc_CFLAGS = $(TEST_CFLAGS)
endif FLEX_WORKS
%D%/parse.c: $(dependencies)
@@ -69,7 +71,9 @@ DASH = -
$(AM_V_LEX)rm -f $@ $@.tmp
$(AM_V_at)$(MKDIR_P) %D%
$(AM_V_at)touch $@.tmp
$(AM_V_at)$(LEX) $(AM_LFLAGS) $(LFLAGS) -o%D%/scan.c --header-file=%D%/scan.h $(srcdir)/%D%/scan.l
## --header introduced in 2.5.6, renamed as --header-file in 2.6.4.
## Backward compatibility ensured since --header is an unambiguous prefix.
$(AM_V_at)$(LEX) $(AM_LFLAGS) $(LFLAGS) -o%D%/scan.c --header=%D%/scan.h $(srcdir)/%D%/scan.l
$(AM_V_at)mv $@.tmp $@
+1 -1
View File
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
seq 0 >/dev/null || exit 77
(seq 0) >/dev/null 2>&1 || skip "gimme one seq"
cat >input <<EOF
1+2*3
+2 -2
View File
@@ -32,9 +32,9 @@
do \
capacity = capacity ? 2 * capacity : 128; \
while (capacity < size + yyleng + 1); \
str = realloc (str, capacity); \
str = realloc (str, (size_t) capacity); \
} \
memcpy (str + size, yytext, yyleng); \
memcpy (str + size, yytext, (size_t) yyleng); \
size += yyleng; \
assert (size < capacity); \
} while (0)
+1
View File
@@ -31,6 +31,7 @@ nodist_%C%_rpcalc_SOURCES = $(rpcalc_sources)
%D%/rpcalc.c: $(dependencies)
# Don't use gnulib's system headers.
%C%_rpcalc_CPPFLAGS = -I$(top_builddir)/%D%
%C%_rpcalc_CFLAGS = $(TEST_CFLAGS)
%C%_rpcalc_LDADD = -lm
dist_TESTS += %D%/rpcalc.test
+1 -1
View File
@@ -9,7 +9,7 @@ afterwards.
The usual calculator, a very simple version.
## calc/Calc.y
The calculator, but with location tracking and debug traces.
The calculator, but with location tracking, debug traces, and a push parser.
<!---
+47 -18
View File
@@ -2,6 +2,7 @@
%define api.parser.class {Calc}
%define api.parser.public
%define api.push-pull push
%define parse.error custom
%define parse.trace
@@ -20,12 +21,19 @@
%code {
public static void main(String[] args) throws IOException {
CalcLexer l = new CalcLexer(System.in);
Calc p = new Calc(l);
CalcLexer scanner = new CalcLexer(System.in);
Calc parser = new Calc(scanner);
for (String arg : args)
if (arg.equals("-p"))
p.setDebugLevel(1);
if (!p.parse())
parser.setDebugLevel(1);
int status;
do {
int token = scanner.getToken();
Object lval = scanner.getValue();
Calc.Location yyloc = scanner.getLocation();
status = parser.push_parse(token, lval, yyloc);
} while (status == Calc.YYPUSH_MORE);
if (status != Calc.YYACCEPT)
System.exit(1);
}
@@ -105,14 +113,17 @@ class CalcLexer implements Calc.Lexer {
Position start = new Position(1, 0);
Position end = new Position(1, 0);
public Position getStartPos() {
return new Position(start);
}
public Position getEndPos() {
return new Position(end);
/**
* The location of the last token read.
* Implemented with getStartPos and getEndPos in pull parsers.
*/
public Calc.Location getLocation() {
return new Calc.Location(new Position(start), new Position(end));
}
/**
* Build and emit a syntax error message.
*/
public void reportSyntaxError(Calc.Context ctx) {
System.err.print(ctx.getLocation() + ": syntax error");
{
@@ -131,20 +142,33 @@ class CalcLexer implements Calc.Lexer {
System.err.println("");
}
public void yyerror(Calc.Location l, String s) {
if (l == null)
System.err.println(s);
/**
* Emit 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 msg The string for the error message.
*/
public void yyerror(Calc.Location loc, String msg) {
if (loc == null)
System.err.println(msg);
else
System.err.println(l + ": " + s);
System.err.println(loc + ": " + msg);
}
Integer yylval;
public Object getLVal() {
/**
* The value of the last token read. Called getLVal in pull parsers.
*/
public Object getValue() {
return yylval;
}
public int yylex() throws IOException {
/**
* Fetch the next token. Called yylex in pull parsers.
*/
public int getToken() throws IOException {
start.set(reader.getPosition());
int ttype = st.nextToken();
end.set(reader.getPosition());
@@ -160,7 +184,7 @@ class CalcLexer implements Calc.Lexer {
end.set(reader.getPreviousPosition());
return NUM;
case ' ': case '\t':
return yylex();
return getToken();
case '!':
return BANG;
case '+':
@@ -185,7 +209,9 @@ class CalcLexer implements Calc.Lexer {
}
}
/**
* A class defining a point in the input.
*/
class Position {
public int line = 1;
public int column = 1;
@@ -227,6 +253,9 @@ class Position {
}
}
/**
* A Stream reader that keeps track of the current Position.
*/
class PositionReader extends BufferedReader {
private Position position = new Position();
+3
View File
@@ -35,6 +35,9 @@
dist_noinst_SCRIPTS = %D%/extexi %D%/test
TEST_LOG_COMPILER = $(SHELL) $(top_srcdir)/%D%/test
TEST_CFLAGS = \
$(WARN_CFLAGS) $(WARN_CFLAGS_TEST) $(WERROR_CFLAGS)
AM_CXXFLAGS = \
$(WARN_CXXFLAGS) $(WARN_CXXFLAGS_TEST) $(WERROR_CXXFLAGS)
+30 -8
View File
@@ -25,7 +25,7 @@ medir=$(dirname "$1" | sed -e 's,.*examples/,,')
number=1
# Exit status of this script.
exit=true
status=0
# top_builddir.
cwd=$(pwd)
@@ -34,6 +34,14 @@ cwd=$(pwd)
# See bistromathic.test.
strip_prompt=false
# If diff supports --strip-trailing-cr, use it, to avoid EOL issues
# when testing Java programs on Windows.
echo "checking for diff --strip-trailing-cr..."
if diff --strip-trailing-cr "$1" "$1"; then
diff_opts=--strip-trailing-cr
fi
echo "checking for diff --strip-trailing-cr... $diff_opts"
# The exercised program.
abs_medir=$cwd/examples/$medir
if test -x "$abs_medir/$me"; then
@@ -68,6 +76,20 @@ trap cleanup 0 1 2 13 15
mkdir $$.dir
cd $$.dir
# skip [MSG]
# ----------
# Skip this test.
skip ()
{
if test x"$1" != x; then
echo "SKIP: $1"
fi
# See Autoconf's doc on 'trap'.
(exit 77); exit 77
}
# run [-noerr, -n] EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
# ----------------------------------------------------------------------
# -noerr: ignore stderr, otherwise merge it into effective output.
@@ -115,7 +137,7 @@ run ()
} >eff
if test $sta_eff -eq $sta_exp; then
if cmp eff exp 2>/dev/null; then
if diff $diff_opts eff exp >/dev/null 2>&1; then
echo "$me: PASS: $number"
else
echo "$me: FAIL: $number"
@@ -126,21 +148,21 @@ run ()
echo "$me: effective output:"
sed -e 's/^/ /' eff
echo "$me: diff:"
diff -u exp eff | sed -e 's/^/ /'
exit=false
diff $diff_opts -u exp eff | sed -e 's/^/ /'
status=1
fi
else
echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
cat err_eff
exit=false
status=1
fi
number=$(expr $number + 1)
}
# We have cd'd one level deeper.
case $1 in
/*) . "$1";;
*) . "../$1";;
/*) . "$1" || status=2;;
*) . "../$1" || status=2;;
esac
$exit
exit $status
+1 -1
Submodule gnulib updated: 5ec4d920e4...ffbb0ced8b
-1
View File
@@ -56,7 +56,6 @@
/gnulib-comp.m4
/gnulib-tool.m4
/host-cpu-c-abi.m4
/iconv.m4
/include_next.m4
/intdiv0.m4
/intl.m4
+16
View File
@@ -41,6 +41,22 @@ else
fi
])
AC_CACHE_CHECK([whether flex supports --header=FILE],
[ac_cv_prog_lex_supports_header_opt],
[if _AC_DO_VAR([LEX --header=conftest.h conftest.l]); then
ac_cv_prog_lex_supports_header_opt=yes
else
ac_cv_prog_lex_supports_header_opt=no
fi
])
if test "$ac_cv_prog_lex_supports_header_opt" = yes; then
FLEX_SUPPORTS_HEADER_OPT=true
else
FLEX_SUPPORTS_HEADER_OPT=false
fi
cat >conftest.l <<_ACEOF[
%%
a { ECHO; }
+2 -2
View File
@@ -23,7 +23,7 @@
#include "system.h"
#include <argmatch.h>
#include <ctype.h>
#include <c-ctype.h>
#include <progname.h>
#include <stdarg.h>
#include <sys/stat.h>
@@ -609,7 +609,7 @@ syntax_error (location loc,
while (*format)
if (format[0] == '%'
&& isdigit (format[1])
&& c_isdigit (format[1])
&& format[2] == '$'
&& format[3] == 's'
&& (format[1] - '0') < argc)
+3 -2
View File
@@ -124,10 +124,11 @@ fixits_run (void)
FILE *out = xfopen (input, "w");
size_t line = 1;
size_t offset = 1;
fixit const *f = NULL;
void const *p = NULL;
gl_list_iterator_t iter = gl_list_iterator (fixits);
while (gl_list_iterator_next (&iter, (const void**) &f, NULL))
while (gl_list_iterator_next (&iter, &p, NULL))
{
fixit const *f = p;
/* Look for the correct line. */
while (line < f->location.start.line)
{
+3 -1
View File
@@ -257,7 +257,8 @@ static const argmatch_trace_doc argmatch_trace_docs[] =
{ "sets", "grammar sets: firsts, nullable etc." },
{ "muscles", "m4 definitions passed to the skeleton" },
{ "tools", "m4 invocation" },
{ "m4", "m4 traces" },
{ "m4-early", "m4 traces starting from the start" },
{ "m4", "m4 traces starting from the skeleton evaluation" },
{ "skeleton", "skeleton postprocessing" },
{ "time", "time consumption" },
{ "ielr", "IELR conversion" },
@@ -279,6 +280,7 @@ static const argmatch_trace_arg argmatch_trace_args[] =
{ "sets", trace_sets },
{ "muscles", trace_muscles },
{ "tools", trace_tools },
{ "m4-early", trace_m4_early },
{ "m4", trace_m4 },
{ "skeleton", trace_skeleton },
{ "time", trace_time },
+6 -5
View File
@@ -100,11 +100,12 @@ enum trace
trace_grammar = 1 << 7, /**< Reading, reducing the grammar. */
trace_time = 1 << 8, /**< Time consumption. */
trace_skeleton = 1 << 9, /**< Skeleton postprocessing. */
trace_m4 = 1 << 10, /**< M4 traces. */
trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
trace_ielr = 1 << 12, /**< IELR conversion. */
trace_closure = 1 << 13, /**< Input/output of closure(). */
trace_locations = 1 << 14, /**< Full display of locations. */
trace_m4_early = 1 << 10, /**< M4 early traces. */
trace_m4 = 1 << 11, /**< M4 traces. */
trace_muscles = 1 << 12, /**< M4 definitions of the muscles. */
trace_ielr = 1 << 13, /**< IELR conversion. */
trace_closure = 1 << 14, /**< Input/output of closure(). */
trace_locations = 1 << 15, /**< Full display of locations. */
trace_all = ~0 /**< All of the above. */
};
/** What debug items bison displays during its run. */
+1 -1
View File
@@ -92,7 +92,7 @@ goto_print (goto_number i, FILE *out)
const state_number dst = to_state[i];
symbol_number var = states[dst]->accessing_symbol;
fprintf (out,
"goto[%ld] = (%d, %s, %d)", i, src, symbols[var]->tag, dst);
"goto[%zu] = (%d, %s, %d)", i, src, symbols[var]->tag, dst);
}
void
+2 -2
View File
@@ -117,6 +117,7 @@ BUILT_SOURCES += \
# definition of libbison, beware that they might expand as flags such as
# `-lm`. Keep them here. Or use a Libtool convenience library.
src_bison_LDADD = \
lib/libbison.a \
$(ISNAND_LIBM) \
$(ISNANF_LIBM) \
$(ISNANL_LIBM) \
@@ -126,8 +127,7 @@ src_bison_LDADD = \
$(LIBTHREAD) \
$(LIB_CLOCK_GETTIME) \
$(LIB_GETHRXTIME) \
$(LIBTEXTSTYLE) \
lib/libbison.a
$(LIBTEXTSTYLE)
EXTRA_DIST += %D%/i18n-strings.c
+18 -13
View File
@@ -687,6 +687,7 @@ output_skeleton (void)
char *skeldir = xpath_join (datadir, "skeletons");
char *m4sugar = xpath_join (datadir, "m4sugar/m4sugar.m4");
char *m4bison = xpath_join (skeldir, "bison.m4");
char *traceon = xpath_join (skeldir, "traceon.m4");
char *skel = (IS_PATH_WITH_DIR (skeleton)
? xstrdup (skeleton)
: xpath_join (skeldir, skeleton));
@@ -698,21 +699,10 @@ output_skeleton (void)
/* Create an m4 subprocess connected to us via two pipes. */
if (trace_flag & trace_tools)
fprintf (stderr, "running: %s %s - %s %s\n",
m4, m4sugar, m4bison, skel);
/* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a
position-dependent manner. Keep it as the first argument so that all
files are traced.
See the thread starting at
<http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
for details. */
int filter_fd[2];
pid_t pid;
{
char const *argv[10];
char const *argv[11];
int i = 0;
argv[i++] = m4;
@@ -730,15 +720,29 @@ output_skeleton (void)
argv[i++] = "-I";
argv[i++] = datadir;
if (trace_flag & trace_m4)
/* Some future version of GNU M4 (most likely 1.6) may treat the
-dV in a position-dependent manner. See the thread starting at
<http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
for details. */
if (trace_flag & trace_m4_early)
argv[i++] = "-dV";
argv[i++] = m4sugar;
argv[i++] = "-";
argv[i++] = m4bison;
if (trace_flag & trace_m4)
argv[i++] = traceon;
argv[i++] = skel;
argv[i++] = NULL;
aver (i <= ARRAY_CARDINALITY (argv));
if (trace_flag & trace_tools)
{
fputs ("running:", stderr);
for (int j = 0; argv[j]; ++j)
fprintf (stderr, " %s", argv[j]);
fputc ('\n', stderr);
}
/* The ugly cast is because gnulib gets the const-ness wrong. */
pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
true, filter_fd);
@@ -747,6 +751,7 @@ output_skeleton (void)
free (skeldir);
free (m4sugar);
free (m4bison);
free (traceon);
free (skel);
if (trace_flag & trace_muscles)
+10 -9
View File
@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 3.5.90. */
/* A Bison parser, made by GNU Bison 3.6. */
/* Bison implementation for Yacc-like parsers in C
@@ -49,7 +49,7 @@
#define YYBISON 1
/* Bison version. */
#define YYBISON_VERSION "3.5.90"
#define YYBISON_VERSION "3.6"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
@@ -408,6 +408,7 @@ typedef int yytype_uint16;
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
/* Stored state numbers (used for stacks). */
typedef yytype_uint8 yy_state_t;
@@ -1304,8 +1305,8 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&yyvsp[(yyi + 1) - (yynrhs)]
, &(yylsp[(yyi + 1) - (yynrhs)]) );
&yyvsp[(yyi + 1) - (yynrhs)],
&(yylsp[(yyi + 1) - (yynrhs)]));
YYFPRINTF (stderr, "\n");
}
}
@@ -1631,6 +1632,8 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
yyarg[yycount++] = yysym;
}
}
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = YYSYMBOL_YYEMPTY;
return yycount;
}
@@ -2702,7 +2705,7 @@ yyerrorlab:
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
// Pop stack until we find a state that shifts the error token.
/* Pop stack until we find a state that shifts the error token. */
for (;;)
{
yyn = yypact[yystate];
@@ -2738,10 +2741,8 @@ yyerrlab1:
YY_IGNORE_MAYBE_UNINITIALIZED_END
yyerror_range[2] = yylloc;
/* Using YYLLOC is tempting, but would change the location of
the lookahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
*++yylsp = yyloc;
++yylsp;
YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
+1 -1
View File
@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 3.5.90. */
/* A Bison parser, made by GNU Bison 3.6. */
/* Bison interface for Yacc-like parsers in C
+4 -1
View File
@@ -67,7 +67,10 @@
Conflict resolution can decide that certain tokens in certain
states should explicitly be errors (for implementing %nonassoc).
For each state, the tokens that are errors for this reason are
recorded in an errs structure, which holds the token numbers.
recorded in an errs structure. The generated parser does not
depend on this errs structure, it is used only in the reports
(*.output, etc.) to describe conflicted actions that have been
discarded.
There is at least one goto transition present in state zero. It
leads to a next-to-final state whose accessing_symbol is the
+41
View File
@@ -144,3 +144,44 @@ export LC_CTYPE
# Empty if no xsltproc was found
: ${XSLTPROC='@XSLTPROC@'}
# Some tests expect a precise diff format. See AT_DIFF_U_CHECK.
# See https://lists.gnu.org/r/bug-bison/2020-05/msg00049.html.
cat >conftest.1 <<EOF
1
2
3
4
5
6
EOF
cat >conftest.2 <<EOF
1
22
3
4
55
6
EOF
cat >conftest.expected <<EOF
@@ -1,6 +1,6 @@
1
-2
+22
3
4
-5
+55
6
EOF
diff -u conftest.1 conftest.2 2>/dev/null | sed -n '/^@@/,$p' | sed 's/^ $//' >conftest.diff
if diff conftest.expected conftest.diff >/dev/null; then
DIFF_U_WORKS=true
else
DIFF_U_WORKS=false
fi
rm conftest.*
+18 -11
View File
@@ -109,11 +109,6 @@ AT_DATA_GRAMMAR([list.yy],
%define parse.assert
%debug
%code top
{
// Get access to stack_symbol_type for the tests.
# define private public
}
%code provides
{
]AT_YYLEX_DECLARE[
@@ -136,6 +131,14 @@ AT_DATA_GRAMMAR([list.yy],
%code requires { #include <vector> }
%code { int yylex (yy::parser::semantic_type* lvalp); }
// A hack which relies on internal hooks to check stack_symbol_type,
// which is private.
%code yy_bison_internal_hook {
public:
typedef stack_symbol_type yy_stack_symbol_type;
typedef stack_type yy_stack_type;
}
%%
exp: "int" { $$.push_back ($1); }
%%
@@ -157,6 +160,9 @@ int main()
// symbol_type: construction, accessor.
{
parser::symbol_type s = parser::make_INT (12);
assert_eq (s.kind (), parser::symbol_kind::S_INT);
assert_eq (parser::symbol_name (s.kind ()), std::string ("\"int\""));
assert_eq (s.name (), std::string ("\"int\""));
assert_eq (s.value.as<int> (), 12);
}
@@ -180,12 +186,13 @@ int main()
}
// stack_symbol_type: construction, accessor.
typedef parser::yy_stack_symbol_type stack_symbol_type;
{
#if 201103L <= YY_CPLUSPLUS
auto ss = parser::stack_symbol_type(1, parser::make_INT(123));
auto ss = stack_symbol_type (1, parser::make_INT(123));
#else
parser::symbol_type s = parser::make_INT (123);
parser::stack_symbol_type ss(1, s);
stack_symbol_type ss(1, s);
#endif
assert_eq (ss.value.as<int> (), 123);
}
@@ -194,17 +201,17 @@ int main()
// Sufficiently many so that it will be resized.
// Probably 3 times (starting at 200).
{
parser::stack_type st;
parser::yy_stack_type st;
const int mucho = 1700;
const int int_reduction_state = 1; // Read list.output to find it.
for (int i = 0; i < mucho; ++i)
{
#if 201103L <= YY_CPLUSPLUS
st.push(parser::stack_symbol_type{int_reduction_state,
parser::make_INT (i)});
st.push(stack_symbol_type{int_reduction_state,
parser::make_INT (i)});
#else
parser::symbol_type s = parser::make_INT (i);
parser::stack_symbol_type ss (int_reduction_state, s);
stack_symbol_type ss (int_reduction_state, s);
st.push (ss);
#endif
}
+27 -13
View File
@@ -19,7 +19,7 @@ AT_BANNER([[Diagnostics.]])
# AT_TEST($1: TITLE, $2: GRAMMAR, $3: EXIT-STATUS, $4: OUTPUT-WITH-STYLE,
# $5: EXTRA_ENV
# $5: EXTRA_ENV, $6: SKIP-IF)
# -----------------------------------------------------------------------
# Run Bison on GRAMMAR with debugging style enabled, and expect
# OUTPUT-WITH-STYLE as diagnostics.
@@ -33,6 +33,9 @@ AT_KEYWORDS([diagnostics])
locale=`locale -a | $EGREP '^en_US\.(UTF-8|utf8)$' | sed 1q`
AT_SKIP_IF([test x == x"$locale"])
m4_ifval([$6],
[AT_SKIP_IF([$6])])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]], [$2])
@@ -220,15 +223,14 @@ exp: an\005error.
AT_TEST([[Tabulations and multibyte characters]],
[[%%
exp: a b c d e f g h
exp: a b c d e f g
a: { }
b: { }
c: {------------}
d: {éééééééééééé}
e: {∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}
f: { 42 }
g: { "฿¥$€₦" }
h: { 🐃 }
e: { 42 }
f: { "฿¥$€₦" }
g: { 🐃 }
]],
[0],
[[input.y:11.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
@@ -248,25 +250,37 @@ input.y:14.4-17: <warning>warning:</warning> empty rule without %empty [<warning
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:15.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
15 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning>
15 | e: <warning>{ 42 }</warning>
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:16.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
16 | f: <warning>{ 42 }</warning>
16 | f: <warning>{ "฿¥$€₦" }</warning>
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:17.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
17 | g: <warning>{ "฿¥$€₦" }</warning>
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y:18.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
18 | h: <warning>{ 🐃 }</warning>
17 | g: <warning>{ 🐃 }</warning>
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
]])
# Likewise, but currently not portable to AIX and Cygwin.
# https://lists.gnu.org/r/bug-bison/2020-05/msg00050.html
# https://lists.gnu.org/r/bug-bison/2020-05/msg00003.html.
AT_TEST([[Tabulations and multibyte characters]],
[[%%
e: {∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}
]],
[0],
[[input.y:10.4-17: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
10 | e: <warning>{∇⃗×𝐸⃗ = -∂𝐵⃗/∂t}</warning>
| <warning>^~~~~~~~~~~~~~</warning>
| <fixit-insert>%empty</fixit-insert>
input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option '--update'. [<warning>-Wother</warning>]
]], [], [uname -a | $EGREP -i 'aix|cygwin'])
## --------------- ##
## Special files. ##
## --------------- ##
+2 -7
View File
@@ -35,14 +35,9 @@ dnl time comes, just use sed to drop the line numbers. For now, as LR(1)
dnl support is rapidly evolving, let's keep that information to be careful.
dnl However, we don't do diffs for canonical LR(1) because the diff is huge.
m4_pushdef([AT_LALR1_DIFF_CHECK],
[dnl We need diff -u, which is not portable.
AT_CHECK([diff -u /dev/null /dev/null || exit 77], [0], [ignore])
AT_CHECK([[sed 's/^%define lr.type .*$//' input.y > input-lalr.y]])
[AT_CHECK([[sed 's/^%define lr.type .*$//' input.y > input-lalr.y]])
AT_BISON_CHECK([[--report=all input-lalr.y]], [[0]], [ignore], [ignore])
AT_CHECK([[diff -u input-lalr.output input.output \
| sed -n '/^@@/,$p' | sed 's/^ $//']],
[[0]], [$1])])
AT_DIFF_U_CHECK([[input-lalr.output input.output]], [$1])])
AT_TEST_TABLES_AND_PARSE([$2[: LALR(1)]], [[LALR]], [[last-state]],
[[%define lr.type lalr
+18 -1
View File
@@ -1352,8 +1352,20 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
]])
# Clang chokes on some of our comments, because it tries to "parse"
# some documentation directives in the comments:
#
# input.c:166:50: error: '\a' command does not have a valid word argument [-Werror,-Wdocumentation]
# FAKE = 258 /* "fake [] \a\b\f\n\r\t\v\"'?\\[\\ ??!??'??(??)??-??/??<??=??> \001\001" */
# ~~^
AT_DATA_GRAMMAR([input.y],
[[%{
[[%code requires {
#if defined __clang__ && 10 <= __clang_major__
# pragma clang diagnostic ignored "-Wdocumentation"
#endif
}
%{
/* This is seen in GCC: a %{ and %} in middle of a comment. */
const char *foo = "So %{ and %} can be here too.";
@@ -1424,6 +1436,11 @@ char quote[] = "@:>@@:>@,";
/* Exercise quotes in strings. */
%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
/* Beware of the generated comments that embed string aliases that
might close the comment. */
%token COMMENT_CLOSE "*/"
%token COMMENT "/* comment */"
%%
/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
+37 -37
View File
@@ -18,9 +18,9 @@
AT_BANNER([[Java Calculator.]])
# ------------------------- #
# Java invalid directives. #
# ------------------------- #
## ------------------------- ##
## Java invalid directives. ##
## ------------------------- ##
AT_SETUP([Java invalid directives])
@@ -42,9 +42,9 @@ YYParser.y:4.13-30: error: %destructor does not make sense in Java
AT_CLEANUP
# ------------------------- #
# Helping Autotest macros. #
# ------------------------- #
## ------------------------- ##
## Helping Autotest macros. ##
## ------------------------- ##
# AT_JAVA_POSITION_DEFINE_OLD
@@ -91,9 +91,9 @@ m4_define([AT_JAVA_POSITION_DEFINE_OLD],
# -----------------#
# Java Parameters. #
# -----------------#
## ----------------- ##
## Java Parameters. ##
## ----------------- ##
AT_BANNER([Java Parameters.])
@@ -146,7 +146,7 @@ m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
System.err.println (loc + ": " + s);
}
public int yylex ()$2
public int yylex()$2
{
$3
}
@@ -164,9 +164,9 @@ m4_define([AT_CHECK_JAVA_GREP],
])])
# ------------------------------------- #
# Java parser class and package names. #
# ------------------------------------- #
## ------------------------------------- ##
## Java parser class and package names. ##
## ------------------------------------- ##
AT_SETUP([Java parser class and package names])
@@ -191,9 +191,9 @@ AT_CHECK_JAVA_GREP([[package user_java_package;]])
AT_CLEANUP
# ----------------------------- #
# Java parser class modifiers. #
# ----------------------------- #
## ----------------------------- ##
## Java parser class modifiers. ##
## ----------------------------- ##
AT_SETUP([Java parser class modifiers])
@@ -255,9 +255,9 @@ AT_CHECK_JAVA_GREP([[/\*@Deprecated @SuppressWarnings("unchecked") @SuppressWarn
AT_CLEANUP
# ---------------------------------------- #
# Java parser class extends and implements #
# ---------------------------------------- #
## ---------------------------------------- ##
## Java parser class extends and implements ##
## ---------------------------------------- ##
AT_SETUP([Java parser class extends and implements])
@@ -275,9 +275,9 @@ AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
AT_CLEANUP
# -------------------------------- #
# Java %parse-param and %lex-param #
# -------------------------------- #
## -------------------------------- ##
## Java %parse-param and %lex-param ##
## -------------------------------- ##
AT_SETUP([Java %parse-param and %lex-param])
@@ -349,9 +349,9 @@ AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
AT_CLEANUP
# ------------------------- #
# Java throw specifications #
# ------------------------- #
## --------------------------- ##
## Java throw specifications. ##
## --------------------------- ##
AT_SETUP([Java throws specifications])
@@ -430,17 +430,17 @@ AT_JT_initial_action],
[AT_JT_yylex_action],
[],
[AT_JT_parse_action])])
AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
AT_CHECK_JAVA_GREP([[ *int yylex()]AT_JT_yylex_throws *[;]])
AT_CHECK_JAVA_GREP([[ *private int yyaction([^)]*)]AT_JT_yyaction_throws[ *]])
AT_CHECK_JAVA_GREP([[ *public boolean parse()]AT_JT_parse_throws[ *]])
])])])
AT_CLEANUP
# ------------------------------------- #
# Java constructor init and init_throws #
# ------------------------------------- #
## --------------------------------------- ##
## Java constructor init and init_throws. ##
## --------------------------------------- ##
AT_SETUP([Java constructor init and init_throws])
@@ -465,9 +465,9 @@ m4_popdef([AT_Witness])
AT_CLEANUP
# ------------------------------------------ #
# Java value, position, and location types. #
# ------------------------------------------ #
## ------------------------------------------ ##
## Java value, position, and location types. ##
## ------------------------------------------ ##
AT_SETUP([Java value, position, and location types])
@@ -496,9 +496,9 @@ AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Location']], [1], [ignore
AT_CLEANUP
# ----------------------------------------------- #
# Java syntax error handling without error token. #
# ----------------------------------------------- #
## ------------------------------------------------ ##
## Java syntax error handling without error token. ##
## ------------------------------------------------ ##
AT_SETUP([Java syntax error handling without error token])
+6 -6
View File
@@ -180,28 +180,28 @@ AT_DATA([[input.y]],
# Verify that the proper procedure(s) are generated for each case.
AT_BISON_CHECK([[-Dapi.push-pull=pull -o Main.java input.y]])
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public boolean parse ().*]],
[[.*public boolean parse().*]],
[1])
# If BISON_USE_PUSH_FOR_PULL is set, then we have one occurrence of
# this function, otherwise it should not be there.
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public int push_parse (int yylextoken, Object yylexval).*]],
[[.*public int push_parse(int yylextoken, Object yylexval).*]],
[${BISON_USE_PUSH_FOR_PULL-0}])
AT_BISON_CHECK([[-Dapi.push-pull=both -o Main.java input.y]])
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public boolean parse ().*]],
[[.*public boolean parse().*]],
[1])
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public int push_parse (int yylextoken, Object yylexval).*]],
[[.*public int push_parse(int yylextoken, Object yylexval).*]],
[1])
AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public boolean parse ().*]],
[[.*public boolean parse().*]],
[0])
AT_CHECK_JAVA_GREP([[Main.java]],
[[.*public int push_parse (int yylextoken, Object yylexval).*]],
[[.*public int push_parse(int yylextoken, Object yylexval).*]],
[1])
AT_JAVA_COMPILE([[Main.java]])
+11 -1
View File
@@ -83,6 +83,16 @@ set x `LC_ALL=C ls -l '$1'` &&
## ------------- ##
# AT_DIFF_U_CHECK(DIFF-ARGS, EXPECTED-DIFF)
# -----------------------------------------
# If diff -u works as we expect, use it, with headers stripped.
m4_define([AT_DIFF_U_CHECK],
[if $DIFF_U_WORKS; then
AT_CHECK([diff -u $1 | sed -n '/^@@/,$p' | sed 's/^ $//'], [0], [$2])
fi
])
# AT_PERL_CHECK(PERL-ARGS, ...)
# -----------------------------
# If Perl is available, run this test.
@@ -490,7 +500,7 @@ m4_define([AT_DATA_SOURCE_PROLOGUE],
# The prologue that should be included in any grammar whose parser is
# meant to be compiled.
m4_define([AT_DATA_GRAMMAR_PROLOGUE],
[[%code top {
[[%code top { /* -*- ]AT_LANG[ -*- */
]AT_DATA_SOURCE_PROLOGUE[]dnl
[}
]])
+1
View File
@@ -56,6 +56,7 @@ TESTSUITE_AT = \
%D%/java.at \
%D%/javapush.at \
%D%/local.at \
%D%/m4.at \
%D%/named-refs.at \
%D%/output.at \
%D%/package.m4 \
+72
View File
@@ -0,0 +1,72 @@
# Basic m4 macros. -*- Autotest -*-
# Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
AT_BANNER([[M4 Macros.]])
AT_SETUP([Generating Comments])
AT_DATA([input.y],
[%%
exp:
])
AT_DATA([input.m4],
[[m4@&t@_include(b4_skeletonsdir/[c.m4])
b4_output_begin([output.txt])
b4_gsub([[abcd]],
[a], [b])
b4_gsub([[abcd]],
[a], [b],
[b], [c],
[c], [d])
_b4_comment([["/* () */"]])
_b4_comment([["/* ( */"]])
_b4_comment([["/* ) */"]])
_b4_comment([["/* [] */"]])
b4_comment([["/* () */"]])
b4_comment([["/* ( */"]])
b4_comment([["/* ) */"]])
b4_comment([["/* [] */"]])
b4_output_end([output.txt])
]])
AT_BISON_CHECK([-S ./input.m4 input.y])
AT_CHECK([cat output.txt], [],
[[
[bbcd]
[dddd]
"/\* () *\/"
"/\* ( *\/"
"/\* ) *\/"
"/\* [] *\/"
/* "/\* () *\/" */
/* "/\* ( *\/" */
/* "/\* ) *\/" */
/* "/\* [] *\/" */
]])
AT_CLEANUP
+17 -6
View File
@@ -372,8 +372,19 @@ m4_pushdef([AT_TEST],
AT_BISON_OPTION_PUSHDEFS([$1])
# Clang chokes on some of our comments, because it tries to "parse"
# some documentation directives in the comments:
#
# input.c:131:48: error: '\a' command does not have a valid word argument [-Werror,-Wdocumentation]
# SPECIAL = 261 /* "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" */
# ~~^
AT_DATA_GRAMMAR([input.y],
[%{
#if defined __clang__ && 10 <= __clang_major__
# pragma clang diagnostic ignored "-Wdocumentation"
#endif
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
@@ -398,14 +409,14 @@ exp: ]AT_ERROR_VERBOSE_IF(["\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"], ["
# C-string literal. Also notice that unnecessary escaping, such as "\?", from
# the user specification is eliminated.
AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]],
[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother]
22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
[[input.y:26.8-14: warning: symbol SPECIAL redeclared [-Wother]
26 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
| ^~~~~~~
input.y:21.8-14: note: previous declaration
21 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
input.y:25.8-14: note: previous declaration
25 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
| ^~~~~~~
input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
input.y:26.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
26 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]])
+2
View File
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Basic M4 macros.
m4_include([m4.at])
# Resistance to user bugs.
m4_include([input.at])