From 619015cf633dbe84b48f61c4bbfe4058d962a635 Mon Sep 17 00:00:00 2001 From: mike lowis Date: Thu, 6 May 2021 23:51:15 -0400 Subject: [PATCH] started implementing array subscripting --- cerise/oberon0/OSP.Mod | 6 +++++- cerise/src/grammar.c | 23 +++++++++++++++++++---- cerise/tests/Module.m | 4 +++- 3 files changed, 27 insertions(+), 6 deletions(-) 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 -- 2.49.0