BBC BASIC for Windows
IDE and Compiler >> Compiler >> Syntax Error in a compiled executable
http://bb4w.conforums.com/index.cgi?board=compiler&action=display&num=1421424621

Syntax Error in a compiled executable
Post by JFS on Jan 16th, 2015, 3:10pm

My programme produces a "Syntax Error" when I run it as a compiled executable with the "Abreviate Names" option selected but not if it is compiled without this option, or run from the IDE. If I number the lines, the line number reported by the Error Message points to a DIM statement which has been unchanged in the code for donkey's years. This came as a complete shock given that I have been compiling this and similar programmes for years without ever having experienced problems before. And I can't think what might be different this time round. Although it has been a few weeks since I compiled this code, I have compiled other versions over the last few days without any problems.

Just by way of a shot in the dark, I tried REM! Keep ing the array in the offending DIM statement but without effect.

As it is a very large programme, I would appreciate any guidance as to where to start looking.

Many thanks,

Howard


Re: Syntax Error in a compiled executable
Post by rtr2 on Jan 16th, 2015, 3:37pm

on Jan 16th, 2015, 3:10pm, JFS wrote:
As it is a very large programme, I would appreciate any guidance as to where to start looking.

Are you by any chance using the new REM!Fast compiler directive available in v6.00a? The symptom you describe is exactly what happens if you inadvertently specify a structure member in such a directive, contrary to the documentation.

If that's not the explanation, compile your program with 'Encrypt and compress' not checked and send it to me (preferably zipped) as an attachment to a private email.

Richard.

Re: Syntax Error in a compiled executable
Post by JFS on Jan 16th, 2015, 4:20pm

Many thanks for this Richard. I have compiled a version with all the embedded files stripped out which makes it less than 200kB and sent that to you. As it is an exe it may get trapped by the thought police so please let me know if it does not get through.

Many thanks again,


Re: Syntax Error in a compiled executable
Post by rtr2 on Jan 16th, 2015, 5:13pm

on Jan 16th, 2015, 4:20pm, JFS wrote:
As it is an exe it may get trapped by the thought police so please let me know if it does not get through.

It survived the journey! Currently I am as puzzled as you are, but I have requested further information from you by email to assist with the diagnosis. I await your response.

Richard.
Re: Syntax Error in a compiled executable
Post by rtr2 on Jan 16th, 2015, 11:07pm

It turns out that the problem was caused by 'dead code', that is code which is never executed when the program is run in the IDE, but the presence of which can upset the 'compiler' and cause the executable to fail.

Often dead code won't be an issue, other than to increase the size of the executable unnecessarily, but if certain kinds of syntax error are present in that code it may confuse the compiler and impact on the operation of the rest of the program. So it was in this case.

Although it isn't a complete remedy, I would strongly recommend that the Cross Reference Utility be run, and any warnings it may give be examined, before any program is compiled. It's entirely likely that the warnings will turn out to be of no importance - that is why they are only warnings - but they may draw attention to a fault or weakness in the code you weren't aware of.

Richard.
Re: Syntax Error in a compiled executable
Post by JFS on Jan 17th, 2015, 07:38am

Richard,

Many thanks for your kind assistance in sorting this one out. Just a question on structure members and the REM!Fast compiler directive. Could you confirm or correct my understanding please, which is that this would all be acceptable:-

Member% +=0
MEMBER% +=0
DIM Structure{Member%,MEMBER%}
DIM StructArray{(10) Member%,MEMBER%}
...
REM!Fast Structure{}, StructArray{()}, Member%

...but the addition of this line:-

REM!Fast Structure.Member%

.. would break things

Many thanks,

Re: Syntax Error in a compiled executable
Post by rtr2 on Jan 17th, 2015, 09:27am

on Jan 17th, 2015, 07:38am, JFS wrote:
REM!Fast Structure{}, StructArray{()}, Member%

It's OK to have Structure{} and StructArray{()} in a REM!Fast directive, but adding Member% will cause the program to fail at run-time with a Syntax Error (it's the name of a structure member).

This is called out in the documentation: "You must not include in the list the names of any structure members (even if they happen to share their name with a normal variable)".

Quote:
REM!Fast Structure.Member%

That is invalid syntax; I don't know exactly what would happen if you tried it but it won't be helpful! The docs state that REM!Fast "accepts a list of variable, array, structure, function and procedure names", and what you have there is none of those.

The REM!Fast directive should only be used if it provides a real benefit, and only after your program has been thoroughly debugged. Its incorporation makes the compiled code 'unreadable' and would have made the diagnostics I performed yesterday, to trace the cause of your problem, impossible to carry out.

Richard.

Re: Syntax Error in a compiled executable
Post by JFS on Jan 17th, 2015, 12:52pm

That's fine - many thanks for the clarification Richard.