mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
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:
21
NEWS
21
NEWS
@@ -68,6 +68,27 @@ GNU Bison NEWS
|
||||
|
||||
The new examples/variant-11.yy shows these features in action.
|
||||
|
||||
*** C++: The implicit default semantic action is always run
|
||||
|
||||
When variants are enabled, the default action was not run, so
|
||||
|
||||
exp: "number"
|
||||
|
||||
was equivalent to
|
||||
|
||||
exp: "number" {}
|
||||
|
||||
It now behaves like in all the other cases, as
|
||||
|
||||
exp: "number" { $$ = $1; }
|
||||
|
||||
possibly using std::move if automove is enabled.
|
||||
|
||||
We do not expect backward compatibility issues. However, beware of
|
||||
forward compatibility issues: if you rely on default actions with
|
||||
variants, be sure to '%require "3.2"' to avoid older versions of Bison to
|
||||
generate incorrect parsers.
|
||||
|
||||
*** C++: Renaming location.hh
|
||||
|
||||
When both %defines and %locations are enabled, Bison generates a
|
||||
|
||||
Reference in New Issue
Block a user