From 9886bf61ea5fbbc8eec3969ca21d72a4dce69afe Mon Sep 17 00:00:00 2001 From: brian Date: Sat, 19 Jun 2004 22:58:52 +0000 Subject: [PATCH] fix unary +/- operators (bug 232) darcs-hash:20040619225852-24bed-f0ae9ce40af69425e6c67f2348a058727f2affb1.gz --- src/org/ibex/js/Parser.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/org/ibex/js/Parser.java b/src/org/ibex/js/Parser.java index 51b23b8..38d15ea 100644 --- a/src/org/ibex/js/Parser.java +++ b/src/org/ibex/js/Parser.java @@ -206,9 +206,17 @@ class Parser extends Lexer implements ByteCodes { 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) -- 1.7.10.4