skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
328 stars 27 forks source link

Handled built-ins as expressions. #26

Closed skx closed 6 years ago

skx commented 6 years ago

This works:

10 PRINT RND 4

These fails:

 10 PRINT RND RND 4
 10 COLOR RND 255, RND 255, RND 255

The reason for this is interesting. We store variables as {token.IDENT }, and we added special code to first of all look for a built-in every time we get the value of a variable. However for that to work we need to skip tokens more than we do.

The solution to this problem is to treat builtins as something that can be handled by expr. Which means we stop faking the invokation of builtins, but actually do it for real. This will be easier to implement than describe!

skx commented 6 years ago

I didn't fully explain, it is 5AM, this means we have to change the way we handle builtins too:

If we find an ident as an argument to a builtin we have to pass the value of that ident, and if a built-in is a built-in we pass the result of the expression being evaluated via expr().

Without this the implementation will break, because when we skip tokens to collect the arguments we'll not skip enough..

skx commented 6 years ago

Made good progress in #27, but there are some breaking-changes for users who embed. Oops.

At some point I need to declare API-stability, but we're not there yet :)

skx commented 6 years ago

Closed in #27.