[antlr-interest] best way do type-checking

Micheal J open.zone at virgin.net
Fri Sep 15 08:21:36 PDT 2006


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.



More information about the antlr-interest mailing list