[antlr-interest] change token type?
Kevin J. Cummings
cummings at kjchome.homeip.net
Fri Jul 31 16:56:47 PDT 2009
On 07/31/2009 07:31 PM, Kendall Shaw wrote:
> Here's my non-working toy grammar:
>
> grammar test;
>
> tokens {
> CAT = 'cat' ;
> LP = '(' ;
> RP = ')' ;
> }
>
> them
> : (cat)=> cat
> | NAME
> ;
Have you tried:
them : (CAT LP)=> cat
| name;
name : NAME
| CAT;
> cat : CAT LP RP ;
>
> NAME : 'a'..'z'+ ;
>
> The lexer insists that "cat" is a CAT instead of a NAME. In the real
> grammar, all keywords can also be identifiers. How can this be done?
> None of the examples I've seen so far really fit this case.
>
> I tried:
>
> cat : c:CAT {if(!input.LT(1).getText().equals("[")) c.setType(NAME);} LP RP ;
>
> but that doesn't seem to work.
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)
More information about the antlr-interest
mailing list