allow .154 and fixed bug in makeBinop

This commit is contained in:
Nicolas Cannasse
2008-09-12 17:11:05 +00:00
parent 4597878b16
commit e1f6bad13d
2 changed files with 27 additions and 9 deletions
+2
View File
@@ -17,6 +17,7 @@ class Test {
test("-123",-123);
test("- 123",-123);
test("1.546",1.546);
test(".545",.545);
test("'bla'","bla");
test("null",null);
test("true",true);
@@ -45,6 +46,7 @@ class Test {
test("var a = 1; a++; a",2);
test("var a = 1; ++a",2);
test("var a = 1; a *= 3",3);
test("a = b = 3; a + b",6);
test("add(1,2)",3,{ add : function(x,y) return x + y });
test("a.push(5); a.pop() + a.pop()",8,{ a : [3] });
test("if( true ) 1 else 2",1);
+25 -9
View File
@@ -186,14 +186,14 @@ class Parser {
}
}
function makeBinop( op, e1, e2 ) {
return switch( e2 ) {
function makeBinop( op, e1, e ) {
return switch( e ) {
case EBinop(op2,e2,e3):
if( priority(op) > priority(op2) )
EBinop(op2,makeBinop(op,e1,e2),e3);
else
EBinop(op,e1,e2);
default: EBinop(op,e1,e2);
EBinop(op,e1,e);
default: EBinop(op,e1,e);
}
}
@@ -486,14 +486,30 @@ class Parser {
case 44: return TComma;
case 46:
char = readChar(s);
if( char != 46 ) {
switch( char ) {
case 48,49,50,51,52,53,54,55,56,57:
var n = char - 48;
var exp = 1;
while( true ) {
char = readChar(s);
exp *= 10;
switch( char ) {
case 48,49,50,51,52,53,54,55,56,57:
n = n * 10 + (char - 48);
default:
this.char = char;
return TConst( CFloat(n/exp) );
}
}
case 46:
char = readChar(s);
if( char != 46 )
throw Error.EInvalidChar(char);
return TOp("...");
default:
this.char = char;
return TDot;
}
char = readChar(s);
if( char != 46 )
throw Error.EInvalidChar(char);
return TOp("...");
case 123: return TBrOpen;
case 125: return TBrClose;
case 91: return TBkOpen;