mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 21:03:04 +00:00
add support for typed mid-rule actions
Prompted on Piotr Marcińczyk's message: http://lists.gnu.org/archive/html/bug-bison/2017-06/msg00000.html. See also http://lists.gnu.org/archive/html/bug-bison/2018-06/msg00001.html. Because their type is unknown to Bison, the values of midrule actions are not treated like the others: they don't have %printer and %destructor support. In addition, in C++, (Bison) variants cannot work properly. Typed midrule actions address these issues. Instead of: exp: { $<ival>$ = 1; } { $<ival>$ = 2; } { $$ = $<ival>1 + $<ival>2; } write: exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; } { $$ = $1 + $2; } * src/scan-code.h, src/scan-code.l (code_props): Add a `type` field to record the declared type of an action. (code_props_rule_action_init): Add a type argument. * src/parse-gram.y: Accept an optional type tag for actions. * src/reader.h, src/reader.c (grammar_current_rule_action_append): Add a type argument. (grammar_midrule_action): When a mid-rule is typed, pass its type to the defined dummy non terminal symbol.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
# include "location.h"
|
||||
# include "named-ref.h"
|
||||
# include "uniqstr.h"
|
||||
|
||||
struct symbol_list;
|
||||
|
||||
@@ -81,8 +82,11 @@ typedef struct code_props {
|
||||
/** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION. */
|
||||
struct symbol_list *rule;
|
||||
|
||||
/* Named reference. */
|
||||
/** Named reference. */
|
||||
named_ref *named_ref;
|
||||
|
||||
/** Type, for mid-rule actions. */
|
||||
uniqstr type;
|
||||
} code_props;
|
||||
|
||||
/**
|
||||
@@ -103,7 +107,8 @@ void code_props_none_init (code_props *self);
|
||||
/* .is_predicate = */ false, \
|
||||
/* .is_used = */ false, \
|
||||
/* .rule = */ NULL, \
|
||||
/* .named_ref = */ NULL \
|
||||
/* .named_ref = */ NULL, \
|
||||
/* .type = */ NULL, \
|
||||
}
|
||||
|
||||
/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */
|
||||
@@ -158,7 +163,8 @@ void code_props_symbol_action_init (code_props *self, char const *code,
|
||||
*/
|
||||
void code_props_rule_action_init (code_props *self, char const *code,
|
||||
location code_loc, struct symbol_list *rule,
|
||||
named_ref *name, bool is_predicate);
|
||||
named_ref *name, uniqstr type,
|
||||
bool is_predicate);
|
||||
|
||||
/**
|
||||
* \pre
|
||||
|
||||
Reference in New Issue
Block a user