Commit Graph

7628 Commits

Author SHA1 Message Date
Akim Demaille
2313f891bd glr2.cc: add sanity checks in glr_stack_item
We obviously have broken pointer arithmetics that hands us
glr_stack_items that are not glr_stack_items.  Have a simple check for
this, to have earlier failures.

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

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

These pass:

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

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

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

And these do not end:

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

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

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

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

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

* data/skeletons/glr2.cc (yyresolveValue): Add missing incrementation
of the iteration variable.
2020-12-06 14:02:38 +01:00
Valentin Tolmer
1b85ac4586 glr2.cc: misc cleanups
* data/skeletons/glr2.cc: Use 'const' on variables and applicable
member functions.
Improve comments.
Use references where applicable.
Enforce names_like_this, notLikeThis.
Reduce scopes.
2020-12-06 14:02:38 +01:00
Valentin Tolmer
2ec6df3b07 glr2.cc: fix memory corruption bug
* data/skeletons/glr2.cc (yyremoveDeletes): Remove double-increment in
the loop.
(glr_state::copyFrom): Handle gracefully when other is resolved.
2020-12-06 14:02:38 +01:00
Akim Demaille
e72eda7aee glr2.cc: turn some pointers into references
* data/skeletons/glr2.cc: Prefer references to pointers.
Add a few more const.
2020-12-06 14:02:38 +01:00
Valentin Tolmer
4f24f5f304 glr2.cc: use 'const' for some constant local variables
* data/skeletons/glr2.cc: here.
2020-12-06 13:54:45 +01:00
Akim Demaille
12b5924939 glr2.cc: fix when the stack is not expandable
* data/skeletons/glr2.cc (yyexpandGLRStackIfNeeded): Fix the
implementation when !YYSTACKEXPANDABLE.
2020-12-06 13:54:45 +01:00
Akim Demaille
d4188398f1 glr.c: fix line numbers in logs
* data/skeletons/glr.c (yyglrReduce): Fix line numbers.
* tests/glr-regression.at: Fix expectations.
2020-12-06 13:54:45 +01:00
Akim Demaille
8ab625e517 tests: glr: run the glr regression tests with glr.cc
* tests/glr-regression.at: Adjust the tests to be more independent of
the language, and run them with glr.cc.
Some tests relied on yychar, yylval and yylloc being global variables:
pass arguments instead.
2020-12-05 12:39:59 +01:00
Akim Demaille
edf6aa7d3b tests: glr: prepare for more languages
* tests/glr-regression.at: Wrap each test in an AT_TEST.
Call it with glr.c.
2020-12-05 12:39:59 +01:00
Akim Demaille
4aec17af93 tests: glr: use AT_FULL_COMPILE
* tests/glr-regression.at: Instead of using AT_BISON_CHECK and
AT_COMPILE, use AT_FULL_COMPILE.  This is shorter, and makes it easier
to add support for other programming languages.
2020-12-05 11:22:20 +01:00
Akim Demaille
c98b8856e6 tests: glr: prefer directives to warnings
* tests/glr-regression.at: Use %expect and %expect-rr in the grammar
files, rather than accepting diagnostics.
This will make it easier to support other programming languages.
2020-12-05 11:22:20 +01:00
Akim Demaille
4ec49a8585 tests: factor the access to token kinds
* tests/local.at (AT_BISON_OPTION_PUSHDEFS): Define AT_TOKEN.
(AT_BISON_OPTION_POPDEFS): Undefine it.
* tests/actions.at, tests/c++.at, tests/calc.at: Use AT_TOKEN.
2020-12-05 11:22:20 +01:00
Akim Demaille
627d275a3a tests: formatting changes
* tests/local.at: here.
2020-12-05 11:22:20 +01:00
Akim Demaille
84a84560c3 glr.cc: don't "leak" yyparse
When using glr.cc, the C function yyparse is an internal detail that
should not be exposed.  Users might call it by accident (I did).

* data/skeletons/glr.c (yyparse): When used for glr.cc, rename as yy_parse_impl.
* data/skeletons/glr.cc: Adjust.
2020-12-05 07:36:01 +01:00
Akim Demaille
0e78a9028e portability: beware of GCC 4.6
src/reader.c: In function 'grammar_start_symbols_add':
    src/reader.c:67:24: error: declaration of 'dup' shadows a global declaration [-Werror=shadow]

* src/reader.c (grammar_start_symbols_add): Rename dup as dupl.
2020-12-03 19:46:20 +01:00
Akim Demaille
24233748ec tables: avoid warnings and save bits
The yydefgoto table uses -1 as an invalid for an impossible case (we
never use yydefgoto[0], since it corresponds to the reduction to
$accept, which never happens).  Since yydefgoto is a table of state
numbers, this -1 forces a signed type uselessly, which (1) might
trigger compiler warnings when storing a value from yydefgoto into a
state number (nonnegative), and (2) wastes bits which might result in
using a int16 where a uint8 suffices.

Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00027.html

* src/tables.c (default_goto): Use 0 rather than -1 as invalid value.
* tests/regression.at: Adjust.
2020-12-03 06:21:53 +01:00
Akim Demaille
9840e5b621 c++: use noexcept where appropriate
Reported by Don Macpherson.
https://github.com/akimd/bison/issues/63
https://github.com/akimd/bison/issues/64

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

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

Suggested by H. S. Teoh.

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

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

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

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

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

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

After:

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

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

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

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

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

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

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

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

Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00002.html

We should avoid emitting lines so long.

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

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

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

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

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

* data/skeletons/c.m4 (b4_token_defines): Do define YYEMPTY.
2020-11-11 08:47:21 +01:00