Author Topic: bc9 Embedded Scripting  (Read 6562 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
bc9 Embedded Scripting
« on: January 10, 2013, 07:08:48 PM »
This is an example of embedding ScriptBasic in bc9.

Code: [Select]
' bc9 Basic Interpreter

#include <scriba.h>
#include <getopt.h>

Global pProgram as pSbProgram

pProgram = scriba_new(malloc,free)
scriba_LoadConfiguration(pProgram,"/etc/scriba/basic.conf")
scriba_SetFileName(pProgram, COMMAND$(1))
scriba_LoadSourceProgram(pProgram)
scriba_Run(pProgram,COMMAND$(2))
scriba_destroy(pProgram)

jrs@laptop:~/bcx9$ gcc ibc9.C -I/home/jrs/sb/source -lscriba -lpthread -o ibc9
ibc9.C: In function ‘int main(int, char**)’:
ibc9.C:169:59: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
jrs@laptop:~/bcx9$ ./ibc9 E01.sb JRS
(0): error &H44:The file can not be read.
Segmentation fault (core dumped)   ???
jrs@laptop:~/bcx9$

If I hard code the arguments and don't use the COMMAND$() option, I get warnings but at least it runs. I don't seem to have this issue with BaCon and embedding SB.

Code: [Select]
' bc9 Basic Interpreter

#include <scriba.h>
#include <getopt.h>

Global pProgram as pSbProgram

pProgram = scriba_new(malloc,free)
scriba_LoadConfiguration(pProgram,"/etc/scriba/basic.conf")
scriba_SetFileName(pProgram,"E01.sb")
scriba_LoadSourceProgram(pProgram)
scriba_Run(pProgram,"JRS")
scriba_destroy(pProgram)

jrs@laptop:~/bcx9$ gcc ibc9.C -I/home/jrs/sb/source -lscriba -lpthread -o ibc9
ibc9.C: In function ‘int main(int, char**)’:
ibc9.C:169:59: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
ibc9.C:170:37: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
ibc9.C:172:26: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
jrs@laptop:~/bcx9$ ./ibc9
ARG = JRS
1
2
3
4
5
6
7
8
9
10
jrs@laptop:~/bcx9$




« Last Edit: January 10, 2013, 09:23:07 PM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: bc9 Embedded Scripting
« Reply #1 on: January 12, 2013, 10:26:10 AM »
I think I'm going to put the bc9 effort on the shelf until James regroups and stabilizes his fork of BCX. I had good success with MBC in the past before it became a C++ centric translator for OSX/Linux. The original idea of a stripped down console ANSI C Basic to C translator was only short lived.

I still think the idea of using SB as the translator to generate ANSI/ISO C using the best concepts of current translators available makes sense. This would allow any dialect of Basic to be translated to C. When you get down to it, Basic converted C syntax looks pretty much the same no matter if BaCon, BCX or whatever translated it.

Once I get this SB IUP project wrapped, maybe there will be enough interest in Basic again a AB2C (All Basic to C) generic translator could be developed.