[antlr-interest] Re: Request enhancement ANTLR
Terence Parr
parrt at jguru.com
Tue Jun 25 11:04:54 PDT 2002
Yeah, I guess I agree. Let's just add a getFilename method to parser
that accepts a token. The problem is: what if k=2 and the tokens have
different filenames? Do you just choose the first filename?
Ter
On Tuesday, June 25, 2002, at 04:38 AM, Ric Klaren wrote:
> 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
> customization.
>
> 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
> flexibility.
>
> Cheers,
>
> Ric
> --
> -----+++++*****************************************************+++++++++-
> ------
> ---- 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/
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list