IIRC, Net Basic didn't throw an error when I attempted to do:
Code: Select all
IF (r < g) AND (r < b) THEN LET min = r
It failed and after looking into the sample codes, I understood I had to jump instead. But I expected an error at least.
I have not yet figured out how to support that (haven't tried much either) or the combining of lines with a colon. I will add else/endif instead. My parser is "different" than most proper ones. It just splits the text as it goes.
I have not made any effort to implement error checking yet. My plan is to do that last by studying the errors in other Tiny BASIC implementations. For now I need to update the documentation to specify that combining statements with IF or : is not supported.
I also expected RND to return a value between 0 (included) and 1 (excluded) but got a very large integer instead. I assume it's an oversight, so I divided the result by 2^31. This one is a bit dirty, but it does the job:
This is due to my use of the PHP RND function. I need to write a custom RND function to return the same range as Qbasic.
Another issue is that PHP returns 1 for true as opposed to -1 like QBasic (I noticed YaBasic also returns a 1). I made functions return -1 and changed AND and OR to return -1 on true. The problem comes with NOT(). I don't know how to make it return the same values as QBasic. Right now it will return a 1 on true. I need to change that to make it return -1 to be consistent. Problem is Qbasic gives other values than just -1 and 1 depending on the number. Oh the decisions....
Anyway, I tried designing scripting languages a few times; I usually have no issue with flow control (GOTO, GOSUB, RETURN, IF, ELSEIF, ELSE, ...) but I really can't write a proper way to evaluate stuff. The moment operators and variables get involved, it turns into some kind of Frankenstein monster of a language.
Kudos to you.
Wow that game demo reminds me of Toki a bit. The language looks interesting I am going to study that a bit. Your code looks extremely well written and pretty advanced at a glance.
The expression evaluation stuff has always been out of my reach, so a little over a year ago I decided to dedicate my life to figuring it out and now here I am. My methods are different, but seem to work. What helped me was studying Reverse Polish Notation. You must convert infix notation to postfix, then evaluate the postfix. This wasn't too hard with just four arithmetic operators. The parenthesis are processed and removed during the infix to postfix phase. I was really stumped on things like boolean and relops. Variables weren't too hard. Functions took some creative gutsy attempts. The arrays are still a struggle too.
I'd be happy to share what I have learned about expression evaluation if needed. I can pull up some of the resources that I had studied. TBH it was a bunch of old college class assignments, calculator websites, and RPN tutorials.