consume(RB);
break;
}
- case SUB: { // negative literal (like "3 * -1")
- consume(NUMBER);
- b.add(parserLine, LITERAL, JS.N(number.doubleValue() * -1));
+ case SUB: case ADD: {
+ if(peekToken() == NUMBER) { // literal
+ consume(NUMBER);
+ b.add(parserLine, LITERAL, JS.N(number.doubleValue() * (tok == SUB ? -1 : 1)));
+ } else { // unary +/- operator
+ if(tok == SUB) b.add(parserLine, LITERAL, JS.ZERO);
+ // BITNOT has the same precedence as the unary +/- operators
+ startExpr(b,precedence[BITNOT]);
+ if(tok == ADD) b.add(parserLine, LITERAL, JS.ZERO); // HACK to force expr into a numeric context
+ b.add(parserLine, SUB);
+ }
break;
}
case LP: { // grouping (not calling)