Commit Graph

7684 Commits

Author SHA1 Message Date
Akim Demaille
c654eb481c c++: variants: minor simplification
Do as Valentin Tolmer did in glr2.cc.

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

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

See also be6fa942ac.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reported by Mingli Yu <mingli.yu@windriver.com>.
https://github.com/akimd/bison/issues/31
https://lists.gnu.org/r/bison-patches/2020-05/msg00055.html

Reported by Claudio Calvelli <bugb@w42.org>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00001.html
https://bugs.gentoo.org/716516

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

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

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

    empty
    : %empty

we used to display

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

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

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

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

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

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

to

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

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

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

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

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

* tests/output.at: Don't use + with sed.
While at it, fix a quotation problem hidden by the use of '#'.
2020-08-30 17:16:18 +02:00
Akim Demaille
b63e3a3352 glr2.cc: fix a few warnings
* data/skeletons/glr2.cc: Fix some documentation.
Be consistent between class/struct.
(yydoAction, yyresolveAction): Avoid passing yyparser where useless.
2020-08-30 12:58:27 +02:00
Valentin Tolmer
ef09bf065a glr2.cc: fork glr.cc to a c++ version
This is a fork of glr.cc to be c++-first instead of a wrapper around
glr.c.

* data/skeletons/glr2.cc: New.
* data/skeletons/bison.m4, data/skeletons/c++.m4: Adjust.
* data/skeletons/c.m4 (b4_user_args_no_comma): New.
* src/reader.c (grammar_rule_check_and_complete): glr2.cc is C++.
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/local.at, tests/regression.at, tests/scanner.at,
* tests/synclines.at, tests/types.at: Also check glr2.cc.
2020-08-30 10:45:21 +02:00
Akim Demaille
a1b7fef045 c: always use YYMALLOC/YYFREE
Reported by Kovalex <kovalex.pro@gmail.com>.
https://lists.gnu.org/r/bug-bison/2020-08/msg00015.html

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

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

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

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

On an empty such as

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

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

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

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

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

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

Reported by Nelson H. F. Beebe.

* src/parse-simulation.c (parse_state): Don't typedef,
parse-simulation.h did it already.
2020-08-03 07:30:35 +02:00