Numeric literals in other than base 10 - was Annoying octal notation

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Sun Aug 23 10:21:52 CEST 2009


On Sat, 22 Aug 2009 14:54:41 -0700 (PDT), James Harris wrote:

> They look good - which is important. The trouble (for me) is that I
> want the notation for a new programming language and already use these
> characters. I have underscore as an optional separator for groups of
> digits - 123000 and 123_000 mean the same. The semicolon terminates a
> statement. Based on your second idea, though, maybe a colon could be
> used instead as in
> 
>   2:1011, 8:7621, 16:c26b
> 
> I don't (yet) use it as a range operator.
> 
> I could also use a hash sign as although I allow hash to begin
> comments it cannot be preceded by anything other than whitespace so
> these would be usable
> 
>   2#1011, 8#7621, 16#c26b
> 
> I have no idea why Ada which uses the # also apparently uses it to end
> a number
> 
>   2#1011#, 8#7621#, 16#c26b#

If you are going Unicode, you could use the mathematical notation, which is

   1011<sub>2</sub>, 7621<sub>8</sub>, c26b<sub>16</sub>

(subscript specification of the base). Yes, it might be difficult to type
(:-)), and would require some look-ahead in the parser. One of the
advantages of Ada notation, is that a numeric literal always starts with
decimal digit. That makes things simple for a descent recursive parser. I
guess this choice was intentional, back in 1983 a complex parser would eat
too much resources...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



More information about the Python-list mailing list