[antlr-interest] How the get the token value of 'ONEOF'

Jared Bunting jared.bunting at peachjean.com
Tue Dec 2 05:55:55 PST 2008


I can't see your grammar, but I believe that the "T__N" tokens are 
generated when you define lexical tokens directly in your parser rules.  
So basically, define it explicitly in the tokens section rather than in 
a parser rule.  Then, it will have a name. 

-Jared

chain one wrote:
> Hello:
> I have a question about the token value, the question is :
>  
> In the generated Java file, the token values are defined in this way:
>
>  public static final String[] tokenNames = new String[] {
>         "<invalid>", "<EOR>", "<DOWN>", "<UP>","ENTITY_VAR_IDENT", 
> "RULE_ID","INTERVAL_ITEM","'ONEOF'"
>     };
>     public static final int ENTITY_VAR_IDENT=4;
>     public static final int RULE_ID=5;
>     public static final int INTERVAL_ITEM=6;
>     public static final int T__7=7;
>
>
>
> if I want to identify a token , I can type this:
>
> Grammar:
> { input.LA(1)== ENTITY_VAR_IDENT}?
>
> Generated Code:
> int LA1_0 = input.LA(1);
> if ( (LA1_0==ENTITY_VAR_IDENT) )
> {
>    alt1=1;
> }
>
>
> that is OK
>
> But what if I want to check if the token is 'ONEOF'?
> How could I know T__7 stands for 'ONEOF' and its value is 7?
>
> Thanks for your help!
> Best Regards,
> chainone
> ------------------------------------------------------------------------
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>   


More information about the antlr-interest mailing list