[antlr-interest] Tree gramer porblem

atif azad atif.azad at hotmail.com
Tue Sep 18 12:59:33 PDT 2007


Hello Dears
I am have a problem while writing a tree grammer.I want to parse input of 
three types , It takes all the three types recognizes all three types as 
seen in the output but parses in the end only the ist two.
Here is my tree grammer and output for more clarification of the 
problem.would be greatful for some suggestion.

tree grammar langDumpDecl;
options {
    tokenVocab=lang;
    ASTLabelType = Tree;
}

decl :  ^(DECL type comma r1=result comma)
        {System.out.println("text "+$r1.text);}

       |   ^(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);}
     ;


type : INTTYPE  | FLOATTYPE| LABELTYPE;

declarator
     : ID
     ;
comma: COMMA ;
result : RESULT ;

I am getting the following output.

tree: (DECL store r1 r2) (DECL add r2) (DECL .file " 11111.java ")
text r1
text r2
type store
text r2
type add

So its not parsing the last line in the tree.
but if I change the order of the way i am printing the output in the decl 
rule , so that I ahve the last line as the first line in the tree, then it 
parses this one too, But again only the first two lines of the tree. Not the 
third one.

Why is it not able to parse the third line in tree??????

Regards
Azad , Atif

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/



More information about the antlr-interest mailing list