Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto]: How to use complex grammars in a domain/extension
From: Roland Bock (rbock_at_[hidden])
Date: 2010-09-20 15:31:15


On 09/20/2010 08:04 PM, joel falcou wrote:
> On 20/09/10 19:59, Roland Bock wrote:
>> Hi,
>>
>> I am trying to create a DSEL with Boost.Proto, which (among other
>> things) should allow expressions like
>>
>> i == j + 3 && t != "foo"
>>
>> and want to prevent disallowed operators to be generated by Proto.
>>
>> Please consider the code below.
>>
>> //
>> -----------------------------------------------------------------------
>> #include<boost/proto/proto.hpp>
>>
>> using namespace boost;
>>
>> typedef proto::terminal<int>::type terminal;
>>
>> struct addition:
>> proto::or_
>> <
>> terminal,
>> proto::plus<addition, addition>
>> >
>> {};
>>
>> struct equation:
>> proto::equal_to<addition, addition>
>> {};
>>
>> struct condition:
>> proto::or_
>> <
>> equation,
>> proto::logical_and<equation, equation>
>> >
>> {};
>>
>> In my_domain, I can replace condition by addition, which allows i +
>> i, but then the == operator is still missing (and the &&, too,
>> probably).
>
> i+i doesn't match your grammar at all.
> an equation is addition == addition which is not matchable by i+i
> if equation was:
>
> struct equation:
> proto::or_< addition, proto::equal_to<addition, addition> >
> {};
>
> then it'll work.
Joel,

ok, got it! I needed to prevent

i && i == i // that's done

and I need to find a bug in the larger SQL grammar, but I am getting
there. Proto takes some time to comprehend, but it sure is fun to use it :-)

Regards,

Roland


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net