]> git.mdlowis.com Git - proto/obnc.git/commitdiff
started implementing array subscripting
authormike lowis <mike@mdlowis.com>
Fri, 7 May 2021 03:51:15 +0000 (23:51 -0400)
committermike lowis <mike@mdlowis.com>
Fri, 7 May 2021 03:51:15 +0000 (23:51 -0400)
cerise/oberon0/OSP.Mod
cerise/src/grammar.c
cerise/tests/Module.m

index dd9022923cef580805daa2dd8c9ce995453cc6bb..ecaf363f961923d29a8536910b7f4e21e78e4ff9 100644 (file)
@@ -272,11 +272,13 @@ MODULE OSP; (* NW 23.9.93 / 9,5.2017   OSPX*)
         factor(y);\r
         CheckInt(y);\r
         OSG.MulOp(x, y)\r
+\r
       ELSIF (op = OSS.div) OR (op = OSS.mod) THEN\r
         CheckInt(x);\r
         factor(y);\r
         CheckInt(y);\r
         OSG.DivOp(op, x, y)\r
+\r
       ELSE (*op = and*)\r
         CheckBool(x);\r
         OSG.And1(x);\r
@@ -322,11 +324,13 @@ MODULE OSP; (* NW 23.9.93 / 9,5.2017   OSPX*)
 \r
   PROCEDURE expression0(VAR x: OSG.Item);\r
     VAR y: OSG.Item; op: INTEGER;\r
-  BEGIN SimpleExpression(x);\r
+  BEGIN\r
+    SimpleExpression(x);\r
     IF (sym >= OSS.eql) & (sym <= OSS.geq) THEN\r
       op := sym;\r
       OSS.Get(sym);\r
       SimpleExpression(y);\r
+\r
       IF x.type = y.type THEN\r
         OSG.Relation(op, x, y)\r
       ELSE\r
index da646dd378c6e388d034af53bc20f9d3443dcf04..414005140d4862b4eda957200d69381e169285df 100644 (file)
@@ -112,10 +112,25 @@ RULE(designator)
 //            expect(p, IDENT);
 //            break;
 //
-//        case '[':
-//            expr_list(p);
-//            expect(p, ']');
-//            break;
+        case '[':
+        {
+            expect(p, '[');
+            Type* type = item->type;
+            while (type && type->form == FORM_ARRAY)
+            {
+                Item expr = {0};
+                expression(p, &expr);
+                check_int(p, &expr);
+                type = type->base;
+                if (type->form == FORM_ARRAY)
+                {
+                    expect(p, ',');
+                }
+            }
+            expect(p, ']');
+            break;
+        }
+
 //
 //        case '^':
 //            expect(p, '^');
index fc5d28efcd1dee62eb70455ad46106f355788808..fc74734d3acd27db1e45603ed58e727bf5cbe291 100644 (file)
@@ -21,6 +21,7 @@ var
   b : Int
   c : Int
   d : Real
+  e : TypeB
 
 procedure Foo*(e : Int, z : Int) : Int
   const FOO = 2
@@ -100,5 +101,6 @@ begin
 #  end
 #
   # Function calls
-  c = Foo(1,2);
+#  c = Foo(1,2);
+  e[0] = 1;
 end