[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Preventing Float 1.2e3.4
I'm sure this is an age old problem. So if there's a good reference for
dealing with the problem in LALR parsers, please point me to it rather than
wasting your breath.
I've been experimenting with the number lexing code in the Java11 grammar
and I was wondering how it can be improved to prevent the scientific
notation value 1.2e3.4. As implemented this is parsed as two numbers 1.2e3
This happens when variants 1,2,or3 are followed by variant 2 and exponent
parts are used.
digit+ '.' digit* exponent_part? float_type_suffix? |
'.' digit+ exponent_part? float_type_suffix? |
digit+ exponent_part float_type_suffix? |
digit+ exponent_part? float_type_suffix;
Is there a way in the grammar to prevent a a variant 2 floating point from
following the variant 1, 2, or 3 float with exponent without putting a space
between them? Or does this have to be done in the lexer by overiding
filter() and, if a variant 2 is found and the previous token is also a float
with exponent, then bomb if there wasn't an ignored token between them? I
imagine it could be done in the grammar by doing some crazy stuff lexer
states. Any other ideas?