[erlang-questions] lexer for IEEE488.2 numbers

dieter@REDACTED dieter@REDACTED
Thu Apr 25 18:04:41 CEST 2019


Hi all,
I am writing a lexer for a SCPI parser. The number format of 488.2 is more tolerant than
list_to_float/1, it seems.
.123 and 456. are both valid in 488.2, but list_to_float/1 rejects them.
I have not yet found an erlang alternative to list_to_float/1,
my current approach is to add the omitted zeroes and feed the patched string to list_to_float/1.
This works if the number is only a mantissa, but
it gets a bit more complicated when there is also an exponent, like 123.e11
my leex expression for the number looks like
{MANTISSA}{EXPONENT} : {token, {float, TokenLine, i488tofloat(TokenChars)}}.
With this approach, I have to parse the string in my function a second time, which is not elegant at all.
Is there a way to have access to the regex macros (or regex groups) on the left side, like 1, 2?
I already tried to push back zeroes, but immediately ran into the promised consequences from note 4 on
http://erlang.org/doc/man/leex.html (http://erlang.org/doc/man/leex.html), so I quickly left that alley.
The question might be heretic, but why is list_to_float so strict? Every calculator allows to omit a leading 0 before the decimal point.
Kind regards,
Dieter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190425/8e6bc255/attachment.htm>


More information about the erlang-questions mailing list