[antlr-interest] Re: Request enhancement ANTLR

Ric Klaren klaren at cs.utwente.nl
Tue Jun 25 04:38:11 PDT 2002

On Tue, Jun 25, 2002 at 08:42:24AM +0200, Silvain Piree wrote:
> > > Why not implement setFilename/getFilename in class Token 
> > > exactly like setText/getText are currently?
> > 
> > Makes sense to me...adding to list.
> That would indeed be the best solution .... with one problem: 
> it's not compatible with current implementations.
> The problem again is the error message (NoViableAlt) raised
> by the parser. The generated parser uses the getFilename()
> method of the Parser class to determine the current filename.
> When registering the filename with the token, the parser
> class would have to get the filename from the token (e.g.
> LT(1).getFilename() ). 
> But that will only work when getFilename() is implemented
> for Token. Otherwise it will fail ....
> That's why I suggested to define another getFilename()
> method in the Parser class where you pass the current 
> token as parameter. Then the implementer can decide
> where to get the current filename.

I'd go for this last scheme anytime. It offers most possibilities for

IMHO Empty place holder methods are evil. (although you sometimes have to
be pragmatic :) )

Btw I'd prefer adding extra things like this as examples and not as default
functionality. If we come to the conclusion though that some extra
interfacing/hooks are necessary to implement this kindoff thing then we
definitely should go for it.

>     throw new NoViableAltException(..., 
>         LT(1).getFilename() != null? 
>             LT(1).getFilename() : getFilename() );

I'd still go for the getFilename( Token t ) solution. It offers more


    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
  "I don't have anything against Java - it's the best damn implementation
              of UCSD Pascal ever released..." --- Larry Smith


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

More information about the antlr-interest mailing list