Share My Creation Device Basic language IDE

Unfortunately without a Device IDE it is no longer possible to whip up quick and dirty programs on an Android device like we could with Basic4ppc on Windows Mobile.

I realised that my BasicLib script interpreter library only lacked one thing that stopped it being used as the basis for an interpreter for a device IDE and that was that it didn't support any means of responding to external events so all it could do was run linear code then exit. Fine for scripts but not for a user driven application that spends most of its time suspended waiting for events to happen. So I added it!

As well as being able to respond to events a program needs to be able to interact with the platform to add controls and access the GUI, file system and other OS services. Unlike previous versions of BasicIDE, which used the normal BasicLib library and relied upon the "Sys" function to call methods, version 2.2, and future, versions use a new BasicLibIDE library that "knows" about the methods in Script.bas so the platform functions are now embedded in the script language. It is important that the version of Script.bas matches that of the BasicLibIDE library as both need to be modified in parallel to add new functions to the language.

The previous Sys and CallHostSub functionality is of course still available.

The demo program here supports the most important views, and their events, for small programs and has graphics and file handling support. Look at Readme.txt for instructions and the comments in the Script module to see what is implemented there.

EDIT :- See post #7 for a suggestion to add Invalidate to the Script module

EDIT :- Version 2.0 posted. See post #8 for details.

EDIT :- Version 2.1 posted. See post #9 for details.

EDIT :- Version 2.2 posted. See post #15 for details.

EDIT :- Version 2.2a posted with the BasicLibIDE library included. See post #17 for details.

EDIT :- Version 2.3 posted. See post #18 for details.

EDIT :- Version 2.4 posted. See post #20 for details.

EDIT :- Version 2.5 posted. See post #23 for details.

EDIT :- JesseW has posted his improved version of the IDE itself, see post #32 for details. You will still need the BasicLibIDE jar and xml from the archive in this post.

EDIT :- Version 2.6 posted. See post #47 for details.

EDIT :- Version 2.7 posted. See post #51 for details.

EDIT :- Version 2.8 posted. See post #52 for details.

EDIT :- Version 2.9 posted. See post #79 for details.

EDIT :- Version 2.91 posted. See post #87 for details.

EDIT :- Version 2.92 posted. See post #92 for details.

EDIT :- Version 2.93 posted. See post #95 for details.

EDIT :- Version 2.94 posted. See post #100 for details.

EDIT :- Version 2.95 posted. See post #118 for details.

EDIT :- Version 2.96 posted. See post #138 for details.

EDIT :- Version 2.97 posted. See post #140 for details.

EDIT :- Version 1.98 of BasicLibIDE is posted below. Use this instead of the version in BasicIDE2.97.zip. It fixes a problem with Call and CallSub.
 

Attachments

  • BasicLibIDE.jpg
    BasicLibIDE.jpg
    12 KB · Views: 30,415
  • BasicIDE2.97.zip
    118 KB · Views: 2,110
  • BasicLibIDE_1.98.zip
    44.1 KB · Views: 1,006
Last edited:

JesseW

Active Member
Licensed User
...End Sub and Return just set the If and Do stacks empty so need no logic as they also pop the SUB stack and so there is no block structuring to remember even if Return exits from one or more nested DOs or IFs....

I really appreciate the explanation! Thx... :)

B4X:
For a = 1 To 5
  If a < 5 Then
    mySub(a)
  Endif
Next

Sub mySub(x)
  ... do some stuff
End Sub

Question: as in the above code, since a sub can be called from, and return to, within a Do/For/If construct (and all indications say it does so correctly) does each entry on the Sub stack have it's own local If and Do stacks? Otherwise, when the sub returned, zero'ing the Do/For/If stacks, and the Next and/or Endif was encountered, it'd report a No Matching For Statement or No Matching If Statement error, or does each Sub remember the Do/For/If stack levels on entry, and reset them to that point upon exit?
 

agraham

Expert
Licensed User
does each entry on the Sub stack have it's own local If and Do stacks?
Yes.

One call stack holding the return point for nested Sub calls
B4X:
private int[] callstack; // SubReturnPoint = callstack[SubDepth]
private int callstackptr; // SubDepth

A stack each for FOR/DO and IF independently for each nested Sub call
B4X:
private _forstruct[,] forstack; // ForStruct = forstack[SubDepth, ForDepth]
private int[] forstackptr; // ForDepth = [SubDepth]

private _ifstruct[,] ifstack; // IfStruct = ifstack[SubDepth, IfDepth]
private int[] ifstackptr; // IfDepth = [SubDepth]

The arrays are initialised at script run time according to the StackDepth property.
B4X:
callstack = new int[MaxStackDepth];
forstack = new _forstruct[MaxStackDepth, MaxStackDepth + 1];
ifstack = new _ifstruct[MaxStackDepth, MaxStackDepth + 1];
 

JesseW

Active Member
Licensed User
Would it be possible to add a method to retrieve a list of global variable names, and a list of local variable names of the current sub? Some day, if I'm ever able to find the time, I plan to expand debug capabilities of B4Script, allowing the listing of all var's with their current values, while stepping through a script.

Thanks...
Jesse
 

agraham

Expert
Licensed User
Something like ...
B4X:
Sub GetVariableNames(Globals As List, Subname As String, Locals As List)
   Dim g As String
   Dim i As Int
   Globals.Clear
   Locals.Clear
   i = 0
   g = Basic.dbgGlobal(i)
   Do Until g = ""
      Globals.Add(g)
      i = i + 1
      g = Basic.dbgGlobal(i)
   Loop
   i = 0
   g = Basic.dbgLocal(SubName, i)
   Do Until g = ""
      Locals.Add(g)
      i = i + 1
      g = Basic.dbgLocal(i)
   Loop
End Sub

EDIT :- I dashed the original code above off from memory and overlooked the fact that you need to define a Sub if you want to get its' locals :( Now fixed.
 
Last edited:

JesseW

Active Member
Licensed User
thank you! looking through the docs, I was unable to find a method to return the current sub name, but I figure I can look upwards through the source from the current line number to find the pprevious occurrence of a sub definition, unless you know an easier way.

I wanted to say I ran across the reflection thread and was saddened to hear of your growing dislike for android. I have always highly respected you and continue to do so. I am glad your still available to answer questions, and hope you continue to do so. wishing you the best life has to offer!

jesse
 

eelias

Active Member
Licensed User
agraham:

Very nice you work.

I have a question that would be very important for my project.

I am writing some android apks and using webservices in a mixture of "some intelligence" in each side.

In fact, I have a lot of code on Delphi in PC side, and there is a need to have native windows apps using that code.

I was looking for RIA applications, and there is a jungle out there about that.

I was thinking about your scripting engine. I got in a point in my application that I could add new functionality on my code using your basic scripting, I believe for business apps most of what is necessary is there. Actually I would use only the script for the business model, since the interface could be standard and someway used by the script (i did not take a look on how this could be integrated).

But I am looking further, that is my question for you: since you wrote this in java, if i am correct, how difficult would it be to have a version available for PC?

My intention was to create the same framework on both sides, on android with B4A and on PC in Delphi and make the same calls for the same scripts.

Then I could implement new functionality to the application writing new scripts. Connecting to the database, etc

This new script could be published on a application library and done! All high level application business stuff created with this script.

The biggest barrier here is to have it working on pc side in a way that could be called from other languages. There is no need to be full script app running, I need more the approach of a javascript in a webpage, small scriptlets to executed defined functions.

What you think?
 

agraham

Expert
Licensed User
how difficult would it be to have a version available for PC?
In fact the Java version is a translation of my C# library for Basic4ppc desktop use and I have kept both versions in sync. It is a .NET dll and so is usable by any language that can reference .NET assemblies. As I have no experience of Delphi I don't know if it would be of any use to you or not.
 

eelias

Active Member
Licensed User
In fact the Java version is a translation of my C# library for Basic4ppc desktop use and I have kept both versions in sync. It is a .NET dll and so is usable by any language that can reference .NET assemblies. As I have no experience of Delphi I don't know if it would be of any use to you or not.

agraham:

Delphi XE2 cannot use .net managed code directly, however I have some options:

1 - if your DLL is already written to be COM compatible, then I can instantiate the interface from any language.

2 - I could wrap your dll (in C#) and create a COM interface for it (I am not C# programmer, but nothing that google could not help)

3 - There this way "unmanaged Exports", but I have no clue how that works https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports

what you think?

Thanks,

Eduardo
 

agraham

Expert
Licensed User
1. It's not COM compatible at the moment and would need some work to make it so but I see no reason why it should not work with some modification to the event mechanism and host callbacks which assume a Basic4ppc environment at the moment (see below).

2. This would be a bit clumsy as the dll expects a Windows Form instance as a constructor parameter and uses it to invoke a Basic4ppc defined delegate for each event. This is designed to enable cross-thread working so that the scripts can be run on a separate thread to the host application. There is also quite a lot of code in there (more than I remembered !) that supports calling back into the host application in both the Basi4ccp IDE interpreted environment and also when compiled stand-alone. You could emulate this but modifying it to be COM callable is probably simpler.

3. Won't work as only static methods can be exported that way.


The C# source code is buried in an archive in the Basic4ppc forums here but as it is version 4.2 it is a bit out of date so I've attached the latest source and help file so you can judge the size of the task for yourself. Please note this does not give you permission to use the source - if you did want to do that we would need to have a further discussion.
 

Attachments

  • BasicLib4.7.zip
    99.5 KB · Views: 237

eelias

Active Member
Licensed User
agraham,

I have downloaded the source code and took a first look: yes there is really good number of lines there.

However looks like an organized, clear and documented source code. My real first impression.

I saw some of the dependencies to the basic4ppc.

What I have on mind right now:

1 - wrapping, or extracting what is needed from this code is not a simple task, for a first look, so I am planning to allocate time for that in some point in the next few weeks. I will modify my working plan for that, because you gave a way to turn real something really interesting.
2 - my preference is to wrap your code, to somehow get benefit from future changes you eventually will make, not sure that it is possible, i really don't know the dependencies. Many things can be simulated to satisfy this class, but there is a dependency with the IDE threading, for example, that could not be kept. I need to look deep.
3 - if I can successfully create a way to use your code to make the idea I shared you, then I talk with you first before put the code in "production". I am willing to share with you, to the reasonable extent, the financial benefit of using your source code. However I am a tiny company, at this moment living in the survival mode, but that will change when I deliver the project. At that moment I will be happy on get you the benefit. Actually you are already on my donate list. I came to use b4a due to your pl2303 library, I searched everywhere over the internet for access to pl2303 and only could find on b4a and your library (at least ready and working). And that is bring me benefit that I will share.

I will keep you informed in the progress and thanks for sharing. I have made language interpreters on the past (Forth, pascal and frankenlanguages!) and this area is fun for me, not an expert, but I like.

Eduardo Elias
 

agraham

Expert
Licensed User
- my preference is to wrap your code, to somehow get benefit from future changes you eventually will make, not sure that it is possible, i really don't know the dependencies.
I think that code is now very mature, feature complete and pretty bug-free so I don't think there will be any significant future changes.

Actually you are already on my donate list.
Nice to hear :)
 

eelias

Active Member
Licensed User
agraham:

There are 2 questions that keep bugging in my mind and I believe you can tell me quickly:

1 - I believe you provided somehow a way that the script communicate and exchange data with the host application, like a way to expose an API. From this API the script makes calls to get database connection, etc, etc. How is this provision on PC C# and in the b4a lib? (i know that the interpreter is the "same" however you could implemented the interface very different), I just want to know if there is support for that, no need of deep details.

2 - You android lib is a java right? How hard to make it go IOs or Win 8 RT? (I am here thinking high)

Not sure if B4a is going to other platform, it should. I am constantly reviewing other tools, and let's say it is a jungle out there. I have some hope put on the Dephi cross compiler that is coming, that promises to generate the same code for all platforms even PC, that will be great, but until get there my framework and apps in b4a will be very mature, I dont want to do everything again... in that case to have the script on other platforms would be great also.

Thanks

Eduardo Elias
 

agraham

Expert
Licensed User
1. There are several ways that the host and the script can interact. The host can get and set script variables and invoke script Subs. Scripts can raise events and invoke host Subs that the host can define by invoking AddSubCalls() with the names of the Subs that can be called. The capabilities are identical on the PC and Android and all the library methods and properties are the same on both platforms but obviously the implementation differs.

The differences are in the event handling, which uses the event model of either Basic4ppc or Basic4android depending on the platform, and the script callback into the host mechanism which uses the event mechanism on Basic4android and direct delegate invocation on Basic4ppc. The reason that a Form instance is required in the constructor on Basic4ppc is because the direct delegate invocation uses Form.Invoke to run a host Sub on the GUI thread if this is required and if the script is not already running on the GUI thread.


2. I don't know about IOs but I guess it's quite a lot of work as I assume it would need to be be coded in Objective-C. However as the code is "traditionally" structured rather than object oriented it is might port quite easily - I don't really know as I will not have anything to do with Apple products.

WinRT should be easy as the library is already in C#. However WinRT is big on asynchronism to keep the main GUI thread responsive, the guidelines state that the GUI thread should not be stalled for more than 50mS. Therefore scripts should be run on a separate thread and there will be synchronisation issues that will need to be addressed.
 

eelias

Active Member
Licensed User
2. I don't know about IOs but I guess it's quite a lot of work as I assume it would need to be be coded in Objective-C.

Just a matter of curiosity

Oracle Gets Java Running on iOS Devices | Javalobby

and this one is also very interesting:

https://code.google.com/p/j2objc/

I see google is using this to delivery some of its own code from android to ios. Not sure if could be a way for b4a to get closer to ios, i know there are things still needed to be done, since the UI is very different in terms of handling.
 

JesseW

Active Member
Licensed User
Andrew, I looked through the source code you offered eelias, looking for the bnf description, and couldn't find it. Are you using a parse tree (which I could also not find), or is the syntax grammar hard coded? bnf makes my brain hurt...
 

agraham

Expert
Licensed User
Are you using a parse tree (which I could also not find), or is the syntax grammar hard coded
It's all hard coded, and is very traditional procedural code rather than object oriented.

LoadCodeAsArray() scans the code to find the line numbers of all the Subs and also adds line numbers to the source and tidies up line endings . After that scanprogram() tokenises the source inserting empty token positions used for jump destinations during interpretation. Finally scanagain() traverses the entire token stream to fill in jump destinations, which is an "interesting" process as it needs to take account of the block structuring of the program to correctly match the block starts and ends.

Interpretation occurs by successively fetching tokens from the token string and calling the appropriate functions. Each line of a program is one statement and statement() starts the interpretation of the leading keyword of each source line then a recursive descent parser headed by expression() takes care of most everything else.
 

JesseW

Active Member
Licensed User
I am working on transcribing B4Script grammar rules into BNF for a new IDE idea I have. When I'm done, I'll upload it for your inspection...
 

eelias

Active Member
Licensed User
I am working on transcribing B4Script grammar rules into BNF for a new IDE idea I have. When I'm done, I'll upload it for your inspection...

JesseW,

I am very interested on using the souce code of agraham in C# to create an IDE on PC to generate scripts that will run on windows and android, both sides using the same scripting.

I am doing all my work right now in this direction. I could not have yet condition to look deeply on the agraham c# source code. However I am working with Delphi, I need that parser working on something that could be accessible from delphi (native 32bits windows code) that could be a COM component for example.

My idea was going thru that code and remove what is dependency from the previous IDE and prepare to be a COM object. Then I can instantiate and prepare the callbacks to interact with it. That ability of the script to call subs from the program is very important. I have a long library of business classes that can be called.

What I am doing is to share part of this library on android using B4A. Then the same script can call it. The final objective is to have a IDE where business apps can be created and executed on the same framework.

I am a consultant and work alone getting projects. Very hard :)

I wonder if there is any way to colaborate of whatever you may suggest, I really wanted to have the agraham script engine working both sides with the same script. I have already look on to the IDE you created for the android with the scripting, nice stuff.

Please, let me know, and what is idea, direction, if i can give a hand, whatever... Anything you share with me will be a blessing.

Thanks

Eduardo Elias
 

JesseW

Active Member
Licensed User
JesseW ... I need that parser working on something that could be accessible from delphi ... Please, let me know, and what is idea, direction, if i can give a hand, whatever... Anything you share with me will be a blessing.

eelias, i am not up to speed with modern parsers and compilers. back in the 1980's i messed around with the internal workings of 8 bit atari basic, because they published the source code in the atari basic source book (click the link for the online version - beware there are some typos) but it contains more than source code. it also contains discussions and examples of its inner workings so that you can understand the concepts outside the source code. its quite good reading if you like computer languages. the really good stuff starts in part 1 chapter 5. this is all the help i can give, because the ideas i have will all be built using basic4android for a new version of b4script, and i will code them all from scratch to fit the needs of that project, so they won't fit in the environment you've specified. sorry...

good luck! :)
 
Last edited:
Top