Author Topic: Script BASIC for Java  (Read 2017 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3004
    • ScriptBasic Open Source Project
Script BASIC for Java
« on: October 10, 2018, 05:17:34 PM »
Quote from: Peter Verhas
ScriptBasic for Java is a BASIC interpreter that can be embedded into Java programs. With SB4J you can script your application (or let the users to script) in good old BASIC. You can start in the JVM an interpreter and execute for example
Code: Script BASIC
  1. PRINT "hello, I am BASIC"
  2. PRINT "\nthe numbers from 1 to 10 are\n"
  3. FOR I=1 to 10
  4.   PRINT I,"\n"
  5. NEXT I
  6.  

SB4J has all the BASIC language features, assignments, loops, subroutines, global and local variables and no GOTO statement. Seriously.

To embed the interpreter into your application you need to use SB4J as a dependency

  <dependency>
    <groupId>com.scriptbasic</groupId>
    <artifactId>jscriptbasic</artifactId>
    <version>1.0.5</version>
  </dependency>

and then use the JSR223 defined scripting interface or use the ScriptBasic native integration API.

The simplest way is to

ScriptBasic.getEngine().eval("PRINT \"hello world\"");
get an execution engine and eval() the program source. There are other possibilities. You can specify the file where the source code is, a java.io.Reader to read the source code and there are even more advanced possibilities.

The BASIC language contains all the usual BASIC features, subroutines, local and global variables, conditional statements, loops and so on. (No GOTO!) Your host program can directly call subroutines, read and write global variables, provide methods implemented in Java to be called from BASIC code.

The interpreter can safely be integrated to applications as the BASIC programs can not access arbitrary objects and call Java methods at their will and there are other features that help controlling the scripts in the application. The language is a "no freak out" language, so you can put the programming possibility into the hands of users who would not ever touch Python, Groovy or some other programming language.

Script BASIC Java Project Repository


Mike Lobanovsky

  • Guest
Re: Script BASIC for Java
« Reply #1 on: October 10, 2018, 11:44:06 PM »
:o  KOOL!  8)

Offline AlyssonR

  • Advocate
  • Posts: 118
Re: Script BASIC for Java
« Reply #2 on: October 11, 2018, 01:35:39 AM »
What Mike said.

But ... no GOTO? Really?

So I can no longer call my error handler by using GOTO Hell

Pity. :D
« Last Edit: October 11, 2018, 01:38:42 AM by AlyssonR »

Offline John

  • Forum Support / SB Dev
  • Posts: 3004
    • ScriptBasic Open Source Project
Re: Script BASIC for Java
« Reply #3 on: October 11, 2018, 07:26:29 AM »
A true Android version of Script BASIC would be very doable using SBJ.

Offline John

  • Forum Support / SB Dev
  • Posts: 3004
    • ScriptBasic Open Source Project
Re: Script BASIC for Java
« Reply #4 on: January 18, 2020, 11:35:07 AM »
Quote from: Peter Verhas
With the pull req made by Petr Pytelka the version 2.1.0 of jScriptBasic is released. It is a simple embeddable BASIC interpreter written in Java that you can use in applications to let users write simple scripts. This rel features multiple commands on a single line. Thanks Petr

Multiple statements per line is a major direction change IMHO.
« Last Edit: January 18, 2020, 11:37:30 AM by John »