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


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.

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

using namespace boost;

typedef proto::terminal<int>::type terminal;

struct addition:
       proto::plus<addition, addition>

struct equation:
    proto::equal_to<addition, addition>

struct condition:
       proto::logical_and<equation, equation>

template<class Expr>
struct extension;

struct my_domain:
         proto::pod_generator< extension>,

template<class Expr>
struct extension
       , 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,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at