[A83] Re: Compiled BASIC ?


[Prev][Next][Index][Thread]

[A83] Re: Compiled BASIC ?




Ahh, I remember reading that a long time ago.  It's an interesting
technique, but not very useful for doing anything complicated or optimized.
Attempting to write a lexer or parser for anything non trivial by hand is
not recommended.  There are tools that have been around for a long time
designed to do this for you: Lex and YACC.  There are free programs that are
upwards compatible with these, Flex and GNU Bison, which most people use.  A
good example of a non trivial language that uses these tools is PHP 4.  Take
a look at the source for PHP, and look at the input files for flex and
bison, then look at the generated code.  It's very easy to see why you don't
want to be writing parsers by hand.

These tools don't do everything, but they will get you started.  I found an
interesting tool, treecc, that handles abstract syntax trees:

http://www.southern-storm.com.au/treecc_doc/treecc_toc.html

If you are truely interested in building compilers, there is one book you
must read:

http://www.amazon.com/exec/obidos/ASIN/0201100886/

That book is the reference on compilers.  It is used as the textbook for
many compiler construction courses.  It is tough to get through, but if you
read it at least a couple of times, you will be amazed at all the
information it contains.

Lex and YACC are not something you can just jump into using.  There is an
O'reilly book on the subject, but it got mixed reviews on amazon.com and I
haven't read it, so I can't really comment on it.  But when you're stuck on
something, another reference is always good.  I did find a howto on the
subject, that provides some nice information and lists some more books on
the subject (including the O'reilly book and Compilers):

http://ds9a.nl/lex-yacc/

If you're interested in discussing compiler design techniques, feel free to
email me :)

> This link right here:
> http://compilers.iecc.com/crenshaw/
> explains how to write a compiler that converts basic
> to assembly with pascal source code.  It is a very
> long document, but I just thought it might be
> interesting to some people that were considering
> working on one of these compilers.






Follow-Ups: References: