[antlr-interest] ANTLRWorks and separate lexer/parser grammars - pleading?

Mark Volkmann r.mark.volkmann at gmail.com
Fri Jan 18 13:53:37 PST 2008


The big lesson learned in this for me is that
if my parser grammar builds an AST
and the lexer rules are combined with it in a single file
then I can debug the AST generation in ANTLRWorks
without writing any Java code

but ...

if my parser and lexer rules are in separate files
then I have to write Java code and run it in order to use the
ANTLRWorks debugger.

Correct?

On Jan 18, 2008 3:30 PM, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> I figured out the issue. In my Java code that uses the generated
> classes I was creating my parser and tree parser objects by passing
> null to the constructor and then later calling setTokenStream on the
> parser and setTreeNodeStream on the tree parser. You can't do that
> when you compile with debug because the generated constructor for the
> parser class will do this.
>
> setTokenStream(new DebugTokenStream(input,proxy));
>
> That means null is passed to the DebugTokenStream constructor which is
> why I was getting the NullPointerException.
>
> I can work around this for now by not creating my parser and tree
> parser objects until I know what stream I want them to use.
>
> I've got it working now. Thanks!
>
>
> On Jan 18, 2008 3:18 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> >
> > On Jan 18, 2008, at 12:55 PM, Mark Volkmann wrote:
> >
> > > On Jan 18, 2008 2:29 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> > >> run -debug on the parser grammar from command line.
> > >
> > > Okay, I added the "-debug" option when running org.antlr.Tool on my
> > > grammar files.
> >
> >   only run it on the one grammar you want to debug.
> >
> > >> compile.  start
> > >
> > > The code generated with -debug compiles fine, but when I run it I get
> > >
> > > Exception in thread "main" java.lang.NullPointerException at
> > > org
> > > .antlr.runtime.debug.DebugTokenStream.<init>(DebugTokenStream.java:45)
> > >
> > >
> > > Do I have to do something different in my code that uses the
> > > generated classes?
> >
> > Hm.... This doesn't happen for me.  Try again only using -debug on the
> > parser grammar.
> >
> > Ter
> >
>
>
>
> --
>
> R. Mark Volkmann
> Object Computing, Inc.
>



-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list