[antlr-interest] Appropriate pattern for interpreter

Mark Bednarczyk voytechs at yahoo.com
Sun Mar 12 12:19:14 PST 2006

I enjoyed reading the article and thead hread with pros and cons
of TreeWalkers by Andy Tripp, but I'm still not sure where my
preference lies. I have implemented my own language (NPL -
Network Protocol Language) geared toward describing network
protocol structure using manual Lexer/Parser and then the
Visitor pattern. This is an interpreted language executed
directly from the AST.
I'm redoing the interpreter and I have already replaced
Lexer/Parser using ANTLR grammar which is actually a superset of
java.g grammar since NPL 90% based on java syntax.
One thing I really don't like about the Visitor pattern is that
the Linker and the Decoder which both use the Visitor pattern,
are huuuugggggeeee. Too big for my taste. I like to break things
up into smaller more managable pieces. It seems to me that the
TreeWalker aproach is simply going to produce a huge TreeWalker
file with the mix of languages.
Andy's approach of looking things up in the AST seems simple on
the surface, but from my experience I could not do it. I had to
pass around state using parameters and some global (within the
class) structures.
The NPL syntax if very rich, all the java statements,
conditianals and operators plus a number of custom ones thrown
in. Stuffing all this logic into a single file is really going
to bloat it, no way around that.
Are there other algorithmic patters that I should consider? I
really only know of the TreeWalker and the Visitor. Is there
anything else that might work better for an interpreter?
One of the things I've considered is simply cross compiling NPL
into java. I'm kind'of afraid of going the TreeWalker approach
since the syntax seems complex, the file is going to end up
being huge and I've gained huge amount of experience with the
Visitor pattern approach (whether I like it or not.)
You guys have all the experience in the world here. I really
would aprechiate some insight or direction from experienced
compiler guru.
Linker.java source:  http://tinyurl.com/f4jx2
Decoder.java source:   http://tinyurl.com/z27hs 
Project pages: http://jnetstream.sourceforge.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060312/224e590d/attachment.html

More information about the antlr-interest mailing list