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

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Jun 20 23:03:23 PDT 2002


Micheal--

If you are writing a new grammar, then "predicates are your friend" is 
good practice for getting past the "Omigod--look at all these 
warnings" stage.  Wherever you have an ambiguity warning that you 
cannot figure out quickly, insert a (syntactic) predicate to 
disambiguate alternatives.  Also, consider inserting semantic 
predicates as "assertions".  Once you get a warning-free antlr pass, 
verify that the generated language processor properly recognizes your 
test input (catch exceptions in the debugger at the point where they 
are thrown).  You may want to have a test version of your language 
processor which produces some sort of text output that can be fed to 
"diff" for regression testing.  Once you get the translator working, 
then go back and refactor on a predicate-by-predicate basis--it's a 
lot easier to clean up ambiguities when you know where to look, and 
having a test suite to run makes it easier to verify correct operation 
after each change.

That approach works for me--ANTLR gives very good visibility for 
testing.  "Debugging" is not a good mindset--it is easy to move 
ambiguities around instead of fixing them.  Cleaning up a working 
grammar to remove syntactic predicates is much easier than getting the 
grammar to work in the first place.

--Loring

--- In antlr-interest at y..., "micheal_jor" <open.zone at v...> 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/ 



More information about the antlr-interest mailing list