📄 cpp_expression_grammar.hpp
字号:
template <typename ScannerT> struct definition { typedef closures::cpp_expr_closure closure_type; typedef boost::spirit::classic::rule<ScannerT, closure_type::context_t> rule_t; typedef boost::spirit::classic::rule<ScannerT> simple_rule_t; simple_rule_t pp_expression; rule_t const_exp; rule_t logical_or_exp, logical_and_exp; rule_t inclusive_or_exp, exclusive_or_exp, and_exp; rule_t cmp_equality, cmp_relational; rule_t shift_exp; rule_t add_exp, multiply_exp; rule_t unary_exp, primary_exp, constant; rule_t const_exp_nocalc; rule_t logical_or_exp_nocalc, logical_and_exp_nocalc; rule_t inclusive_or_exp_nocalc, exclusive_or_exp_nocalc, and_exp_nocalc; rule_t cmp_equality_nocalc, cmp_relational_nocalc; rule_t shift_exp_nocalc; rule_t add_exp_nocalc, multiply_exp_nocalc; rule_t unary_exp_nocalc, primary_exp_nocalc, constant_nocalc; boost::spirit::classic::subrule<0, closure_type::context_t> const_exp_subrule; definition(expression_grammar const &self) { using namespace boost::spirit::classic; using namespace phoenix; using namespace boost::wave; using boost::wave::util::pattern_p; pp_expression = const_exp[self.val = arg1] ; const_exp = logical_or_exp[const_exp.val = arg1] >> !(const_exp_subrule = ch_p(T_QUESTION_MARK) >> const_exp [ const_exp_subrule.val = arg1 ] >> ch_p(T_COLON) >> const_exp [ const_exp_subrule.val = impl::questionmark(const_exp.val, const_exp_subrule.val, arg1) ] )[const_exp.val = arg1] ; logical_or_exp = logical_and_exp[logical_or_exp.val = arg1] >> *( if_p(impl::as_bool(logical_or_exp.val)) [ // if one of the || operators is true, no more // evaluation is required pattern_p(T_OROR, MainTokenMask) >> logical_and_exp_nocalc [ logical_or_exp.val = impl::to_bool(logical_or_exp.val) ] ] .else_p [ pattern_p(T_OROR, MainTokenMask) >> logical_and_exp [ logical_or_exp.val = impl::binary_or(logical_or_exp.val, arg1) ] ] ) ; logical_and_exp = inclusive_or_exp[logical_and_exp.val = arg1] >> *( if_p(impl::as_bool(logical_and_exp.val)) [ pattern_p(T_ANDAND, MainTokenMask) >> inclusive_or_exp [ logical_and_exp.val = impl::binary_and(logical_and_exp.val, arg1) ] ] .else_p [ // if one of the && operators is false, no more // evaluation is required pattern_p(T_ANDAND, MainTokenMask) >> inclusive_or_exp_nocalc [ logical_and_exp.val = impl::to_bool(logical_and_exp.val) ] ] ) ; inclusive_or_exp = exclusive_or_exp[inclusive_or_exp.val = arg1] >> *( pattern_p(T_OR, MainTokenMask) >> exclusive_or_exp [ inclusive_or_exp.val = impl::binary_bitor(inclusive_or_exp.val, arg1) ] ) ; exclusive_or_exp = and_exp[exclusive_or_exp.val = arg1] >> *( pattern_p(T_XOR, MainTokenMask) >> and_exp [ exclusive_or_exp.val = impl::binary_bitxor(exclusive_or_exp.val, arg1) ] ) ; and_exp = cmp_equality[and_exp.val = arg1] >> *( pattern_p(T_AND, MainTokenMask) >> cmp_equality [ and_exp.val = impl::binary_bitand(and_exp.val, arg1) ] ) ; cmp_equality = cmp_relational[cmp_equality.val = arg1] >> *( ch_p(T_EQUAL) >> cmp_relational [ cmp_equality.val = impl::binary_eq(cmp_equality.val, arg1) ] | pattern_p(T_NOTEQUAL, MainTokenMask) >> cmp_relational [ cmp_equality.val = impl::binary_ne(cmp_equality.val, arg1) ] ) ; cmp_relational = shift_exp[cmp_relational.val = arg1] >> *( ch_p(T_LESSEQUAL) >> shift_exp [ cmp_relational.val = impl::binary_lesseq(cmp_relational.val, arg1) ] | ch_p(T_GREATEREQUAL) >> shift_exp [ cmp_relational.val = impl::binary_greateq(cmp_relational.val, arg1) ] | ch_p(T_LESS) >> shift_exp [ cmp_relational.val = impl::binary_less(cmp_relational.val, arg1) ] | ch_p(T_GREATER) >> shift_exp [ cmp_relational.val = impl::binary_greater(cmp_relational.val, arg1) ] ) ; shift_exp = add_exp[shift_exp.val = arg1] >> *( ch_p(T_SHIFTLEFT) >> add_exp [ shift_exp.val <<= arg1 ] | ch_p(T_SHIFTRIGHT) >> add_exp [ shift_exp.val >>= arg1 ] ) ; add_exp = multiply_exp[add_exp.val = arg1] >> *( ch_p(T_PLUS) >> multiply_exp [ add_exp.val += arg1 ] | ch_p(T_MINUS) >> multiply_exp [ add_exp.val -= arg1 ] ) ; multiply_exp = unary_exp[multiply_exp.val = arg1] >> *( ch_p(T_STAR) >> unary_exp [ multiply_exp.val *= arg1 ] | ch_p(T_DIVIDE) >> unary_exp [ multiply_exp.val /= arg1 ] | ch_p(T_PERCENT) >> unary_exp [ multiply_exp.val %= arg1 ] ) ; unary_exp = primary_exp[unary_exp.val = arg1] | ch_p(T_PLUS) >> unary_exp [ unary_exp.val = arg1 ] | ch_p(T_MINUS) >> unary_exp [ unary_exp.val = -arg1 ] | pattern_p(T_COMPL, MainTokenMask) >> unary_exp [ unary_exp.val = ~arg1 ] | pattern_p(T_NOT, MainTokenMask) >> unary_exp [ unary_exp.val = impl::unary_neg(arg1) ] ; primary_exp = constant[primary_exp.val = arg1] | ch_p(T_LEFTPAREN) >> const_exp[primary_exp.val = arg1] >> ch_p(T_RIGHTPAREN) ; constant = ch_p(T_PP_NUMBER) [ constant.val = impl::as_intlit(arg1) ] | ch_p(T_INTLIT) [ constant.val = impl::as_intlit(arg1) ] | ch_p(T_CHARLIT) [ constant.val = impl::as_chlit(arg1) ] ; // here follows the same grammar, but without any embedded // calculations const_exp_nocalc = logical_or_exp_nocalc >> !( ch_p(T_QUESTION_MARK) >> const_exp_nocalc >> ch_p(T_COLON)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -