Commit Graph

738 Commits

Author SHA1 Message Date
Akim Demaille
9476783307 doc: formatting changes
* doc/bison.texi: Here.
2018-11-26 07:56:06 +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
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
e02ce4c7f0 build: minor fixes in doc/
* doc/local.mk: Consistently use *.tmp for temporary files.
Fix comments.
2018-11-06 07:26:01 +01:00
Akim Demaille
f1e0839c9e doc: -Wzero-as-null-pointer-constant was added to GCC 4.7
It is not supported by previous versions.
See https://www.gnu.org/software/gcc/gcc-4.7/changes.html
Reported by Nelson H. F. Beebe.

* doc/bison.texi (Calc++ Scanner): here.
2018-11-03 07:23:10 +01:00
Adam Sampson
3bf429aed8 examples: #include <cstring> in calc++
strerror is defined by <string.h>, and recent versions of GNU libstdc++
no longer include this automatically from <string>.
2018-11-02 10:20:30 +01:00
Akim Demaille
a9d6e16e0a build: don't depend on the libc to generate bison.help
The "Report translation bugs to..." part of --help is issued only on
glibc systems.  So if the tarball is not wrapped on such a system, and
used on such a system (or the converse), then bison.help will differ
on the user's system, and help2man will be called to update bison.1.

But help2man should not be a requirement.

Reported by Alexandre Duret-Lutz.

* doc/local.mk (doc/bison.help): Remove the possible doc about
translation bugs.
Pass LC_ALL=C, as reported in src/getargs.c's usage().
(doc/cross-options.texi): Use bison.help instead of calling bison
--help.
2018-10-29 20:24:30 +01:00
Akim Demaille
c45f86d286 doc: fix distcheck
The extracted example, simple.yy, does not use %require "3.2", so it
generates a stack.hh, which breaks distcheck.

* doc/bison.texi: Fix it.
2018-10-27 08:53:30 +02:00
Akim Demaille
3f5e6905da doc: spell check
* README, doc/bison.texi, examples/README, examples/c++/README: here.
2018-10-26 08:40:07 +02:00
Akim Demaille
ee175dfd00 doc: some improvements
* doc/bison.texi (Calc++ Scanner): Show how exception can be thrown
from auxiliary functions.
Clarify the meaning of the various flex %options we use.
Get rid of a warning.
(Calc++ Parsing Driver): Use the parser as a functor.
2018-10-26 07:42:28 +02:00
Akim Demaille
18743948b5 doc: minor fixes
* doc/bison.texi: Simplify wording.
Fix Texinfo error.
(Complete Symbols): Handle the token EOF.
(Calc++ Parser): In the modern C++ world, prefer assignment to swap.
(Strings are Destroyed): Prefer an explicit 'continue' to a comment.
2018-10-25 07:03:15 +02:00
Akim Demaille
73a822e636 doc: mention earlier how to disable the generation of location.hh
Suggested by Victor Khomenko.

* doc/bison.texi (C++ Bison Interface): Here.
2018-10-24 18:57:15 +02:00
Akim Demaille
5b879c8980 c++: std::to_string is available in C++11
Reported by Victor Khomenko.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00033.html

* doc/bison.texi, examples/c++/variant-11.yy: Use std::to_string
instead of ours.
2018-10-24 18:49:04 +02:00
Akim Demaille
a4dce889a4 doc: an introductory example for C++
Suggested by Victor Khomenko.
http://lists.gnu.org/archive/html/bug-bison/2018-08/msg00037.html

* doc/bison.texi (A Simple C++ Example): New.
* examples/c++/local.mk, examples/c++/simple.test: New.
Extract, check, and install this new example.
* examples/local.mk: Adjust.
* examples/test: Adjust to the case where the dirname differs
from the test name.
2018-10-24 06:18:57 +02:00
Akim Demaille
f9bba892bd c++: make operator() an alias to the parse function
* data/glr.cc, data/lalr1.cc (operator()): New.
* doc/bison.texi: Update.
2018-10-24 06:18:57 +02:00
Akim Demaille
06f3245fa4 flex: work around more warnings
* doc/bison.texi: here.
2018-10-23 09:08:57 +02:00
Akim Demaille
4b0efdeb28 c++: minor changes
* data/lalr1.cc: Fix oldish comment.
* data/stack.hh: Prefer typename for type names.
Use size() instead of duplicating it.
* examples/variant-11.yy, examples/variant.yy (yylex): Use int,
as this is the type of the semantic value.
2018-10-22 08:40:39 +02:00
Akim Demaille
3ead69b1c1 c++: prefer a perfect forwarding version of variant's emplace
* data/variant.hh (emplace): In modern C++, use only a perfect
forwarding version.
And use it.
* doc/bison.texi: Document it.
2018-10-20 19:03:01 +02:00
Akim Demaille
42f0b949ec c++: prefer 'emplace' to 'build'
When we introduced variants in Bison, C++ did not have the 'emplace'
functions, and we chose 'build'.  Let's align with modern C++ and
promote 'emplace' rather than 'build'.

* data/lalr1.cc, data/variant.hh (emplace): New.
(build): Deprecate in favor of emplace.
* doc/bison.texi: Adjust.
2018-10-20 19:03:01 +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
35068fbe66 doc: improve the C++ section
* doc/bison.texi (C++ Parser): file.hh and location.hh are no longer
mandatory.
Various minor fixes.
2018-10-20 14:13:07 +02:00
Akim Demaille
16d34d8036 doc: reorder C++ sections
* doc/bison.texi (C++ Parser Interface): Document before semantic_type
and location_type.
2018-10-20 14:13:07 +02:00
Akim Demaille
bfbd73f3e0 git: don't ignore auxiliary Texinfo files
As a matter of fact, I think it is wrong to gitignore generated files
that belong to the build tree.  There should be the strict minimum,
and it's up to people that build in place to adjust their own
~/.gitignore.

* doc/.gitignore: here.
Remove files we no longer produce (thanks to texi2dvi).
2018-10-20 14:12:08 +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
c69944ff8b doc: do not advertise %nterm
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

* NEWS, doc/bison.texi: here.
2018-10-15 19:23:49 +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
4fb70e4dd3 doc: spell check 2018-10-09 17:02:30 +02:00
Akim Demaille
3ac6af879d doc: document api.*.file and the like
* doc/bison.texi (Exposing the Location Classes): New.
(%define Summary): Document api.location.file, api.location.include,
api.stack.file and api.position.file.
(C++ Bison Interface): stack.hh and position.hh are deprecated.
2018-10-09 17:02:26 +02:00
Akim Demaille
c164fc0822 build: fix distcheck
Now that distcheck no longer fails (see previous commit), let's
address the shortcomings.

* Makefile.am (CLEANDIRS, clean-local): New.
* doc/local.mk, examples/calc++/local.mk, examples/local.mk,
* examples/mfcalc/local.mk, examples/rpcalc/local.mk,
* src/local.mk
(CLEANDIRS): Get rid of Apple's *.dSYM directories.
(CLEANFILES): Get rid of *.output files.
* examples/variant-11.yy, examples/variant.yy: Don't generate
any of the auxiliary files (location.hh and the like).
2018-10-07 10:41:40 +02:00
Akim Demaille
5281d09af7 doc: restore spello made on purpose 2018-10-06 07:38:15 +02:00
Josh Soref
b89b6517f2 spelling: troubleshooting 2018-10-05 07:01:06 +02:00
Josh Soref
cd45c269e2 spelling: transparent 2018-10-05 07:01:06 +02:00
Josh Soref
8c3eae0d44 spelling: diagnostics 2018-10-05 07:01:04 +02:00
Josh Soref
23a37cc1c5 spelling: detailed 2018-10-05 07:01:04 +02:00
Akim Demaille
2d07940325 doc: clean up the C++ section
* doc/bison.texi: Minor fixes in typography.
It is no longer require to pass --defines for C++ (it was addressed
long ago).
No longer refer to the `variant` define variable, it was replaced by
`api.value.type variant`.
Prefer nullptr to 0 for the null pointer.
Use deftypeop for constructors.
(Complete Symbols): Give the expected signature of yylex.
Don't document the symbol_type constructors, as we want users to focus
on make_TOKEN.
Also show the case without locations.
2018-09-26 21:49:20 +02:00
Akim Demaille
154bc7ddac doc: work around Flex's use of 'register'
The CI uses an old version of Flex.
See 65fa634cdc.

* doc/bison.texi (calc++/scanner.ll): Here.
2018-09-22 19:40:37 +02:00
Akim Demaille
878dc0a172 news: c++: move semantics 2018-09-22 14:52:13 +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
857be0e10f doc: fix typo
Introduced in the previous commit.

* doc/bison.texi: here.
2018-09-19 22:13:57 +02:00
Akim Demaille
bbfa419b89 style: use midrule only, not mid-rule
The code was already using midrule only, never mid_rule.  This is
simpler to remember, and matches a similar change we made from
look-ahead to lookahead.

* NEWS, doc/bison.texi, src/reader.c, src/scan-code.h, src/scan-code.l
* tests/actions.at, tests/c++.at, tests/existing.at: here.
2018-09-19 22:09:53 +02:00
Paul Eggert
f475105c2f doc: document older compiler issues
* doc/bison.texi (Compiler Requirements for GLR):
Rename from Compiler Requirements.
(I can't build Bison): Add FAQ for older compilers.
2018-09-18 13:17:46 -07:00
Akim Demaille
65fa634cdc doc: work around Flex's use of 'register'
The CI uses an old version of Flex.

* doc/bison.texi (calc++/scanner.ll): Here.
2018-09-18 13:21:38 +02:00
Akim Demaille
ce99bc67b8 doc: formatting changes
* doc/bison.texi: No changes in the output.
2018-09-15 07:20:49 +02:00
Akim Demaille
e1c33f04d1 build: work around warnings in Flex
See ea0db44fed.  We also need to disable
the warning in the examples (but don't want to clutter the
documentation with such details).

* doc/bison.texi (scanner.ll): Disable Clang's -Wdocumentation.
While at it, hide the other kludges.
2018-09-08 12:13:29 +02:00
Akim Demaille
ea0db44fed build: work around warnings in Flex 2.5.35
That's the version on Ubuntu Precise.
See also 1dac131ec4.

* src/flex-scanner.h: Disable -Wdocumentation.
* doc/bison.texi: Turn off a warning triggered by Flex 2.6.4.
2018-09-08 07:53:08 +02:00
Akim Demaille
de64159e7f examples: calc++: a Makefile and a README
* examples/calc++/Makefile, examples/calc++/README: New.
* examples/calc++/local.mk: Ship and install them.
* doc/bison.texi: Formatting changes.
2018-08-25 08:49:26 +02:00
Akim Demaille
b4e9eaefd5 examples: calc++: minor improvements
* doc/bison.texi (A Complete C++ Example): Prefer throw exceptions
from the scanner.
Show the invalid characters.
Since the scanner sends exceptions, it no longer needs to report
errors, so we can get rid of the driver's routine to report error,
do it in yyerror.
Use @group/@end group to improve rendering.
2018-08-24 19:40:36 +02:00
Akim Demaille
1a968edcb8 examples: calc++: make sure the file name in location is set
Reported by Hans Åberg.
http://lists.gnu.org/archive/html/bug-bison/2018-08/msg00039.html

* doc/bison.texi (A Complete C++ Example): Move the token's location
from the scanner to the driver.
2018-08-24 19:24:37 +02:00
Akim Demaille
82fa282a1b examples: calc++: remove prefixes
This example uses the calcxx_ prefix for each class.  That's uselessly
heavy.

* doc/bison.texi (A Complete C++ Example): Simplify the class names.
Since now 'driver' denotes the class, use 'drv' for the values.
Formatting changes.
2018-08-24 19:24:34 +02:00