Parcourir la source

! for inverting

Kajetan Johannes Hammerle il y a 3 ans
Parent
commit
55bced0c92
3 fichiers modifiés avec 22 ajouts et 0 suppressions
  1. 10 0
      Compiler.c
  2. 6 0
      tests/if/invert
  3. 6 0
      tests/if/invert.out

+ 10 - 0
Compiler.c

@@ -232,6 +232,16 @@ static void cPreUnary() {
         cPreIncrement();
     } else if(cConsumeTokenIf(T_DECREMENT)) {
         cPreDecrement();
+    } else if(cConsumeTokenIf(T_NOT)) {
+        int counter = 1;
+        while(cConsumeTokenIf(T_NOT)) {
+            counter++;
+        }
+        cPrimary();
+        cAddOperation(OP_NOT);
+        if((counter & 1) == 0) {
+            cAddOperation(OP_NOT);
+        }
     } else {
         cPrimary();
     }

+ 6 - 0
tests/if/invert

@@ -0,0 +1,6 @@
+print !true;
+print !false;
+print !!true;
+print !!false;
+print !!!true;
+print !!!false;

+ 6 - 0
tests/if/invert.out

@@ -0,0 +1,6 @@
+false
+true
+true
+false
+false
+true