From: mike lowis Date: Fri, 7 May 2021 03:51:15 +0000 (-0400) Subject: started implementing array subscripting X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=619015cf633dbe84b48f61c4bbfe4058d962a635;p=proto%2Fobnc.git started implementing array subscripting --- diff --git a/cerise/oberon0/OSP.Mod b/cerise/oberon0/OSP.Mod index dd90229..ecaf363 100644 --- a/cerise/oberon0/OSP.Mod +++ b/cerise/oberon0/OSP.Mod @@ -272,11 +272,13 @@ MODULE OSP; (* NW 23.9.93 / 9,5.2017 OSPX*) factor(y); CheckInt(y); OSG.MulOp(x, y) + ELSIF (op = OSS.div) OR (op = OSS.mod) THEN CheckInt(x); factor(y); CheckInt(y); OSG.DivOp(op, x, y) + ELSE (*op = and*) CheckBool(x); OSG.And1(x); @@ -322,11 +324,13 @@ MODULE OSP; (* NW 23.9.93 / 9,5.2017 OSPX*) PROCEDURE expression0(VAR x: OSG.Item); VAR y: OSG.Item; op: INTEGER; - BEGIN SimpleExpression(x); + BEGIN + SimpleExpression(x); IF (sym >= OSS.eql) & (sym <= OSS.geq) THEN op := sym; OSS.Get(sym); SimpleExpression(y); + IF x.type = y.type THEN OSG.Relation(op, x, y) ELSE diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index da646dd..4140051 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -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, '^'); diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index fc5d28e..fc74734 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -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