[antlr-interest] Re: Problems with token class-type override feature (with C# codegen)

micheal_jor open.zone at virgin.net
Mon Jul 29 12:30:11 PDT 2002


Thanks for the reply Loring:

> Manually constructed AST nodes use the default AST type--Ric says 
that 
> he's fixed that for C++ (although I don't remember if that is yet 
in 
> an available version).  The ASTFactory needs to use a table of 
token 
> values and classes to make this work properly.

OK. I hope Ric can clarify that particular point.

I'll have a quick peek to see if I can coax ANTLR, ASTFactory and the 
C# codegen into doing this myself seeing as I am right in the middle 
of a project.  ;-(

> For automatic construction, ANTLR creates ASTs using the specified 
> classes, but doesn't do typecasting properly.  The solution that I 
> found was to modify the code generation to specify all AST 
variables 
> declared by ANTLR as being of type "AST"--that effectively avoids 
the 
> typecasting problems since ANTLR only references the child and 
sibling 
> fields.

So the client code is properly responsible for it's own typecasting. 
OK. I'll keep this is mind too.

Once again, thanks for the reply.

Micheal


> --Loring
> 
> 
> --- In antlr-interest at y..., "micheal_jor" <open.zone at v...> wrote:
> > Hi,
> > 
> > While exploring the idea of custom AST classes, I noticed that 
the 
> > feature is supposed to that allow me to specify alternative AST 
> > classes on a per-token basis isn't working.
> > 
> > I specified the following in my grammar but in the generated code 
> the 
> > default AST class type is still used for all nodes. There is no 
> > reference to the specified class type at all.
> > 
> >     tokens
> >     {
> >       LOCK_STMT<AST=LockStatement>;
> >     }
> > 
> > I though it might be related to the fact that I use manual 
> > treebuilding commands such as:
> > 
> >     lockStatement
> >       :  LOCK! 
> >          (  ( LPAREN! stmtList )=> LPAREN! expression RPAREN! 
block
> >             { ## = #( [LOCK_STMT, "LOCK_STMT"], ##); } 
> >          |  block
> >             { ## = #( [LOCK_DIRECTIVE, "LOCK_DIRECTIVE"], ##); } 
> >          )
> >       ;
> > 
> > This is with C#. Does this feature work at all?. If it does, can 
> > anyone give me a quick pointer to what I should look out for in 
> > fixing the C# codegen pls (it needs an update soon anyways 
> methinks).
> > 
> > Micheal


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list