3 Jul 03:31
boost::spirit -- semantic values
Anand <anandrl <at> gmail.com>
2009-07-03 01:31:35 GMT
2009-07-03 01:31:35 GMT
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
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RSS Feed