Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2006-08-11 19:02:07


Andreas Pokorny wrote:

>> Not sure if I follow. I'm an examples type of guy. It would be
>> enlightening if you can provide a simple example. Say, we want
>> to write a DSEL which has primitives a_, b_ and c_ (objects)
>> of types A B and C and operations >> and |. How shall I develop
>> the ET using your library?
>>
>> Example usage:
>>
>> a_ >> b_ | c_
>>
>
> Given that a_ >> b_ invokes the operator of the library, e.g. by
> deriving at least A from a library type, and given the domain_tag
> can be evaluated from the participating datastructures. These
> rules have to be written:
>
> // domain:
> struct example_domain {};
>
> // rules:
> template<typename EnableIfT>
> struct rule<example_domain,right_shift_tag,A,B,EnableIfT>
> : defined, mpl::true_
> {
> typedef TYPE_WHICH_ENCODES_THE_EXPRESSION result_type;
> static result_type init(A const& a, B const& b) { return result_type(...); }
> };
>
> template<typename EnableIfT>
> struct rule<example_domain,bitor_tag,TYPE_WHICH_ENCODES_THE_EXPRESSION,C,EnableIfT>
> : defined, mpl::true_
> {
> typedef TYPE_WHICH_ENCODES_THE_WHOLE_TREE result_type;
> static result_type init(A const& a, B const& b) { return result_type(...); }
> };

Do we have to write rules for all permutations of A and B and C?
What about literals and built-in types? Example:

     a_ >> b_ >> "hi" | c_ >> 12345

> This weekend I plan to work on the code, clean things up a bit,
> and try to reintegrate everthing into proto again.

Sounds good. Thanks!

Cheers,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk