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.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.