Source to source compiling

Casper Gripenberg <casper@snakemail.hut.fi>
Sun, 11 Sep 1994 23:44:09 GMT

          From comp.compilers

Related articles
Source to source compiling casper@snakemail.hut.fi (Casper Gripenberg) (1994-09-11)
Re: Source to source compiling eanders+@CMU.EDU (Eric A. Anderson) (1994-09-12)
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)
[5 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: Casper Gripenberg <casper@snakemail.hut.fi>
Keywords: translator, question
Organization: Compilers Central
Date: Sun, 11 Sep 1994 23:44:09 GMT

I am currently working on a source to source compiler. The source
language is a kind of state langage. A program containes 1-n states. 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.


Example:


STATE1:
    Do something;
    if (a) goto STATE3;
    if (b) goto STATE2;
    etc...


STATE2:
    ....


STATE3:
    ....


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.


One kludgy solution would be to model every state as a function in the
destination language. Then every goto statement in the source language
would simply convert to a function call in the destination language.


I have made compilers that convert loops & if-then-else statements into
goto statements, ie. using short-circuit code (from the dragon book :)),
but I have no idea how to do it the other way.


Are there any books on the subject or any ready-made similar compilers
that I could check out.


Thanks.


// Casper
--


Post a followup to this message

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