Posts: 61
Threads: 17
Joined: Dec 2020
Reputation:
4
I'm new to the compiler, using it on Mac OS. Compiling a simple test program works fine. If I paste in the code from the FSin function from the documentation it won't compile:
Code: ../sine.bas:16: error: Syntax Error. Unexpected token 'ELSE' <ELSE>
../sine.bas:17: error: Syntax Error. Unexpected token 'IF' <IF>
../sine.bas:44: error: Syntax Error. Unexpected token 'FUNCTION' <FUNCTION>
I can't understand why the compiler doesn't like this, it looks ok to me. However, I can see an IF without an END IF. This is not how this listing is expressed in the forum post where it was first published. However, adding the missing END IF doesn't appear to help with the compiler errors. What is the problem here?
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
12-28-2020, 09:04 AM
(This post was last modified: 12-28-2020, 04:21 PM by boriel.)
(12-28-2020, 01:43 AM)-lpatters Wrote: I'm new to the compiler, using it on Mac OS. Compiling a simple test program works fine. If I paste in the code from the FSin function from the documentation it won't compile:
Code: ../sine.bas:16: error: Syntax Error. Unexpected token 'ELSE' <ELSE>
../sine.bas:17: error: Syntax Error. Unexpected token 'IF' <IF>
../sine.bas:44: error: Syntax Error. Unexpected token 'FUNCTION' <FUNCTION>
I can't understand why the compiler doesn't like this, it looks ok to me. However, I can see an IF without an END IF. This is not how this listing is expressed in the forum post where it was first published. However, adding the missing END IF doesn't appear to help with the compiler errors. What is the problem here?
Thanks for the report!
I've fixed it. This has been also updated in the wiki:
https://zxbasic.readthedocs.io/en/docs/library/fsin.bas
That syntax was allowed in legacy version of the compiler where every IF had be closed with END IF. To improve the compatibility with traditional BASIC syntax, a more relaxed form was allowed. So if a sentence follows the THEN or ELSE tokens, the compiler understands it's a single-line IF. So the fix is just breaking the line with after the THEN :-)
Please, try and tell me.
Posts: 61
Threads: 17
Joined: Dec 2020
Reputation:
4
12-28-2020, 12:17 PM
(This post was last modified: 12-28-2020, 02:23 PM by patters.
Edit Reason: Sorry - quite a few edits, I had mucked up the radians conversion and needed to re-do the Sinclair BASIC screenshot
)
Thanks, that has resolved the compilation issue. However, the maths doesn't seem correct for this fSin function. My sample FOR loop below should draw a sine wave across the screen.
Code: REM SINCLAIR BASIC SIN (radians)
10 FOR d=0 TO 255: PLOT d,90: LET r=(d+90)*PI/180: DRAW 0,64*(SIN r): NEXT d
SIN - Sinclair BASIC.png (Size: 3.82 KB / Downloads: 3,189)
Code: REM BORIEL BASIC fSIN (degrees)
FOR d=0 TO 255: PLOT d,90: DRAW 0,64*(fSin (d+90)): NEXT d
fSin - Boriel BASIC.png (Size: 4 KB / Downloads: 3,172)
In both cases I have offset the sine wave by 90 degrees on the X axis. Notice that the fSIN pattern seems to break and reset just as it prepares to enter the fourth quad (but slightly before the symmetry point) of the pre-calculated table.
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
12-28-2020, 04:28 PM
(This post was last modified: 12-28-2020, 04:30 PM by boriel.)
(12-28-2020, 12:17 PM)patters Wrote: Thanks, that has resolved the compilation issue. However, the maths doesn't seem correct for this fSin function. My sample FOR loop below should draw a sine wave across the screen.
Code: REM SINCLAIR BASIC SIN (radians)
10 FOR d=0 TO 255: PLOT d,90: LET r=(d+90)*PI/180: DRAW 0,64*(SIN r): NEXT d
Code: REM BORIEL BASIC fSIN (degrees)
FOR d=0 TO 255: PLOT d,90: DRAW 0,64*(fSin (d+90)): NEXT d
In both cases I have offset the sine wave by 90 degrees on the X axis. Notice that the fSIN pattern seems to break and reset just as it prepares to enter the fourth quad (but slightly before the symmetry point) of the pre-calculated table.
I get the correct result if I DIM d as Integer first.
Seems that you're not doing it and d + 90 is results in overflow (200 + 90 for example is out of the range 0-255).
Code: REM BORIEL BASIC fSIN (degrees)
DIM d as Integer
FOR d=0 TO 255: PLOT d,90: DRAW 0,64*(fSin (d+90)): NEXT d
Posts: 805
Threads: 135
Joined: Apr 2009
Reputation:
5
12-28-2020, 04:33 PM
(This post was last modified: 12-28-2020, 04:34 PM by britlion.)
That's intriguing.
What sort of variable is d? I think when d+90 = 255, then it wraps to d+90 = 0 sent into the function, giving you sin 0 again.
I see mister Boriel got to the same answer while I was looking and typing
Posts: 61
Threads: 17
Joined: Dec 2020
Reputation:
4
Thanks guys, die hard Sinclair BASIC user here, forgot the variable wouldn't default to a float. And to think an Ariane 5 rocket was lost to a very similar error:
https://www.bugsnag.com/blog/bug-day-ariane-5-disaster
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
(12-28-2020, 06:05 PM)patters Wrote: Thanks guys, die hard Sinclair BASIC user here, forgot the variable wouldn't default to a float. And to think an Ariane 5 rocket was lost to a very similar error:
https://www.bugsnag.com/blog/bug-day-ariane-5-disaster
Oh RIP Ariane
A pitty and a (hard) lesson learned.
|