Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools Pccts > Problems with A...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 102 of 134
Post > Topic >>

Problems with AST construction and walking

by Glenn <me@[EMAIL PROTECTED] > May 9, 2005 at 10:27 PM

Hi!

I have to write a "compiler" to transfer eODL-source-codes  to a 
repository. I'm using ANTLR to parse programs and to build up an AST.
I have the following problem:

A possible extract I have to parse:
interface foo : AA::BB::CC , EE::FF::GG {
....
}

It's an interface which inherits from defined interfaces AA::BB::CC and 
EE::FF::GG.
I have to store these inheritance specification:

Interface's names which I collect in the AST don't appear in the rule 
<interface_inheritance_spec>. I only get the first Interface: in my 
example: AA::BB::CC


here the extract from the parser, where interface_inheritance_spec is 
something like :AA::BB::CC

interface_inheritance_spec:
             ":"^ scoped_name ( ","! scoped_name )*
;

scoped_name :
               "::"^ scoped_name_rest        //then it is full qualified
     |         scoped_name_rest
     ;

scoped_name_rest :
             IDENT^ ( "::"! IDENT )*
;

here is the appropriate extract from the tree walker:

interface_inheritance_spec { ArrayList<String> ine; ArrayList<String> 
inr ; } :
       #( ":" ine = scoped_name
               {
                                 System.out.println("##############");
                                 for ( String s : ine ) { 
System.out.println(s); }
                                 System.out.println("##############");
               }
                             (
                                       // this branch never seems to be 
entered, but I need it:-)
                                       inr = scoped_name
                                                     {
 
System.out.println("############## hinteres");
                                                            for ( String 
s : inr ) { System.out.println(s); }
 
System.out.println("############## hinteres");
                                                     }
                             )*
       )
;


// That seems to work well! debug printing of ArrayLists works.
scoped_name returns [ ArrayList<String> strs ] { ArrayList<String> in; 
strs = new ArrayList<String>(); } :
         #( "::" in = scoped_name_rest )
                     {
                                 in.add("::");
                                 return in;
                     }
     |    in = scoped_name_rest
                     {
                                 strs = in; return strs;
                     }
     ;

scoped_name_rest returns [ArrayList<String> strs] { strs = new 
ArrayList<String>(); int i = 0;} :
             #( ide:IDENT
                                 {
                                          strs.add(ide.getText());
                                 }
                         ( idr:IDENT
                                         {
 
strs.add(idr.getText());
                                         }
                         )*
             )
             {
                  return strs; }
         ;





Thank you very much!!!
Bye, Glenn.
 




 1 Posts in Topic:
Problems with AST construction and walking
Glenn <me@[EMAIL PROTE  2005-05-09 22:27:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 14:27:11 CDT 2008.