Entomy / Ada-Improvements

Repository of Ada language improvement ideas
GNU General Public License v3.0
4 stars 0 forks source link

Semicolon termination #4

Open Entomy opened 5 years ago

Entomy commented 5 years ago

Ada does: All statements are terminated in semicolons.

This is something contentious and should be discussed, as including them just because of legacy use isn't a very valid argument. However it should be noted the use of semicolons isn't a legacy artifact either.

Entomy commented 5 years ago

I am personally in favor of keeping semicolon termination. The reason being that it's considerably easier on the parser, which isn't just a parser complexity issue, but actually speeds up parsing considerably, while also not requiring much out of the programmer. Of course, statements could simply be line/formatting terminated, but then this is a massive change from the way Ada code is normally written and is considered too extreme of a change.

Consider the case of parsing X := 5 + 4;. We can tell by the second token we are doing an assignment, and everything up until the ; is an expression to evaluate. Because we know we are looking for a ; we can blindly capture everything up until that point, only looking for a ; each position. Once found, not only can the parser continue, but a second parsing thread can evaluate the expression.

Consider the case of parsing X := 5 + 4 where semicolon termination does not happen. Each position we have to check against every possible statement beginning to be sure the end of a statement did not occur. Ada has an absolutely massive amount of statement types, and suddenly the amount of work the parser must do has exploded.

All over one extra keypress.