Author Topic: conditional expression error  (Read 3312 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
conditional expression error
« on: March 06, 2011, 11:42:20 AM »
Deleted
« Last Edit: May 07, 2015, 11:27:15 AM by Peter »

Charles Pegge

  • Guest
Re: conditional expression error
« Reply #1 on: March 06, 2011, 01:17:17 PM »
Hi Peter,

I put this header code at the top of your first sample. No crashes when invoking ScanBees(). Crashes are most often caused by array boundary errors, Could this be a possibility?



Code: [Select]
indexbase 0
sys map2[100]
sys xbm,beeras,icx,idx
ibx=10
sys xbee[100],ybee[100],ibee[100],rbee[100]

Charles

PS: AND has a higher precedence level than OR

Charles Pegge

  • Guest
Re: conditional expression error
« Reply #2 on: March 06, 2011, 09:44:31 PM »
Hi Peter,

I found a precedence bug which I am fairly certain was the cause of the problems you found. Oxygen does not group these together correctly.

Code: [Select]
if a[2]>10 and a[3]>10 or a[4]>10 then print "yes" else print "no"

but if you supply brackets around the AND clause then it works correctly.

Code: [Select]
if ( a[2]>10 and a[3]>10 ) or a[4]>10 then print "yes" else print "no"

I have now fixed this problem by making the precedenter more recursive! - The precedenter's duty is to insert brackets into expressions before they are compiled, but it was failing to insert more than one bracket pair when the precedence dropped by more than one level.

thus the precedenter needs to insert 2 opening brackets at the start:
Code: [Select]
if ( (a[2]>10) and (a[3]>10) ) or (a[4]>10) then print "yes" else print "no"

This correction will be in the next release (A29)

Charles


Charles Pegge

  • Guest
Re: conditional expression error
« Reply #3 on: March 07, 2011, 08:53:25 AM »
Peter,

A29 should be ready within the next few hours. I have just got the new runtime library working, and need to run a few more tests.

It will save you from bracket hell :)

Charles

Charles Pegge

  • Guest
Re: conditional expression error
« Reply #4 on: March 08, 2011, 08:32:32 AM »
Hi Peter,

Do you agree with these groupings  ;D

Code: [Select]

if a=a and a==a or a==a and a==a then
  'translates to ((a==a)and(a==a))or((a==a)and(a==a))
end if


if a==a*a+a and a*a+a==a or a==a and a==a then
  'translates to ((a==((a*a)+a))and(((a*a)+a)==a))or((a==a)and(a==a))
end if


if a==a << a * a + a and a xor a or a
  'translates to (((a==a<<((a*a)+a)))and a)xor a)or a
end if

Charles