| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
February 11, 2012 Octal-like integer literals | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
February 11, 2012 Re: Octal-like integer literals | ||||
|---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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. | |||
February 11, 2012 Re: Octal-like integer literals | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | 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. > | |||
February 11, 2012 Re: Octal-like integer literals | ||||
|---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply