[Oberon] The Extended WHILE Statement

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Fri Jun 12 20:17:55 CEST 2026


One obvious example would be ORP.selector, which could be expressed using the Dijkstra guarded repetition as follows:

  PROCEDURE selector(VAR x: ORG.Item);
    VAR y: ORG.Item; obj: ORB.Object;
  BEGIN
    WHILE sym = ORS.lbrak DO
      REPEAT ORS.Get(sym); expression(y);
        IF x.type.form = ORB.Array THEN
          CheckInt(y); ORG.Index(x, y); x.type := x.type.base
        ELSE ORS.Mark("not an array")
        END
      UNTIL sym # ORS.comma;
      Check(ORS.rbrak, "no ]")
    ELSIF sym = ORS.period DO
      ORS.Get(sym);
      IF sym = ORS.ident THEN
        IF x.type.form = ORB.Pointer THEN ORG.DeRef(x); x.type := x.type.base END ;
        IF x.type.form = ORB.Record THEN
          obj := ORB.thisfield(x.type); ORS.Get(sym);
          IF obj # NIL THEN ORG.Field(x, obj); x.type := obj.type
          ELSE ORS.Mark("undef")
          END
        ELSE ORS.Mark("not a record")
        END
      ELSE ORS.Mark("ident?")
      END
    ELSIF sym = ORS.arrow DO
      ORS.Get(sym);
      IF x.type.form = ORB.Pointer THEN ORG.DeRef(x); x.type := x.type.base
      ELSE ORS.Mark("not a pointer")
      END
    ELSIF (sym = ORS.lparen) & (x.type.form IN {ORB.Record, ORB.Pointer}) DO (*type guard*)
      ORS.Get(sym);
      IF sym = ORS.ident THEN
        qualident(obj);
        IF obj.class = ORB.Typ THEN TypeTest(x, obj.type, TRUE)
        ELSE ORS.Mark("guard type expected")
        END
      ELSE ORS.Mark("not an identifier")
      END ;
      Check(ORS.rparen, " ) missing")
    END
  END selector;



More information about the Oberon mailing list