#include #include #include namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; // // expression and operator datatypes // used for parsing the tree // struct binary_op; struct expr_node { typedef boost::variant, boost::recursive_wrapper, boost::recursive_wrapper > > type; expr_node() : type_str("none") {} template expr_node(Expr const& expr, const std::string type_str = "none") : expr(expr), type_str(type_str) {} type expr; std::string type_str; }; struct binary_op { binary_op(const std::string& op, expr_node const& left, expr_node const& right) : op(op), left(left), right(right) {} std::string op; expr_node left; expr_node right; }; struct expr_node_phx { template struct result { typedef expr_node type; }; expr_node operator()(expr_node const& expr, const std::string& type_str) const { expr_node e(expr.expr,type_str); return e; } }; boost::phoenix::function exnd; struct binary_op_phx { template struct result { typedef T type; }; expr_node operator()(const std::string& name, expr_node const& expr, expr_node const& rhs) const { return expr_node(binary_op(name,expr,rhs)); } }; boost::phoenix::function biop; // // grammar for parsing expressions // template struct Grammar : qi::grammar { Grammar() : Grammar::base_type(log_expr) { using qi::_val; using qi::_1; log_expr = log_term [_val = _1] >> *( '|' >> log_term [_val = biop("|",_val,_1)]); } // auto and basic parsers qi::rule log_expr,log_term; }; std::string parse() { typedef std::string::const_iterator iterator_type; Grammar ixgrammar; }