Re: Source to source compiling

pjj@cs.man.ac.uk (Pete Jinks)
Fri, 16 Sep 1994 15:14:40 GMT

          From comp.compilers

Related articles
[2 earlier articles]
Re: Source to source compiling norman@flaubert.bellcore.com (1994-09-14)
Re: Source to source compiling mabp@bga.com (1994-09-13)
Re: Source to source compiling f1rederc@iia.org (1994-09-13)
Re: source to source compiling ghiya@vani.cs.mcgill.ca (1994-09-18)
Re: Source to source compiling bernecky@eecg.toronto.edu (Robert Bernecky) (1994-09-18)
Re: Source to source compiling toconnor@vcd.hp.com (1994-09-18)
Re: Source to source compiling pjj@cs.man.ac.uk (1994-09-16)
Re: Source to source compiling rgg@tidos.tid.es (1994-09-19)
Re: Source to source compiling lexa@adam.botik.yaroslavl.su (1994-09-22)
Re: Source to source compiling md@pact.srf.ac.uk (1994-09-22)
| List of all articles for this month |
Newsgroups: comp.compilers
From: pjj@cs.man.ac.uk (Pete Jinks)
Keywords: translator
Organization: Dept of Computer Science, University of Manchester, U.K.
References: 94-09-031
Date: Fri, 16 Sep 1994 15:14:40 GMT

Casper Gripenberg <casper@snakemail.hut.fi> wrote:
>The source language is a kind of state langage. All
>states have the same kind of structure, ie. in the beginning you initilaze
>variables, then comes some code to execute and at last a bunch of
>conditional jumps to other states.
>
>The destination langage is very c-like. With while loops and if-then-else
>statements.
>
>Now the problem is that I don't know how to convert these conditional goto
>statements in the source language to while/if-then-else constructs in the
>destination language. How do I check for eg. loops, and presumably some of
>the goto statements just cannot be translated into if-them-else statements.


Bo:hm & Jacopini did something similar to show any arbitrary flowchart can
be expressed without gotos:


state= 1;
while (state)
    switch (state)
    {
    case 1:
        Do something;
        if (a) state=3; else
        if (b) state=2; else
        etc...


    case 2:
        ....


    case 3:
        ....
    }


You can use state=0 to cause the code to terminate.
You could replace the switch by more nested if-then-elses if your
destination language hasn't got that construct.


I am not sure why you want to check for loops - in general this is akin to
the halting problem isn't it?
--


Post a followup to this message

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