Commit Graph

5988 Commits

Author SHA1 Message Date
Akim Demaille
b7577ea6f6 parser: shorten side-effects on current_type
* src/parse-gram.y (tag.opt): Don't change current_type.
Rather, return its value.
Adjust dependencies.
2018-11-30 06:07:56 +01:00
Akim Demaille
6220e96e76 style: reduce scopes
* src/symlist.c: here.
2018-11-30 06:04:03 +01:00
Akim Demaille
2c6b7c8b2c tests: don't name C++ files *.c
* tests/synclines.at (syncline escapes): Here.
Otherwise, Clang generates an error and skips the test.
2018-11-29 07:44:37 +01:00
Akim Demaille
36e587b1f6 gnulib: update 2018-11-29 06:16:20 +01:00
Akim Demaille
b1d6c42ae5 regen 2018-11-29 06:16:20 +01:00
Akim Demaille
8e092082cb parser: factor the symbol definition
* src/parse-gram.y (int.opt, string_as_id.opt): New.
(symbol_def): Use it.
2018-11-29 06:16:20 +01:00
Akim Demaille
2c5e933672 parser: improve location of string alias errors
* src/parse-gram.y (symbol_def): Pass the right location for symbol_make_alias.
* tests/regression.at (Duplicate string): Move to...
* tests/input.at: here.
(Token collisions): New.
2018-11-29 06:16:20 +01:00
Akim Demaille
d92ed9d9f7 diagnostics: complain about Bison directives when -Wyacc
* src/complain.h, src/complain.c (bison_directive): New.
* src/scan-gram.l (BISON_DIRECTIVE): New.
Use it for Bison extensions.
2018-11-29 06:16:20 +01:00
Akim Demaille
ebe9b20841 doc: formatting changes
* doc/bison.texi: here.
2018-11-28 13:07:41 +01:00
Akim Demaille
23e022718b style: fix quotation in the test suite
* tests/input.at: here.
2018-11-27 20:08:18 +01:00
Akim Demaille
0e9eade009 regen 2018-11-27 08:32:49 +01:00
Akim Demaille
9686b585e7 %nterm: do not accept character literals
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

* src/complain.h: Formatting change.
* src/parse-gram.y (id): Reject character literals used in a context
for non-terminals.
* tests/input.at (Invalid %nterm uses): Check that.
2018-11-27 08:25:38 +01:00
Akim Demaille
4bddd33439 %nterm: do not accept numbers nor string alias
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

* src/parse-gram.y (symbol_def): Refuse string aliases and numbers
for non-terminals.
(prologue_declaration): Recover from errors ended with ';'.
* tests/input.at (Invalid %nterm uses): New.
2018-11-27 08:25:38 +01:00
Akim Demaille
4ad877fdab TODO: update 2018-11-27 06:12:48 +01:00
Akim Demaille
9476783307 doc: formatting changes
* doc/bison.texi: Here.
2018-11-26 07:56:06 +01:00
Akim Demaille
e1c55d83f8 style: comment changes
* tests/testsuite.at: here.
2018-11-26 07:56:06 +01:00
Akim Demaille
647bf48797 gnulib: update ignores 2018-11-26 07:03:55 +01:00
Akim Demaille
bcecfbafab gnulib: update to use its bitsets
Bison's bitset were moved to gnulib.

* lib/abitset.c, lib/abitset.h, lib/bbitset.h, lib/bitset.c,
* lib/bitset.h, lib/ebitset.c, lib/ebitset.h, lib/lbitset.c,
* lib/bitset_stats.c, lib/bitset_stats.h, lib/bitsetv-print.c,
* lib/bitsetv-print.h, lib/bitsetv.c, lib/bitsetv.h,
* lib/lbitset.h, lib/vbitset.c, lib/vbitset.h:
Remove.

* gnulib: Update.
* bootstrap.conf, lib/local.mk: Adjust.
2018-11-26 06:33:45 +01:00
Akim Demaille
deb2fc1dfc gnulib: use conditional dependencies
* bootstrap.conf: here.
2018-11-25 19:57:08 +01:00
Akim Demaille
3a203e2e56 CI: run on xenial
Xenial (Ubuntu 16.04) is finally available on Travis.  Let's use it.

Among the changes:

- Automake 1.14.1 -> 1.15.0
- Doxygen  1.8.6  -> 1.8.11
- Flex     2.5.35 -> 2.6.0, with plenty of new compiler warnings
- Gettext  0.18.3 -> 0.19.7
- Graphviz 2.36.0 -> 2.38.0
- Texinfo  5.2    -> 6.1

* .travis.yml: here.
2018-11-25 13:22:54 +01:00
Akim Demaille
709c87bb41 CI: we don't need git show
* .travis.yml: Don't run it.
2018-11-25 11:34:10 +01:00
Akim Demaille
9ffed56cd9 regen 2018-11-25 11:27:08 +01:00
Akim Demaille
cc050fd321 warning: avoid warnings about unreachable code
Reported by Uxio Prego.
https://lists.gnu.org/archive/html/help-bison/2018-11/msg00031.html

We also need to move the unreachable 'goto' to a reachable place,
otherwise clang complains about the code being unreachable anyway.
See also https://bugs.llvm.org/show_bug.cgi?id=39736.

Interestingly, we don't have to apply that trick to
`#define YYCDEBUG if (false) std::cerr`, clang does not warn when the
code comes from macro expansion.

* configure.ac: Use -Wunreachable-code when supported.
* data/lalr1.cc, data/yacc.c: Pacify clang's warning about `if (0)`
by using a macro.
Another possibility was to move this statement to a reachable place.
* tests/actions.at, tests/c++.at: Avoid generating unreachable code.
2018-11-25 11:22:31 +01:00
Akim Demaille
660811a6c5 yacc.c: avoid generating dead code
We should probably introduce some struct and functions to deal with
stack management, rather than open coding it.  yyparse would be much
nicer to read, and a better model for possible other skeletons.

* data/yacc.c (yyparse::yysetstate): Avoid generating code when
neither yyoverflow nor YYSTACK_RELOCATE is defined.
2018-11-24 13:26:27 +01:00
Akim Demaille
7ded5bb764 %expect-rr: tune the number of conflicts per rule
Currently on a grammar such as

    exp : a '1' | a '2' | a '3' | b '1' | b '2' | b '3'
    a:
    b:

we count only one rr-conflict on the `b:` rule, i.e., we expect:

    b: %expect-rr 1

although there are 3 conflicts in total.  That's because in the
conflicted state we count only a single conflict, not three (one for
each of the lookaheads: '1', '2', '3').

    State 0

        0 $accept: . exp $end
        1 exp: . a '1'
        2    | . a '2'
        3    | . a '3'
        4    | . b '1'
        5    | . b '2'
        6    | . b '3'
        7 a: . %empty  ['1', '2', '3']
        8 b: . %empty  ['1', '2', '3']

        '1'       reduce using rule 7 (a)
        '1'       [reduce using rule 8 (b)]
        '2'       reduce using rule 7 (a)
        '2'       [reduce using rule 8 (b)]
        '3'       reduce using rule 7 (a)
        '3'       [reduce using rule 8 (b)]
        $default  reduce using rule 7 (a)

        exp  go to state 1
        a    go to state 2
        b    go to state 3

See https://lists.gnu.org/archive/html/bison-patches/2013-02/msg00106.html.

* src/conflicts.c (rule_has_state_rr_conflicts): Rename as...
(count_rule_state_sr_conflicts): this.
DWIM.
(count_rule_rr_conflicts): Adjust.
* tests/conflicts.at (%expect-rr in grammar rules)
(%expect-rr too much in grammar rules)
(%expect-rr not enough in grammar rules): New.
2018-11-22 08:34:10 +01:00
Akim Demaille
ad0b4661d1 %expect-rr: fix the computation of the overall number of conflicts
On a grammar such as

   exp: "num" | "num" | "num"

we currently report only one RR conflict, instead of two.

This bug is present since the origins of Bison

    commit 08089d5d35
    Author: David MacKenzie <djm@djmnet.org>
    Date:   Tue Apr 20 05:42:52 1993 +0000

       Initial revision

and was preserved in

    commit 676385e29c
    Author: Paul Hilfinger <Hilfinger@CS.Berkeley.EDU>
    Date:   Fri Jun 28 02:26:44 2002 +0000

       Initial check-in introducing experimental GLR parsing.  See entry in
       ChangeLog dated 2002-06-27 from Paul Hilfinger for details.

See
https://lists.gnu.org/archive/html/bison-patches/2018-11/msg00011.html

* src/conflicts.h, src/conflicts.c (count_state_rr_conflicts)
(count_rr_conflicts): Use only the correct count of conflicts.
* tests/glr-regression.at: Fix expectations.
2018-11-22 08:34:07 +01:00
Akim Demaille
260ae5481c tests: generate *.output files
* tests/glr-regression.at: here.
2018-11-21 22:10:35 +01:00
Akim Demaille
e51fd547ca %expect: tune the number of conflicts per rule
Currently on a grammar such as

    exp: "number" | exp "+" exp | exp "*" exp

we count only one sr-conflict for both binary rules, i.e., we expect:

    exp: "number" | exp "+" exp  %expect 1 | exp "*" exp  %expect 1

although there are 4 conflicts in total.  That's because in the states
in conflict, for instance that for the "+" rule:

    State 6

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

        "+"  shift, and go to state 4
        "*"  shift, and go to state 5

        "+"       [reduce using rule 2 (exp)]
        "*"       [reduce using rule 2 (exp)]
        $default  reduce using rule 2 (exp)

we count only a single conflict, although there are two (one on "+"
and another with "*").

See https://lists.gnu.org/archive/html/bison-patches/2013-02/msg00106.html.

* src/conflicts.c (rule_has_state_sr_conflicts): Rename as...
(count_rule_state_sr_conflicts): this.
DWIM.
(count_rule_sr_conflicts): Adjust.
* tests/conflicts.at (%expect in grammar rules): New.
2018-11-21 22:10:35 +01:00
Akim Demaille
4ebebcc438 regen 2018-11-21 22:10:35 +01:00
Akim Demaille
2b2556b41c style: reduce scopes
* src/conflicts.c, src/reader.c: Minor style changes.
2018-11-21 22:08:47 +01:00
Paul Hilfinger
b34b12c4f9 allow %expect and %expect-rr modifiers on individual rules
This change allows one to document (and check) which rules participate
in shift/reduce and reduce/reduce conflicts.  This is particularly
important GLR parsers, where conflicts are a normal occurrence.  For
example,

    %glr-parser
    %expect 1
    %%

    ...

    argument_list:
      arguments %expect 1
    | arguments ','
    | %empty
    ;

    arguments:
      expression
    | argument_list ',' expression
    ;

    ...

Looking at the output from -v, one can see that the shift-reduce
conflict here is due to the fact that the parser does not know whether
to reduce arguments to argument_list until it sees the token AFTER the
following ','.  By marking the rule with %expect 1 (because there is a
conflict in one state), we document the source of the 1 overall shift-
reduce conflict.

In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
conflicts.  In this case, we mark each of the conflicting rules.  For
example,

    %glr-parser
    %expect-rr 1

    %%

    stmt:
      target_list '=' expr ';'
    | expr_list ';'
    ;

    target_list:
      target
    | target ',' target_list
    ;

    target:
      ID %expect-rr 1
    ;

    expr_list:
      expr
    | expr ',' expr_list
    ;

    expr:
      ID %expect-rr 1
    | ...
    ;

In a statement such as

    x, y = 3, 4;

the parser must reduce x to a target or an expr, but does not know
which until it sees the '='.  So we notate the two possible reductions
to indicate that each conflicts in one rule.

See https://lists.gnu.org/archive/html/bison-patches/2013-02/msg00105.html.

* doc/bison.texi (Suppressing Conflict Warnings): Document %expect,
%expect-rr in grammar rules.
* src/conflicts.c (count_state_rr_conflicts): Adjust comment.
(rule_has_state_sr_conflicts): New static function.
(count_rule_sr_conflicts): New static function.
(rule_nast_state_rr_conflicts): New static function.
(count_rule_rr_conflicts): New static function.
(rule_conflicts_print): New static function.
(conflicts_print): Also use rule_conflicts_print to report on individual
rules.
* src/gram.h (struct rule): Add new fields expected_sr_conflicts,
expected_rr_conflicts.
* src/reader.c (grammar_midrule_action): Transfer expected_sr_conflicts,
expected_rr_conflicts to new rule, and turn off in current_rule.
(grammar_current_rule_expect_sr): New function.
(grammar_current_rule_expect_rr): New function.
(packgram): Transfer expected_sr_conflicts, expected_rr_conflicts
to new rule.
* src/reader.h (grammar_current_rule_expect_sr): New function.
(grammar_current_rule_expect_rr): New function.
* src/symlist.c (symbol_list_sym_new): Initialize expected_sr_conflicts,
expected_rr_conflicts.
* src/symlist.h (struct symbol_list): Add new fields expected_sr_conflicts,
expected_rr_conflicts.
* tests/conflicts.at: Add tests "%expect in grammar rule not enough",
"%expect in grammar rule right.", "%expect in grammar rule too much."
2018-11-21 22:08:47 +01:00
Akim Demaille
487a2a9eca NEWS: update 2018-11-21 22:05:45 +01:00
Akim Demaille
559114c3cb gnulib: update 2018-11-21 22:03:50 +01:00
Akim Demaille
dee62718ae remove ancient lint directives
* data/c++.m4, data/yacc.c: Remove surprising remains of lint
directives.
2018-11-21 08:59:38 +01:00
Jannick
bee10f5774 doc: calc++: remove ancient fix for flex
* doc/bison.texi (Calc++ Scanner): Remove fix for Flex 2.5.31-2.5.33.
2018-11-21 08:58:35 +01:00
Jannick
7795db64d1 doc: calc++: ignore \r in the scaner
* doc/bison.texi (Calc++ Scanner): Ignore \r.
2018-11-21 08:39:22 +01:00
Akim Demaille
6bc54a934e style: harmonize the labels of yyparse
* data/glr.c, data/lalr1.cc, data/yacc.c: Fix indentation and
other formatting issues.
2018-11-20 20:52:58 +01:00
Akim Demaille
ebb92c0545 regen 2018-11-20 20:04:06 +01:00
Akim Demaille
e0de1020ea style: avoid lengthy actions
We also lack a consistent naming for directive implementations.
`directive_skeleton` is too long, `percent_skeleton` is not very nice
looking, `process_skeleton` looks ambiguous, `do_skeleton` is somewhat
ambiguous too, but seems a better track.

* src/parse-gram.y (version_check): Rename as...
(do_require): this.
(do_skeleton): New.
Use it.
2018-11-20 20:03:01 +01:00
Akim Demaille
4e510c69b1 c++: using macros around user types breaks when they include comma
We may generate code such as

    basic_symbol (typename Base::kind_type t, YY_RVREF (std::pair<int,int>) v);

which, of course, breaks, because YY_RVREF sees two arguments.  Let's
not play tricks with _VA_ARGS__, I'm unsure about it portability.
Anyway, I plan to change more things in this area.

Reported by Sébastien Villemot.
http://lists.gnu.org/archive/html/bug-bison/2018-11/msg00014.html

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Don't use macro on user types.
* tests/types.at: Check that we support pairs.
2018-11-20 20:01:50 +01:00
Akim Demaille
b72d654fa2 README: update 2018-11-16 17:37:47 +01:00
Akim Demaille
77086ab57d tests: remove duplicate definition
Probably imported by 6d58c63202, a merge
commit.

* tests/atlocal.in (POSIXLY_CORRECT_IS_EXPORTED): Define it once.
2018-11-16 17:37:47 +01:00
Akim Demaille
8474dbc09e glr.c: fix use of _Noreturn
In C++, [[noreturn]] must not be between "static" and the rest of the
function signature, it must precede it.  C's _Noreturn does not seem
to have such a constraint, but it is therefore compatible with the C++
constraint.  Since we #define _Noreturn as [[noreturn]] is modern C++,
be sure to push the _Noreturn first.

Unfortunately this was not caught by the test suite, because it always
loads config.h first, and config.h contains another definition of
_Noreturn that does not use [[noreturn]], and hides ours.  That's
probably a sign we should avoid always loading config.h.

* data/glr.c (yyFail, yyMemoryExhausted): here.
2018-11-16 17:37:47 +01:00
Akim Demaille
8eb1d79333 tests: run the api.value.type tests for all C++ standards
* tests/local.at (AT_LANG_FOR_EACH_STD): New.
(AT_REQUIRE_CXX_VERSION): Rename as...
(AT_REQUIRE_CXX_STD): this.
Accept an argument for what to do when the requirement is not met.
* tests/types.at (api.value.type): Check all the C++ stds.
2018-11-16 17:37:47 +01:00
Akim Demaille
7bd7644702 CI: split the ASAN job in two
The following commit introduce even more compilations/runs than
before, and with ASAN on, we go beyond to 50min credit from Travis.

* .travis.yml (Clang 7 libc++ and ASAN): Split in two.
2018-11-16 17:36:28 +01:00
Akim Demaille
037eff335b c++: use YY_CPLUSPLUS
* data/c++.m4: here.
2018-11-14 21:25:29 +01:00
Akim Demaille
7adeb80765 c++: factor the handling of __cplusplus into YY_CPLUSPLUS
* data/c++.m4 (b4_cxx_portability): Define it.
Use it.
* data/lalr1.cc, data/variant.hh: Use it.
2018-11-13 07:46:08 +01:00
Akim Demaille
a52723e3e8 style: formatting changes
* src/scan-gram.l: here.
2018-11-13 07:46:08 +01:00
Akim Demaille
e4fd17bffa tests: clarify some magic constant
* tests/c++.at (C++ Variant-based Symbols Unit Tests): here.
2018-11-13 07:46:08 +01:00
Akim Demaille
8ff6ff3ab0 examples: remove useless includes
* examples/c++/variant-11.yy, examples/c++/variant.yy: here.
Fix warning when storing a long into an int.
2018-11-13 06:53:21 +01:00