www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Octal-like integer literals

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
Alright, I'm plodding along slowly with my D lexer, and I'm running into
an interesting case. According to the spec, int literals that begin with
'0' are supposed to be octal, with the exception of "0" itself, which is
decimal 0. DecimalInteger is defined to begin with a non-zero digit
followed by one or more digits (may be zero).

So how should the lexer treat a literal like "0800" or "0900"?

(Since octal literals are deprecated, I'm leaving them out of my lexer,
so should 0800 and 0900 be rejected as invalid?)


T

-- 
Change is inevitable, except from a vending machine.
Feb 11 2012
next sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
As an error.  Because they're allowed in C/C++/etc having them accepted by D 
but interpreted differently is just errors waiting to happen.

"H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message 
news:mailman.230.1328975949.20196.digitalmars-d puremagic.com...
 Alright, I'm plodding along slowly with my D lexer, and I'm running into
 an interesting case. According to the spec, int literals that begin with
 '0' are supposed to be octal, with the exception of "0" itself, which is
 decimal 0. DecimalInteger is defined to begin with a non-zero digit
 followed by one or more digits (may be zero).

 So how should the lexer treat a literal like "0800" or "0900"?

 (Since octal literals are deprecated, I'm leaving them out of my lexer,
 so should 0800 and 0900 be rejected as invalid?)


 T

 -- 
 Change is inevitable, except from a vending machine. 

Feb 11 2012
parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
OT: http://d.puremagic.com/issues/show_bug.cgi?id=5132

On 02/11/2012 10:06 AM, Daniel Murphy wrote:
  interpreted differently is just errors waiting to happen.

Feb 11 2012
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/11/2012 05:00 PM, H. S. Teoh wrote:
 Alright, I'm plodding along slowly with my D lexer, and I'm running into
 an interesting case. According to the spec, int literals that begin with
 '0' are supposed to be octal, with the exception of "0" itself, which is
 decimal 0. DecimalInteger is defined to begin with a non-zero digit
 followed by one or more digits (may be zero).

 So how should the lexer treat a literal like "0800" or "0900"?

 (Since octal literals are deprecated, I'm leaving them out of my lexer,
 so should 0800 and 0900 be rejected as invalid?)


 T

Octal literals whose value is larger than 7 must be rejected. Octal literals with values up to 7 must be accepted.
Feb 11 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/11/2012 07:05 PM, H. S. Teoh wrote:
 On Sat, Feb 11, 2012 at 06:48:20PM +0100, Andrej Mitrovic wrote:
 Octals are going away, the use of them in Phobos have been removed and
 Walter confirmed this too afaik.

So the question is, how will things like "0744" and "098" be interpreted once octals have gone away? Will they still be rejected by the compiler? T

Probably yes, except for '0+[1-7]?'.
Feb 11 2012
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
 You can only use them with the -d switch.

And 0744 will never be valid D code, for the simple reason that code moved over from C would silently break in awful ways.
Feb 16 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
 $ dmd test.d
 $ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744 instead

I was inordinately proud of that error message :-)
Feb 16 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
I had a look at moving them from deprecated to error, but druntime uses them 
extensively in the os headers.  I think we need a better solution than a 
template in the standard library - you shouldn't need a dependency on phobos 
to use them, and the compiler shouldn't directly reference anything in the 
standard library.

"Walter Bright" <newshound2 digitalmars.com> wrote in message 
news:jhkqsj$30j$2 digitalmars.com...
 On 2/11/2012 10:43 AM, Andrej Mitrovic wrote:
 $ dmd test.d
 $ test.d(5): octal literals 0744 are deprecated, use std.conv.octal!744 
 instead

I was inordinately proud of that error message :-)

Feb 16 2012