$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] boost::spirit -- semantic values
From: Anand (anandrl_at_[hidden])
Date: 2009-07-02 21:31:35
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