expression * parser_expression::parse_add_sub() { expression *e = parse_mul(); try { while(l == lex::CMD && (l.get_word() == "+" || l.get_word() == "-")) if(l.get_word() == "+") { ++l; e = new add(e, parse_mul()); } else { ++l; e = new subtract(e, parse_mul()); } } catch(...) { delete e; throw; } return e; }
static bool parse_add(ExprParseState *state) { CHECK_ERROR(parse_mul(state)); for (;;) { switch (state->token) { case '+': CHECK_ERROR(parse_next_token(state) && parse_mul(state)); parse_add_func(state, OPCODE_FUNC2, 2, op_add); break; case '-': CHECK_ERROR(parse_next_token(state) && parse_mul(state)); parse_add_func(state, OPCODE_FUNC2, 2, op_sub); break; default: return true; } } }