Commit Graph

1413 Commits

Author SHA1 Message Date
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
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
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
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
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
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
35b8e0e947 parser: deprecate %error-verbose
It is unfortunate that %error_verbose was properly diagnosed as
obsoleted by "%define parse.error verbose", but %error-verbose was
not.

* src/parse-gram.y (%error-verbose): Remove support.
* src/scan-gram.l: Do it here instead, with a warning.
* tests/input.at (Deprecated directives): Check it.
2018-11-12 07:41:46 +01:00
Akim Demaille
be7c620d65 tests: migrate from %error-verbose to %define parse.error verbose
* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/cxx-type.at, tests/existing.at, tests/glr-regression.at,
* tests/headers.at, tests/input.at, tests/java.at, tests/javapush.at,
* tests/local.at, tests/regression.at, tests/skeletons.at,
* tests/torture.at:
Here.
2018-11-12 07:28:23 +01:00
Akim Demaille
7928c3e6fb parser: deprecate %nterm
It has several weaknesses.
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

* src/scan-gram.l: here.
2018-11-12 07:28:20 +01:00
Akim Demaille
8d454b843c tests: fix syncline tests
These tests are skipped with GCC:

    "\"".c:1:5: error: function declaration isn't a prototype [-Werror=strict-prototypes]
     int main() { return 0; }
         ^~~~

* tests/synclines.at: Stop writing C++ in C.
* tests/local.at: Formatting changes.
2018-11-12 07:10:04 +01:00
Akim Demaille
86efe28222 c++: improve the generated documentation
* data/lalr1.cc, data/location.cc: Improve documenting comments.
* tests/c++.at (Doxygen Documentation): Fix AT_BISON_OPTION_PUSHDEFS,
so that the generated yyerror is correct.
* tests/c++.at, tests/headers.at: Prefer %empty.
2018-11-04 17:56:09 +01:00
Akim Demaille
cf1446dc9e tests: don't fail if the C++ compiler does not work
Also, make sure that `make dist` generates a correct tarball even if
the C++ compiler does not work.

Reported by Nelson H. F. Beebe.

* m4/cxx.m4 (BISON_CXX_WORKS): Define to true/false instead of
true/exit 77.  The latter is too dangerous to use (it directly quits).
(ENABLE_CXX): New name for the Automake conditional, for consistency
with ENABLE_CXX11 etc.
* tests/local.at (AT_COMPILE, AT_COMPILE_CXX): Adjust to the new
semantics of BISON_CXX_WORKS.
* examples/c++/local.mk: Skip the variant test if C++ does not work.
* examples/calc++/local.mk: Likewise.
2018-11-04 17:56:09 +01:00
Akim Demaille
e93c40b33d tests: don't disable C++ warnings in C files
This triggers error with GCC.
See eff6739124.

* tests/testsuite.h: Disable -Wzero-as-null-pointer-constant only for
C++.
2018-11-04 17:56:09 +01:00
Akim Demaille
eff6739124 c++: workaround portability issue
On some systems (x86_64-pc-solaris2.11), with Developer Studio 12.5's
CC, we get:

    ".../include/CC/Cstd/vector.cc", line 127: Error: Cannot assign const yy::parser::stack_symbol_type to yy::parser::stack_symbol_type without "yy::parser::stack_symbol_type::operator=(const yy::parser::stack_symbol_type&)";.
    ".../include/CC/Cstd/vector", line 475:     Where: While instantiating "std::vector<yy::parser::stack_symbol_type>::__insert_aux(yy::parser::stack_symbol_type*, const yy::parser::stack_symbol_type&)".
    ".../include/CC/Cstd/vector", line 475:     Where: Instantiated from non-template code.
    1 Error(s) detected.

Don't expect __cplusplus to be always defined.  If it's not, consider
this is C++98.

Reported by Nelson H. F. Beebe.

* data/c++.m4, data/lalr1.cc, examples/c++/variant.yy, tests/local.at,
* tests/testsuite.h:
An undefined __cplusplus means pre C++11.
2018-11-04 08:00:01 +01:00
Akim Demaille
5a0d7802f4 tests: work around getopt portability issues
On some systems, we don't use our getopt.  As a consequence the error
messages vary:

    $ bison --skeleton
    bison: option requires an argument -- skeleton
    Try 'bison --help' for more information.

instead of

    bison: option '--skeleton' requires an argument
    Try 'bison --help' for more information.

Reported by Jannick and Nelson H. F. Beebe.
https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00140.html

* tests/input.at (Invalid number of arguments): work around getopt
portability issues.
2018-11-03 08:02:15 +01:00
Akim Demaille
71758d854a tests: beware of Windows file name constraints
Don't expect to be able to build a file named '"\"".y' (6 characters)
on Windows.

Reported by Jannick.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00042.html

* tests/synclines.at (syncline escapes): Skip if we failed to create
the file.
2018-10-26 18:59:01 +02:00
Akim Demaille
3751d50e70 tests: fix invocation of m4_map
* tests/actions.at, tests/synclines.at: m4_map takes a list of
arguments in $2, m4_map_args takes arguments in $2, $3, etc.
2018-10-26 18:59:01 +02:00
Akim Demaille
7c4b40de61 build: remove a few copies of the Copyright from the generated Makefile
* build-aux/local.mk, cfg.mk, examples/calc++/local.mk,
* examples/local.mk, examples/mfcalc/local.mk,
* examples/rpcalc/local.mk, lib/local.mk, src/local.mk,
* tests/local.mk:
Use Automake comments so that we don't get a copy of each in the
generated Makefile.
2018-10-24 06:18:57 +02:00
Akim Demaille
ba9db64745 printf returns a signed int
* tests/local.at: Adjust location_print's signature.
2018-10-22 17:49:08 +02:00
Akim Demaille
b4b8666e4a tests: be strict about types
* tests/actions.at, tests/c++.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/local.at, tests/torture.at,
* tests/types.at:
Pay stricter attention to types to avoid warnings.
2018-10-22 17:49:06 +02:00
Akim Demaille
85f7c08036 tests: refactor
* tests/actions.at, tests/synclines.at: Prefer iteration to
copy-paste.
2018-10-21 08:28:50 +02:00
Akim Demaille
098f5084a0 tests: rename AT_SKEL_CC_IF/AT_SKEL_JAVA_IF as AT_CXX_IF/AT_JAVA_IF
The previous name is too obscure, and the other macros for C++ use
CXX, not CC.

* tests/local.at (AT_SKEL_CC_IF, AT_SKEL_JAVA_IF): Rename as...
(AT_CXX_IF, AT_JAVA_IF): these.
Adjust callers.
2018-10-21 08:28:47 +02:00
Akim Demaille
07a4b32f4d c++: check that emplace for rvalues works
See the previous commit.

* tests/local.at (AT_REQUIRE_CXX_VERSION): New.
* tests/types.at (api.value.type): Check emplace in C++14.
2018-10-21 08:02:52 +02:00
Akim Demaille
e7b709ab0b %printer: promote yyo rather than yyoutput
* doc/bison.texi: Promote yyo rather than yyoutput.

* data/c.m4, data/glr.cc, tests/types.at, tests/calc.at,
tests/regression.at: Adjust.
2018-10-20 19:03:01 +02:00
Akim Demaille
3967e46a2d lalr1.cc: fix stack symbol move
In some casing, once we moved a stack symbol, we forget to mark the
source stack symbol as emptied.  As a consequence, it may be destroyed
a second time.

This happens when the stack has to be resized.

* data/lalr1.cc (stack_symbol_type::stack_symbol_type): Record that
the source was emptied.
(stack_symbol_type::operator=): Likewise.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Force the stack
to be resized.  Check its content.
2018-10-18 07:15:30 +02:00
Akim Demaille
5cdbc97c9d pacify syntax-checks
* lib/lbitset.c, tests/c++.at: here.
* cfg.mk: Add exceptions.
2018-10-16 18:54:06 +02:00
Akim Demaille
ea31f21fd8 C++: let %require "3.2" disable the generation of obsolete files
The files stack.hh and position.hh are deprecated.  Rather than
devoting specify %define variables to discard them (api.position.file
and api.stack.file), and rather than having to use special rules when
api.location.file is used, let's simply decide that from %require
"3.2" onwards, these files will not be generated.

The only noticeable thing here is that, in order to be able to check
the behavior of %require "3.2", to have this version (which is still
3.1-*) to accept %require "3.2".

* src/gram.h, src/gram.c (required_version): New.
* src/parse-gram.y (version_check): Set it.
* src/output.c (prepare): Pass it m4.
* data/bison.m4 (b4_required_version_if): Receive it and use it.
* data/location.cc, data/stack.hh: Replace the api.*.file with only
required version comparison.
* tests/input.at: No longer check api.stack.file and api.position.file.
* NEWS, doc/bison.texi: Don't mention them.
Document the %require 3.2 behavior.
* tests/output.at: Use %require 3.2 instead.
2018-10-16 13:33:32 +02:00
Akim Demaille
01898726e2 generate the default semantic action
Currently, in C, the default semantic action is implemented by being
always run before running the actual user semantic action.  As a
consequence, when the user action is run, $$ is already set as $1.

In C++ with variants, we don't do that, since we cannot manipulate the
semantic value without knowing its exact type.  When variants are
enabled, the only guarantee is that $$ is default contructed and ready
to the used.

Some users still would like the default action to be run with
variants.  Frank Heckenbach's parser in
C++17 (http://lists.gnu.org/archive/html/bug-bison/2018-04/msg00011.html)
provides this feature, but relying on std::variant's dynamic typing,
which we forbid in lalr1.cc.

The simplest seems to be actually generating the default semantic
action (in all languages/skeletons).  This makes the pre-action (that
sets $$ to $1) useless.  But...  maybe some users depend on this, in
spite of the comments that clearly warn againt this.  So let's not
turn this off just yet.

* src/reader.c (grammar_rule_check_and_complete): Rename as...
(grammar_rule_check_and_complete): this.
Install the default semantic action when applicable.
* examples/variant-11.yy, examples/variant.yy, tests/calc.at:
Exercise the default semantic action, even with variants.
2018-10-14 18:53:21 +02:00
Akim Demaille
b8351d06f1 C++: issue a better CPP guard and Doxygen file command
Currently we use "<dir><api.location.file>" as \file argument, and as
base for the CPP guard.  This is not nice when <dir> is absolute, in
which case it is expected that the user will use api.location.include
to get something nicer.  If defined, use that name instead.

* data/location.cc (b4_location_path): New.
Use it.
* tests/c++.at (Shared locations): Check the guard and Doxygen doc.
2018-10-09 18:58:50 +02:00
Akim Demaille
5fe636c7ee c++: provide a means to control how location.hh is included
Users may want to generate the location file elsewhere, say
$top_srcdir/include/ast/location.hh.  Yet, we should not generate
`#include "$top_srcdir/include/ast/location.hh"` but probably
something like `#include <ast/location.hh>`, or `#include
"ast/location.hh", or `#include <location.hh>`.  It entirely depends
on the compiler flags (-I/-isystem) that are used.  Bison cannot guess
what is expected, so let's give the user a means to tell how the
location file should be included.

* data/location.cc (b4_location_file): New.
* data/glr.cc, data/lalr1.cc: Use it.
2018-10-06 18:13:48 +02:00
Akim Demaille
50b8d4ba5a c++: support absolute api.location.file names
In the case a user wants to create location.hh elsewhere, it can be
helpful to define api.location.file to some possibly absolute path
such as -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"'.
Currently this does not work with `-o foo/parser.cc`, as we join foo/
and $(top_srcdir) together, the latter starting with slash.

We should not try to do that in m4, manipulating file names is quite
complex when you through Windows file name in.  Let m4 delegate this
to gnulib.

* src/scan-skel.l (at_output): Accept up to two arguments.
* data/bison.m4 (b4_output): Adjust.
* tests/skeletons.at (Fatal errors but M4 continues producing output):
Adjust to keep the error.

* data/location.cc, data/stack.hh: Leave the concatenation to @output.
* tests/output.at: Exercise api.location.file with an absolute path.
2018-10-06 17:17:25 +02:00
Akim Demaille
57d69b04b2 c++: when api.location.file is defined, don't generate stack.hh
Make it easier to have fewer files.

* data/stack.hh: Don't generate stack.hh when api.location.file is
specified.
* tests/calc++.at, tests/output.at: Adjust tests.
2018-10-06 17:17:25 +02:00
Akim Demaille
3e6a075f7f c++: make position.hh completely useless
Let's put the definition of position into location.hh, there's no real
value in keeping them separate: they are small, and share the same
requirements.

To help users transition to this new model, still generate position.hh
by default, but as a simple include to location.hh.

* data/location.cc (api.position.file): Accept only 'none' as possible
value.
(position.hh): Make it a stub.
(location.hh): Adjust.
(b4_position_define): Merge into...
(b4_location_define): this.
* data/glr.cc, data/lalr1.cc, tests/input.at, tests/output.at: Adjust.
2018-10-06 17:17:25 +02:00
Akim Demaille
29b1da4e18 c++: make stack.hh completely useless
Let's completely deprecate stack.hh.  Don't provide a means to give it
a new name, allow only its removal.

See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00151.html
and https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00182.html.

* data/stack.hh: Reduce stack.hh to a simple comment explaining how to
get rid of it.
* data/lalr1.cc: Adjust
* tests/input.at (%define file variables): Adjust.
* tests/output.at: Remove cases where stack.hh was removed.
2018-10-06 17:17:25 +02:00
Akim Demaille
667588ee8a c++: add support for api.position.file and api.location.file
* data/location.cc: Sort includes.
(b4_position_file, b4_location_file): New.
When there's a file for locations but not for positions, include the
definition of position in the location file.
* data/lalr1.cc (b4_shared_declarations): Include the
position/location file when it exists.
Otherwise, define the class.
* data/glr.cc: Likewise.
* tests/input.at (%define file variables): Check them.
* tests/output.at (C++ output): Check various cases with
api.position.file and api.location.file.
2018-10-06 17:17:25 +02:00
Akim Demaille
b122a71c83 c++: provide control over the stack.hh file name
It was not a good idea to generate the file stack.hh.  It never was.
But now we have to deal with backward compatibility: if we stop
generating it, the build system of some build system will probably
break.

So offer the user a means to (i) decide what the name of the output
file should be, and (ii) not generate this file at all (its content
will be inline where the parser is defined).

* data/lalr1.cc (b4_percent_define_check_file_complain)
(b4_percent_define_check_file): New.
* data/stack.hh: Generate the file only if api.stack.file is not
empty.
In that case, use it as file name.
* data/lalr1.cc: Adjust to include the right file, or to include
the definition of stack.
* tests/calc.at, tests/output.at: Exercise api.stack.file.
2018-10-06 17:17:25 +02:00
Akim Demaille
1a0b3bf83b tests: c++: don't fuse prefix and namespace
They are not the same concept.  It appears that we still consider that
api.prefix is the default for api.namespace.  We should stop that.

* tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS):
Separate namespace and prefix.
Adjust dependencies.
2018-10-06 17:16:55 +02:00
Akim Demaille
53bde230c6 style: tests: factor file extension computations
* tests/local.at (AT_LANG_HDR): New.
* tests/calc.at, tests/headers.at, tests/synclines.at: Use it, and
AT_LANG_EXT.
2018-10-06 17:16:54 +02:00
Josh Soref
d573ef0d69 spelling: suppress 2018-10-05 07:01:05 +02:00
Josh Soref
6cdd3287dd spelling: succesful 2018-10-05 07:01:05 +02:00
Josh Soref
13b70e2218 spelling: minimal 2018-10-05 07:01:05 +02:00
Josh Soref
3c2b71cde6 spelling: included 2018-10-05 07:01:05 +02:00
Josh Soref
bb077f38f7 spelling: compatibility 2018-10-05 07:01:04 +02:00
Josh Soref
795f7e32cc spelling: combination 2018-10-05 07:01:04 +02:00
Akim Demaille
26859f6d61 main: fix error message for missing argument
* src/getargs.c (getargs): Don't display any argv other that argv[0]
when reporting a missing argument.
* tests/bison.in: Neutralize path differences in stderr.
* tests/input.at (Invalid number of arguments): New.
2018-10-04 22:24:11 +02:00
Akim Demaille
cf4e3eecef c++: fix warning message for automove
* src/scan-code.l: Remove 'enabled'.
Use only $k (numeric), even for named references, for clarity.
* tests/c++.at: Adjust expectations.
2018-09-24 21:52:55 +02:00
Akim Demaille
6537a59c98 tests: fix a memory leak
This has been bugging me for while.  I was hard to reproduce: it
worked only on GNU/Linux, probably because libc++ implements the small
string optimization, while libstdc++ did not and actually allocated on
the heap for this small string.

See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00110.html.

* tests/types.at (api.value.type): Do not provide a semantic value to
EOF.
2018-09-23 11:50:58 +02:00
Akim Demaille
a874011e37 c++: issue a warning with a value is moved several times
Suggested by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2018-09/msg00022.html

* src/scan-code.l (parse_ref): Check multiple occurrences of rhs
values.
* tests/c++.at (Multiple occurrences of $n and api.value.automove): New.
2018-09-22 11:22:31 +02:00
Akim Demaille
3eb9042a30 c++: introduce api.value.automove
Based on work by Frank Heckenbach.
See http://lists.gnu.org/archive/html/bug-bison/2018-04/msg00000.html
and http://lists.gnu.org/archive/html/bug-bison/2018-09/msg00019.html.

* data/lalr1.cc (b4_rhs_value): Use YY_MOVE api.rhs.automove is set.
* doc/bison.texi (%define Summary): Document api.rhs.automove.
* examples/variant-11.yy: Use it.

* tests/local.at (AT_AUTOMOVE_IF): New.
* tests/c++.at (Variants): Check move semantics.
2018-09-22 09:49:46 +02:00
Akim Demaille
aa5de5728c tests: c++: use a custom string type
The forthcoming automove feature, to be properly checked, will require
that we can rely on the value of a moved-from string, which is not
something the C++ standard guarantees.  So introduce our own wrapper.

Suggested by Frank Heckenbach.
https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00111.html

* tests/c++.at (Variants): Introduce and use a new 'string' class.
2018-09-22 09:49:42 +02:00