[antlr-interest] Question about antlr 3 AST tree building

Vinh N. Pham vnpham.us at gmail.com
Mon Sep 11 09:17:22 PDT 2006


Hi,
    First of all, I would like to thanks the antr developers for the 
wonderful tool.  It is one of the best parser generators I've ever used.
    I'm currently have some difficulty of using antlr 3.  In one of my 
project, I want to write a parser for a language, produce the AST for 
other developers to use as input so that they can get the information 
and do whatever translations they want.  Since most of other developers 
are not computer scientists, I think it is best to describe the AST tree 
in term of the target language (Java or C++) for them without referring 
about antlr or tree parser/walker at all because that means they have to 
learn another tool.  However, in antlr 3, the tree construction 
mechanism only build tree with type Object, and it is difficult to get a 
particular data member because it doesn't have a descriptive name.  Of 
course, I can create the whole tree manually but I'm hoping there are 
some mechanisms in antlr 3 to do this automatically.  After all, all 
information needed are already in the grammar file.
    Also, if even if we use the tree parser, what should we do if we 
need more than one way to do the translation from of the same node (an 
expression node for example)?  Using more than one tree parser may be a 
little bit confusing.

    for example, can we do this in the same grammar file
        subroutineName1=expression: ......... will be translated to 
subroutine named subroutineName1
        subroutineName2=expression: ......... will be translated to 
subroutine named subroutineName2

    Please let me know what I should use

Thanks,

Vinh N. Pham


More information about the antlr-interest mailing list