[antlr-interest] What tool[s] do you use when debugging ANTLR grammars?

Greg Lindholm glindholm at yahoo.com
Thu Jun 20 21:04:49 PDT 2002

The two things I've found helpful is:

1) In the parser override reportError() so that it prints type (name)
of the token and prints a stack trace. The default reportError() only
prints the text of the token which is often not enough if you have a
bug in your lexer.

    // Override default error reporting
    public void reportError(RecognitionException ex) {
        if (ex instanceof NoViableAltException) {
            NoViableAltException e = (NoViableAltException) ex;
                 "("+ MyParser._tokenNames[e.token.getType()]+")");

2) When things get really tough I build with the "-T" option to print
trace info.


--- micheal_jor <open.zone at virgin.net> wrote:
> Following on from my grammar debugging issues and recent ParseView 
> post, I'd like to know what tools others rely on for debugging 
> grammars.
> I've re-written my grammar many times already due to a number of 
> seemingly intractable warnings/errors. I am just about to rewrite 
> again but this time I am starting off by designing an heterogenous 
> AST structure and working my way back from that to the grammar.
> So what tools do you use for grammar debugging and, what tips can you
> offer an ANTLR newbie on grammar creation and debugging?
> Micheal
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/ 

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list