[antlr-interest] How to distinguish between integer an binary number?

Sohail Somani sohail at taggedtype.net
Sat Dec 13 12:40:31 PST 2008


You can use a prefix or a suffix to distinguish. I find it hard to
determine whether 1001 is 1001 base 2 or 1001 base 10. A good compromise
could be #b1001 to indicate numbers in base 2.

Mario Prada wrote:
> I need to distinguish between integer an binary number in my grammar.<P>
> In Lexer I have this code:
> <P>
> <font size=2><pre>
> BINARIO : (BIN_DIGIT)+;
> INT :   DIGIT+ ;
> fragment BIN_DIGIT
> : '0'|'1';
> fragment DIGIT
>     :    '0'..'9';
> </pre></font>
> <P>
> and in Parser, when I have a grammar rule with an INT token, it seems to
> work, but this error appears:
> <P>
> mismatched input '1' expecting INT
> <P>
> How can I solve this problem?
> 
> Thanks in advance.



More information about the antlr-interest mailing list