[antlr-interest] How to match variables with reserved words in it?
David-Sarah Hopwood
david-sarah at jacaranda.org
Tue Dec 22 14:49:32 PST 2009
Natan wrote:
> Hi,
>
> I have a grammar like this :
>
> tokens {
> ERROR = 'error';
> IF = 'if';
> ELSE = 'else';
> }
>
> ...
>
> variableAssignment
> : variable '=' expression
> ;
>
> variable
> : '$' ID
> ;
>
> errorStatement
> : ERROR STRING
> ;
>
> ...
>
> ID
> : ('a' .. 'z' | 'A' .. 'Z' | '_') ( 'a' .. 'z' | 'A' .. 'Z' |
> '0' .. '9' | '_' )*
> ;
>
>
> As you can see, variables are like in Perl with $ in front of them.
> Everything works fine until I try to call a variable "$error" or "$if".
Variable should be a lexer rule.
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091222/4972091c/attachment.bin
More information about the antlr-interest
mailing list