[antlr-interest] Problem with Tree Parser

Steven Robenalt sarobenalt at yahoo.com
Mon May 16 15:46:09 PDT 2005


Hi all,

I'm having trouble with a tree parser that I'm just
starting to build based on the Standard C parser. I'm
using the GnuCTreeWalker/GnuCEmitter as the starting
point, but this particular problem doesn't seem to be
related to the grammar itself.

In brief, I am attempting to parse a simple (no
preprocessor directives) header file containing only
structure declarations. The parser generates what
appears to be a complete and valid AST using automatic
AST generation. The tree parser is then applied to
simply convert the parse tree back to an equivalent
declaration. 

After all of the field declarations in the structure
have been emitted, The tree parser halts with a
ClassCastException when it encounters an ASTNULLType
node and tries to typecast it to a TNode:
 
     return (TNode)_t; 

where _t is ASTNULLType at this point in the parse.
Unfortunately, although ASTNULLType and TNode both
have a common ancestor interface, the classes are not
compatible for a type cast to TNode. This doesn't
appear to me to be related to the grammar, but rather
with the TNode class as related to a built-in ANTLR
type. I would appreciate hearing from anyone who may
have encountered this problem, particularly if you
have done any useful work with the example C grammar.
In particular, I would like to know if there is a
workaround or if I need to add something to the
grammar file to handle this situation.

I could post the grammar file, etc. but it would be
easier to use the posted example C grammar directly to
parse a struct declaration since I really haven't
deviated from it significantly at this point in the
process.

Thanks for any help you can offer,
- Steve Robenalt
sarobenalt at yahoo.com




More information about the antlr-interest mailing list