[antlr-interest] adding enum token types output for java target

Johannes Luber JALuber at gmx.de
Mon May 26 15:32:58 PDT 2008


> On May 26, 2008, at 2:27 PM, Brian Goetz wrote:
> 
> > Think of the enum as a form of "reflection for ANTLR grammars."  Its  
> > not required that you actually have to USE the generated enum; its a  
> > way for third-party code to enumerate the tokens, including their  
> > names.  The enums can also be used as keys in hashmaps.
> >
> > If you import another grammar, and therefore its tokens become  
> > yours, you can simply "inline" the set of tokens at each level of  
> > the hierarchy.  (In that case, you could include as a constructor  
> > param the grammar from which they are imported, to further preserve  
> > the provenance.)
> 
> So we'd leave everything as-is, just provide a new enum as a  
> reflection thing.  I could buy that.  I'd make it in a separate file  
> though like a .h file so it wouldn't look weird (i.e., like a dup) in  
> the parser file.  It'd be XTokens.java for recognizer X.  Would that  
> work for everybody?
> 
> Ter

It would for me. BTW, C# always supported enums. Considering that enums are mapped onto other base types, this language feature can be resolved by compilers easily - thus I've never understood why Java didn't support them from the beginning.

Johannes

-- 
Super-Aktion nur in der GMX Spieleflat: 10 Tage für 1 Euro.
Über 180 Spiele downloaden und spiele: http://flat.games.gmx.de


More information about the antlr-interest mailing list