Kajetan Johannes Hammerle 3 years ago
parent
commit
7d9398fe47
3 changed files with 36 additions and 1 deletions
  1. 5 1
      Compiler.c
  2. 24 0
      tests/if/elseif
  3. 7 0
      tests/if/elseif.out

+ 5 - 1
Compiler.c

@@ -427,7 +427,11 @@ static void cIf() {
         cAddOperation(OP_GOTO);
         int elseP = cReserveInt();
         cSetInt(ifP, code->length);
-        cConsumeBody();
+        if(cConsumeTokenIf(T_IF)) {
+            cIf();
+        } else {
+            cConsumeBody();
+        }
         cSetInt(elseP, code->length);
     }
 }

+ 24 - 0
tests/if/elseif

@@ -0,0 +1,24 @@
+function test(a) {
+    if(a == 1) {
+        print 10;
+    } else if(a == 1) {
+        print null;
+    } else if(a == 2) {
+        print 20;
+    } else if(a == 3) {
+        print 30;
+    } else if(a == 2) {
+        print null;
+    } else if(a == 4) {
+        print 40;
+    } else {
+        print 50;
+    }
+}
+test(0);
+test(1);
+test(2);
+test(3);
+test(4);
+test(5);
+test(6);

+ 7 - 0
tests/if/elseif.out

@@ -0,0 +1,7 @@
+50
+10
+20
+30
+40
+50
+50