Recent

Author Topic: "program" keyword, Borland compatibility and documentation  (Read 986 times)

Arioch

  • Sr. Member
  • ****
  • Posts: 414
"program" keyword, Borland compatibility and documentation
« on: October 01, 2022, 06:00:50 pm »
This is minor issue, but for the record.

Quote from: Free Pascal Reference guide
16.1  Programs
A Pascal program consists of the program header, followed possibly by a “uses” clause, and a block.
  ...
The program header is provided for backwards compatibility, and is ignored by the compiler.

Well, the latter is not true. It is NOT ignored and it is not drop-in compatible too.

Code: Pascal  [Select][+][-]
  1. {$mode tp}
  2. program;
  3.  
  4. begin
  5. end.

and

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. program;
  3.  
  4. begin
  5. end.

result in

Quote
project1.lpr(2,8) Fatal: Syntax error, "identifier" expected but ";" found

So, not ignored.

It, perhaps, was indeed ignored in TP, but it is not ignored in Delphi, see the error message near resource directive in the attached screenshot

Quote from: Free Pascal Programmer’s Guide
D.2  TP mode
This mode is selected by the  $MODE TP  switch. It tries to emulate...

this deviation is not mentioned

Quote from: Free Pascal Programmer’s Guide
8.6  When porting Turbo Pascal code

neither

MarkMLl

  • Hero Member
  • *****
  • Posts: 5572
Re: "program" keyword, Borland compatibility and documentation
« Reply #1 on: October 01, 2022, 06:12:40 pm »
It says "program header" and "program" without a following identifier is not a valid program header.

I'm not sure, but the requirement might have been tweaked a bit when InstantFPC was introduced.

https://wiki.freepascal.org/InstantFPC mentions the compiler's -o option for setting the name.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Bogen85

  • Full Member
  • ***
  • Posts: 148
Re: "program" keyword, Borland compatibility and documentation
« Reply #2 on: October 01, 2022, 06:14:18 pm »
The .lpr extension is for a Lazarus project, so if you are building from Lazarus, that will likely be what it wants.

Occasionally I build Lazarus projects from the command line using lazbuild but for all my own software projects I don't use Lazarus.

So I assume you are trying to build via the project manager, and not build your example as a standalone program, which I don't know off hand how to do in Lazarus, as I don't use it.

When using fpc outside of the GUI, a program with the .pas extension named the same as the program name in the source code works fine.

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. program ProgramName;
  3.  
  4. begin
  5. end.
  6.  

A source file with the above content named ProgramName.pas is fine and is accepted by fpc and will result in the executable ProgramName (or ProgramName.exe if on Windows).

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: "program" keyword, Borland compatibility and documentation
« Reply #3 on: October 01, 2022, 06:29:10 pm »
Well, TP/BP/BPW 5.5/6.0/7.0 certainly provided for program keyword without identifier.

And the Delphi versions i think of did too, though i did not test often. Delphi has a ready templates, that TP/BP did not.

So, in the modes that claim compatibility - this syntax is expected to be tolerated.

Or, otherwise, explicitly documented as incompatibility.

> is not a valid program header.

that is a bit of scholasticism, biut to me if the header was actually ignored - the cmpiler would never know if it is valid or not, it would just fast-forward until the end, and get over. But this header is no more ignored actually, if it ever was. It is now parser for ID for $R directives, probably even in Sybil :-)

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: "program" keyword, Borland compatibility and documentation
« Reply #4 on: October 01, 2022, 06:40:59 pm »
BTW, dynamic arrays AFAIR also are not fully compatible without that being mentioned in the docs

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode delphi}
  4.  
  5. var a: array of integer;
  6.  
  7. begin
  8.   SetLength(a,2);
  9.   a := nil;
  10.  
  11.   Writeln(Length(a));
  12.   Writeln(nil = a);
  13.   // project1.lpr(12,15) Error: Operator is not overloaded: "Pointer" = "{Dynamic} Array Of LongInt"
  14.  
  15.   Readln;
  16. end.      

PascalDragon

  • Hero Member
  • *****
  • Posts: 4759
  • Compiler Developer
Re: "program" keyword, Borland compatibility and documentation
« Reply #5 on: October 01, 2022, 07:54:02 pm »
This is minor issue, but for the record.

Quote from: Free Pascal Reference guide
16.1  Programs
A Pascal program consists of the program header, followed possibly by a “uses” clause, and a block.
  ...
The program header is provided for backwards compatibility, and is ignored by the compiler.

Well, the latter is not true. It is NOT ignored and it is not drop-in compatible too.

What is meant here is that the whole program header can be left out. E.g. the following is a valid Pascal program:

Code: Pascal  [Select][+][-]
  1. begin
  2. end.

Well, TP/BP/BPW 5.5/6.0/7.0 certainly provided for program keyword without identifier.

And the Delphi versions i think of did too, though i did not test often. Delphi has a ready templates, that TP/BP did not.

Current Delphi allows this as well. Please report as a bug. (Sidenote: Delphi also allows the use of the file list in the program header without a program identifier, so program (Input, Output) is valid as well)

BTW, dynamic arrays AFAIR also are not fully compatible without that being mentioned in the docs

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode delphi}
  4.  
  5. var a: array of integer;
  6.  
  7. begin
  8.   SetLength(a,2);
  9.   a := nil;
  10.  
  11.   Writeln(Length(a));
  12.   Writeln(nil = a);
  13.   // project1.lpr(12,15) Error: Operator is not overloaded: "Pointer" = "{Dynamic} Array Of LongInt"
  14.  
  15.   Readln;
  16. end.      

It works if you do a = nil. Please report as a bug.


d.ioannidis

  • Full Member
  • ***
  • Posts: 198
    • Nephelae
Re: "program" keyword, Borland compatibility and documentation
« Reply #7 on: October 03, 2022, 01:03:43 am »
Hi,

  BTW, Delphi 7 ( Pro Build 4.453 ) help writes :

Quote
The program heading specifies the program's name. It consists of the reserved word program, followed by a valid identifier, followed by a semicolon. The identifier must match the project file name. In the previous previous example, since the program is called Editor, the project file should be called Editor.dpr.

In standard Pascal, a program heading can include parameters after the program name:

program Calc(input, output);

Borland's Delphi compiler ignores these parameters.

And in the Object Pascal grammar has :

Quote
Goal -> (Program | Package | Library | Unit)
Program -> [PROGRAM Ident ['(' IdentList ')'] ';']
           ProgramBlock '.'
Unit -> UNIT Ident [PortabilityDirective] ';'
        InterfaceSection
        ImplementationSection
        InitSection '.'

..............

IdentList -> Ident ','...

..............

Ident -> <identifier>

..............

regards,

KodeZwerg

  • Hero Member
  • *****
  • Posts: 548
  • Fifty shades of code.
    • Delphi & FreePascal
Re: "program" keyword, Borland compatibility and documentation
« Reply #8 on: October 03, 2022, 01:45:50 am »
BTW, Delphi 7 ( Pro Build 4.453 ) help writes...
A more current version can be reviewed here -> https://docwiki.embarcadero.com/RADStudio/en/Programs_and_Units_(Delphi)

Best regards.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: "program" keyword, Borland compatibility and documentation
« Reply #9 on: October 03, 2022, 08:50:53 pm »
  BTW, Delphi 7 ( Pro Build 4.453 ) help writes :

We all know that documentation is often faulty, be it Delphi or FPC or any other program.
The particularly nightmarish example o both compielr and docs broken was Delphi 2009, IMHO

Frankly, this is a realy edge case.
I believe it would be better to fix it one time in the compiler and make transiting programmers less confused.
But since those proigrammers would have to learn how to enable mode tp or mode delphi - they can learn to check "program" keyword too.
So, the opposite approach (do not fix incompatibility, but document it in 2+ articles in the help as intended one) is fine too. Slightly worse IMHO but not much.

Just fix it by any of the means and forget :-)

P.S. BTW, expectedly in Delphi XE2 the same works with "library" clause for DLL projects.

Library (Input, Output); did not work though. Not that i tried hard, maybe just a typo.

MarkMLl

  • Hero Member
  • *****
  • Posts: 5572
Re: "program" keyword, Borland compatibility and documentation
« Reply #10 on: October 03, 2022, 09:10:55 pm »
We all know that documentation is often faulty, be it Delphi or FPC or any other program.
The particularly nightmarish example o both compielr and docs broken was Delphi 2009, IMHO

Almost as nightmarish as your lack of a spieling chuckler :-)

Not intended personally... but does /any/ language permit "lr" at the end of a word?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: "program" keyword, Borland compatibility and documentation
« Reply #11 on: October 03, 2022, 09:26:41 pm »
i am really typing on the run, sorry  :-)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 548
  • Fifty shades of code.
    • Delphi & FreePascal
Re: "program" keyword, Borland compatibility and documentation
« Reply #12 on: October 03, 2022, 09:48:34 pm »
Not intended personally... but does /any/ language permit "lr" at the end of a word?
Yes, english/american does  :P  https://www.wordnik.com/words/reproachablr
and somewhere i also read about tumblr  :D
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bogen85

  • Full Member
  • ***
  • Posts: 148

MarkMLl

  • Hero Member
  • *****
  • Posts: 5572
Re: "program" keyword, Borland compatibility and documentation
« Reply #14 on: October 03, 2022, 10:09:40 pm »
Wherever it was... I don't want to go there.

I admit to being humbled by my possible error... but suspect that the case is still so egregious that people have gone out of their way to try to find examples.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018