[MUD-Dev] Storing tokens with flex & bison

Jon A. Lambert jlsysinc at ix.netcom.com
Sun Jan 2 20:13:24 New Zealand Daylight Time 2000

Christer Enfors wrote:
>On Sat, 1 Jan 2000, Jon A. Lambert wrote:
>> Christer Enfors wrote:
>> On Sat, 1 Jan 2000, Chris Turner wrote:
>> >> 
>> >> The O'Reilly Lex & Yacc book is well written and contains many tutorials.
>> >
>> >Right, but it doesn't have a tutorial that involves storing the source
>> >code in any format for later execution, which is what I'm looking for in
>> >this case.
>> Nod.  In order to use a byte code, one must first design and implement
>> a virtual machine, or target it for an existing VM (i.e. Java)
>> I think what you are looking for is documentation on designing Virtual
>> Machines.  The way I learned was by snooping through all the notes,
>> examples, and syllabus (syllabi?) left out on the net by university professors
>> teaching it.  For some reason the CS course numbers (505 and 565) seem
>> familar, though it has been a couple years.  :-( 
>> There's Sun's Java VM doc, the Smart tiny VM, the Luck VM, the ANTLR 
>> tutorial by Scott Stanchfield(?) that implements a language called
>> X.  I don't know offhand of any books that cover VM design in depth.  
>Ah, now the pieces are starting to fall into place.
>I am not supposed to use lex & yacc for the execution at all, am I? I
>thought I was. 

Well, Bison can act as an executable interpreter, but it's probably not an
ideal vehicle for processing a mud programming language/script.
Also, you might want to take a look at the Interlude server.  I think Chris has
a copy on ftp.kanga.nu.  Interlude uses lex as a scanner but implements
an RD parser by hand.   

>All I should use lex & yacc for is the source code to byte
>code compilation, right? And since my byte code is so clever / simple, I
>can code the VM manually in C, without needing lex & yacc? Am I on the
>right track now? =)

Yes. :-)  BTW, writing scanners and recusive descent parsers is easy.
Definitely read the Crenshaw tutorial.   The CoolMUD VM is a simple
and well-written example of a VM.

Like JC Lawrence and Chris Gray I've written my own scanners and recursive 
descent parsers.  Personally, I'm a bit anal about not using globals, having 
readable and debugable code.  Yacc and Bison generate extremely ugly

On the other hand, ANTLR (formerly PCCTS) generates fairly readable and 
passable object-oriented C++ code.  I wrote the grammar for Aphrodite using
ANTLR and debugged it using ANTLR's Parseview tool.  ANTLR's notation 
is better than Bison/Yacc because you can write a handmade RDP by hand 
by just looking at the grammar notation itself.   Crenshaw talks about how to do 
this with BNF notation.  Bison/yacc grammars use very confusing notations to
show precedence and resolve syntax conflicts.    

Oh and here's the link to Stanchfield's XL compiler/Antlr tutorial :
<URL: http://www.javadude.com/articles/antlrtut/>

--*     Jon A. Lambert - TychoMUD Email: jlsysinc at nospam.ix.netcom.com     *--
--*     Mud Server Developer's Page <http://jlsysinc.home.netcom.com>      *--
--* "No Free man shall ever be debarred the use of arms." Thomas Jefferson *--

MUD-Dev maillist  -  MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list