added ~ unary operator
This commit is contained in:
@@ -30,6 +30,7 @@ class Test {
|
||||
test("0 < 0",false);
|
||||
test("-1 <= -1",true);
|
||||
test("1 + 2",3);
|
||||
test("~545",-546);
|
||||
test("'abc' + 55","abc55");
|
||||
test("'abc' + 'de'","abcde");
|
||||
test("-1 + 2",1);
|
||||
|
||||
@@ -246,6 +246,12 @@ class Interp {
|
||||
return increment(e,prefix,1);
|
||||
case "--":
|
||||
return increment(e,prefix,-1);
|
||||
case "~":
|
||||
#if neko
|
||||
return haxe.Int32.complement(expr(e));
|
||||
#else
|
||||
return ~expr(e);
|
||||
#end
|
||||
default:
|
||||
throw Error.EInvalidOp(op);
|
||||
}
|
||||
|
||||
+2
-2
@@ -61,7 +61,7 @@ class Parser {
|
||||
|
||||
public function new() {
|
||||
line = 1;
|
||||
opChars = "+*/-=!><&|^%";
|
||||
opChars = "+*/-=!><&|^%~";
|
||||
identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
||||
opPriority = [
|
||||
"...",
|
||||
@@ -74,7 +74,7 @@ class Parser {
|
||||
"*","/",
|
||||
"%"
|
||||
];
|
||||
unopsPrefix = ["!","++","--","-"];
|
||||
unopsPrefix = ["!","++","--","-","~"];
|
||||
unopsSuffix = ["++","--"];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user