Hi folks!
In our department, we have a little conversion about Pascal-Standards:
Is the following allowed and should the program be compiled if the unit and the program share the same file? It seems, that GPC does and TurboPascal (tm) does not AFAIK.
8<---------------- unit foo;
interface ... implementation ... end.
program bar; uses foo;
begin ... end.
------------->8
Eike
In our department, we have a little conversion about Pascal-Standards:
Is the following allowed and should the program be compiled if the unit and the program share the same file? It seems, that GPC does and TurboPascal (tm) does not AFAIK.
This is not defined in standards afaik, but most compilers don't accept it. So I wouldn't use it for pure practical reasons.
Eike Lange wrote:
In our department, we have a little conversion about Pascal-Standards:
Is the following allowed and should the program be compiled if the unit and the program share the same file? It seems, that GPC does and TurboPascal (tm) does not AFAIK.
8<---------------- unit foo;
interface ... implementation ... end.
program bar; uses foo;
begin ... end.
------------->8
Marco van de Voort wrote:
This is not defined in standards afaik,
No. In fact the standards don't say anything about source files (including file names or anything) AFAIK. (Besides, units are a BP extension, but the same question could be constructed with EP modules.)
but most compilers don't accept it. So I wouldn't use it for pure practical reasons.
Indeed, this feature might (but not sure) be dropped sometime. The original reason was that for EP modules, interface and implementation are separate entities, yet it might be convenient to put them in the same source file. But whether the generalization to allow any combination of units, modules and (at least one :-) program in a source file is so good, I'm not sure ...
Frank
Eike Lange wrote:
In our department, we have a little conversion about Pascal-Standards:
Is the following allowed and should the program be compiled if the unit and the program share the same file? It seems, that GPC does and TurboPascal (tm) does not AFAIK.
8<---------------- unit foo;
interface ... implementation ... end.
program bar; uses foo;
begin ... end.
Why would you use a unit at all if in the same file? You should simply incorporate the code in the program. Units are nothing to do with any standard anyhow, I believe that ISO10206 uses modules while ISO7185 doesn't provide for separate compilation. Turbo Pascal has historically ignored (and contravened) standards. If I am wrong I am sure I will be loudly corrected.
On Tue, Jun 04, 2002 at 06:31:23AM -0400, CBFalconer wrote:
Eike Lange wrote:
In our department, we have a little conversion about Pascal-Standards:
[Units and Programs share same file]
Why would you use a unit at all if in the same file?
In fact, it wasn't my intention. I'm porting _a_lot_of_ units and programs from TP 6.0 to GPC 2.1 these days and I was complaining about the style of this mixture of units and programs by the original programmer. In fact, I very dislike the way, he did it.
He told me, that stopping after the first "end." (after unit) should stop the compiler. I don't know, why he has written the program in the same file so far. :-/
Eike
Eike Lange wrote:
On Tue, Jun 04, 2002 at 06:31:23AM -0400, CBFalconer wrote:
Eike Lange wrote:
In our department, we have a little conversion about Pascal-Standards:
[Units and Programs share same file]
Why would you use a unit at all if in the same file?
In fact, it wasn't my intention. I'm porting _a_lot_of_ units and programs from TP 6.0 to GPC 2.1 these days and I was complaining about the style of this mixture of units and programs by the original programmer. In fact, I very dislike the way, he did it.
He told me, that stopping after the first "end." (after unit) should stop the compiler. I don't know, why he has written the program in the same file so far. :-/
Put in those terms, he is absolutely right IMO. Anything that follows the "end ." should be ignored, in fact not even read. The period should be parsed and cause compilation to stop. I think the syntax is something like:
program ::= 'program' progparms ';' declarations block '.' ... block ::= 'begin' statement 'end'
so that reaching the final '.' MUST signal a successful compilation.
Hi!
On Tue, Jun 04, 2002 at 10:16:21AM -0400, CBFalconer wrote:
He told me, that stopping after the first "end." (after unit) should stop the compiler. I don't know, why he has written the program in the same file so far. :-/
Put in those terms, he is absolutely right IMO. Anything that follows the "end ." should be ignored, in fact not even read. The period should be parsed and cause compilation to stop. I think the syntax is something like: program ::= 'program' progparms ';' declarations block '.'
Yes, but there might be a statement like this (not exactly BNF :-) part ::= program or unit file ::= part until EOF
Thank you all, for clearing this.
Eike
Eike Lange wrote:
On Tue, Jun 04, 2002 at 10:16:21AM -0400, CBFalconer wrote:
He told me, that stopping after the first "end." (after unit) should stop the compiler. I don't know, why he has written the program in the same file so far. :-/
Put in those terms, he is absolutely right IMO. Anything that follows the "end ." should be ignored, in fact not even read. The period should be parsed and cause compilation to stop. I think the syntax is something like: program ::= 'program' progparms ';' declarations block '.'
Yes, but there might be a statement like this (not exactly BNF :-) part ::= program or unit file ::= part until EOF
Yes, I'd also think so. Normally, a grammar doesn't imply that anything may follow the program.
However, BP behaves like this, and GPC does so with `--borland-pascal' (but I don't think we should make this the default).
Frank
Yes, I'd also think so. Normally, a grammar doesn't imply that anything may follow the program.
However, BP behaves like this, and GPC does so with `--borland-pascal' (but I don't think we should make this the default).
FPC doesn't afaik (but this can depend on mode). We keep CVS logs in comments ( '{'...'}' style), but something something gets wrong with the logs, and it still compiles.
Frank Heckenbach wrote:
Eike Lange wrote:
On Tue, Jun 04, 2002 at 10:16:21AM -0400, CBFalconer wrote:
He told me, that stopping after the first "end." (after unit) should stop the compiler. I don't know, why he has written the program in the same file so far. :-/
Put in those terms, he is absolutely right IMO. Anything that follows the "end ." should be ignored, in fact not even read. The period should be parsed and cause compilation to stop. I think the syntax is something like:
program ::= 'program' progparms ';' declarations block '.'
Yes, but there might be a statement like this (not exactly BNF :-) part ::= program or unit file ::= part until EOF
Yes, I'd also think so. Normally, a grammar doesn't imply that anything may follow the program.
However, BP behaves like this, and GPC does so with `--borland-pascal' (but I don't think we should make this the default).
Who are you agreeing with? I hope it is me :-)
I actually had to go to some trouble to get this to work correctly in PascalP, because I allowed EOF to appear immediately after the '.', with no eoln. At the same time I wanted to collect source lines for a listing. Thus I had to buffer the input in lines for printing only after completion of parsing of a line. Thus the one character look-ahead had a tendency to issue a read after EOF. Things were much easier when the '.' was not the last character in the source file.
This characteristic is convenient for appending rambling notes after the final "end." without worrying about forming proper comments. Doesn't work for C though.
BTW I just ran across a fascinating essay at:
http://www.epemag.com/zuse/forword.htm
which might especially interest you.
CBFalconer wrote:
Frank Heckenbach wrote:
Eike Lange wrote:
On Tue, Jun 04, 2002 at 10:16:21AM -0400, CBFalconer wrote:
Put in those terms, he is absolutely right IMO. Anything that follows the "end ." should be ignored, in fact not even read. The period should be parsed and cause compilation to stop. I think the syntax is something like:
program ::= 'program' progparms ';' declarations block '.'
Yes, but there might be a statement like this (not exactly BNF :-) part ::= program or unit file ::= part until EOF
Yes, I'd also think so. Normally, a grammar doesn't imply that anything may follow the program.
However, BP behaves like this, and GPC does so with `--borland-pascal' (but I don't think we should make this the default).
Who are you agreeing with? I hope it is me :-)
No, Eike who I quoted directly.
I actually had to go to some trouble to get this to work correctly in PascalP, because I allowed EOF to appear immediately after the '.', with no eoln. At the same time I wanted to collect source lines for a listing.
Why don't you just read it as a text file (provided PascalP was written in Pascal)? According to the standard, a text file in Pascal consists of lines, so there is always an EOLn before EOF (whether or not the external file contains a newline at the end).
Obviously, GPC (written in C) doesn't do this, either. It just processes the input character-wise and counts the newlines (for messages) and outputs it character-wise (with `--debug-source').
This characteristic is convenient for appending rambling notes after the final "end." without worrying about forming proper comments.
The question is not whether it's convenient, but whether it's allowed by the standards. Do you have any reference where they allow it?
BTW I just ran across a fascinating essay at:
<http://www.epemag.com/zuse/forword.htm>
which might especially interest you.
Gives me a 404.
Frank
On Wed, 5 Jun 2002, Marco van de Voort wrote:
BTW I just ran across a fascinating essay at:
<http://www.epemag.com/zuse/forword.htm>
which might especially interest you.
It's foreword.htm apparantly an "e" got lost, typo. If you remove the "forword.htm" you find the whole article.
Thanks! Yes, use http://www.epemag.com/zuse so that you don't miss the opening page, which has a great picture of the Z1. This is really the best material I have found on Zuse, written by his son Horst, who is also an Informatiker. Vielen Dank!
* Nick Geovanis The very term 'icon' has been appropriated and | IT Computing Svcs changed radically in our computer age, signifying | Northwestern Univ an ultimately unreal, 'virtual' world. | n-geovanis@nwu.edu - Metropolitan Iakovos, Hierarch of Chicago +------------------->