Re: Translating from lagugae which allows Goto's

nmm1@cus.cam.ac.uk (Nick Maclaren)
17 Jul 2003 00:31:05 -0400

          From comp.compilers

Related articles
[2 earlier articles]
Re: Translating from lagugae which allows Goto's syring@email.com (Karl M Syring) (2003-07-13)
Re: Translating from lagugae which allows Goto's strohm@airmail.net (John R. Strohm) (2003-07-13)
Re: Translating from lagugae which allows Goto's bsheff2@yahoo.com (Bob Sheff) (2003-07-15)
Re: Translating from lagugae which allows Goto's postmaster@paul.washington.dc.us (Paul Robinson) (2003-07-15)
Re: Translating from lagugae which allows Goto's genew@mail.ocis.net (2003-07-15)
Re: Translating from lagugae which allows Goto's lex@cc.gatech.edu (Lex Spoon) (2003-07-17)
Re: Translating from lagugae which allows Goto's nmm1@cus.cam.ac.uk (2003-07-17)
Re: Translating from lagugae which allows Goto's joachim.durchholz@web.de (Joachim Durchholz) (2003-07-17)
Re: Translating from lagugae which allows Goto's vbdis@aol.com (2003-07-17)
Re: Translating from lagugae which allows Goto's Martin.Ward@durham.ac.uk (Martin Ward) (2003-07-21)
Re: Translating from lagugae which allows Goto's strohm@airmail.net (John R. Strohm) (2003-07-21)
| List of all articles for this month |

From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.compilers
Date: 17 Jul 2003 00:31:05 -0400
Organization: University of Cambridge, England
References: 03-07-042 03-07-093
Keywords: translator, analysis
Posted-Date: 17 Jul 2003 00:31:05 EDT



  Bob Sheff <bsheff2@yahoo.com> wrote:
>Removal of GOTO is done all the time (by humans and) source code
>translators. The simple case of GOTO is to find the <target> label,
>bracket the group of statements and then logically invert the <if>
>expression. An even simpler case is in assembly when the GOTO is used to
>allow definition of constant/variable local storage which may just be
>relocated after the GOTO is removed.


Yes. Back in 1972, I wrote an ad-hoc Algol 68 program to convert
some of my Fortran 66 code to Algol 60 (don't ask). Because I
used a consistent programming style, I could replace almost all
of the loops and conditionals by the Algol 60 ones. I had to remove
very few by hand.


>Sometimes a "rats nest" of tests and GOTOs can actually be de-compiled to a
>more complicated but human understandable logic expression:
> if ( a>b ) goto 1;
> if ( c<5 ) goto 2 => if ( a>b || c>=5 ) foo();
>1 call foo
>2 ...


Interestingly enough, the converse can be true. I have sometimes
changed a rat's nest of conditionals and temporary booleans into much
cleaner code by using Fortran computed GOTOs. The key was, of course,
that the code was implementing precisely the sort of multi-target
finite state machine that such operations model most closely.


Regards,
Nick Maclaren.



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.