PackageDescription: SYSEXT-NumberParser


SYSEXT - Number Parser

Last published: July 25, 2011 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 here for FORTRAN and some Smalltalk dialects.
Thus we can mimic Dolphin and Squeak number parsing in VW.

Example of main API:

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

Errors canbe controlledusing an error block:

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

Precision can eventually be forced to double using this snippet:

(VWNumberParser on: '-1.0e3')
failBlock: [^nil];
nextDouble.

Another interesting topic is efficiency for reading LargeInteger:
| tmp |
tmp := 4000 factorial printString.
(1 to: 3) collect: [:i | Time millisecondsToRun: [VWNumberParser parse: tmp readStream]].
versus:
| 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