[fpc-pascal] Re: Very odd case parsing problem

Sven Barth pascaldragon at googlemail.com
Sun Dec 29 12:06:19 CET 2013

Am 29.12.2013 09:10 schrieb "Mark Morgan Lloyd" <
markMLl.fpc-pascal at telemetry.co.uk>:
> leledumbo wrote:
>>> I can fix that either by putting a semicolon before the else- which I
>> believe is strictly incorrect
>> Nope, that's correct. Take a look at the syntax diagram for case
>> here:
>> http://www.freepascal.org/docs-html/ref/refsu50.html
>> As you can see, each "case" is terminated by ";". From the parser point
>> view, your code is exactly parsed as:
> No, that shows a semicolon separating successive cases, not terminating
each one. What's more  statement  can be a  compound statement  and that's
similarly defined as using ; as a separator.
> Bit of an old chestnut, and my recollection is that an extra semicolon
would crash some versions of Turbo Pascal. I'm not sure where my copy of
J&W is, so I can't go back to the BNF... but it wouldn't help since else
 was added to the  case  statement by Turbo Pascal which explicitly has
>   case expression of case-element { ; case-element } else
> where a case-element ends with a statement which can be a
compound-statement which again defines ; as a separator.
> (Oh Lord this is all we need: a syntax war to round off the year.)

In case you don't need Delphi compatibility you can use "otherwise" instead
of "else" inside a case-statement. This keyword comes from the ISO dialects
and is enabled in all modes.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131229/b9e58fe6/attachment.html>

More information about the fpc-pascal mailing list