[antlr-interest] Re: Request enhancement ANTLR

Dennis Marsa drm at xilinx.com
Tue Jun 25 07:42:10 PDT 2002

Silvain Piree wrote:
> Ter,
> > > 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.
> An alternative would be something like:
>     throw new NoViableAltException(...,
>         LT(1).getFilename() != null?
>             LT(1).getFilename() : getFilename() );
> Silvain

The NoViableAltException constructor in question takes two
arguments, a Token and a string (filename).

Since the filename will be available from the Token itself
(via the new getFilename method), why pass the filename
as the second argument at all?  NoViableAltException can
retrieve it from the token on its own.

So, a new single argument NoViableAltException constructor
could be defined that takes just a Token, and gets the
filename from using the new getFilename() method.

Throwing a NoViableAltException would then look like:

   throw NoViableAltException(LT(1));



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

More information about the antlr-interest mailing list