|How to build your own stack frames? (interpreter questions) firstname.lastname@example.org (1995-08-20)|
|Re: How to build your own stack frames? (interpreter questions) email@example.com (1995-08-21)|
|Re: How to build your own stack frames? (interpreter questions) Lassi.Tuura@hut.fi (1995-08-21)|
|Re: How to build your own stack frames? (interpreter questions) firstname.lastname@example.org (1995-08-22)|
|Re: How to build your own stack frames? (interpreter questions) email@example.com (1995-08-22)|
|From:||firstname.lastname@example.org (Rick Barton)|
|Organization:||Texas Metronet, Inc (login info (214/705-2901 - 817/571-0400))|
|Date:||Tue, 22 Aug 1995 05:52:52 GMT|
Ralph Seguin (email@example.com) wrote:
: We are looking at creating some interpreter code, and we would
: very much like to have the interpreter call into various methods and
: functions that we have available.
I have been working on a BASIC interpreter which now run on FreeBSD,
Linux, Sparc and (dare I say it), DOS. It needs lots of work on some
of these architecutres, but FreeBSD is my platform.
Anyhow, I used 'THE UNIX PROGRAMMING ENVIRONMENT' (sorry, but the
title is in all caps) by Brian W. Kernighan and Rob Pike. It has
an excellent example of doing an interpreter (hoc). I diverged
at different places. They use a recursive method of having a STOP
constant and then the recursion backs up, where as I generated code
to be executed straight through. This book uses the stack for almost
everything which makes it quite simple to implement. It does use
only simple types (I use the BASIC types such as integer, real, string).
For parameter lists for functions such as PRINT, they are NULL terminated
(much like *argv). For each built-in function, you just take
whatever arguements are in the calling sequence and push them onto
the stack. The function will perform a pop to retrieve them. There's
more to it than that, but you get the idea.
I hope this helps. The book realy helped me a lot.
Return to the
Search the comp.compilers archives again.