Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15

Hans-Peter Diettrich <DrDiettrich@compuserve.de>
7 Jun 2006 23:18:37 -0400

          From comp.compilers

Related articles
Compilers, Aho/Sethi/Ullman, Exercise 2.15 tomazos@gmail.com (2006-06-05)
Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 pjb@informatimago.com (Pascal Bourguignon) (2006-06-07)
Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 cdodd@acm.org (Chris Dodd) (2006-06-07)
Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-06-07)
| List of all articles for this month |
From: Hans-Peter Diettrich <DrDiettrich@compuserve.de>
Newsgroups: comp.compilers
Date: 7 Jun 2006 23:18:37 -0400
Organization: Compilers Central
References: 06-06-019
Keywords: books
Posted-Date: 07 Jun 2006 23:18:37 EDT

tomazos@gmail.com wrote:


> Consider the following for-statement:
>
> for i:= 1 step 10 - j until 10 * j do j := j + 1
>
> The limit 10 * j and increment 10 - j are to be evaluated once before
> the loop. For example if j = 5 before the loop, we would run through
> ten times and exit.
>
> Construct a syntax-directed translation scheme to translate this
> for-loop into the following stack-machine code.
...
> The parts labeled with ???? are illegal in the stack machine-code. The
> problem is that I need to store the initial evaluation of STEP and
> LIMIT somewhere, and I don't see how this is possible to do using the
> stack. There is also no mention of a way to create and allocate a new
> variable, or anywhere else I could store them.
>
> Any enlightenment on this topic appreciated.


IMO you can assume that according variables have been created,
somewhere, somehow. At least I can't imagine how else this problem could
be solved, on a single-stack machine with the limited instruction set
you mentioned. With more instructions, for stack pointer relative
operands (FORTH: DUP, SWAP, OVER...), it were possible to have the STEP
and LIMIT values on the stack.


DoDi



Post a followup to this message

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