Author Topic: 9K BASIC Interperter  (Read 4301 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
9K BASIC Interperter
« on: December 10, 2015, 09:59:08 PM »
Here is how to build a 64 bit full featured BASIC console interpreter. (9 KB executable)

sbembed.c
Code: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <getopt.h>
  4. #include "scriba.h"
  5. #include "cbasic.h"
  6.  
  7. MAIN
  8. BEGIN_FUNCTION
  9.   DIM AS pSbProgram pProgram;
  10.   pProgram = scriba_new(malloc,free);
  11.   scriba_LoadConfiguration(pProgram, "/home/jrs/sb/sb22/bin/basic.conf");
  12.   scriba_SetFileName(pProgram, argv[1]);
  13.   scriba_LoadSourceProgram(pProgram);
  14.   scriba_Run(pProgram, argv[2]);
  15.   scriba_destroy(pProgram);
  16.   RETURN_FUNCTION(0);
  17. END_FUNCTION
  18.  

hello.sb
Code: ScriptBasic
  1. cmd = COMMAND()
  2.  
  3. PRINT cmd,"\n"
  4. FOR x = 1 TO 5
  5.   PRINT x,"\n"
  6. NEXT
  7.  


jrs@laptop:~/sb/sb22/test$ gcc -O2 sbembed.c -I/home/jrs/sb/source -lscriba -lpthread -o sbembed
jrs@laptop:~/sb/sb22/test$ ls -l sbembed
-rwxrwxr-x 1 jrs jrs 8903 Dec 10 21:48 sbembed
jrs@laptop:~/sb/sb22/test$ time ./sbembed hello.sb JRS
JRS
1
2
3
4
5

real   0m0.004s
user   0m0.000s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$