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
[email protected]
[email protected]
[email protected]
Registered Linux User #1232 (http://counter.li.org)
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---