gobasic icon indicating copy to clipboard operation
gobasic copied to clipboard

Error in DEF FN: Expected FN after DEF

Open udhos opened this issue 6 years ago • 3 comments

gobasic is reporting error for this program. How can I find the root cause?

lab@ubu1:~$ gobasic basgo/examples/trek/superstartrek.bas
Error constructing interpreter:
        Error in DEF FN: Expected FN after DEF
lab@ubu1:~$

Full source code: https://github.com/udhos/basgo/blob/master/examples/trek/superstartrek.bas

udhos avatar Feb 01 '19 13:02 udhos

"Error in DEF FN: Expected FN after DEF" means:

  • The program started processing a "DEF..." statement.
  • But the next token was not "FN".

gobasic expects something like:

DEF FN blah(arg) = arg * arg

Instead it received something without FN:

DEF ....

If you look at the sample code you posted you'll see:

  470 DEF FND(D)=SQR((K(I,1)-S1)^2+(K(I,2)-S2)^2)
  475 DEF FNR(R)=INT(RND(R)*7.98+1.01)

DEF FNR.. != DEF FN ...

skx avatar Feb 01 '19 14:02 skx

Got it, thanks!

Do you think that gobasic could support both modes? FN A() and FNA() ? See example below.

Code:

$ more fn.bas
10 DEF FNA(X)=X*X
20 DEF FN B(X)=X*X*X
30 PRINT "fna(2)=";FNA(2)
40 PRINT "fn b(2)=";FN B(2)

Output:

fna(2)= 4
fn b(2)= 8

udhos avatar Feb 01 '19 14:02 udhos

That would be a harder change than I'd like; since the parse would need to know that "FNA" was not the identifier "FNA" but instead two tokens "FN + A"..

skx avatar Feb 02 '19 08:02 skx