[fpc-pascal] case statement
Michael Van Canneyt
michael at freepascal.org
Thu Dec 14 18:11:18 CET 2023
On Thu, 14 Dec 2023, Adriaan van Os via fpc-pascal wrote:
>
> I am looking in detail at the syntax diagrams in the Freepascal Language
> Reference (version 3.2.0)
>
> Section 13.2.2 discusses the case-statement. Translated to EBNF (WSN) the
> syntax is
>
> case-statement = "CASE" expression "OF" case { ";" case } [ else-part ] [ ";"
> ] .
> case = constant [ ".." constant ] { "," constant [ ".." constant ] } ":"
> statement .
> else-part = [ "ELSE" | "OTHERWISE" ] statementlist .
>
> If this is correct (and the compiler really allows it) then a semicolon
> between <case> and <else-part> is not required.
It is not required.
> Consequently, there is an
> ambiguity between an if-then-else statement (as last statement of the <case>)
> and an if-then statement (as last statement of the <case>) and an
> <else-part>. This is extremely dangerous and I feel that at least the
> Language Reference should warn against it.
A good point. I will add a warning.
>
> Even with an obliged semicolon, I always use "OTHERWISE instead of ELSE, but
> that's my personal preference.
Indeed. By contrast I abhorr the OTHERWISE. Tastes differ.
Thanks for bringing the ambiguity to my attention.
Michael.
More information about the fpc-pascal
mailing list