PackageDescription: SYSEXT-NumberParser

SYSEXT - Number Parser

Last published: March 15, 2018 by 'nice'

Defines 7 Classes
Extends 10 Classes

This package provides classes for reading Numbers efficiently in Smalltalk.
Mainly, NumberParser, an abstract class with utility methods for parsing numbers.

NumberParser is a class that convert Number string decimal (or other bases) representation to binary machine representation.
If some patches are applied to #asDouble and #asFloat, then this package should answer the nearest Floating point approximating decimal representation (see SYSBUG-FloatConversion).

Subclasses should provide concrete implementation for parsing some particular syntax (Smalltalk, C, FORTRAN, ...)
Some examples are provided in this package for FORTRAN and some Smalltalk dialects.
Thus it is possible to emulate Dolphin and Squeak number parsing in VW.

Example of main API:

VWNumberParser parse: '1.0s'.
VWNumberParser parse: '-1.0e3'.
VWNumberParser parse: '16rA374'.

Errors can be controlled by using an error block:

VWNumberParser parse: '.e+3' onError: [^nil].

Precision can eventually be forced to double using this snippet:

(VWNumberParser on: '-1.0e-3')
failBlock: [^nil];

And this is different than converting a posteriori:
-1.0e-3 asDouble

Another interesting topic is efficiency for reading LargeInteger:
| tmp |
tmp := 4000 factorial printString.
(1 to: 3) collect: [:i | Time millisecondsToRun: [VWNumberParser parse: tmp readStream]].
| tmp |
tmp := 4000 factorial printString.
(1 to: 3) collect: [:i | Time millisecondsToRun: [Number readFrom: tmp readStream]].

This package is easy to extend with extended number syntax and also to port to other dialects.
Variants can be already found in Squeak and Dolphin at least.

AUTHOR: nicolas cellier , any question, remarks, etc... go to this email.
LICENSE: (MIT), see copyright information

Bon voyage