A syntax for numeric literals has to allow things like:
$
0
23
-17
23.5
0.5
-0.5
5e8
-5.17e-23.5
This is traditionally handled with a regular expression which permits all of these forms.
However, we might do it by only handling positive integer literals directly, and treating some of the symbols as operators. In particular:
: - _n_ : The negation of n
: _n_ . _m_ : Take m as a decimal fraction and add it to n
: _n_ e _m_ : Take m as an exponent, raise 10 to this power, and multiply n by it.
This happily handles all of the above forms, is simpler, and even supplies some useful arithmetic operators to the rest of the language.
The only problems are with the specific symbols; '.' might also be the member access operator, which could make trouble, and 'e' would normally be taken as an identifier, not an operator. The solution might be to use alternative symbols, ',' would make a good decimal point (it is already more of a standard than '.'!) and star-star or star-caret might do for times-ten-to-the.
CategorySoftware