Accidental space inserted - Why does this compile?

delphi, delphi-xe2, pascal

Solution

The parser first translates text to tokens. So the text:

lTTEvent .CustUpdateStatus := usUnchanged;

Is translated to the tokens:

- identifier

- period

- identifier

- becomes

- identifier

- semicolon

The space is a whitespace and it can have three functions:

- separator between tokens (for example between an identifier and a keyword).

- a literal space (in that case it is included in a string.

- cosmetic.

The first and last function spaces are lost in the translation to tokens.

An identifier and a period don't have any characters in common so there is no way those can be confused so a space is not required but it still can be used.

short answer

'lTTEvent' and '.' are tokens. Tokens can (sometimes) be separated by whitespace.

Problem

I accidentally hit the spacebar and wrote this: ``` lTTEvent .CustUpdateStatus := usUnchanged; ``` and was surprised to see that the compiler accepted the space in front of the dot (actually, any number of spaces). Is the dot such a special character that the parser can interpret it correctly? How would that work in Pascal?

Original source