[antlr-interest] Debugging ANTLR tree grammar...
The Researcher
researcher0x00 at gmail.com
Wed Apr 6 18:08:43 PDT 2011
This is not an exact answer to your question, but a possible direction to
take for solving your problem.
I would suggest looking at the AST from the parser using ToTokenString() and
ToStringTree().
ToTokenString() will print the AST as a stream of tokens, with DOWN and UP
tokens noted in the error message.
ToStringTree() will print the AST using nested ( ), and is more human
readable.
Since these are two different perspectives of the same AST, by comparing
them you will soon notice that DOWN corresponds to ( and UP corresponds to
).
*pseudo code* for the conversions.
Parser parser = new Parser(nodes);
Paser.startrule_return parseResult = parser.startrule();
CommonTree ast = ((CommonTree)parseResult.Tree);
CommonTreeNodeStream astTokens= new CommonTreeNodeStream (new
CommonTreeAdaptor(), ast);
Print(astTokens.ToTokenString());
Print( ((CommonTree)ast).ToStringTree() );
If you plan on spending more than a few days on this, I would strongly
recommend getting "The Definitive ANTLR Reference" and possibly "Language
Implementation Patterns" by Ter.
More information about the antlr-interest
mailing list