QLiberator bug

Anything QL Software or Programming Related.
Post Reply
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

QLiberator bug

Post by Andrew »

It took me 6 hours to compile PI Cole 2 and now I have much more grey hair then before.
I had hundreds of warnings and errors which I could not understand.
The cause is this QLiberator compiler bug:
this code will compile without errors or warnings, as expected:

Code: Select all

10 if a>0 then
20    print "a>0"
30 end if
40:
50 if b>0 then 
60    print "b>0"
70 else
80    print "b<=0"
90 end if
But this code will generate "Warning: END IF without if in line 30" and "ERROR: ELSE without IF in line 70"

Code: Select all

10 if a>0 then :REMark test for a
20    print "a>0"
30 end if
40:
50 if b>0 then :REMark test for b
60    print "b>0"
70 else
80    print "b<=0"
90 end if
So never have a REMark on the same line with an IF !


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: QLiberator bug

Post by tofro »

Andrew,

That's actually not a QLiberator bug, but rather an S*Basic quirk (?):

Code: Select all

IF <condition> : <statement>
Is a "single-line conditional" - like in Microsoft (and other) BASICs: The statement after the colon is executed when the condition is true, an implicit END IF is assumed at the end of the line. In your case, it's a REMark, unfortunately, and causes the compiler to see an un-matched END IF - The interpreter should see the same thing, only without complaining.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: QLiberator bug

Post by Andrew »

tofro wrote: The interpreter should see the same thing, only without complaining.
As far as I can tell in interpreter the code works correctly and the IF is fully executed, regardless or the REMark


User avatar
janbredenbeek
Super Gold Card
Posts: 630
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: QLiberator bug

Post by janbredenbeek »

tofro wrote:Andrew,
That's actually not a QLiberator bug, but rather an S*Basic quirk (?):
It seems that SBASIC behaves differently here than JS or Minerva. Try this

Code: Select all

100 FOR i=1 to 10: REMark test
110   PRINT i
120 ENDFOR i
When you execute this in SBASIC, you get numbers 1 to 10 printed. However in JS and Minerva it only prints 10!
The same goes for IF/ENDIF:

Code: Select all

100 condition=0
110 IF condition THEN: REMark test
120   PRINT "True"
130 ELSE
140   PRINT "False"
150 END IF
On JS and Minerva, this will print "True" even if condition is 0. When you remove the REMark after THEN, it prints "FALSE" as expected.
So, in SBASIC a REMark after an IF or FOR does not count as inline statement but in JS and Minerva it does!

Jan


User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: QLiberator bug

Post by Andrew »

Thank you Tofro and Jan for the explanations - now it makes sense.
Next time I'll keep in mind not to put comments on same line with an IF


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: QLiberator bug

Post by mk79 »

Andrew wrote:
tofro wrote: The interpreter should see the same thing, only without complaining.
As far as I can tell in interpreter the code works correctly and the IF is fully executed, regardless or the REMark
My guess is that the SBasic compiler throws away the REMarks in one pass so that the next pass does not see that you made a single-line IF anymore, so it works as you expected. SuperBasic, not being compiler based, doesn't work and QLiberator doesn't either as it probable has different phases. As "REMark" is more or less a normal command from a language perspective (unlike for example the comments in other languages that are started by special character sequences and are often removed before the actual compiler phase) the behaviour was completely non-surprising to me, but I can see that from a user perspective it's not ideal...


Post Reply