<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ralf Quint via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Fr., 9. Feb. 2024, 20:36:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2/8/2024 11:01 AM, Martin Wynne via fpc-pascal wrote:<br>
> Hi Thomas,<br>
><br>
> The error is not the file content after "end.".<br>
><br>
> The error is not having the expected "end;" after "begin".<br>
><br>
> This works ok:<br>
><br>
> _________________________<br>
><br>
> program test;<br>
><br>
> begin<br>
> end;<br>
><br>
> end.<br>
><br>
> abc 123<br>
><br>
> _________________________<br>
><br>
> Martin. <br>
<br>
This is not a valid Pascal source code to begin with (pun intended)...<br>
<br>
The "begin" is the start of the actual Pascal program and by definition, <br>
that program is terminated by matching that with an "end." That's what <br>
the code completion in Lazarus for example is adding into a new "simple <br>
program" project source code.<br>
<br>
Just adding a random "end;" should also just yield an error message...<br>
<br>
Well, I actually did just tested this and it gives as expected an <br>
"Error: Syntax error,  "." expected but ";" found. It Doesn't even <br>
process past the "end." in that case.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That's what I had expected.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
What is however interesting is that an open comment, as mention by the <br>
OP,  immediately after the "end." results in the "Error: unexpected end <br>
of file" message, however any other addition text past that "end." will <br>
result in no error message and completing to compile the program <br>
successfully...<br>
<br>
I just tried a couple more things, and it seems it is just the "{" or <br>
"(*" opening of a comment that is causing the error message, having a <br>
"//" comment until end of  line after the "end."  will also compile just <br>
fine<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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).</div><div dir="auto">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. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>