Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Ralf Quint via fpc-pascal schrieb am Fr., 9. Feb. 2024, 20:36: > On 2/8/2024 11:01 AM, Martin Wynne via fpc-pascal wrote: > > Hi Thomas, > > > > The error is not the file content after "end.". > > > > The error is not having the expected "end;" after "begin". > > > > This works ok: > > > > _ > > > > program test; > > > > begin > > end; > > > > end. > > > > abc 123 > > > > _ > > > > Martin. > > This is not a valid Pascal source code to begin with (pun intended)... > > The "begin" is the start of the actual Pascal program and by definition, > that program is terminated by matching that with an "end." That's what > the code completion in Lazarus for example is adding into a new "simple > program" project source code. > > Just adding a random "end;" should also just yield an error message... > > Well, I actually did just tested this and it gives as expected an > "Error: Syntax error, "." expected but ";" found. It Doesn't even > process past the "end." in that case. > That's what I had expected. > What is however interesting is that an open comment, as mention by the > OP, immediately after the "end." results in the "Error: unexpected end > of file" message, however any other addition text past that "end." will > result in no error message and completing to compile the program > successfully... > > I just tried a couple more things, and it seems it is just the "{" or > "(*" opening of a comment that is causing the error message, having a > "//" comment until end of line after the "end." will also compile just > fine > If one knows how the compiler is structured (I do) then it isn't that surprising that it behaves that way with a dangling comment due to the interaction between the scanner (which is responsible for the comments) and the parser (which triggers the consumption of the final point). The problem is that the parser does not know that the end of the program has been reached when that point is consumed and happily searches for the next token, consuming all whitespace and comments along the way. Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
On 2/8/2024 11:01 AM, Martin Wynne via fpc-pascal wrote: Hi Thomas, The error is not the file content after "end.". The error is not having the expected "end;" after "begin". This works ok: _ program test; begin end; end. abc 123 _ Martin. This is not a valid Pascal source code to begin with (pun intended)... The "begin" is the start of the actual Pascal program and by definition, that program is terminated by matching that with an "end." That's what the code completion in Lazarus for example is adding into a new "simple program" project source code. Just adding a random "end;" should also just yield an error message... Well, I actually did just tested this and it gives as expected an "Error: Syntax error, "." expected but ";" found. It Doesn't even process past the "end." in that case. What is however interesting is that an open comment, as mention by the OP, immediately after the "end." results in the "Error: unexpected end of file" message, however any other addition text past that "end." will result in no error message and completing to compile the program successfully... I just tried a couple more things, and it seems it is just the "{" or "(*" opening of a comment that is causing the error message, having a "//" comment until end of line after the "end." will also compile just fine Ralf ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
No, the original post has the correct program, dropping a ";" in that spot is incorrect syntax. The problem comes in because there is an open comment, but no close comment. If you add the closing } the compiler behaves properly. On the other hand, I do understand that once the "end." is encountered, further processing is unnecessary, and so the error shouldn't occur, because any text showing up after that should be ignored. Honestly, it's is a case of six of one, half dozen of the other. It's all in the design of the compiler. I personally wouldn't consider it a bug, but I can see why some folks would, so On 2/8/2024 7:01 PM, Martin Wynne via fpc-pascal wrote: Hi Thomas, The error is not the file content after "end.". The error is not having the expected "end;" after "begin". This works ok: _ program test; begin end; end. abc 123 _ Martin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Martin Wynne via fpc-pascal schrieb am Do., 8. Feb. 2024, 22:03: > Hi Thomas, > > The error is not the file content after "end.". > > The error is not having the expected "end;" after "begin". > > This works ok: > > _ > > program test; > > begin > end; > > end. > > abc 123 > If that works then that is a bug as well, because the begin of the main *must* be terminated with a "end.", not a "end;". Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Hello Martin, I've been using Pascal for more than 30 years now, but I must admit I've never before seen the construct you posted. And it doesn't compile either: project1.lpr(4,4) Error: Syntax error, "." expected but ";" found Kind regards, Thomas - Original Message - From: Martin Wynne via fpc-pascal To: fpc-pascal@lists.freepascal.org Sent: Thursday, February 8, 2024, 20:01:17 Subject: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end." Hi Thomas, The error is not the file content after "end.". The error is not having the expected "end;" after "begin". This works ok: _ program test; begin end; end. abc 123 _ Martin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Hi Thomas, The error is not the file content after "end.". The error is not having the expected "end;" after "begin". This works ok: _ program test; begin end; end. abc 123 _ Martin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Thomas Kurz via fpc-pascal schrieb am Do., 8. Feb. 2024, 13:31: > Hello all, > > I'm unsure about whether or not to report this as a bug. Imho, it is a > bug, but maybe there's a good reason to handle this. > Please report a bug. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] "Unexpected end of file" when having an open comment after the final "end."
Hello all, I'm unsure about whether or not to report this as a bug. Imho, it is a bug, but maybe there's a good reason to handle this. Please take the following example: ---start--- program test; begin end. { ---end--- Result: Z:\>ppc386.exe testproj.pas Free Pascal Compiler version 3.2.2 [2022/05/15] for i386 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling testproj.pas testproj.pas(6,1) Fatal: Unexpected end of file Fatal: Compilation aborted I'd say the code should compile without any errors for the following reasons: 1. The "end." tells the compiler that the file is finished here. Whatever comes after this should not be considered by the compiler. 2. The compiler doesn't consider any other statement after "end.". For example, replacing the open comment with something like "vra" doesn't cause an error either. Kind regards, Thomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal