04-27-2009, 08:16 PM
britlion Wrote:Not sure whether this is as intended, but it's not quite compatible with Sinclair Basic:That's right. They start from 0. The reason is it's a little faster to compute string index starting from 0 (otherwise, a "dec" asm instruction would be needed). In the future, the --sinclair compatibility flag would enable strings starting from 1 (as it does currently with arrays).
LET K$="1234567890"
PRINT K$(TO 3)
PRINT K$( 3 TO)
All seems to compile - though strings are numbered from 0, whereas Sinclair basic numbers them from 1.
Quote:So ZX Basic gives the output:Well, that's the idea above. On the other hand, the compiler tries to be somewhat Sinclair compatible, but it's more similar to FreeBasic. The reason is, FreeBasic, like ZX Basic is a standard, and it's oriented to compiled execution, whilst Sinclair Basic is more designed to be used as an interpreted language. Hence, emulating some Sinclair Basic instructions like VAL or VAL$ are almost impossible (VAL$ is not implemented, and VAL behaves as a in FreeBasic).
1234, where Sinclair basic would give the output 123
If the aim is to be able to compile Sinclair Basic, we're not there with that one. (Perhaps a switch, or configurable option?)
Quote:Also:Could be a grammar bug. I will try to include these grammar cases.
Print K$(3) fails. We would need to use k$(3 TO 3). Is this a bug?
PRINT K$( TO ) also fails, and ZX Basic allows it. It's an unusual corner case, though - it means the same thing as just K$. If it was to be supported for compatibility, a preprocessor tweak ought to be able to optimize it to disappear before the compiler saw it.
Thanks a lot for your feed back. :wink: