|Compilers, Aho/Sethi/Ullman, Exercise 2.15 firstname.lastname@example.org (2006-06-05)|
|Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 email@example.com (Pascal Bourguignon) (2006-06-07)|
|Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 firstname.lastname@example.org (Chris Dodd) (2006-06-07)|
|Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15 DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-06-07)|
|From:||Hans-Peter Diettrich <DrDiettrich@compuserve.de>|
|Date:||7 Jun 2006 23:18:37 -0400|
|Posted-Date:||07 Jun 2006 23:18:37 EDT|
> 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.
Return to the
Search the comp.compilers archives again.