Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-01

Semicolon checking

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vojtěch Čihák

Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I accidentally did this stupid mistake:  
if ... then
  begin
     ...
  end else;
  begin
    ...
    exit;
  end;
 
Note the semicolon behind the "else".
Semicolon as an empty command is sometimes useful (temporary solution).  
Thanks, V.

Reply by email

Lars
to Vojtěch Čihák
Vojtěch Čihák wrote 10 lines
Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I accidentally did this stupid mistake:   if ... then begin   end else;   begin     ...     exit;   end;  

Yikes! I think you just discovered a bug in the pascal language itself that was not thought of... as when using a text editor it's easy to leave a semi colon laying around by accident some times.

I wonder if Oberon solves this issue, or semi-colon-less languages have any advantage. If you remove the begin from a language (Wirth did in his later languages) you get rid of some issues.

Reply by email

Mark Morgan Lloyd
to Lars
Lars wrote
On Sun, January 15, 2017 3:30 pm, Vojtěch Čihák via Lazarus wrote:> Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I> accidentally did this stupid mistake: > if ... then begin>> end else;> begin> ...> exit;> end;> Yikes! I think you just discovered a bug in the pascal language itselfthat was not thought of... as when using a text editor it's easy to leavea semi colon laying around by accident some times. I wonder if Oberon solves this issue, or semi-colon-less languages haveany advantage. If you remove the begin from a language (Wirth did in hislater languages) you get rid of some issues.-- _______________________________________________Lazarus mailing ://lists.lazarus-ide.org/listinfo/lazarus

It's one of a number of known nasties in the language definition. This is controversial, but Pascal was defined with ; being a /separator/ not a /terminator/, so strictly a semicolon is not needed before end else until etc. and in my experience only using it where necessary is a good habit to get into ( ;until was a syntax error in at least some versions of Turbo Pascal).

One other thing that helps in a very small way is to use case-otherwise-end rather than case-else-end, since it reduces the number of ambiguities.

Apart from that Wirth deserves no credit at all for leaving the dangling-else ambiguity in Pascal when it had been recognised and eliminated in ALGOL-68.

I expect to get kicked for all of the above. They are my opinions only, and might not be aligned with e.g. the coding style expected in patches submitted to the FPC or Lazarus projects.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

DougC
to Mark Morgan Lloyd

I'm not going to kick you, Mark, as your comments are spot on.

What I think wold be very helpful to the FPC community is a warning that is issued when a semi-colon is immediately followed by a "begin" as that is an unusual construct and, as shown in the example here, an indicator of a likely mistake.

Doug C.

---- On Mon, 16 Jan 2017 03:27:25 -0500 Mark Morgan Lloyd via Lazarus <> wrote ----

On 16/01/17 07:30, Lars via Lazarus wrote:

> On Sun, January 15, 2017 3:30 pm, Vojtěch Čihák via Lazarus wrote:> Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I> accidentally did this stupid mistake: > if ... then begin>> end else;> begin> ...> exit;> end;>

> Yikes! I think you just discovered a bug in the pascal language itselfthat was not thought of... as when using a text editor it's easy to leavea semi colon laying around by accident some times.

> I wonder if Oberon solves this issue, or semi-colon-less languages haveany advantage. If you remove the begin from a language (Wirth did in hislater languages) you get rid of some issues.-- _______________________________________________Lazarus mailing ://lists.lazarus-ide.org/listinfo/lazarus

It's one of a number of known nasties in the language definition. This

is controversial, but Pascal was defined with ; being a /separator/ not

a /terminator/, so strictly a semicolon is not needed before end else

until etc. and in my experience only using it where necessary is a good

habit to get into ( ;until was a syntax error in at least some versions

of Turbo Pascal).

One other thing that helps in a very small way is to use

case-otherwise-end rather than case-else-end, since it reduces the

number of ambiguities.

Apart from that Wirth deserves no credit at all for leaving the

dangling-else ambiguity in Pascal when it had been recognised and

eliminated in ALGOL-68.

I expect to get kicked for all of the above. They are my opinions only,

and might not be aligned with e.g. the coding style expected in patches

submitted to the FPC or Lazarus projects.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] --

Reply by email

Martin Frb
to DougC
DougC wrote 7 lines
I'm not going to kick you, Mark, as your comments are spot on. What I think wold be very helpful to the FPC community is a warning that is issued when a semi-colon is immediately followed by a "begin" as that is an unusual construct and, as shown in the example here, an indicator of a likely mistake.

Well you can set the IDE to highlight such cases. (At least so long as the ; is on the same line, and right after the else)

In Options / Editor / go to "user defined markup" (F1 should get the wiki help)

Add a new term. Add the words
then;
then ;
else;
else ;

and if you want with several spaces too.

Then set the background color to a strong red. Et voila.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170116/8d240ca5/attachment.html>

Reply by email