Author Topic: 'Eval' function  (Read 12894 times)

rafalg

  • Guest
'Eval' function
« on: July 02, 2007, 12:59:53 AM »
Hello, please tell me if scriptbasic implements an 'eval' function (that is, a function that would execute arbitrary SB code passed as a string argument).
If not, is there any way of achieving similar behavior?

Best Regards
Rafal Gwizdala

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
'Eval' function
« Reply #1 on: July 02, 2007, 01:31:53 AM »
ScriptBasic can be embedded into another application. (see libscriba docs)

This will allow you to pass code and expresions to the scripting engine and have it return results.

I use Business Basic as well and it has a EXECUTE feature that will process a string of code/expressions.

Can you expand on what your trying to do?

John

rafalg

  • Guest
'Eval' function
« Reply #2 on: July 02, 2007, 03:49:17 AM »
I have quite a specific requirement: Some time ago I developed an application for managing motion-control hardware (robotics, automation in general). The main functions of the applications are: hardware configuration, programming motion paths and monitoring the status. The application provides a scripting interface based on TCL. From some points of view TCL is perfect for that purpose - multithreaded, embeddable, concise and supports dynamic scripting to an extreme. The dynamic scripting feature is especially important, as it is heavily used throughout the application.
Examples:
- reading/writing configuration parameters
- interactive commandline/console interface for device operators (remote console)
- networked communication (script commands are sent through network and executed on server)
- monitoring arbitrary parameters (server periodically executes a script that collects the data, and the script to execute is sent from the client application)

As you can see, it is essential that the script supports eval.
The main problem with TCL is its syntax. It is completely unintuitive for engineers, and what they would rather use is BASIC-like language.

Best regards,
RG

paopao

  • Guest
'Eval' function
« Reply #3 on: July 02, 2007, 08:40:49 AM »
Hi RG :)

I'm a newbie with ScriptBasic but it looks to me there is no eval function (at least in the user guide or in the folder commands..maths functions).

Anyway I remember quite a long ago, when I used the early versions of VB or QuickBasic,  that there were more than a source code example how to implement the eval function by yourself. So if you don't know C/C++ I guess you could easily create a custom function using other basic commands.

In http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=21277&lngWId=1 there is a sample for VB that I believe might be easily ported to ScriptBasic.

Hope it helps,
Roberto

verhas

  • Guest
why there is no eval and limitations in ScriptBasic
« Reply #4 on: October 17, 2007, 01:33:57 AM »
ScriptBasic is compiled interpreter. The source code is compiled into an intermediate code and the code created by the first pass is interpreted. Much like Python. This is to reach faster execution not needing recompilation each time the program is executed.



The generated code contains a symbol table of the global and local variables attached at the end of the file. However this is a debugger feature and is not needed by the interpreter. The interpreter does not use this symbol table and as a matter of fact the table itself could be chopped off from the generated file (as far as I can remember I wrote a sample BASIC program many years ago that did this) and the interpreter still runs.



If one wants to implement a module that contains a function something like 'eval' he or she should have a look at the debugger that accesses the table and also calls the compiler part of the interpreter to compile the code with a prebuilt symbol table. Very difficult.



After all: the language was designed 10 years ago from the very start with this architecture that does not allow 'eval'. I knew it by that time. It was my decision not to have 'eval' and to get a better performance and compact generated code that can be saved and loaded easily.