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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,affd14e05b8fb09a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-28 22:14:12 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!nntp.giganews.com!local1.nntp.ash.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 29 Apr 2004 00:14:11 -0500 Date: Thu, 29 Apr 2004 01:14:11 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Hierarchical States Machines References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-2gDdWjZUQxyFdICjxSbD+FCrUcf9PLGLdeTD/4garesH1joB7pJGmHsYUeIMmCLmtSg7pHmH2PjOwZh!nw4w53UFhx0qQ2e9QgVOAVwEfPHKG2v1PhUwFl17mwDHHAOD61EhYRDOzSiFcw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:7554 Date: 2004-04-29T01:14:11-04:00 List-Id: Steve wrote: > I don't have anything against using goto's for state machines... but... > > I usually set up an enumeration for each state... > > In my opinion it makes things easier to follow since the entry > to a new state always happens from the same place. Exactly. My point is that this: loop case State is when... end case; -- post processing end loop; ...is the real underlying structure, and you should use gotos when needed to preserve it. Randy mentioned one such case continue. (His code looked exactly like a FSM to me, even if he wants to call it something else.) Other typical patterns you run into are where you need multiple exits from the loop, or you need to return to the beginning while skipping the post-processing. For example in the Ada parser driver I wrote for state machines created by LALR1 on Multics, there were some "merged" state entries where several states action tables were almost identical. So LALR1 generated table entries that said essentially: if the next token is X do Y, otherwise go to the state table for state Z. You could distort the engine all out of shape to implement this, or put in a goto to just before the loop. Someone who had been taught the "gotos are evil" religion reorganized the code with a couple of added state variables to demonstrate the goto wasn't necessary. His code was only twenty lines longer than my code, and ran 40% slower. (Register pressure from those state variables push things that should have been in registers onto the stack.) Although he talked about looking at the generated code to see why it was so much slower, I think he realized that his version was the spaghetti. -- Robert I. Eachus "The terrorist enemy holds no territory, defends no population, is unconstrained by rules of warfare, and respects no law of morality. Such an enemy cannot be deterred, contained, appeased or negotiated with. It can only be destroyed--and that, ladies and gentlemen, is the business at hand." -- Dick Cheney