Hi,
I'm using spirit first time. I'm trying to write a boolean expression (with
only &, | and ! operators) parser. I've defined my grammar like following:
template <typename Iterator>
struct boolean_expression_parser : qi::grammar
{
boolean_expression_parser() :
boolean_expression_parser::base_type(expr)
{
using namespace qi;
using ascii::char_;
using boost::spirit::ascii::alnum;
using namespace qi::labels;
using phoenix::construct;
using phoenix::val;
operand %= lexeme[+(alnum)];
simple_expr %= ('(' > expr > ')') | operand;
unary_expr %= ('!' > simple_expr ) ;
and_expr %= ( expr > '*' > expr);
or_expr %= (expr > '|' > expr);
expr %= simple_expr | unary_expr | *and_expr | *or_expr;
// on_error<fail>
// (
// unary_expr,
// std::cout
// << val("Error! Expecting ")
// << _4 // what
failed?
// << val(" here: \"")
// << constructstd::string(_3, _2) // iterators
to error-pos, end
// << val("\"")
// << std::endl
// );
}
qi::rule operand;
qi::rule simple_expr;
qi::rule unary_expr;
qi::rule and_expr;
qi::rule or_expr;
qi::rule expr;
};
I'm facing few hurdles here:
1. It's not working for any binary expression (like 'A + B'). It's working
fine for unary expressions (like '!(A)' or '(!A)'.
Can someone point me what I'm doing wrong?
2. I want store it in tree form (as I want to build a BDD out of it). Can
someone point me how to do that?
3. Also, why on_error<> is not working even when I enable it?
I'm using boost 1.49 and gcc-4.2.2.
Regards,
~ Soumen
--
View this message in context: http://boost.2283326.n4.nabble.com/Spriti-parser-for-boolean-expression-tp46...
Sent from the Boost - Users mailing list archive at Nabble.com.