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

2013-12-29 Thread Mark Morgan Lloyd

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]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Sven Barth
Am 29.12.2013 09:10 schrieb "Mark Morgan Lloyd" <
markmll.fpc-pas...@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
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.)

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.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

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

2013-12-29 Thread Saunders, Rich

On 2013-12-28 15:47, Mark Morgan Lloyd wrote:

I can fix that either by putting a semicolon before the else- which I
believe is strictly incorrect- or by putting begin/end around that
conditional, or by inserting a dummy statement before the else like

  quit_:   if High(lexemeListArray) = 1 then begin
   end;
  nop: begin end
else


The problem is the compiler associates the else with the if..then and 
not with the case statement. All your fixes break the possible 
connection between the else and the if..then and that's why they work.


Your first fix (to just add a semicolon) would be my preferred one. I 
have lots of code that is written that way. I'm not sure why you think 
this is "strictly incorrect".


--

Cheers!
Rich Saunders
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Android cross-compiler: arm-linux-androideabi- binutilsprefix

2013-12-29 Thread Reinier Olislagers
Complete log: http://pastebin.com/Bj2EGmWD

FPC trunk, trying to get an Android ARM cross compiler going.
1. Optimistically using FPC 2.6.2 as bootstrap - should I be using
trunk? (Trying that now anyway)

Copied Android NDK crossbinutils (as.exe etc) and libs
(crtbegin_dynamic.o, libc.so) etc.

This is the command I let fpcup execute to build the cross compiler:
Executing : C:\development\fpcbootstrap\make.exe
"FPC=C:\development\fpcbootstrap\ppc386.exe"
"--directory=C:\development\fpctrunk"
"INSTALL_PREFIX=C:\development\fpctrunk"
"CROSSBINDIR=C:\development\cross\bin\arm-android" "UPXPROG=echo"
"COPYTREE=echo" "all" "OS_TARGET=android" "CPU_TARGET=arm" "CROSSOPT=
-CpARMV6" "OPT= -Xd -FlC:\development\cross\lib\arm-android"

2. Running the module I get quite far until I suddenly see reference to
a binutils prefix that I haven't set...:
make.exe[5]: Entering directory `C:/development/fpctrunk/rtl/android'
...
system.pp(380) Error: Assembler arm-linux-androideabi-as.exe not found,
switching to external assembling

Am I doing something wrong? Should I rename the binutils from the NDK
and use -XP/BINUTILSPREFIX?

This entry in fpc.cfg (fpc trunk) is ominous:
# for android cross-prefix is set by compiler
#ifdef android
#undef NEEDCROSSBINUTILS
#endif

Does fpc (trunk) require arm-linux-androideabi- ?
(And if so, why?)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Android cross-compiler: arm-linux-androideabi- binutilsprefix

2013-12-29 Thread Florian Klämpfl
Am 29.12.2013 14:12, schrieb Reinier Olislagers:
> Complete log: http://pastebin.com/Bj2EGmWD
> 
> FPC trunk, trying to get an Android ARM cross compiler going.
> 1. Optimistically using FPC 2.6.2 as bootstrap - should I be using
> trunk? (Trying that now anyway)
> 
> Copied Android NDK crossbinutils (as.exe etc) and libs
> (crtbegin_dynamic.o, libc.so) etc.
> 
> This is the command I let fpcup execute to build the cross compiler:
> Executing : C:\development\fpcbootstrap\make.exe
> "FPC=C:\development\fpcbootstrap\ppc386.exe"
> "--directory=C:\development\fpctrunk"
> "INSTALL_PREFIX=C:\development\fpctrunk"
> "CROSSBINDIR=C:\development\cross\bin\arm-android" "UPXPROG=echo"
> "COPYTREE=echo" "all" "OS_TARGET=android" "CPU_TARGET=arm" "CROSSOPT=
> -CpARMV6" "OPT= -Xd -FlC:\development\cross\lib\arm-android"
> 
> 2. Running the module I get quite far until I suddenly see reference to
> a binutils prefix that I haven't set...:
> make.exe[5]: Entering directory `C:/development/fpctrunk/rtl/android'
> ...
> system.pp(380) Error: Assembler arm-linux-androideabi-as.exe not found,
> switching to external assembling
> 
> Am I doing something wrong? Should I rename the binutils from the NDK
> and use -XP/BINUTILSPREFIX?
> 
> This entry in fpc.cfg (fpc trunk) is ominous:
> # for android cross-prefix is set by compiler
> #ifdef android
> #undef NEEDCROSSBINUTILS
> #endif
> 
> Does fpc (trunk) require arm-linux-androideabi- ?
> (And if so, why?)

>From fpc/compiler/options.pas:

  { Set up a default prefix for binutils when cross-compiling }
  if source_info.system<>target_info.system then
case target_info.system of
  { Use standard Android NDK prefixes }
  system_arm_android:
utilsprefix:='arm-linux-androideabi-';
  system_i386_android:
utilsprefix:='i686-linux-android-';
end;



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread leledumbo
> No, that shows a semicolon separating successive cases, not terminating
each one

Right, sorry I misinterpret "separate" with "terminate".



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Very-odd-case-parsing-problem-tp5717723p5717731.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Android cross-compiler: arm-linux-androideabi- binutilsprefix

2013-12-29 Thread Reinier Olislagers
On 29/12/2013 14:22, Florian Klämpfl wrote:
> Am 29.12.2013 14:12, schrieb Reinier Olislagers:
>> Does fpc (trunk) require arm-linux-androideabi- ?
>> (And if so, why?)
> 
>>From fpc/compiler/options.pas:
> 
>   { Set up a default prefix for binutils when cross-compiling }
>   if source_info.system<>target_info.system then
> case target_info.system of
>   { Use standard Android NDK prefixes }
>   system_arm_android:
> utilsprefix:='arm-linux-androideabi-';
>   system_i386_android:
> utilsprefix:='i686-linux-android-';
> end;

Thanks.
I see I probably copied over the wrong directory from the NDK: the one
from arm-linux has
android-ndk-r9c\toolchains\arm-linux-androideabi-4.8\prebuilt\windows-x86_64\arm-linux-androideabi\bin\as.exe
etc
as well as
D:\cop\t\android-ndk-r9c\toolchains\arm-linux-androideabi-4.8\prebuilt\windows-x86_64\bin\arm-linux-androideabi-as.exe

Sorry about that; I'll fix things up, try again... and get back if needed.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Martin Frb

On 29/12/2013 07:33, Mark Morgan Lloyd wrote:

Saunders, Rich wrote:

On 2013-12-28 15:47, Mark Morgan Lloyd wrote:


  quit_:   if High(lexemeListArray) = 1 then begin
   end;
  nop: begin end
else


Drat- a dangling else in a case! I should have spotted that, but 
instead spent an hour or so picking at it.




1) If you use Lazarus then you can have case-labels highlighted (e.g add 
underline/border, blend foreground by mixing in another color, bold, 
...) It is in the color config.


That will (in this case) not highlight the else, so you will know the 
else is part of the if.


2) I tried your code and it compiles (2.6.2 win32)

{$mode objfpc}{$H+}


procedure TForm1.FormCreate(Sender: TObject);
var
  a: (help, help_, quit_);
  b: Integer;
begin
   try
case a of
  help:begin
   end;
  help_:   begin
   end;
  quit_:   if b = 1 then begin
   end
else
end // line 323
  finally
  end;
end;

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Mark Morgan Lloyd

Martin Frb wrote:

Drat- a dangling else in a case! I should have spotted that, but 
instead spent an hour or so picking at it.


1) If you use Lazarus then you can have case-labels highlighted (e.g add 
underline/border, blend foreground by mixing in another color, bold, 
...) It is in the color config.


That will (in this case) not highlight the else, so you will know the 
else is part of the if.


Thanks, noted.


2) I tried your code and it compiles (2.6.2 win32)

{$mode objfpc}{$H+}


procedure TForm1.FormCreate(Sender: TObject);
var
  a: (help, help_, quit_);
  b: Integer;
begin
   try
case a of
  help:begin
   end;
  help_:   begin
   end;
  quit_:   if b = 1 then begin
   end
else
end // line 323
  finally
  end;
end;


There were additional statements in between the  else  and the final 
end. Since the  else  associated with a  case  accepts multiple 
statements while the  else  associated with an  if  doesn't, the 
compiler was getting confused by what it thought was a spurious  end 
statement. I'm sure I've been bitten by this one before, and recently 
enough for it to be embarrassing.


I find myself habitually putting in an explicit  else  part in each 
case  statement, even if it's empty. That's a habit from Modula-2 days, 
I can't remember what the spec said but some (if not all) compilers 
insisted on it. In view of the potential for a dangling else, I'm not 
sure whether that's a good or a bad habit.


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

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Sven Barth

On 29.12.2013 15:06, Martin Frb wrote:

On 29/12/2013 07:33, Mark Morgan Lloyd wrote:

Saunders, Rich wrote:

On 2013-12-28 15:47, Mark Morgan Lloyd wrote:


  quit_:   if High(lexemeListArray) = 1 then begin
   end;
  nop: begin end
else



Drat- a dangling else in a case! I should have spotted that, but
instead spent an hour or so picking at it.



1) If you use Lazarus then you can have case-labels highlighted (e.g add
underline/border, blend foreground by mixing in another color, bold,
...) It is in the color config.

That will (in this case) not highlight the else, so you will know the
else is part of the if.


Does Lazarus recognize "otherwise" as an alternative for "else" inside a 
"case"-statement as well?


Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Martin Frb

On 29/12/2013 16:37, Sven Barth wrote:


Does Lazarus recognize "otherwise" as an alternative for "else" inside 
a "case"-statement as well?


Not yet
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Martin Frb

On 29/12/2013 17:08, Martin Frb wrote:

On 29/12/2013 16:37, Sven Barth wrote:


Does Lazarus recognize "otherwise" as an alternative for "else" 
inside a "case"-statement as well?


Not yet


Now 1.3 does
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Sven Barth

On 29.12.2013 18:20, Martin Frb wrote:

On 29/12/2013 17:08, Martin Frb wrote:

On 29/12/2013 16:37, Sven Barth wrote:


Does Lazarus recognize "otherwise" as an alternative for "else"
inside a "case"-statement as well?


Not yet


Now 1.3 does


Great! :)

Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2013-12-29 Thread Mark Morgan Lloyd

Sven Barth wrote:

On 29.12.2013 18:20, Martin Frb wrote:

On 29/12/2013 17:08, Martin Frb wrote:

On 29/12/2013 16:37, Sven Barth wrote:


Does Lazarus recognize "otherwise" as an alternative for "else"
inside a "case"-statement as well?


Not yet


Now 1.3 does


Great! :)


Ruefully agrees :-)

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

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal