From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_20,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b45952e5dedb7e9a X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: State Machine Implementation Date: 1998/08/06 Message-ID: #1/1 X-Deja-AN: 378423489 Sender: matt@mheaney.ni.net References: <35C90369.CFE8ED98@inficad.com> NNTP-Posting-Date: Wed, 05 Aug 1998 22:47:37 PDT Newsgroups: comp.lang.ada Date: 1998-08-06T00:00:00+00:00 List-Id: "Ray A. Lopez" 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 <> null; select accept Start; or accept Stop; goto Idle; or terminate; end select; <
> null; select accept Change_Mode (Mode : Missle_Mode) do IO_Manager.Mode := Mode; end; <> 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.