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

Terence Parr parrt at cs.usfca.edu
Mon Sep 11 09:23:31 PDT 2006


On Sep 11, 2006, at 9:17 AM, Vinh N. Pham wrote:

> 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.

Hooray!

>    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.

You can use whatever tree type you want.  Set ASTLabelType I think as  
an option  in the grammar.

>    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

That differs by an ID...how are you differentiating them?

Ter



More information about the antlr-interest mailing list