[antlr-interest] Re: one question regarding tree walking plz help
Muhammad Masoom Alam
doublemalam at yahoo.co.uk
Wed Nov 17 10:08:05 PST 2004
really thanks man
u really helped me to out of this situation , The problem is resloved but still i after the parsing of the tree , i get the excetpion that
var int a,b,c;real d,e;
s
( TYPENAME int a b c ) ( TYPENAME real d e )
The NAME of the Auxilary variable is :a
The type of the Auxilary variable is :int
The NAME of the Auxilary variable is :b
The type of the Auxilary variable is :int
The NAME of the Auxilary variable is :c
The type of the Auxilary variable is :int
The NAME of the Auxilary variable is :d
The type of the Auxilary variable is :real
The NAME of the Auxilary variable is :e
The type of the Auxilary variable is :real
<AST>:0:0: unexpected AST node: int
<AST>:0:0: unexpected AST node: real
i dont know why these two exceptions occur,
but any way Thanks again.
with Best regards.
Muhammad.
kozchris <csnyder at alumni.ncsu.edu> wrote:
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
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
---------------------------------
ALL-NEW Yahoo! Messenger - all new features - even more fun!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20041117/b4538fcc/attachment.html
More information about the antlr-interest
mailing list