Syntax error in a case statement when not expected.

General discussion on mikroPascal.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Syntax error in a case statement when not expected.

#1 Post by Dany » 04 Aug 2008 18:39

Hi,
I encountered something odd :lol: using a case statement with constants as case identifiers.

Additional info from yo2lio: The same problems occur when using variables as case identifiers, see post below.

This are my constants:

Code: Select all

Const   // Modes
      Off_   = 0;
      On_    = 1;
      One_Hr = 2;
      Two_Hr = 3;
      For_Hr = 4;
      Eit_Hr = 5;
This is OK:

Code: Select all

      Case Mode of
        Off_: //
           begin
             ...
           end;
        ...
and this gives an error (Syntax error: expected expression, but label found):

Code: Select all

     Case Mode of
        Off_:
           begin
             ...
           end;
        ...

In general, if anything (comment, the "begin")... is present on the same line after the case identifier, then it is Ok, if nothing is present the compiler give the error.

The problem does not show when using literals in the code in stead of contstants, so this is OK:

Code: Select all

     Case Mode of
        0:
           begin
             ...
           end;
        ...

Of course the work around is very easy here. :D
Last edited by Dany on 04 Aug 2008 20:24, edited 2 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: Syntax error in a case statement when not expected.

#2 Post by yo2lio » 04 Aug 2008 19:06

Dany wrote:I encountered something odd :lol: using a case statement with constants as case identifiers.
Same for this :

Code: Select all

var i : byte;
    
begin
  case i of
    i:
      begin

      end;
  end;
end.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#3 Post by janni » 05 Aug 2008 00:44

These are old quirks and there are more of them (for example, semicolon is supposed to be used for comments in assembly block - try to use keywords, like end, in the comment, or a quote char ' - the compiler will report errors).

Unfortunately, all these quirks continue to exist and even permeated the new IDE (and command line compiler), which in future is going to replace the present one :cry: .

Post Reply

Return to “mikroPascal General”