[antlr-interest] 回复: Re: best way do type-checking

孙纪刚 Jigang (Robert) Sun sunjigang1965 at yahoo.com.cn
Sun Sep 17 05:31:55 PDT 2006


>From v3 introduction, I know it supports parameter passing to sub rule and a rule can return
mutiple results. With this function, I can excute actions while walking AST. Unfortunately
currently it could not generate c#. Who knows when?

--- Micheal J <open.zone at virgin.net>写道:

> Hi,
> 
> > I am using 2.7.7 and target language is c#.
> > 
> > For doing type checking, I feel I have to generate a class 
> > object for each rule when I walk the AST generated during 
> > parsing, then fall to use the coventional visitor method. 
> > Could anyone tell me if this is right way that antlr expects? 
> 
> There is no right way that ANTLR expects.
> 
> If your AST is an homogenous ANTLR AST (all nodes are instances of the same
> type), you can use ANTLR TreeParser(s) or you could write your own ad-hoc
> type checker (like Andy Tripp does).
> 
> If you wish to use the visitor pattern with ANTLR ASTs, you should develop
> and use heterogeneous ANTLR AST nodes.
> 
> Otherwise you could use a custom AST implementation with the visitor pattern
> (or some other ad-hoc solution). The TreeDL toolset
> (http://treedl.sourceforge.net/) can generate a lot of the code for the AST
> Nodes as well as visitor templates etc for you in this case. I've tested the
> C# output and it does work reasonably well.
> 
> 
> Micheal
> 
> -----------------------
> The best way to contact me is via the list/forum. My time is very limited.
> 
> 



		
___________________________________________________________ 
雅虎免费邮箱-3.5G容量,20M附件 
http://cn.mail.yahoo.com/


More information about the antlr-interest mailing list