comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: State Machine Implementation
Date: 1998/08/06
Date: 1998-08-06T00:00:00+00:00	[thread overview]
Message-ID: <m3yat3kpna.fsf@mheaney.ni.net> (raw)
In-Reply-To: 35C90369.CFE8ED98@inficad.com

"Ray A. Lopez" <rdsys@inficad.com> writes:

> Does anyone have any implementions of a state machine?  The states would
> be just an enumerated type and I am guessing you would use a case
> statement.  Just looking for more info on how to implement this using
> Ada.

I prefer to implement a state machine using labels and gotos.  That's
how I usually write tasks.  For example:

task body IO_Manager is

   Mode : Missle_Mode;

begin

   <<Idle>> null;

   select
      accept Start;
   or
      accept Stop; 
      goto Idle;
   or
      terminate;
   end select;

   <<Main>> null;

   select
      accept Change_Mode (Mode : Missle_Mode) do
         IO_Manager.Mode := Mode;
      end;

      <transmit mode>
      <make asynchorous read>

      <<Waiting_For_Response>> null;

      select
        accept IO_Completion;
        goto Main;

      or 
        accept ...;
        goto Waiting_For_Response;

      ...


Scanners typically have a state-machine implementation.  I just wrote a
scanner to parse real literals that weren't quite in legal Ada format,
using gotos to skip over optional parts of the lexical expression.




  parent reply	other threads:[~1998-08-06  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-05  0:00 State Machine Implementation Ray A. Lopez
1998-08-06  0:00 ` Robert Dewar
1998-08-06  0:00 ` dennison
1998-08-06  0:00   ` John M. Mills
1998-08-06  0:00 ` State Machine Implementation (long) dana
1998-08-06  0:00   ` Tarjei Tj�stheim Jensen
1998-08-06  0:00 ` Matthew Heaney [this message]
1998-08-11  0:00 ` State Machine Implementation Bill Meahan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox