Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Advice needed: book on interpreter construction

53 views
Skip to first unread message

David PC Wollmann

unread,
Dec 30, 1995, 3:00:00 AM12/30/95
to
I need to write a simple interpreter and a language as part of a
database conversion program. The language will be used to define the
source database, reporting, error handling, target format, etc. I'm
looking for a good book that deals with interpreters--I've got several
compiler books but they aren't really much help. A book with example
code (even fragments) would be very useful as I'm in a big hurry.


David PC Wollmann
Digital Systems Technologies, Support for withdrawn IBM products
Data conversion services
(918) 438-9085 (918) 234-3129 fax
ibms...@sccsi.com, http://www.oknet.com/ibmstuff/dstnet.html
[I compile to byte codes or a tree and then interpret that, keeping
intermediate results on a stack. It's easier than compiling for a
real machine mostly because you can change the target machine to make
it easier to compile for. -John]

--
Send compilers articles to comp...@iecc.com,
meta-mail to compiler...@iecc.com.

Brian V. McGroarty

unread,
Dec 31, 1995, 3:00:00 AM12/31/95
to
> [...] I'm

>looking for a good book that deals with interpreters--I've got several
>compiler books but they aren't really much help. A book with example
>code (even fragments) would be very useful as I'm in a big hurry.
>
>[I compile to byte codes or a tree and then interpret that, keeping
>intermediate results on a stack. It's easier than compiling for a
>real machine mostly because you can change the target machine to make
>it easier to compile for. -John]

If you need to do something approximating John's suggest quickly, you could
simply bastardize Lex to substitute subroutine pointers for tokens, build
tree of same and traverse the tree. To keep things simple, you may want to
forgo the implementation of any control structure and simply traverse the
tree once per data record. If your record names and types are always the
same, this too could be hard-coded with offsets to an array of pointers to
the data structures to shorten implementation time.
Compiler Design in C (Allen Holub, ISBN 0-13-155045-4) includes a complete
discussion of Lex as well as source for what seems a more straightforward
version of same -- this might be the best reference for what you're trying
to do.

---
Brian V. McGroarty -- bria...@bix.com -- phone/fax (708) 439-7714*
*(847) 439-7714 as of 1/20/96

Patrick Herring

unread,
Jan 12, 1996, 3:00:00 AM1/12/96
to
ibms...@sccsi.com writes in article <95-1...@comp.compilers>:

>
> I need to write a simple interpreter and a language as part of a
> database conversion program. The language will be used to define the
> source database, reporting, error handling, target format, etc. I'm

> looking for a good book that deals with interpreters--I've got several
> compiler books but they aren't really much help. A book with example
> code (even fragments) would be very useful as I'm in a big hurry.

Rexx has a defined API so it can be a bolt-on script language (ref:
'The Rexx Language' 2nd ed by Mike Cowlishaw, Prentice Hall). It's a
string-manipulation language so can do anything at a pinch. That might
be the quickest solution since it already has built-in error handling
etc.

'The UNIX Programming Environment' by Kernighan & Pike, Prentice Hall,
has a worked example of how to make an interpreter, including C code.

--
Yours, Patrick
_____________________________________________________________________________

Patrick Herring, Primrose Hill, London, UK
I tend to eat my UUCP feed once a day so replies can take two days

Alex Martelli

unread,
Jan 12, 1996, 3:00:00 AM1/12/96
to
ibms...@sccsi.com (David PC Wollmann) writes:

>I need to write a simple interpreter and a language as part of a
>database conversion program. The language will be used to define the
>source database, reporting, error handling, target format, etc. I'm
>looking for a good book that deals with interpreters--I've got several
>compiler books but they aren't really much help. A book with example
>code (even fragments) would be very useful as I'm in a big hurry.

Why not just grab a simple readymade language and interpreter from
somewhere on the net and just use it, possibly with tweaks if you
really need some? You can hardly beat such wholesale reuse when
you're in a big hurry. You will of course have to pick one with
copyright conditions that match what you want and need to do with it.
Many are particularly suited to embedding and extending -- lots of
scheme-like or other lisp-like languages, Tcl if you can't/won't use
lisp-like syntax...

After all, the best answer to "I need a wheel, where can I find a book
with examples thereof that I can reuse, I'm in a big hurry" is quite
probably ``lots of excellent makes of wheels are already on the market
at perfectly reasonable prices, and you're probably better off buying
any of those than reinventing your own'' -- particularly since, here,
the already-invented wheels can be free.


Alex

Robert Bernecky

unread,
Jan 14, 1996, 3:00:00 AM1/14/96
to
ibms...@sccsi.com writes in article <95-1...@comp.compilers>:
> I need to write a simple interpreter and a language as part of a
> database conversion program. ...

The source code for a J interpreter {An ascii-based derivative of APL)
is available on waterv1.uwaterloo.ca. You can order it AND Roger Hui's
book "The Implementation of J" from Iverson Software Inc, Toronto, Ontario.
Not very expensive at all..

OR, you could just use J as is -- APL and J are heavily used for such
tasks. In fact, the world's largest collection of numeric data bases
is maintained, supplied, AND delivered in APL.

Bob

Luiz Henrique de Figueiredo

unread,
Jan 15, 1996, 3:00:00 AM1/15/96
to
ibms...@sccsi.com (David PC Wollmann) writes:
>I need to write a simple interpreter and a language as part of a
>database conversion program. ...

Alex Martelli <mart...@cadlab.it> wrote:
>Why not just grab a simple readymade language and interpreter from
>somewhere on the net and just use it, possibly with tweaks if you
>really need some? You can hardly beat such wholesale reuse when

try Lua (see below).

* What is Lua?
Lua is a simple, yet powerful, language for extending applications.
Lua has been developed by TeCGraf, the Computer Graphics Technology Group
of PUC-Rio, the Pontifical Catholic University of Rio de Janeiro, Brazil.
Dozens of industrial products developed by TeCGraf use Lua.

* Some features of Lua
+ a simple, pascal-like, syntax
+ powerful data description constructs (e.g., associative arrays)
+ user-controlled type constructors
+ fallbacks for extending the language in unconventional ways (e.g.,
inheritance, overloading)
+ garbage collection
+ Lua programs are compiled into bytecodes, which are then interpreted
+ portable, written in ANSI C (runs in Unix, DOS, Windows, Mac, Cray, ...)

* Availability
In Brazil: ftp://ftp.icad.puc-rio.br/pub/lua/lua-2.2.tar.gz
In Canada: ftp://csg.uwaterloo.ca/pub/lhf/lua/lua-2.2.tar.gz
Home page: http://www.inf.puc-rio.br/~roberto/lua.html

* Legal matters
Lua is freely available for both academic and commercial purposes.
Lua is not in the public domain; TeCGraf keeps its copyright.
See COPYRIGHT.

* Changes since version 2.1 (current version is 2.2)
+ functions now may be declared with any "lvalue" as a name
+ garbage collection of functions
+ support for pipes

* Changes since version 1.1
+ object-oriented support
+ fallbacks
+ simplified syntax for tables
+ many internal improvements

* Installing
To make, simply type domake.
If make succeeds, you get an interpreter in ./bin/lua.
If make fails, please let me know.
The libraries are in ./lib. The include files are in ./include.
You don't need the other directories for development.
There is a reference manual in ./doc, and tests and examples in ./test.
This distribution is biased towards SunOS 4 with gcc but it is simple to
change the Makefiles for other systems, if necessary.
If you are running SunOs, type also "domake dynamic" to build shared
libraries in ./lib.
If your system does not have "popen", then change ./clients/lib/Makefile.

* Contacting the authors
Send your comments, bug reports and anything else to l...@icad.puc-rio.br.
Please send me email if you download Lua so that we can know how far it goes.
--
Luiz Henrique de Figueiredo l...@csg.uwaterloo.ca
Computer Systems Group, Department of Computer Science, University of Waterloo
Waterloo, Ontario, Canada N2L 3G1 (519) 885-1211 x5517, fax (519) 746-5422

Francis Burton

unread,
Jan 27, 1996, 3:00:00 AM1/27/96
to
l...@csg.uwaterloo.ca (Luiz Henrique de Figueiredo) writes:
>
>try Lua

Lua is a splendid piece of software, imho -- very clean language
design, powerful through its reflexivity, nice API. The documentation
is a pleasure to read. Would that all software were as neat as Lua!

It also appears to be quite portable. I don't know if it was ever
intended to be used in the MS-DOS environment, but I got it running
more or less "out of the box". Borland C 3.1 compiled all the files
fine. There was a warning for some files: "Undefined structure 'hash'"
which I corrected by including hash.h in the pertinent files. The test
program executed all but one of the sample scripts correctly. Frankly,
I was amazed and delighted.

However, the script long.lua failed spectacularly crashing the DOS
session I was running under Windoze. This script creates an array of
5000 descending integers by adding them one at a time, selection sorts
them into ascending order and prints the 512th element. Using Bounds
Checker to screen memory accesses I discovered that the fault occurred
when a vector node occupying more than 64k bytes memory was created
and initialised (in hashnodecreate). Of course, this was the old
segmented memory problem: pointers in the large memory model wrap
round at 64k. Recompiling using the huge memory model didn't work --
I think pointers have to be declared as 'huge' too.

I'd love to be able to use Lua in my DOS programs, so if anyone can
think of a simple solution to this I would be extremely grateful.

Francis

[maybe followups should be set out of comp.compilers, to
comp.os.msdos.programmer?]

Ranjan Bhattacharya

unread,
Jan 31, 1996, 3:00:00 AM1/31/96
to
ibms...@sccsi.com (David PC Wollmann) writes:
> I need to write a simple interpreter and a language as part
> of a database conversion program. ...

You may have a look at the good old "The Unix Programming Environment"
- Kernighan & Pike. (Prentice-Hall). It has the complete design and
code for a simple interpreter.

Hope this helps.

--
--
Ranjan Bhattacharya
MSMAIL: ranjan.bh...@fmr.com
UNIX: sy7...@vantage.fmr.com

0 new messages