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

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sun Dec 29 09:09:35 CET 2013


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 statement
> here:
> http://www.freepascal.org/docs-html/ref/refsu50.html
> 
> As you can see, each "case" is terminated by ";". From the parser point of
> 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.)

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list