On Fri, 15 Dec 2023, Adriaan van Os via fpc-pascal wrote:

Michael Van Canneyt via fpc-pascal wrote:


On Fri, 15 Dec 2023, Adriaan van Os via fpc-pascal wrote:

Note that the same ambiguity exists in the <exception-handler> syntax (and this is less well known)

exceptionhandlers = [ exception-handler { ";" exception-handler } [ "ELSE" statement-list ] | statement-list ] . exception-handler = "ON" [ identifier ":" ] class-type-identifier "DO" statement .

as <exception-handler> ends with a <statement> and the optional <"ELSE" statement-list> part start with "ELSE". Sloppy language design, I assume by Borland.

What exactly do you consider "sloppy" ?

The ambiguity in the syntax whether ELSE belong to <statement> or to <"ELSE" statement-list>.

Why do you think this is ambiguous ? It always belongs to statement list.

If there is ambiguity, it is in the if then else construct.
This makes it difficult to read for humans.

The fact that the semicolon before the else is optional ?

I don't see a semicolon in the formal syntax.

This works:

---
{$mode objfpc}

uses sysutils;

begin
  try
  except
    on E: EAccessViolation do
      begin
      end;
    on E: EInoutError do
      begin
      end; // can be removed or not.
    else
      begin
      Writeln('OK');
      end;
  end;

end.
---

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to