[antlr-interest] Help parsing floating point and integer numbers
Peizhao Hu
peizhao at itee.uq.edu.au
Fri Oct 19 16:08:31 PDT 2007
try to combine the last two matches together
FloatingPointLiteral
: (Sign)? ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
| (Sign)? '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
| (Sign)? ('0'..'9')+ Exponent? FloatTypeSuffix?
;
it works for my grammar, where Sign rule is just:
Sign : ('+'|'-') ;
regards;
Peizhao
Cristian Peraferrer wrote:
> Hi, I can't see where is the error, for parsing floating point and
> integer numbers:
>
> DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
>
> fragment
> IntegerTypeSuffix : ('l'|'L') ;
>
> FloatingPointLiteral
> : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
> | '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
> | ('0'..'9')+ Exponent FloatTypeSuffix?
> | ('0'..'9')+ Exponent? FloatTypeSuffix
> ;
>
> fragment
> Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
>
> fragment
> FloatTypeSuffix : ('f'|'F'|'d'|'D') ;
>
>
>
> The multiple alternatives problem is in the FloatingPointLiteral rule.
>
> Thanks,
> Cristian.
>
> --
> GPG Key-ID: 0x564903FA - JID: corellian at swissjabber.ch
> <mailto:corellian at swissjabber.ch>
More information about the antlr-interest
mailing list