]> git.mdlowis.com Git - proto/obnc.git/commitdiff
added if statement to parser. need to add codegen hooks
authormike lowis <mike@mdlowis.com>
Thu, 29 Apr 2021 03:28:18 +0000 (23:28 -0400)
committermike lowis <mike@mdlowis.com>
Thu, 29 Apr 2021 03:28:18 +0000 (23:28 -0400)
cerise/backend/x86_64/codegen.c
cerise/oberon0/OSP.Mod
cerise/src/parser.c
cerise/tests/Module.m

index ac961a68b94c3b8e7386270be99b1c1b470a8b0b..4f8602c6ae8aa8d154c06d8a8859b139cb26b951 100644 (file)
@@ -238,6 +238,7 @@ void codegen_main(Parser* p)
 
 void codegen_startproc(Parser* p, char* name, bool exported)
 {
+    (void)exported;
     printf("    .text\n");
     if (name)
     {
index 44335499cd7667ee8d29e1efdca8a7e25c37b1c5..7b0fb376888599f7d1775e672c2794fa9eacb7f5 100644 (file)
@@ -335,6 +335,7 @@ MODULE OSP; (* NW 23.9.93 / 9,5.2017   OSPX*)
             OSS.Mark("not a procedure")\r
           END\r
         END\r
+\r
       ELSIF sym = OSS.if THEN\r
         OSS.Get(sym);\r
         expression(x);\r
index 508cccbca502667bb599eb3ea2162ae96a512011..a458a55b1b4cc5993e77ed682213ea2b54829993 100644 (file)
@@ -560,14 +560,30 @@ RULE(statement_seq)
         }
         else if (matches(p, IF))
         {
-            assert("!not implemented");
+            expect(p, IF);
+            expression(p, item);
+            check_bool(p, item);
+            expect(p, THEN);
+            statement_seq(p, &(Item){0});
+            while (accept(p, ELSIF))
+            {
+                expression(p, item);
+                check_bool(p, item);
+                expect(p, THEN);
+                statement_seq(p, &(Item){0});
+            }
+            if (accept(p, ELSE))
+            {
+                statement_seq(p, &(Item){0});
+            }
+            expect(p, END);
         }
         else
         {
             error(p, "expected a statement");
         }
 
-        if (matches(p, END))
+        if (matches(p, END) || matches(p, ELSE) || matches(p, ELSIF))
         {
             break;
         }
index c78051e66e010e1e0087c7b2c973a758c5e44894..57fcc0541480626f3342de70c5f018229d8bb4f9 100644 (file)
@@ -14,29 +14,45 @@ var
     c : Int
 
 begin
-    a = true;
-    a = A;
-    b = 24;
-    b = B;
-
-    # Unary ops
-    b = +b;
-    b = -b;
-
-    # Immediate ops
-    c = b + 1;
-    c = b - 1;
-    c = b * 1;
-
+#    a = true;
+#    a = A;
+#    b = 24;
+#    b = B;
+#
+#    # Unary ops
+#    b = +b;
+#    b = -b;
+#
+#    # Arithmetic ops
+#    c = b + 1;
+#    c = b - 1;
+#    c = b * 1;
+#    c = b / 1;
+#    c = b % 1;
+#
+#    # Comparison ops
 #    c = b == 1;
-
-    # Register ops
-    c = 1 + b;
-    c = 1 - b;
-    c = 1 * b;
-
-    c = b + b;
-
-    # Complex arithmetic
-    c = b + b * b + b;
+#    c = b != 1;
+#    c = b < 1;
+#    c = b > 1;
+#    c = b <= 1;
+#    c = b >= 1;
+#
+#    # Register ops
+#    c = 1 + b;
+#    c = 1 - b;
+#    c = 1 * b;
+#
+#    c = b + b;
+#
+#    # Complex arithmetic
+#    c = b + b * b + b;
+
+    if 1 == 1 then
+        c = 1;
+    elsif 2 == 2 then
+        c = 2;
+    else
+        c = 3;
+    end
 end