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.
This commit is contained in:
Akim Demaille
2018-10-14 11:27:05 +02:00
parent 20a6c3175f
commit 01898726e2
6 changed files with 60 additions and 28 deletions

View File

@@ -6348,8 +6348,7 @@ Obsoleted by @code{api.namespace}
@item Purpose: Issue runtime assertions to catch invalid uses.
In C++, when variants are used (@pxref{C++ Variants}), symbols must be
constructed and
destroyed properly. This option checks these constraints.
constructed and destroyed properly. This option checks these constraints.
@item Accepted Values: Boolean
@@ -11594,13 +11593,13 @@ assignment:
%left "+" "-";
%left "*" "/";
exp:
exp "+" exp @{ $$ = $1 + $3; @}
"number"
| "identifier" @{ $$ = drv.variables[$1]; @}
| exp "+" exp @{ $$ = $1 + $3; @}
| exp "-" exp @{ $$ = $1 - $3; @}
| exp "*" exp @{ $$ = $1 * $3; @}
| exp "/" exp @{ $$ = $1 / $3; @}
| "(" exp ")" @{ std::swap ($$, $2); @}
| "identifier" @{ $$ = drv.variables[$1]; @}
| "number" @{ std::swap ($$, $1); @};
%%
@end example