Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in DEF FN: Expected FN after DEF #94

Open
udhos opened this issue Feb 1, 2019 · 3 comments
Open

Error in DEF FN: Expected FN after DEF #94

udhos opened this issue Feb 1, 2019 · 3 comments

Comments

@udhos
Copy link

udhos commented Feb 1, 2019

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

@skx
Copy link
Owner

skx commented Feb 1, 2019

"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 ...

@udhos
Copy link
Author

udhos commented Feb 1, 2019

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

@skx
Copy link
Owner

skx commented Feb 2, 2019

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"..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants