Page 1 of 1

QLiberator bug

Posted: Mon Jan 04, 2021 5:33 pm
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 !

Re: QLiberator bug

Posted: Mon Jan 04, 2021 5:43 pm
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.

Re: QLiberator bug

Posted: Mon Jan 04, 2021 5:47 pm
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

Re: QLiberator bug

Posted: Mon Jan 04, 2021 11:35 pm
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

Re: QLiberator bug

Posted: Tue Jan 05, 2021 12:00 am
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

Re: QLiberator bug

Posted: Tue Jan 05, 2021 10:10 am
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...