
I couldn't find a way to associate a semantic value with a non-terminal. Bison/yacc allows this. For example, here is a rule in Bison that says an expression can be the sum of two subexpressions: expr: expr '+' expr { $$ = $1 + $3; } ; The action says how to produce the semantic value of the sum expression from the values of the two subexpressions. Having semantic values for non-terminals is useful to build an expression tree. For, e.g, I can create a new node in the tree by passing in the semantic values of child nodes in the action. expr: expr '+' expr { $$ = makeNode($1, $3, "+"); } ; In this case the semantic value for each expression is of type Node*. Spirit provides parse trees and ASTs and also semantic actions that take the first last iterator pair. But is there some way I can associate a semantic value with each non-terminal and pass in these semantic values to the action for the rule. Thanks, Anand

Anand wrote:
I couldn't find a way to associate a semantic value with a non-terminal. Bison/yacc allows this.
For example, here is a rule in Bison that says an expression can be the sum of two subexpressions:
expr: expr '+' expr { $$ = $1 + $3; } ;
The action says how to produce the semantic value of the sum expression from the values of the two subexpressions.
Having semantic values for non-terminals is useful to build an expression tree.
For, e.g, I can create a new node in the tree by passing in the semantic values of child nodes in the action. expr: expr '+' expr { $$ = makeNode($1, $3, "+"); } ;
In this case the semantic value for each expression is of type Node*.
Spirit provides parse trees and ASTs and also semantic actions that take the first last iterator pair. But is there some way I can associate a semantic value with each non-terminal and pass in these semantic values to the action for the rule.
"classic" Spirit is basically a transduction type parser with attributes creeping in later in the form of closures, and rule attributes, etc. You should look at Spirit-2 instead. Spirit2 is a full attribute-grammar PEG parser. I am cross-posting this to the spirit list. Please post further questions there: http://www.boost.org/community/groups.html#spirit Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
participants (2)
-
Anand
-
Joel de Guzman