Re: Source to source compiling

"Eric A. Anderson" <eanders+@CMU.EDU>
Mon, 12 Sep 1994 19:46:24 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)
Re: Source to source compiling toconnor@vcd.hp.com (1994-09-18)
[4 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: "Eric A. Anderson" <eanders+@CMU.EDU>
Keywords: translator
Organization: Carnegie Mellon, Pittsburgh, PA
References: 94-09-031
Date: Mon, 12 Sep 1994 19:46:24 GMT

Casper Gripenberg <casper@snakemail.hut.fi> writes:
> Example:
>
> STATE1:
> Do something;
> if (a) goto STATE3;
> if (b) goto STATE2;
> etc...
>
> STATE2:
> ....
>
> STATE3:
> ....
One way I've seen for doing this is with a "current-state" variable;
e.g. your example becomes (in C):


#define STATE1 1
#define STATE2 2
#define STATE3 3
#define DEADSTATE 0


{
    int curstate = INITIAL_STATE;


    while(curstate != FINAL_STATE) {
        switch(curstate) {
            case STATE1: Do something;
                if (a) { curstate = STATE3; }
                else if (b) { curstate = STATE2; }
                ...
                else { curstate = DEADSTATE; }
            break;
            ...
            case DEADSTATE:
                printf("Bad state diagram, bad, bad!!\n");abort();
            default:
                printf("Bad compiler, bad, bad!!\n");abort();
        }
    }
--
The switch can be obviously translated into an if-then series.
                    -Eric
--


Post a followup to this message

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