Interpreted language: Choosing intermediate code

Per Frykenvall <>
Fri, 12 May 1995 07:16:00 GMT

          From comp.compilers

Related articles
Interpreted language: Choosing intermediate code (Per Frykenvall) (1995-05-12)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Per Frykenvall <>
Keywords: interpreter, design, question, comment
Organization: WM-data Applikationslosningar
Date: Fri, 12 May 1995 07:16:00 GMT

What are the pros and cons of using an intermediate code, as
output of a compiler (and to be executed by an interpreter), based on:

        (1) Postfix operators, pushing operands on a stack
                a := f(a+b,2*(a+b)); -> PUSH a
                                                                        PUSH b
                                                                        PUSH 2
                                                                        MUL // 2*(a+b) on top of stack
                                                                        PUSH a
                                                                        PUSH b
                                                                        ADD // a+b on top of stack
                                                                        CALL f // f will push return value
                                                                        POP a // assign return value to a
                                                                        POP // adjust stack

        (2) Similar to machine language
                a := f(a+b,2*(a+b)); -> ADD a,b,t1 // t1=a+b
                                                                        MUL 2,t1,t1 // t1=2*t1
                                                                        PARAM t1
                                                                        ADD a,b,t1 // t1=a+b
                                                                        PARAM t1
                                                                        CALL f,2,a // a=f(2 parameters)

(Of course, the output should be binary coded)

Source in our case is a PL/1 derivate.

The language I depicted in (2) is on the "three-address code" form
described in the dragon book. Are there any reasons not to use three-address
code as final output of the compiler?

References on these topics are welcome.

Regards, Per

* Per Frykenvall Internet: *
* WM-data Applikationslosningar AB Fax: +46-31-45 05 88 *
* Box 2065, S-421 02 V.FROLUNDA, Sweden Voice: +46-31-89 04 78 *
[It's a little eaiser to build ab RPN interpreter than a 3-address one, but
the main advantage seems to me to be that RPN lets you avoid having to deal
with allocation of temporaries. -John]

Post a followup to this message

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