[antlr-interest] help: scanning multiple lines of input

atif azad atif.azad at hotmail.com
Thu Sep 13 01:25:05 PDT 2007


Thankyou very much for the replies.
I am using decl+ as shown below. But in my tree grammer this is what i have 
in my grammer.May be I am not printing the nodes in the right way in the 
tree grammer.
I copy it

start : decl+ ;
decl : ^(DECL type declarator+ )
        {System.out.println("text "+$declarator.text);}
       {System.out.println("type "+$type.text);}
      |^(DECL type d1=declarator d2=declarator )
             {System.out.println("text "+$d1.text);}
   {System.out.println("text "+$d2.text);}
       {System.out.println("type "+$type.text);}
     ;

which corresponds to these rule in grammer

start : decl+ ;
decl : (type ID) ';' -> ^(DECL type ID)
       | (type ID ID)';' -> ^(DECL type ID ID)


I may be doing some thing wrong while printing the nodes in my tree garmmer.


Regards
Azad , Atif




>From: Gavin Lambert <antlr at mirality.co.nz>
>To: "atif azad" <atif.azad at hotmail.com>,antlr-interest at antlr.org
>Subject: Re: [antlr-interest] help: scanning multiple lines of input
>Date: Thu, 13 Sep 2007 19:36:56 +1200
>
>At 17:19 13/09/2007, atif azad wrote:
> >and output i get is like this
> >
> >tree: (DECL add r2) (DECL store r2 r2)
> >text r2
> >type add
> >
> >But I want output like this
> >
> >tree: (DECL add r2) (DECL store r2 r2)
> >text r2
> >type add
> >text r2 r2
> >type store
>[...]
> >		langDumpDecl walker = new langDumpDecl(nodes);
> >		walker.decl();
>
>Assuming that the "decl" rule matches one DECL-rooted tree, the problem 
>would be that you're only calling it once, and hence only recognising one 
>DECL tree.
>
>Either call it in a loop or just create a new rule containing decl* or 
>decl+ and call that in your Main instead (depending on what you want to do 
>with it).
>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the antlr-interest mailing list