f$ = "1+2"
PRINT VAL(f$)
gives 3
PRINT VAL("1+2")
gives 0
PRINT VAL(f$)
gives 3
PRINT VAL("1+2")
gives 0
VAL = ? (solved)
|
f$ = "1+2"
PRINT VAL(f$) gives 3 PRINT VAL("1+2") gives 0
11-02-2023, 11:11 AM
Will investigate this (it should work in both cases).
However, bear in mind that VAL in Sinclair BASIC actually calls the ROM interpreter, and that ZX BASIC calls the ROM too for maximum compatibility. However evaluating variables won't work, since "x" must be declared in the Sinclair BASIC variable space, and the compiler does another thing. The same applies for functions (i.e. SQR, SIN, COS...). If you evaluate VAL("SQR 2") it will work if you use the "SQR" token. But if you type "SQR(2)" letter by letter it will fail. Most BASICs (other than Sinclair) will always return 0 in this case, because VAL only parse numbers, not expressions. Since this is *compiled* BASIC, using dynamic VAL evaluation is complex and costly. However if you need it, there's a function that even run entire BASIC code from within compiled BASIC.
11-02-2023, 11:20 AM
11-05-2023, 09:08 AM
(11-05-2023, 09:08 AM)boriel Wrote: EvalBasic. I got this error trying to compile the example: src/arch/zx48k/library/basic.bas:122: error: Syntax error. Unexpected token 'f' [ID]
11-07-2023, 11:13 PM
It's a bug, try downloading this beta:
http://www.boriel.com/files/zxb/zxbasic-...ta4.tar.gz http://www.boriel.com/files/zxb/zxbasic-...-beta4.zip http://www.boriel.com/files/zxb/zxbasic-...-win32.zip http://www.boriel.com/files/zxb/zxbasic-...x64.tar.gz http://www.boriel.com/files/zxb/zxbasic-...cos.tar.gz That routine only works in 48ik mode (not in +2 mode).
EVAL works, thanks.
01-03-2024, 10:28 PM
This version uses a more powerful VAL implementation.
http://www.boriel.com/files/zxb/zxbasic-...ta2.tar.gz http://www.boriel.com/files/zxb/zxbasic-...-beta2.zip http://www.boriel.com/files/zxb/zxbasic-...-win32.zip http://www.boriel.com/files/zxb/zxbasic-...x64.tar.gz http://www.boriel.com/files/zxb/zxbasic-...cos.tar.gz It will evaluate arithmetic expressions (parenthesis, numbers, and - / + *)
01-03-2024, 11:44 PM
Thanks
|
« Next Oldest | Next Newest »
|