Subtraction not processed
eotect opened this issue · comments
gobasic version v1.8 under windows 7 x64
Code:
LET a="Hello, World!"
LET b=LEN a
PRINT "b=",b,"\n"
b=b-1
PRINT "b=",b,"\n"
Output:
b= 13
b= 13
I figured it out, i need to put a space after -.
changed b=b-1 to b=b- 1, and it works.
Thanks for the bug-report, and the work-around.
It seems this is caused by bad parsing (as you can tell!) interestingly the other operations are working as expected:
LET a="Hello, World!"
LET b=LEN a
PRINT "b=",b,"\n"
b=b+1
PRINT "b=",b,"\n"
b=b*3
PRINT "b=",b,"\n"
b=b/6
PRINT "b=",b,"\n"
b=b-37
PRINT "b=",b,"\n"
Shows:
$ ./gobasic bug.bas
b= 13
b= 14
b= 42
b= 7
b= 7 # WRONG
Looks like this is a consequence of the tokenizer.
- "a - 1" is parsed as "a", "-", "1".
- "a-1" is parsed as "a", "-1".
Which explains why adding the space fixes it. Frustratingly this is a hard thing to fix, without losing support for negative numbers. I'll have to ponder whether it can be done, or whether it should be resolved by documenting it.
i found my issue title was totally wrong...
glad you addressed the problem, i don't know about parsing tokens, but a variable followed by negative numbers make no senses. maybe there are some method for helping the parser make right decisions?
thanks for this program i enjoy playing with it.