Hi Nishanth,

Please try to ask more specific questions.  This list is not the place 
to have your parser project done for you.  Summer interns are supposed 
to do that!

That said, you might have an easier time if you don't construct an AST. 
  Instead you can build your data structure as you parse.  Here's what I 
mean (my example is in Java):


grammar Example

options {
  language = Java;
}

@members {
   private HashMap<String,Integer> MyMap;
}

file
   returns [HashMap<String,Integer> rval]
   @init {
     MyMap = new HashMap<String,Integer>();
   }
   @after {
     rval = MyMap;
   }
   : list_item* EOF
   ;

list_item
   : str:ID '=' num:INT
     {
       Integer myint = Integer.parseInt($num.getText());
       MyMap.put($str.getText(), myint);
     }
   ;

ID : ('a'..'z' | 'A'..'Z')* ;

INT : ('0'..'9')+ ;

WS : (' '|'\r'|'\n'|'\t')+ {$channel = HIDDEN;} ;


In this example no AST is made.  Instead a Java HashMap is built.  This 
is probably similar to what you want.  The HashMap is returned by the 
'file' rule instead of an AST.  Please note that if you tell ANTLR to 
build an AST you will have an error, so turn AST building off.  The 
above code will not produce anything if there's a parse error.  This is 
also probably what you want.

If you follow up to this reply, please ask a specific question!

Cheers
./m

Nishanth singh wrote:
> Hello,
> 
> Kindly read the mail completely and please reply back to me.
> 
> I am a student doing an intern this summer . I was given a task of
> building a compiler using antlr. I read the book called "The
> definitive antlr reference" and was able to build the grammer which
> generates an abstract syntax tree and parse the data file and check it
> for errors. Now using the parser and lexer files generated they want
> me to convert the tree into a list structure of C sharp code. I am
> having no idea of how to do it. I searched a lot in the net but
> couldnt find it. There is no one in my work place who knows antlr. I
> am really getting depressed  because of this. If any one can help me
> please reply to me. Please help me guys I am really frustated.
> 
> 
> 
>                                                                  Regards,
>                                                                  Nishanth.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to