[antlr-interest] Simple Question

Tiller, Michael (M.M.) mtiller at ford.com
Fri Jun 13 08:32:31 PDT 2003


As usual, I'm struggling with the best way to structure my AST processing.  I followed the example from the GCC parser and create my own nodes, e.g.:
 
modelica_file
    : (within_clause)? (("final")? class_definition SEMI!)* EOF!
        { ## = #([FILE, "FILE"], ##); }
    ;

 
Note, specifically, the use of "#([FILE, "FILE"], ...)"
 
Now I'd like to use my own AST class for this node so I can associate additional "meta" information (i.e. data that gets generated as I make a few passes over the tree).  My personal preference is to have specific classes for each AST node.  I know you can do it in a generic way, but it just doesn't feel right to me.
 
OK, enough on that, here is the issue.  My token section looks like this:
 
tokens {
    FILE<AST=FileNode>; DECLARATION; DEFINITION; FUNCTION_CALL; TYPE;
   ...
}
 
Note the "File<AST=FileNode>..." part.
 
I would have thought that the combination of defining this special token (and the custom AST that goes with it) along with the tree construction shorthand would have created an appropriate "initialFactory" method for my parser that would have mapped a FILE token to a FileNode.  This doesn't happen.  It appears that ANTLR doesn't do this automatically for these "synthetic" tokens (ones that do not originate from the lexer).
 
So, is my assessment correct (i.e. this feature doesn't work with synthetic nodes...of which I have *many*).  Or am I doing something wrong?
 
--
Mike
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030613/a81ac8ce/attachment.html


More information about the antlr-interest mailing list