views:

116

answers:

2

I'm using attribute propagation to construct a syntax tree for a toy language. I've hit a problem at the definition of my if statement, it's hard to tell from the error message but I think the rhs attribute isn't collapsing into the expected attribute. It should collapse to a tuple <double,Statement,optional<Statement>> I think.

The error: C:\Program Files (x86)\CodeBlocks\MinGW\boost_1_43_0\boost\variant\variant.hpp|1293|error: no matching function for call to 'boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::initializer_root, mpl_::int_<0> >, boost::mpl::l_iter<boost::mpl::list3<boost::recursive_wrapper<Lang::CompoundStatement>, boost::recursive_wrapper<Lang::IfStatement>, Lang::VarStatement> > >::initializer_node, mpl_::int_<1> >, boost::mpl::l_iter<boost::mpl::list2<boost::recursive_wrapper<Lang::IfStatemen [error cuts out here]

Thanks.

P.S. I couldn't get the code to display right, there's a plaintext version here: http://freetexthost.com/a3smzx0zk5

P.P.S. Some information I forogt to mention. It works if I remove "else" >> and change > statement to >> statement, but "else" >> statement should collapse to just statement. Explicitly creating "else" as a qi::lit doesn't help.

A: 

The sequence operator>>() and the expectation operator>() do not mix well in terms of attribute handling. If you use both operators in the same expression the overall attribute does not get flattened. That would happen if you were using the one or the other only.

For this reason the attribute exposed by the expression:

if_statement %= "if" > qi::double_ > statement >> -("else" > statement) ;

is:

tuple <tuple <double, Statement>, optional<Statement> >

which explains your compilation problems. Rewriting the epression as:

if_statement %= "if" > qi::double_ > statement > -("else" > statement) ;

should solve the issue, though (without changing the semantics).

hkaiser
Good thought but it's still not working. Works if I remove the else, that's the only clue I have.
Dave
Ok, then I would like to see a small self-contained test I can compile. Otherwise it's almost impossible to tell what's wrong.
hkaiser
A: 
Dave