[antlr-interest] How to interpret object creation sentence?

Alexey Demakov allex at all-x.net
Wed Feb 1 22:26:07 PST 2006


If you need to create object for the given class name you can use CreateInstance method in Assembly class.
Assembly is returned by the correspondent property of System.Type class.

System.Type type = ...;
object instance = type.Assembly.CreateInstance( fullName )

But it is not so easy - you need to know fully qualified name of class to create, not just last identifier.

---
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com

  ----- Original Message ----- 
  From: Ëï¼Í¸Õ Jigang (Robert) Sun 
  To: antlr-interest at antlr.org 
  Sent: Thursday, February 02, 2006 4:16 AM
  Subject: [antlr-interest] How to interpret object creation sentence?




  Now I want to interpret an object creation with actions in C#, source syntax like "new ClassName()",  objective code is the same, such as" ClassName aObject=new ClassName();"

  The first grammar is refused by C# compiler,
  createObject returns [Object o=null]
   :
   "new" id:ID LPAREN RPAREN { o= new  id.getText()+"()";} 
   ;

  The second just return a string, e.g. "new ClassName ()",
  createObject returns [string r=null]
   :
   "new" id:ID LPAREN RPAREN{r= "new "+id.getText()+"()";}
   ;

  Could any ony give me an idea?

  Jigang




------------------------------------------------------------------------------
  ¿ìÀ´ÑÅ»¢ÓÊÏä·¢ºØ¿¨£¬°Ý´óÄêÀ²£¡ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060202/55629ea9/attachment.html


More information about the antlr-interest mailing list