Basic Interpreter 32-bit DLL for script
Blitz3D Forums/Blitz3D Userlibs/Basic Interpreter 32-bit DLL for script
| ||
BINT32 is a small Basic Interpreter 32-bit DLL build by Eros Olmi for PowerBasic. I make a Blitz3D wrapper for it. http://www.zinfo972.net/pubip/bint32_pack.rar A Blitz3D Example ;++++++++++++++++++++++++++++++++++++++++++++++++ ; BINT32 Wrapper (c) zjp ;++++++++++++++++++++++++++++++++++++++++++++++++ BINT_Reset BINT_About ; Global FileName$ = "Test03_Speed.txt" ; << The script Global buffer$ title$="Script to run" ; load script Script$ = BINT_FileLoad(FileName$) BINT_Message(title$, Script$ ) ; display the script. For fun !!! ; run the script and check for error result% = BINT_Run(Script) If result% Then Print "Error number " +result% Print "Error at line " +BINT_ErrorGetLine%() Print "Error description " +BINT_ErrorDescription$(result%) Delay 5500 End EndIf ; Variables tests SeedRnd MilliSecs() MyProgram$ = "a*x^4 + b*x^3 + c*x^2 + d*x + e" BINT_SetNumber("a", Rnd(-10,10)) BINT_SetNumber("b", Rnd(-10,10)) BINT_SetNumber("c", Rnd(-10,10)) BINT_SetNumber("d", Rnd(-10,10)) BINT_SetNumber("e", Rnd(-10,10)) BINT_SetNumber("x", Rnd(-10,10)) ; get variables. just check a = BINT_GetNumber("a") b = BINT_GetNumber("b") c = BINT_GetNumber("c") d = BINT_GetNumber("d") e = BINT_GetNumber("e") x = BINT_GetNumber("x") Print "a = " + a Print "b = " + b Print "c = " + c Print "d = " + d Print "e = " + e Print "x = " + x ; MyProgramPtr% = BINT_EvalMathPreParse(MyProgram$) If BINT_Error Then Print "Error during PreParsing operation. Program aborted." Delay 3000 End End If loop% = 100 For counter = 1 To Loop BINT_SetNumber("x", counter) If BINT_Error Then Print "Variable error" Delay 3000 End EndIf Result_math# = Result_math# + BINT_EvalMath(MyProgramPtr) rtError% = BINT_ErrorClear() If rtError Then Print "An error occurred.Error code: " + rtError Print "Description: " + BINT_ErrorDescription(rtError) Print "Token found: " + BINT_ErrorGetToken() Print "Occurred at line:" + BINT_ErrorGetLine() Delay 3000 End End If Next ; Print "Result parse "+ Result_math# Delay 3000 ;---------------- ; a string script ;---------------- crlf$=Chr(13)+Chr(10) MyProgram$ = "" ; MyProgram$ = MyProgram$ + "'--------------------------------------- " + CRLF MyProgram$ = MyProgram$ + "'Test nested IF " + CRLF MyProgram$ = MyProgram$ + "'--------------------------------------- " + CRLF MyProgram$ = MyProgram$ + "DIM aNumber AS Number " + cRLF MyProgram$ = MyProgram$ + "aNumber = 999 " + CRLF MyProgram$ = MyProgram$ + " " + CRLF MyProgram$ = MyProgram$ + "IF aNumber >= 100 THEN " + CRLF MyProgram$ = MyProgram$ + " IF aNumber >= 1000 THEN " + CRLF MyProgram$ = MyProgram$ + " IF aNumber >= 2000 THEN " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''>= 2000'') " + CRLF MyProgram$ = MyProgram$ + " ELSE " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''>= 1000 AND < 2000'') " + CRLF MyProgram$ = MyProgram$ + " END IF " + CRLF MyProgram$ = MyProgram$ + " ELSE " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''>= 100 AND < 1000'') " + CRLF MyProgram$ = MyProgram$ + " END IF " + CRLF MyProgram$ = MyProgram$ + "ELSE " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''< 100'') " + CRLF MyProgram$ = MyProgram$ + "END IF " + CRLF MyProgram$ = MyProgram$ + "'--------------------------------------- " + CRLF MyProgram$ = MyProgram$ + "IF ''A'' > ''B'' THEN " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''A > B'') " + CRLF MyProgram$ = MyProgram$ + "ELSE " + CRLF MyProgram$ = MyProgram$ + " MSGBOX(''A < B'') " + CRLF MyProgram$ = MyProgram$ + "END IF " + CRLF MyProgram$ = MyProgram$ + crlf ;--- ; Show the script ;--- BINT_Message("Code that will be executed", MyProgram) ;--- ; Run the script ;--- BINT_Run(MyProgram) rtError = BINT_ErrorClear If rtError Then Print "An error occurred.Error code: " + rtError Print "Description: " + BINT_ErrorDescription(rtError) Print "Token found: " + BINT_ErrorGetToken() Print "Occurred at line:" + BINT_ErrorGetLine() Delay 3000 End End If End A Script example "Test03_Speed.txt" DIM t0 AS NUMBER VALUE TIMER DIM t1 AS NUMBER DIM t2 AS NUMBER DIM t3 AS NUMBER DIM t4 AS NUMBER DIM t9 AS NUMBER DIM Count AS NUMBER DIM MaxLoops AS NUMBER VALUE 1000 DIM tmpNumber AS NUMBER DIM tmpString AS STRING DIM Message AS STRING DIM tFormat as string VALUE "#0.0000000" '----------------------------------------------------------------------------- 'Test speed: FOR loop '----------------------------------------------------------------------------- t1 = TIMER FOR Count = 1 TO MaxLoops INCR tmpNumber NEXT '----------------------------------------------------------------------------- 'Test speed: WHILE loop '----------------------------------------------------------------------------- t2 = TIMER Count = 0 tmpString = "" WHILE Count < MaxLoops INCR Count WEND '----------------------------------------------------------------------------- 'Test speed: DO loop WHILE '----------------------------------------------------------------------------- t3 = TIMER Count = 0 tmpString = "" DO INCR Count LOOP WHILE Count < MaxLoops '----------------------------------------------------------------------------- 'Test speed: DO loop UNTIL '----------------------------------------------------------------------------- t4 = TIMER Count = 0 tmpString = "" DO INCR Count LOOP UNTIL Count >= MaxLoops t9 = TIMER Message = _ "Test " & MaxLoops & " loops:" & CRLF$ & _ "Declaration time: " & FORMAT$(t1-t0,tFormat) & " seconds." & CRLF$ & _ "FOR time: " & FORMAT$(t2-t1,tFormat) & " seconds." & CRLF$ & _ "WHILE time: " & FORMAT$(t3-t2,tFormat) & " seconds." & CRLF$ & _ "DO WHILE time: " & FORMAT$(t4-t3,tFormat) & " seconds." & CRLF$ & _ "DO UNTIL time: " & FORMAT$(t9-t4,tFormat) & " seconds." & CRLF$ & _ "MessageStr time: " & FORMAT$(Timer-t9,tFormat) & " seconds." & CRLF$ MSGBOX(Message) |