[antlr-interest] Fwd: [Newbie] "keywords vs. identifiers": how can I fix this?

Greg Lindholm glindholm at yahoo.com
Thu Apr 10 09:30:31 PDT 2003


That should work but it's not practical if you have a large number of keywords.
Take a look at the testLiterals option http://antlr.org/doc/options.html#testLiterals
Use this with the tokens section http://antlr.org/doc/metalang.html#TokensSection
tokens {
  TRUE="true";
  FALSE="false";
}
Also read about Token Vocabularies http://antlr.org/doc/vocab.html
Greg
 "Thiago F.G. Albuquerque" <tfga at terra.com.br> wrote:
>ID : LETRA (LETRA | DIGITO)* ;
>
>INT : (DIGITO)+ ;
>
>BOOL : "true"
> | "false"
> ;
>
>ANTLR Parser Generator Version 2.7.2 1989-2003 jGuru.com
>grammar.g: warning:lexical nondeterminism between rules ID and BOOL upon
>grammar.g: k==1:'f','t'

I fixed it like this:

ID : ("true") => ("true") { $setType(BOOL); }
| ("false") => ("false") { $setType(BOOL); }
| LETRA (LETRA | DIGITO)* ;

Is this ok? Is there a better way to do this?

TIA,
Thiago

PS:

LETRA == LETTER
DIGITO == DIGIT

(sorry, I forgot to translate)




Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030410/39dfbad2/attachment.html


More information about the antlr-interest mailing list