comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Help with Exceptions!
Date: 1996/05/13
Date: 1996-05-13T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96May13172506@spectre.mitre.org> (raw)
In-Reply-To: 318F94D9.35AB@io.com


In article <319764DA.3A8C@io.com> Dave Jones <davedave@io.com> writes:

  > Most others seem to have an experience similar to mine: "goto"
  > means you need to change your approach.  So I was wondering, has
  > anyone out there ever encountered a situation where "goto" was
  > actually necessary?

   The only two cases in which I have used gotos in are:

   1) Testing the compiler's implementation of gotos for correctness.

   2) Implementation of table driven finite-state machines.

    The latter requires a bit of explanation.  Machine generated FSMs
can use lots of gotos, but I have never seen an Ada FSM generator
which does that. Implementing the entire FSM by hand with gotos is
heap bad juju.  But often you want a state table entry to have the
form (in pseudo-code):

    table-identifier table-type number-of-entries = 3
    when input = x goto state yyy
      "    "   = y goto state zzz
    when others => continue with state abc.

    This allows parse tables to be stored more compactly, and is best
implemented by having a loop over the table entries that contains a
goto back to the code for reading to table headers when the default
case is encountered.

    The code structure is:

    <<label>> ...
              for I in ... loop
                ...
                if entry_type = continue
                then
                  ...
                  goto label; 
                end if;
              end loop;

    Now those of you with academic backgrounds will cleverly realize
that this can be "fixed" with a recursive call. Those with compiler
experience will understand that I have seen parsers in states with
several hundred (often large) frames on the stack.  Doubling the
number of stack frames for stylistic reasons is very unappealing.

     Are there any other known cases where a goto "makes sense" in
Ada?  The only one I can come up with is for teaching gotos!
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  parent reply	other threads:[~1996-05-13  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-07  0:00 Help with Exceptions! Robert Gelb
1996-05-07  0:00 ` John Herro
1996-05-07  0:00 ` Steve Howard
1996-05-07  0:00   ` Robert Dewar
     [not found]   ` <4mqio5$a8b@news.sanders.lockheed.com>
1996-05-09  0:00     ` Robert L. Spooner, AD3K
1996-05-10  0:00   ` Jon S Anthony
1996-05-10  0:00     ` Robert A Duff
1996-05-07  0:00 ` Vincent Smeets
     [not found] ` <318F94D9.35AB@io.com>
1996-05-10  0:00   ` George F.Rice
1996-05-13  0:00     ` Dave Jones
1996-05-13  0:00   ` Robert I. Eachus [this message]
1996-05-14  0:00     ` John Herro
1996-05-14  0:00       ` Robert I. Eachus
1996-05-14  0:00   ` Theodore E. Dennison
1996-05-14  0:00     ` Robert A Duff
1996-05-14  0:00 ` Michel Gauthier
1996-05-14  0:00   ` Robert A Duff
1996-05-15  0:00     ` Norman H. Cohen
1996-05-15  0:00       ` Robert A Duff
1996-05-15  0:00 ` Michel Gauthier
1996-05-16  0:00 ` Jon S Anthony
1996-05-16  0:00   ` Robert A Duff
1996-05-16  0:00 ` Jon S Anthony
  -- strict thread matches above, loose matches on Subject: below --
1996-05-09  0:00 tmoran
replies disabled

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