[antlr-interest] Re: can't override nextToken in c# version

netminka netminka at netscape.net
Fri Oct 10 16:26:57 PDT 2003


thanks for the suggestion.
I tried defining nextToken() as new in the derived class and it
doesn't override the base class 'new' nextToken. I'll try adding
virtual to the derived class nextToken, though I suspect that
adding virtual to the derived doesn't change the dominance of the base
class method.
megan



--- In antlr-interest at yahoogroups.com, "micheal_jor" <open.zone at v...>
wrote:
> --- In antlr-interest at yahoogroups.com, "netminka" <netminka at n...> wrote:
> > hi all,
> > the generated nextToken() is defined as
> >    public new Token nextToken()
> > in the generated lexer class. 
> > 
> > I have used the generated lexer class as a base class to my lexer,
> > and as I need to override nextToken(), I have to hand edit
> > the generated lexer file after each run of antlr.Tool.
> > 
> > I think the signature of the generated nextToken() should be:
> > 
> > public virtual Token nextToken()
> 
> Megan,
> 
> You may be right about this although I seem to remember a makeToken()
> method too. In the meantime you can use the following workaround in
> your subclass(es):
> 
> class LexerSubClass : MyLexer, TokenStream
> {
>    .....
>    public new /*virtual?*/ Token nextToken()
>    {
>       //do your stuff
>       .....
>       .....
> 
>       // optionally call inherited stiff
>       Token t = base.nextToken();
>    }
>    Token TokenStream.nextToken()
>    {
>        return ((LexerSubClass) this).nextToken();
>    }
>    ....
> }
> 
> Cheers,
> 
> Micheal


 

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




More information about the antlr-interest mailing list