
On 1/11/2011 2:58 AM, alfC wrote:
As Joel pointed out already, you need to wrap your expression templates to give them their domain specific meaning. In your case, the cast operator. This cast operator would need to have a context, or preferably a transform (a transform is a grammar is a transform) to evaluate your expression to std::complex<double>. See:http://www.boost.org/doc/libs/1_45_0/doc/html/proto/users_guide.html#... for an example with contexts.
The steps to define a grammar that does the transformation are the following: 1) define a grammar that matches your expression
ok, at the level I am working it seem that the following grammar is what I need. note that it is not recursive and it is a completely rigid structure.
struct complex_cartesian_grammar : proto::plus< proto::terminal<double>, proto::multiplies< proto::terminal<double>, proto::terminal
> {}; (complete code at the end)
Like Joel says, it's just as simple to make this correct and general. This is artifically constrained.
2) attach semantic actions, step by step to your grammar rules
not so fast, how do I do that?
Read about transforms: http://www.boost.org/doc/libs/1_45_0/doc/html/proto/users_guide.html#boost_p...
I also defined the "domain" struct complex_cartesian_domain : proto::domain< proto::generator< complex_cartesian_expr >, complex_cartesian_grammar
{};
I still have to somehow connect the define grammar with the expression itself. how?
Read about expression extension: http://www.boost.org/doc/libs/1_45_0/doc/html/proto/users_guide.html#boost_p...
I also understand that the expression convertible to std::complex<double> must match double + double*i (the simple grammar) but again I don't understand how to do it.
See attached. -- Eric Niebler BoostPro Computing http://www.boostpro.com