[antlr-interest] Re: one question regarding tree walking plz help

kozchris csnyder at alumni.ncsu.edu
Wed Nov 17 06:38:20 PST 2004



i think your problem is that your code block is in the wrong place. 

try this:
variable_definition 
 : #(TYPENAME t:typeName (i:IDENT { 
 
 System.out.println("The NAME of the Auxilary variable is : +i.getText());
 
 System.out.println("The type of the Auxilary variable is : +t.getText());
 
}
  )+ 
) ;

that should run for each IDENT.
What you had ran for the entire rule. E.G. once.

Chris


 
 

--- In antlr-interest at yahoogroups.com, Muhammad Masoom Alam
<doublemalam at y...> wrote:
> Dear all.
>  
> i will be more specific in this email to my problem
> i will state my problem in the following points.
>  I have a small language for which i want to do syntax and sematic
checking. 
> 
>    As for as syntax checking is concerned , i am able to do it with
Parser and Lexer of ANTLR and that is no problem 
>    but when it comes to semantic checking, where i need to build a
tree and then later on parse the tree(i.e. extract tree node values ,
so that i can check according to my logic and to have some fruit ful
results ,    my work fails) and so far , i have no help regarding this
over the internet.
>             suppose i have a rule in my Parser file i.e.
>              startrule
>                         : ( VAR! (variable_definition SEMI! )+)?
>                         ;
>           
> variable_definition : typeName ( IDENT (COMMA)? )+
{#variable_definition = #([TYPENAME,"TYPENAME"],#variable_definition);} 
> 
>                         ; 
>                                                                       ;
>      now rule state that 
>             if i have an expression var int i,j,k; real a,b,c;
>  
>    it should make TYPENAME as root and int , i , j , k as childs.
> similarly   TYPENAME as root and real a,b,c as childs.
>  
> that is done becaz when i print the tree , it gives me the results
like this 
> 
> ( TYPENAME int I , j ,k ) ( TYPENAME real a , b, c )
> 
> The problem is that i cant read the tree in the Treewalker section 
> 
> if i specify a rule in tree walking section like this
> 
> variable_definition
> 
> : #(TYPENAME t:typeName (i:IDENT)+ )
> 
> { 
> 
> System.out.println("The NAME of the Auxilary variable is :
"+i.getText());
> 
> System.out.println("The type of the Auxilary variable is :
"+t.getText());
> 
> }
> 
> it does give me just first child and next sibling but not more. how
i can take infinite sibling nodes 
> 
> I am enclosing the JAVA file and grammar file and if you give the
input as follow
> 
>  var int I,j,k;real a,b,c;
> 
> you will see a tree and other results.
> 
> whether i am wrong in the tree construction , or i am doing some
other error.
> 
> I will be very thankful to you for your kind time .
> 
> with Best Regards.
> 
> Muhammad.
> 
> 
> 
> 
> 		
> ---------------------------------
> Moving house? Beach bar in Thailand? New Wardrobe? Win £10k with
Yahoo! Mail to make your dream a reality.





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list