[antlr-interest] Repost: ANTLRworks: Why do these rules behave differently in the embedded interpreter?

Kyle Ferrio kferrio at gmail.com
Fri Jan 1 17:53:24 PST 2010


On Fri, Jan 1, 2010 at 5:28 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> yeah, the interp has never been quite right...just haven't had time to
> fix. now that book is done (printed just about now I guess) I can get
> back to ANTLR.
> Ter

Cool.  Having not looked at the code, I might have guessed that Jean
Bovet was the guy to talk to about the AW interp.  I'm glad I posted
to the list.  Yep, looks like your book will ship at just the right
time to maximize the number of questions you get during midterms.
lol.  There is no rest for the creative mind.

I had a crazy (read: probably deeply flawed) idea while playing with
ANTLRWorks and the ANTLR IDE.  As I tried to black-box about what
might be going on inside the interp, I thought about how the
java-targeted output always ran fine.  And so I began to appreciate
all over again some of the challenges faced by anyone trying to write
a fault-tolerant interpreter.  I realized that much of the work is
probably redundant with what has already been done for the target
codegen.  So, I thought, why not just build and run the target?  Sure,
codegen takes a second, and compiling to bytecode takes another
second.  So what?  Small price for knowing it's right.  Ok, but what
about drawing concrete syntax trees?  No problem, just insert actions.
 Ok, but what about debugging with single stepping and peeking into
state variables?  No problem, just insert a callback to the GUI at
each decision point.  In fact, it might even be possible to make
predicates work in such an interp, by either "gating off" the
callbacks or just "marking in the debugger" when we're processing a
predicate.  Sure, an "instrumented parser" may be an ugly way to
implement an interp.  But if fidelity to the final product is a goal,
as in emulators, then speed and beauty may be negotiable.  How far out
in left field am I?  I realize that the objective of this line of
reasoning may be to solve a problem outside the intended scope of
ANTLRworks.  I assumed without justification that the interp would
"tell me how my grammar would perform."  But that is not at all the
same as "being a tool for demonstrating simple cases."  So I have no
basis for critiquing the interp, and I'm surely not suggesting a
course of action.  And before I dig a deeper hole for myself, I
preemptively apologize for not having time to implement any of this.
But maybe there's the germ of a class project in this for someone.

Kind Regards,
Kyle


More information about the antlr-interest mailing list