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:
@@ -101,7 +101,7 @@ list:
|
||||
;
|
||||
|
||||
item:
|
||||
TEXT { $$ = $1; }
|
||||
TEXT
|
||||
| NUMBER { $$ = make_string_uptr (to_string ($1)); }
|
||||
;
|
||||
%%
|
||||
|
||||
@@ -89,7 +89,7 @@ list:
|
||||
;
|
||||
|
||||
item:
|
||||
TEXT { std::swap ($$, $1); }
|
||||
TEXT
|
||||
| NUMBER { $$ = to_string ($1); }
|
||||
;
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user