[antlr-interest] Java1.5 grammar and enum as identifier and
not as a keyword
David Ewing
dewing at apple.com
Thu Jun 30 10:15:48 PDT 2005
On Jun 29, 2005, at 1:10 PM, Jörg Rech wrote:
> Hi,
> maybe I got something wrong here but isn't the lexer called before
> the recognizer for the methods? So if I enter a method changes to
> enableEnum have no effect on the lexer?
>
> Or is the lexer just registered and called by the recognizer/parser
> on demand?
It's called on demand. Another possibility would be to change 'IDENT'
to '(IDENT | "enum")' in a few key places elsewhere in the grammar
(e.g. variable declarators, expressions). That might be a tad more
compatible, but it also might add ambiguities to the grammar. In any
case, I haven't tried either, but I'd be interested to hear if they
work.
Dave
> Bye,
> Joerg
>
> David Ewing schrieb:
>
>
>> You might be able to call JavaLexer.enableEnum(false) from an
>> action when you enter the recognition of a method, and call
>> JavaLexer.enableEnum(true) when leaving. A hack, but perhaps a
>> useful one. :)
>>
>> Dave
>>
>> On Jun 26, 2005, at 3:13 PM, Jörg Rech wrote:
>>
>>
>>> Michael Studman schrieb:
>>>
>>>
>>>
>>>> If you're not in a position to be able to change the source
>>>> code you're parsing and you can guarantee "enum" is not used as
>>>> a keyword then you can call JavaLexer.enableEnum(false) on
>>>> the lexer before you pass it into the recogniser.
>>>>
>>>>
>>>
>>> If you mean by "guarantee enum is not used" that I can decide
>>> wether the class is either 1.4 or 1.5 I fear that this is not
>>> possible. The only way I currently see is to have two different
>>> pipelines with lexer, filter, and parser for 1.4 and 1.5 and
>>> then parse the class first with 1.5 and if errors occur use the
>>> 1.4 pipeline.
>>> I haven't tried it yet but it seems feasible (and ugly :-( )
>>>
>>> Thanks for your idea,
>>> Joerg.
>>>
>>
>>
>
>
> --
> Joerg Rech
> Computer Scientist Web: http://www.joerg-rech.de
> Tel.: (+49|0) 631/10653 email: joerg.rech at gmail.com
>
>
More information about the antlr-interest
mailing list