Re: Implementing a stack-based interpreter

glen herrmannsfeldt <gah@ugcs.caltech.edu>
22 Jul 2005 20:15:51 -0400

          From comp.compilers

Related articles
Implementing a stack-based interpreter cvrebert@gmail.com (2005-07-17)
Re: Implementing a stack-based interpreter ar.mcdonald@virgin.net (Alex McDonald) (2005-07-22)
Re: Implementing a stack-based interpreter mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2005-07-22)
Re: Implementing a stack-based interpreter gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-07-22)
Re: Implementing a stack-based interpreter john.carter@tait.co.nz (John Carter) (2005-07-22)
Re: Implementing a stack-based interpreter Jan.Bogaerts@telenet.be (Jan Bogaerts) (2005-07-22)
Re: Implementing a stack-based interpreter anton@mips.complang.tuwien.ac.at (2005-07-26)
Re: Implementing a stack-based interpreter dot@dotat.at (Tony Finch) (2005-07-26)
Re: Implementing a stack-based interpreter marcov@stack.nl (Marco van de Voort) (2005-08-03)
Re: Implementing a stack-based interpreter mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2005-08-05)
[4 later articles]
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: 22 Jul 2005 20:15:51 -0400
Organization: Compilers Central
References: 05-07-070
Keywords: interpreter

cvrebert@gmail.com wrote:


> I know this is comp.compilers, but since there isn't a
> comp.interpreters, I figure this is the right place to ask.
> I'm trying write an interpreter for a programming language but haven't
> been able to find anything on how to write a stack-based interpreter.
> If anyone could point me to a book/website I'd be much obliged.


> [Compile to a string of reverse polish operators, then interpret that string
> pushing results on the stack and popping operands off the stack. -John]


Yes.


Many of the needed techniques are the same, so many compiler books
should also be useful to interpreter writers.


Most interpreters do at least a little bit of compiling.


The usual BASIC interpreter compiled each line, mostly by converting
keywords to a single byte, and sometimes converting numeric constants
to internal form. That is done to each line as it is typed in.


Also, it is very unusual for compilers to compile everything down to
machine code. Most use subroutine calls for I/O and more complicated
mathematical operations. On machines without hardware multiply and
divide, those are done by subroutine call.


Also, formatted output (printf() and Fortran's FORMAT) usually involves
interpreting the format strings.


-- glen


Post a followup to this message

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