Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "for I := 0to aList.Count-1 do" work with a missing space?

I was writing a small console application in Delphi (XE), and by mistake wrote:

for I := 0to aList.Count-1 do 

Note the missing space between "0" and "to"

I didn't notice this until after I had run the program, and I was surprised the compiler accepted this. It's probably no big deal, but it made me curious.

Why does Delphi accept this typo?

like image 898
Svein Bringsli Avatar asked Oct 24 '11 06:10

Svein Bringsli


People also ask

Are all whitespace characters ignored in HTML?

Most whitespace characters are ignored, not all of them are. In the earlier example one of the spaces between "Hello" and "World!" still exists when the page is rendered in a browser.

How to solve the problem of whitespace nodes in JavaScript?

You can also solve this problem by putting your list items all on the same line in the source, which causes the whitespace nodes to not be created in the first place: When trying to do DOM manipulation in JavaScript, you can also encounter problems because of whitespace nodes.

How does the presence of whitespace in the Dom affect layout?

The presence of whitespace in the DOM can cause layout problems and make manipulation of the content tree difficult in unexpected ways, depending on where it is located. This article explores when difficulties can occur, and looks at what can be done to mitigate resulting problems. What is whitespace?


1 Answers

It's for the same reason that you don't need spaces around the . or the -. Since a t can never come after an initial 0 in any recognisable token, the lexical analyser simply returns the 0 as an integer-literal token, and then recognises the to as a distinct keyword token. If you had made a different mistake instead — for I := 0 to10 — you'd now have a problem, since to10 is recognised as a valid identifier, which is illegal immediately after the 0.

like image 99
Marcelo Cantos Avatar answered Sep 18 '22 14:09

Marcelo Cantos