[fpc-pascal] case statement
Bernd Oppolzer
bernd.oppolzer at t-online.de
Sun Dec 17 18:25:19 CET 2023
Am 17.12.2023 um 16:36 schrieb Adriaan van Os via fpc-pascal:
>
> As the otherwise-clause is not in ISO-7185 Pascal, it seems more
> plausible that Borland invented the else-clause (without semicolon)
> independently. All other Pascals I have looked at, use an
> otherwise-clause (with an obligatory semicolon). The motivation for
> this, given in IBM Pascal is interesting. The manual says that the
> statement-part of the otherwise-clause can be intentionally "left
> blank" and be used "to prevent possible errors during execution". I
> recall that in ISO-7185 Pascal it is an error if no case discriminator
> matches at runtime. So, the otherwise-clause was seen as a way to get
> around that !
>
This was one of Niklaus Wirth's mistakes: that the original Pascal
definition did not tell how the syntax of the "otherwise" part of the
case statement should be.
I recall that our profs in the computer science classes in the 1970s
criticized this serious flaw of the language.
So almost every compiler had to find its own solution.
The compilers for the IBM machines were, to some degree, influenced by
PL/1. There we have:
IF ... THEN ... ELSE
and
SELECT ... WHEN ... OTHER(WISE) ... END
SELECT is much the same as case, although more general; not limited to
simple expressions;
not even limited to expressions ... there are two flavors of SELECT:
SELECT (expr); WHEN (A) ...; WHEN (B) ...; OTHER ...; END;
SELECT; WHEN (cond1) ...; WHEN (cond2) ...; OTHER ...; END;
PL/1 was first defined in the mid 1960s, so maybe some of the Pascal
compiler designers may have been influenced (to some degree) by PL/1.
Even C was influenced by PL/1 (because PL/1 was the implementation
language of the Multics system, and K & R had that experience
and agreed about how things should NOT be done).
BTW: my Stanford compiler uses OTHERWISE (no abbreviation). There is no
error, if OTHERWISE is omitted and no case label matches;
in this case, simply no action is taken. And: my compiler took some
inspiration from IBMs Pascal compilers ... and some builtin functions
were inspired by PL/1 functions, indeed.
Kind regards
Bernd
> Regards,
>
> Adriaan van Os
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list