Boost logo

Boost Users :

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


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>
>
{};

template<class Expr>
struct extension;

struct my_domain:
    proto::domain
    <
         proto::pod_generator< extension>,
         condition
>
{};

template<class Expr>
struct extension
{
     BOOST_PROTO_EXTENDS(
         Expr
       , extension<Expr>
       , my_domain
     )
};

int main()
{
     terminal c;
     BOOST_PROTO_ASSERT_MATCHES(c + c, addition); // OK
     BOOST_PROTO_ASSERT_MATCHES(c == c, equation); // OK
     BOOST_PROTO_ASSERT_MATCHES(c == c, condition); // OK
     BOOST_PROTO_ASSERT_MATCHES(c == c&& c == c, condition); // OK

     extension<terminal> i;

     // I was hoping for the following to be legal
     i + i; // ERROR: operator+ not found
     i == i; // ERROR: operator== not found
     i == i&& i == i; // ERROR: operator== not found
}

// -----------------------------------------------------------------------

In my_domain, I can replace condition by addition, which allows i + i,
but then the == operator is still missing (and the &&, too, probably).

How can I solve this?

Thanks and 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