Re: Want to get started - would like to write a simple interpreter

John Carter <john@dwaf-hri.pwv.gov.za>
19 Nov 1996 00:20:43 -0500

          From comp.compilers

Related articles
Want to get started - would like to write a simple interpreter ravenpub@southwind.net (1996-11-01)
Re: Want to get started - would like to write a simple interpreter adrian@dcs.rhbnc.ac.uk (1996-11-03)
Re: Want to get started - would like to write a simple interpreter norman@kbss.bt.co.uk (Norman Hilton) (1996-11-05)
Re: Want to get started - would like to write a simple interpreter ravenpub@southwind.net (1996-11-06)
Re: Want to get started - would like to write a simple interpreter fburton@nyx10.cs.du.edu (1996-11-10)
Re: Want to get started - would like to write a simple interpreter john@dwaf-hri.pwv.gov.za (John Carter) (1996-11-19)
Re: Want to get started - would like to write a simple interpreter kimf@avs.uniras.dk (Kim G. Frei) (1996-11-24)
Re: Want to get started - would like to write a simple interpreter jlilley@empathy.com (1996-12-01)
Re: Want to get started - would like to write a simple interpreter ikellenb@iiic.ethz.ch (Ivan Kellenberger) (1996-12-07)
| List of all articles for this month |

From: John Carter <john@dwaf-hri.pwv.gov.za>
Newsgroups: comp.compilers
Date: 19 Nov 1996 00:20:43 -0500
Organization: Compilers Central
References: 96-11-049
Keywords: interpreter, design

On Fri, 1 Nov 1996, Carl D. Cravens wrote:


> I want to write an interpreter for a very simple language. (A personal
> project that you might find silly if I actually told you what it was
> for.) If I wanted to write just a compiler, I'd buy the dragon book


> Can anyone give me some pointers on where to find the kind of
> information I want? Will a book on compilers help me to write an
> interpreter?


I have recently completed just such an exercise. My advice is browse
the Dragon book or any book from the library that will give you the
idea of what a parser generator does. Push it into the cupboard and
download BISON and FLEX from FSF. (Comes along standard with Linux and
DJGPP)


Write a couple of play-play parsers. (I slammed a wee pin with a
sledgehammer, I used FLEX & BISON to parse a weird old mainframe style
report into nice simple x,y columns for a colleague. AWK would have
done the job but I wouldn't have learnt as much :-))


The main trick is to compile to some sort of byte code. This frees you
from the stark screaming horrors of dealing with real
assembler. (Fine, I can hack assembler if I have to, but if you just
writing an interpretor without any loud yelling speed constraints for
pity sake keep away from real assembler.)


It also frees you to choose where to put features. I have features in
my byte code you will never see in real assembler in a million years.


Make your bytecode a code for an imaginary stack machine. Like a HP
calculator.


That's my 2c worth.


PS: Does anybody have any other worthy design principles for byte
codes. I personally would love to hear them. So much of a
compiler-to-byte code + interpretor can be simplified by a good design
of byte code.


John Carter EMail: ece@dwaf-hri.pwv.gov.za
Telephone : 27-12-808-0374x194 Fax:- 27-12-808-0338
--


Post a followup to this message

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