- // consume '-' (or '+')
- get_next_tok();
- ex v = parse_expression();
- switch (s) {
- case '-':
- return (new mul(v, *_num_1_p))->setflag(status_flags::dynallocated);
- case '+':
- return v;
- default:
- throw std::invalid_argument(
- std::string(__func__)
- + ": invalid unary operator \""
- + char(s) + "\"");
- }
+ // Unlike most other parse_* method this one does NOT consume
+ // current token so parse_binop_rhs() knows what kind of operator
+ // is being parsed.
+
+ // There are different kinds of expressions which need to be handled:
+ // -a+b
+ // -(a)
+ // +a
+ // +(a)
+ // Delegete the work to parse_binop_rhs(), otherwise we end up
+ // duplicating it here.
+ ex lhs = _ex0; // silly trick
+ ex e = parse_binop_rhs(0, lhs);
+ return e;