Automaten in Oberon

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

FloatingPointAutomaton.om
MODULE FloatingPointAutomaton;
   IMPORT ASCII, Read, Write;
   VAR state: INTEGER; symbol: CHAR;
BEGIN
   state := 1; (* initial state *)
   Read.Char(symbol);
   WHILE symbol # ASCII.nl DO
      CASE symbol OF
      | "0".."9":
         CASE state OF
         | 1:  state := 2;
         | 2:  state := 2;
         | 3:  state := 4;
         | 4:  state := 4;
         | 5:  state := 5;
         END;
      | ",":
         CASE state OF
         | 1:  state := 5;
         | 2:  state := 3;
         | 3:  state := 5;
         | 4:  state := 5;
         | 5:  state := 5;
         END;
      ELSE
         state := 5;
      END;
      Read.Char(symbol);
   END;
   CASE state OF
   | 2, 4:  Write.Line("Looks good!");
   ELSE     Write.Line("Invalid input!");
   END;
END FloatingPointAutomaton.

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 2004, 2005 Andreas Borchert, in HTML konvertiert am 18.02.2005