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

chain one chainone at gmail.com
Tue Dec 2 06:07:18 PST 2008


Hi Jared Bunting:

Thanks for your quick response.
Your suggestion must work. But there are so many tokens just like 'ONEOF' in
my grammar right now, to explicitly  define all of this kind of tokens is
quiet a bit boring.
I am wondering if there is another way to do this? If not, I will define
them : )


2008/12/2 Jared Bunting <jared.bunting at peachjean.com>

> 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
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081202/da2233eb/attachment.html 


More information about the antlr-interest mailing list