📄 expr.cxx
字号:
} case T_Minus : { next_token(); parse_unary(expr); CdlSubexpression& last_sub = current_subexpression(expr); if (CdlExprOp_IntegerConstant == last_sub.op) { // Do the negating inline, no need for another subexpression. last_sub.constants = last_sub.constants.get_integer_value() * -1; } else if (CdlExprOp_DoubleConstant == last_sub.op) { last_sub.constants = last_sub.constants.get_double_value() * -1; } else { // We could detect certain cases such as string constants etc. // For now don't bother. subexpr.op = CdlExprOp_Negate; subexpr.lhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } break; } case T_Plus : { next_token(); parse_unary(expr); CdlSubexpression& last_sub = current_subexpression(expr); if ((CdlExprOp_IntegerConstant == last_sub.op) || (CdlExprOp_DoubleConstant == last_sub.op)) { // No need to do anything here. } else { subexpr.op = CdlExprOp_Plus; subexpr.lhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } break; } case T_Times : { next_token(); parse_unary(expr); subexpr.op = CdlExprOp_Indirect; subexpr.lhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); break; } case T_Exclamation : { next_token(); parse_unary(expr); subexpr.op = CdlExprOp_LogicalNot; subexpr.lhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); break; } case T_Tilde : { next_token(); parse_unary(expr); subexpr.op = CdlExprOp_BitNot; subexpr.lhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); break; } case T_Questionmark: { // This is the `active' operator, it can only be applied directly to a reference. next_token(); parse_unary(expr); CdlSubexpression& last_sub = current_subexpression(expr); if (CdlExprOp_Reference != last_sub.op) { throw CdlParseException("The active operator ? can only be applied directly to a reference.\n" + get_error_location()); } // There is no point in creating a new subexpression object, just modify // the existing one. This has the useful side effect of avoiding // reference substitution in the eval code. last_sub.op = CdlExprOp_Active; break; } default: { throw CdlParseException("Unexpected token `" + token_to_string() + "', expecting an operand.\n" + get_error_location()); } } CYG_REPORT_RETURN();}static voidparse_multiply(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_multiply"); parse_unary(expr); while ((T_Times == current_token) || (T_Divide == current_token) || (T_Remainder == current_token)) { CdlSubexpression subexpr; subexpr.op = (T_Times == current_token) ? CdlExprOp_Multiply : (T_Divide == current_token) ? CdlExprOp_Divide : CdlExprOp_Remainder; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_unary(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_add(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_add"); parse_multiply(expr); while ((T_Plus == current_token) || (T_Minus == current_token)) { CdlSubexpression subexpr; subexpr.op = (T_Plus == current_token) ? CdlExprOp_Add : CdlExprOp_Subtract; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_multiply(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_shift(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_shift"); parse_add(expr); while ((T_LeftShift == current_token) || (T_RightShift == current_token)) { CdlSubexpression subexpr; subexpr.op = (T_LeftShift == current_token) ? CdlExprOp_LeftShift : CdlExprOp_RightShift; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_add(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_comparison(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_comparison"); parse_shift(expr); while ((T_LessThan == current_token) || (T_LessEqual == current_token) || (T_GreaterThan == current_token) || (T_GreaterEqual == current_token)) { CdlSubexpression subexpr; subexpr.op = (T_LessThan == current_token) ? CdlExprOp_LessThan : (T_LessEqual == current_token) ? CdlExprOp_LessEqual : (T_GreaterThan == current_token) ? CdlExprOp_GreaterThan : CdlExprOp_GreaterEqual; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_shift(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_equals(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_equals"); parse_comparison(expr); while ((T_Equal == current_token) || (T_NotEqual == current_token)) { CdlSubexpression subexpr; subexpr.op = (T_Equal == current_token) ? CdlExprOp_Equal : CdlExprOp_NotEqual; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_comparison(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_bitand(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_bitand"); parse_equals(expr); while (T_BitAnd == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_BitAnd; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_equals(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_bitxor(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_bitxor"); parse_bitand(expr); while (T_BitXor == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_BitXor; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_bitand(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_bitor(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_bitor"); parse_bitxor(expr); while (T_BitOr == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_BitOr; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_bitxor(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_and(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_and"); parse_bitor(expr); while (T_And == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_And; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_bitor(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_or(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_or"); parse_and(expr); while (T_Or == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_Or; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_and(expr); subexpr.rhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_conditional(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_conditional"); parse_or(expr); if (T_Questionmark == current_token) { CdlSubexpression subexpr; subexpr.op = CdlExprOp_Cond; subexpr.lhs_index = expr->first_subexpression; next_token(); parse_conditional(expr); subexpr.rhs_index = expr->first_subexpression; if (T_Colon != current_token) { throw CdlParseException("Expected colon in conditional expression.\n" + get_error_location()); } next_token(); parse_conditional(expr); subexpr.rrhs_index = expr->first_subexpression; push_subexpression(expr, subexpr); } CYG_REPORT_RETURN();}static voidparse_expression(CdlExpression expr) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("parse_expression"); parse_conditional(expr); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// The entry point.voidCdlExpressionBody::continue_parse(CdlExpression expr, std::string data, int& index, CdlExprOp& token, int& token_end) throw(CdlParseException, std::bad_alloc){ CYG_REPORT_FUNCNAME("CdlExpression::continue_parse"); CYG_REPORT_FUNCARG1XV(expr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -