Author Topic: C BASIC Interpreter  (Read 4913 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
C BASIC Interpreter
« on: December 01, 2013, 10:40:56 PM »
This is the first in a series of examples as I build a ScriptBasic IDE with C BASIC. I plan to use IUP for the cross platform IDE and run interactively like a Chipmunk Basic interpreter. This project has two goals. A modern IDE for SB and showing folks how to embed SB into their projects. The following example can run all the scripts that scriba (ScriptBasic console interpreter) can run.

-rwxrwxr-x 1 jrs jrs 6304 Dec  1 23:11 sb1 

Yes, that is a 6304 byte 64 bit traditional BASIC interpreter .

FYI - I'm going to be changing RETURN to RETURN_FUNCTION due to a conflict with SB already using it.

Code: [Select]
// C BASIC - ScriptBasic IDE
// gcc embed-b1.c -I/home/jrs/sb/source -lscriba -lpthread -o sb1

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "scriba.h"
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS pSbProgram pProgram;
  pProgram = scriba_new(malloc,free);
  scriba_SetFileName(pProgram, argv[1]);
  scriba_LoadSourceProgram(pProgram);
  scriba_Run(pProgram, argv[2]);
  scriba_destroy(pProgram);
  RETURN_FUNCTION(0);
END_FUNCTION

jrs@laptop:~/C_BASIC/SB-IDE$ gcc embed-b1.c -I/home/jrs/sb/source -lscriba -lpthread -o sb1
jrs@laptop:~/C_BASIC/SB-IDE$ time ./sb1 test.sb JRS
ARG = JRS
1
2
3
4
5

real   0m0.005s
user   0m0.000s
sys   0m0.000s
jrs@laptop:~/C_BASIC/SB-IDE$

test.sb
Code: [Select]
cmd = COMMAND()

PRINT "ARG = ",cmd,"\n"

FOR x = 1 TO 5
PRINT x,"\n"
NEXT
« Last Edit: December 02, 2013, 10:16:48 AM by John »