why ; ?

Walter Bright newshound1 at digitalmars.com
Mon May 5 11:26:35 PDT 2008


Tomasz Sowinski wrote:
> What's the reason of having lines end with a semicolon?

A well designed language has some redundancy built in. The reason for 
the redundancy is so the compiler can detect and diagnose errors. If 
there was no redundancy, any random stream of characters, i.e. 
oidhfoi123413j4h1ohsc!@#$%^&*(vjkasdasdf
would be a valid program.

Having the ; end statements provides a nice "anchor" point for the 
parser. It means that what comes before it must form a grammatically 
correct statement. Otherwise, the compiler must hopefully keep scanning 
forward, and then try all kinds of parse trees out on the jumble of 
tokens looking for a set of statements that will fit it.

Furthermore, when the compiler does diagnose an error, error recovery 
can be as simple as "skip forward to the ;, then restart the statement 
parser." Without such an anchor, you'll get one error message followed 
by a cascade of useless drivel.

BTW, double entry bookkeeping, invented in the middle ages, was a huge 
advance in accounting. It essentially made everything redundant, which 
helped find and correct arithmetic errors. It spawned the term 
"balancing the books" which is nothing more than tracking down and 
reconciling all the errors. Without the redundancy, there'd be no way to 
balance the books because there'd be no way to detect errors.



More information about the Digitalmars-d mailing list