3 ms·
$ echo 'PRINT 3+4∗5' > test.bas $ go run main.go test.bas 34 $ echo 'PRINT (3+4*5)' > test.bas $ go run main.go test.bas 23 $ echo 'PRINT (3+4)*5
by tyingq 8y ago
$ echo 'PRINT 3+4∗5' > test.bas
$ go run main.go test.bas
34
$ echo 'PRINT (3+4*5)' > test.bas
$ go run main.go test.bas
23
$ echo 'PRINT (3+4)*5' > test.bas
$ go run main.go test.bas
35
No idea where it's getting 34 from though.
- stevekemp 8y agoGrr. Expressions are hard: 10 LET a = 3+4*5 20 PRINT a, "\n" Produces the expected outcome: -> 23 Bug filed: https://github.com/skx/gobasic/issues/41 https://github.com/skx/gobasic/issues/41
- jacquesm 8y agoYes, but it should not require that LET statement. The expression evaluator looks subtly broken.
- stevekemp 8y agoBug filed, as per the edited comment above. I definitely agree this is wrong!
- tyingq 8y agoDon't know if it's the same bug, but "PRINT 1/0" returns 1. "PRINT (1/0)" prints nothing. Using "LET a=1/0" raises a div by zero error. Also, "LET a=1%0" panics.
- stevekemp 8y agoThe issue with the "PRINT 1/0" and "PRINT (1/0)" are the same as the previous one. LET a = 1/0 SHOULD produce a division by error, so I think that's correct. But 1%0 shouldn't panic. I'll fix that.
- jacquesm 8y agoThank you! At the airport and no access to my desktop so I could not run the code but I suspected that was going to cause a problem. Deskchecking ftw ;)
- rpeden 8y agoIn the first case, maybe it's treating the '+' as string concatenation - so 3+4 is giving 34? Then it's just dropping the 5 because it can't multiply a string and a number. Regardless, I really like this project. :)
- tyingq 8y agoAhh, you're correct. go run main.go /dev/tty PRINT 1+2*5,"\n" ^D 12