[Oberon] EXIT statement?

Chris Burrows chris at cfbsoftware.com
Sat Aug 30 07:02:44 CEST 2014


> -----Original Message-----
> From: Diego Sardina [mailto:sardinadiego at gmail.com]
> Sent: Saturday, 30 August 2014 1:28 AM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] EXIT statement?
> 

> These forms of iteration in Oberon have a precise semantic ...

Great explanation!


> There is always an alternative formulation that doesn't require any of
those
> forms and they are often surprisingly better in look, code quality and
> maintenance.
> 

My favourite example is code to handle Oberon's nested comments. It goes
something like this:


(* With LOOP / EXITs *)
PROCEDURE Comment;	
BEGIN 
  Read(ch);
  LOOP
    LOOP
      WHILE ch = "(" DO Read(ch);
        IF ch = "*" THEN Comment END
      END;
      IF ch = "*" THEN Read(ch); EXIT END;
      IF EOF() THEN EXIT END;
      Read(ch)
    END;
    IF ch = ")" THEN Read(ch); EXIT END;
    IF EOF() THEN Mark("unterminated comment"); EXIT END
  END
END Comment;


(* Without LOOP / EXITs *)
PROCEDURE Comment;
BEGIN 
  Read(ch);
  REPEAT
    WHILE ~EOF() & (ch # "*") DO
      IF ch = "(" THEN 
        Read(ch);
        IF ch = "*" THEN Comment END
      ELSE Read(ch)
      END
    END;
    WHILE ch = "*" DO Read(ch) END
  UNTIL (ch = ")") OR EOF();
  IF ~EOF() THEN Read(ch) ELSE Mark("unterminated comment") END
END Comment;


Regards,
Chris

Chris Burrows
CFB Software
Oberon for Cortex-M4, Cortex-M3 and ARM7.
http://www.astrobe.com





More information about the Oberon mailing list