[antlr-interest] Java1.5 grammar and enum as identifier and not as a keyword

Jörg Rech joerg.rech at gmail.com
Sun Jun 26 14:13:28 PDT 2005


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.

> Akhilesh Mritunjai wrote:
>
>>Hi
>>
>>I encountered similar problem, and since we were
>>transitioning to 1.5, we decided to clean up the code.
>>Fortunately, for java 1.4, it can be done using a
>>simple find/replace. sed -i 's/\<enum\>/_enum/' takes
>>care of it :-)
>>    
>>

-- 
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