Number literals (Was: Re: Case Range Statement ..)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 7 22:56:52 PDT 2009
Rainer Deyke wrote:
> Andrei Alexandrescu wrote:
>> Derek Parnell wrote:
>>> I would not complain if trailing dot and leading dot were disallowed.
>> I think the question that should be asked is: would anyone complain if
>> they were kept? We have bigger rocks to move than that one.
>
> It seems rather disingenuous to complain loudly about '...' used as a
> separator, but to accept leading/trailing dots without question.
Well it's rather congruent. The leading and trailing dots have been in
the language for a good while and haven't caused major problems. So I am
not bent on eliminating them. On the other hand, I don't feel like
throwing ellipses in the mix just to make things more confusing.
> I'm
> sure you remember this list:
>
>> 0.....wyda
>> 0....wyda
>> 0... .wyda
>> 0. .. .wyda
>> 0.... wyda
>> 0. ...wyda
>> 0. ....wyda
>> 0.. .wyda
>
> I'm sure you agree that this is a mess.
I do.
> Never mind if any of these
> token sequences are syntactically valid, this is a mess at the lexical
> level.
They all are parsable if ellipsis is to be allowed as separator. Not at
all. They are very easy to parse lexically. It's the humans who have
problems.
> If '0.....wyda' is interpreted as the token sequence '0. ... .
> wyda', then you have bigger things to worry about than whether or not
> that token sequence is ever syntactically valid.
What you describe is standard lexing. The sequence 0.....wyda is lexed
using maximum munch (the longest thing that looks like a token is chosen
left to right). First we have a 0 and so the longest token is 0. Then
follow four dots, but a maximum of three form a token. Finally, we have
.wyda which is a token. And that's about it. The rule is not
complicated, but of course having to count the dots and exacerbating the
importance of whitespace placement is undesirable.
Andrei
More information about the Digitalmars-d
mailing list