[antlr-interest] ANTLRworks vs. Stand-Alone Parser

Thomas Brandon tbrandonau at gmail.com
Tue Jun 26 07:17:57 PDT 2007


On 6/26/07, Randall R Schulz <rschulz at sonic.net> wrote:
> On Tuesday 26 June 2007 06:38, Thomas Brandon wrote:
> > On 6/26/07, Randall R Schulz <rschulz at sonic.net> wrote:
> > > Hi,
> > >
> > > I have a grammar, that's working (though far from complete). It's
> > > does not appear to be parsing the inputs the way I intend, so I
> > > wanted to look at the parse tree in the ANTLRworks Interpreter
> > > pane. The problem is that input that is parsed successfully when I
> > > run the parser on its own (outside ANTLRworks) just gives a one or
> > > two derivations (depending on which non-terminal I choose as the
> > > start symbol) and then NoViableAltException. ...
> > >
> > > Am I doing something wrong? Why the discrepancy between the parser
> > > when executed on its own and when executed within ANTLRworks? ...
> > >
> > >
> > > Randall Schulz
> >
> > The ANTLRWorks interpreter does not execute actions, including
> > predicates.
>
> Why not?
I believe the interpreter mode does not compile grammars but instead
uses custom support in ANTLR to go through the grammar without
actually generating any code. So executing actions would be very
difficult (if not impossible) in this case.
>
>
> > So if your grammar uses predicates or actions which alter
> > the lexing\parsing behaviour it will not work in the ANTLRWorks
> > interpreter.
>
> At the moment, I have no syntactic predicates and no actions other than
> some simple println() calls. However, I seem to recall from looking at
> the generated code recently that when you use the backtracking option,
> which I am, ANTLR itself can generate syntactic predicates, right?
>
> So might that explain the discrepancy?
Yes, backtracking auto-generates predicates wherever needed to resolve
ambiguities so it would not in general work in the interpreter.
>
> > The ANTLRWorks debugger does do actions properly and should be
> > identical to running externally (apart from classpath issues which
> > may necessitate external debugging).
>
> OK. I guess I'll try to make that work. I've never had success in the
> past, and have been deterred by the complications from trying hard
> enough to make it work.
>
> E.g., at the moment there's a diagnostic in the console telling me about
> class file version incompatibility (found 50.0, wants 49.0)...
Not quite sure but sounds like different java versions are being used
to compile the grammar and to execute it. Check out the Compiler tab
in ANTLRWorks' Preferences and make sure it has the right JDK path.
And ensure that ANTLRWorks is being executed on the correct JDK.
After debugging code is generated (done when you do Debug, or you can
specify -debug as an option to ANTLR) you can also execute the
resulting class externally (as you would normally) and then do Debug
Remote to attach to this parser. Note that the debugging parser will
wait for a socket connection before parsing, so if you run it and do
not attach ANTLRWorks to it it will just sit there. So if you are
executing code for other tests then you will need to turn off
debugging to do so.

>
> > Tom.
>
>
> Randall Schulz
>
Tom.


More information about the antlr-interest mailing list