fix unary +/- operators (bug 232)
authorbrian <brian@brianweb.net>
Sat, 19 Jun 2004 22:58:52 +0000 (22:58 +0000)
committerbrian <brian@brianweb.net>
Sat, 19 Jun 2004 22:58:52 +0000 (22:58 +0000)
darcs-hash:20040619225852-24bed-f0ae9ce40af69425e6c67f2348a058727f2affb1.gz

src/org/ibex/js/Parser.java

index 51b23b8..38d15ea 100644 (file)
@@ -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)