Poll

What method would you prefer to translate BASIC to a cross platform binary executable.

Daniel's uCalc Transform --> C++
1 (33.3%)
ScriptBasic --> Nimrod --> C (project abandoned by John)
0 (0%)
Nimrod --> C
0 (0%)
Python --> Nimrod --> C
1 (33.3%)
C BASIC (Charles Pegge's BASIC wrapper for C)
1 (33.3%)
Other (post your idea)
0 (0%)

Total Members Voted: 2

Author Topic: BAS2NIM  (Read 20905 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #30 on: October 12, 2013, 05:47:57 PM »
Daniel,

Once a uCalc Transform script has been created, it there a console mode facility to process the conversions? (batch mode)

OT Have you had much luck with the PowerBASIC folks converting to C++ with your tool?

John

Update

Code: [Select]
uCalc Transform 1.8 Command Prompt
Type T /? for help with uCalc Transform 1.8 Command Prompt options.

F:\uCalcTransform>T /?
Runs uCalc Transform in batch mode (see examples at bottom)

T  [/A] [/B] [/P] [/Q] [/S] [/CR | /LF | /CRLF] [/ENCODING:{name|codepage}]
   transformfile inputfile [outputfile] [/SEND:data] [#comment]

/A     Appends to output file instead of overwriting it.
/B     Backs up output file before overwriting it (if it already exists).
/P     Previews changes instead of saving them into a file.
/Q     Quiet mode; does not ask if you want to overwrite existing output file.
/S     Saves stats to a file (whose name can be configured in Setup.cnf).

/CR    Saves with carriage return (\r, ASCII 13, hex D) as end-of-line marker.
/LF    Saves with line feed (\n, ASCII 10, hex A) as end-of-line marker.
/CRLF  Saves with CRLF (\r\n, ASCII 10:13 or hex A:D) as end-of-line marker.

/ENCODING:{name|codepage}
       Saves using encoding based on given name (string) or code page (number).

/SEND  This sends data to the SEND variable, which can be used by the
       current transform.  This is useful when you want to use the same
       transform but with slight variations for different files.

transformfile   Name of file(s) containing transform patterns.  To select the
                transform patterns currently being edited in a separate GUI
                session of uCalc Transform, use @ in place of a file name.
inputfile       Name of file(s) containing text to be modified.
outputfile      Name of file in which modified text will be saved.  If this
                file is omitted, modifications are saved in inputfile.  If a
                directory is given instead of a file, the output goes to a
                file in that directory.
#               Everything after # at the end is ignored.

Preferred settings can be configured in Setup.cnf.  Parameters explicitly
invoked at the command line supersede those configured in Setup.cnf.
Parameters can be placed anywhere before, between, or after file names.

To select multiple files for transformfile & inputfile, you may use wildcards.
When using wildcards for transformfile, it's useful (though it's not required)
to choose a given file name for the OutputFile property within each transform.

If ENCODING is omitted, the output file is saved with UTF-8 encoding without a
byte order mark (BOM).  A BOM is always inserted when an encoding is specified.

If inputfile & outputfile are omitted, then uCalc simply opens the file(s) for
editing.  To open multiple files in the current directory, use wildcards.


Examples
--------

T Change.uc  In.Txt  Out.Txt    # Modifies In.Txt & saves changes to Out.Txt
T Beautify.uc  Program.Bas      # Changes saved directly in Program.Bas
T Modify.uc  *.c                # All files ending with .c are modified
T Modify.uc  *.c  \Temp         # Saves modified *.c files in Temp directory
T Log.uc  *.xml  Log.Txt  /A    # Changes to *.xml are appended to Log.Txt
T Web.uc  index.html /LF        # Saves file using LF (\n) instead of CRLF
T @  \temp\*.vb                 # *.vb modified based on current transform
T @  *.xml  /P                  # Preview of changes shown; no files modified
T @  Item.xml  /ENCODING:utf-8  # Saves with utf-8 encoding (including BOM)
T @  C:\ABC.Txt  /ENCODING:1252 # Saves using Windows-1252 encoding
T *.uc  test.c                  # Multiple changes to test.c (if OutputFile="")
T *.uc  Interface.Bas           # Saves to different files if OutputFile set
T *.uc Source.vb profile.txt /A # Transforms are appended to profile.txt
T ReadMe.Txt                    # Simply opens up ReadMe.Txt for editing
T *.Txt                         # Open all .Txt files for editing
T Change.uc File.cpp /SEND:x64  # Variable SEND set to x64 in Change.uc
« Last Edit: October 12, 2013, 06:37:17 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #31 on: October 13, 2013, 12:25:18 AM »
Kent and I were chatting on C9IDE about what BASIC we should use to test with. I suggested ScriptBasic since it was already running on the project site. The more I thought about it, PowerBASIC Console Compiler 5 would be a much better target to work with.

  • Daniel started the project as a PB to C++ conversion tool so he is already focused on PB.
  • A PB --> Nimrod --> C would be a much easier conversion than going directly to C++. IMHO
  • PB users are in trouble and need a way out. (cross platform migration path with a future)
  • PBCC would be a good foundation BASIC that doesn't have the PB specifics that are off the traditional BASIC path. (could be debatable)
  • I think there would be more interest in this project by others if the goal had a valued target.
  • I would guess most of the developers here have PB 9/5 (Classic) or greater.
  • Branching to other BASIC dialects would be much easier if PB core was it's base.

Who knows, this direction might even get Eros to contribute to the project. (and join the forum)
« Last Edit: October 13, 2013, 03:25:01 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #32 on: October 13, 2013, 12:45:31 PM »
I detect that Kent is finding ScriptBasic easy to work with and using it to test with on the C9IDE project site. The concerns I have with using Daniel's uCalc Transform tool is that we have no access to it's source if anything were to happen to him. The PB user base is still spinning over Bob's passing and the product left in a limbo state. Using the GUI interface of uCalc Transform is easy to use but labor intensive creating pattern matching templates. I would like to hear from others interested in this project what their thoughts are about using uCalc Tranform and PBCC 5 as first target language to port to Nimrod.

ScriptBasic actually has a nice pattern matching feature built into the language. (LIKE & JOKER) This example shows how this feature could be use to parse BASIC syntax to translate to Nimrod.

ScriptBasic Pattern Matching

Code: [Select]
code = "FOR x = 1 TO 10 STEP 2"

IF code LIKE "FOR * = # TO # STEP #" THEN
  PRINT "Iterator: ",JOKER(1),"\n"
  PRINT "Start: ",JOKER(2),"\n"
  PRINT "End: ",JOKER(3),"\n"
  PRINT "Step: ",JOKER(4),"\n"
END IF

jrs@laptop:~/bas2nim$ scriba pm_01.sb
Iterator: x
Start: 1
End: 10
Step: 2
jrs@laptop:~/bas2nim$

Code: [Select]
code = "FOR x = 1 TO 10"

IF code LIKE "FOR * = # TO #" THEN
  PRINT "Iterator: ",JOKER(1),"\n"
  PRINT "Start: ",JOKER(2),"\n"
  PRINT "End: ",JOKER(3),"\n"
  PRINT "Step: ",JOKER(4),"\n"
END IF

jrs@laptop:~/bas2nim$ scriba pm_02.sb
Iterator: x
Start: 1
End: 10
Step: undef
jrs@laptop:~/bas2nim$

Code: [Select]
begin = 1
done = 10
code = "FOR x = begin TO done"

PRINT "BASIC: ",code,"\n"

IF code LIKE "FOR * = * TO *" THEN
  PRINT "Iterator: ",JOKER(1),"\n"
  PRINT "Start: ",JOKER(2),"\n"
  PRINT "End: ",JOKER(3),"\n"
END IF

jrs@laptop:~/bas2nim$ scriba pm_03.sb
BASIC: FOR x = begin TO done
Iterator: x
Start: begin
End: done
jrs@laptop:~/bas2nim$

Code: [Select]
done = 10
code = "FOR x = 1 TO done"

PRINT "BASIC: ",code,"\n"

IF code LIKE "FOR * = * TO *" THEN
  PRINT "Iterator: ",JOKER(1),"\n"
  PRINT "Start: ",JOKER(2),"\n"
  PRINT "End: ",JOKER(3),"\n"
END IF

IF ISNUMERIC(VAL(JOKER(2))) THEN
  PRINT "The Start value is number ",JOKER(2),"\n"
END IF

jrs@laptop:~/bas2nim$ scriba pm_04.sb
BASIC: FOR x = 1 TO done
Iterator: x
Start: 1
End: done
The Start value is number 1
jrs@laptop:~/bas2nim$
« Last Edit: October 13, 2013, 02:43:24 PM by John »

kryton9

  • Guest
Re: BAS2NIM
« Reply #33 on: October 13, 2013, 06:23:00 PM »
John, I can't visualize this project in my mind yet as well as you do. So I am just following and can't really offer opinions-- as the last few years I was really focusing on oxygen, but mainly c++.
This is without any real knowledge-- just a hunch on my part, but there are so many BASICs out there, to write a translator for all of them seems like a huge undertaking.

To show how bad the state of BASIC is these days with new programmers. Look at the languages supported by the Cloud9 IDE syntax highlighter... out of 95 languages, not one BASIC.
Closest thing was VBScript. See attached screenshot.

I do believe 100% with you that a new BASIC is needed. It should be able to run on any platform that C can be compiled to. I also believe like you that having all of the brilliant minds of all of these BASIC creators all working on their own and not together is hurting the BASIC world. We need to bring everyone together to work on a killer BASIC to compete with Python and C/C++

The new basic should have 3 abilities. These are to attract Python and C/C++ users and other similar language users.
1. Interactive mode in a command line
2. Interpreted
3. Compiled to true executables with no runtime dependencies.

4. Then an IDE to take the game to a whole new level.
    Charles and I had talked about a cool IDE a couple of years back.
    No need to get into that now. But we had some great ideas that
   were very different than other IDES.

5. The langauge should be like oxygen in that you could do procedural, object oriented or a mix of the two and not force one paradigm on users.

You are right, ScirptBasic I am seeing is very flexible and fun to use. I did see that when we dabbled with it in Android when I had my tablet. But I had forgotten.

We are lucky to have you as a facilitator. With your energy and passion for wanting BASIC to be relevant well into the future, there might actually be a chance for some
positive change!

Forgot to comment on ScriptBasic for translation. Your sample code looked very nice to me. A lot easier to use than to do it in Nimrod I would think or the other tools.
« Last Edit: October 13, 2013, 06:36:22 PM by kryton9 »

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #34 on: October 13, 2013, 06:46:24 PM »
If ScriptBasic is chosen as the language we are going to use for the BASIC to Nimrod translator, this is how I would approach the challenge.

I like the idea of being able to use multiple dialects of BASIC at the same time along with embedding C and ASM in-line. With this in mind, I would use a SB MODULE (class) for each BASIC language dialect which would contain specifics to that language and are not processed by common syntax routines handled in the MAIN module. (what SB runs by default) I would create a keyword matrix using a combination of associative and indexed based arrays.

Example:
Code: [Select]
pbcc5{"CLS"}[0] = ADDRESS(PB_CLS())
pbcc5{"CLS"}[*] = Rules, flags and whatever else is needed

As each line(s - if multiple continuations) of the BASIC program is read in, the MAIN program will determine if the line is an assignment or directive. I would find the fist space starting from the beginning of the line and see if it's a keyword.

Code: [Select]
IF pbcc5{kwtest} = undef THEN ...must be an assignment, meta statement or other non-directive ...

Each keyword function is responsible for building its Nimrod code using expected calling arguments and global settings that might indicate state that would affect the generated Nimrod code.

I would be happy to collaborate with Kent and others to get our fist pass done in SB. (closing arguments)


« Last Edit: October 13, 2013, 06:58:24 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #35 on: October 13, 2013, 07:24:04 PM »
Quote
Forgot to comment on ScriptBasic for translation. Your sample code looked very nice to me. A lot easier to use than to do it in Nimrod I would think or the other tools.

Sounds like SB deserves your vote in our poll.  ;)


kryton9

  • Guest
Re: BAS2NIM
« Reply #36 on: October 13, 2013, 07:34:17 PM »
Got my vote.

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #37 on: October 13, 2013, 09:16:21 PM »
Quote from: Kent
Got my vote.

Thanks! The SB team appreciates it.

I have posted on the ScriptBasic project site (Download - Sticky) a fixed scriba for accessing JOKER(n)'s beyond the number of match characters defined. (caused seg. fault / GPF) Please replace your SB 2.2 build 1 with this build 2 release. (Ubuntu 32 version posted soon)

The scriba JOKER fix download.
« Last Edit: October 14, 2013, 02:42:02 AM by John »

kryton9

  • Guest
Re: BAS2NIM
« Reply #38 on: October 13, 2013, 09:41:52 PM »
I am doing all my Nimrod and ScriptBasic coding on your Cloud9 Nimrod site John. It makes it very nice and easy.

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #39 on: October 13, 2013, 09:50:22 PM »
Quote
I am doing all my Nimrod and ScriptBasic coding on your Cloud9 Nimrod site

Cloud9 is a collaborative development service. I would think that makes it our development site.  :)

kryton9

  • Guest
Re: BAS2NIM
« Reply #40 on: October 13, 2013, 10:09:22 PM »
You figured out how to set it all up, so as far as I am concerned it is your site just as the forums you run. You deserve credit where credit is due.
Thanks for making them a community.

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #41 on: October 13, 2013, 10:15:33 PM »

kryton9

  • Guest
Re: BAS2NIM
« Reply #42 on: October 13, 2013, 10:50:33 PM »
Clever it worked :)

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #43 on: October 14, 2013, 12:18:30 PM »
The updated scriba (ScriptBasic 2.2 Build 2) for all release candidate builds have been posted. Please update your copy of scriba.

Download Link



« Last Edit: October 14, 2013, 12:20:15 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2345
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #44 on: October 14, 2013, 03:41:21 PM »
ScriptBasic does Old School BASIC.

Code: [Select]
10 REM My Program
20 LET A = 1
30 LET B$ = "Hello"
40 GOSUB 100
50 END
100 PRINT B$
110 PRINT
120 RETURN

OR

Code: [Select]
10 REM My Program
   LET A = 1
   LET B$ = "Hello"
   GOSUB 100
   END
100 PRINT B$
    PRINT
    RETURN

OR

Code: [Select]
' My Program
a = 1
b = "Hello"
GOSUB 100
END
100:
PRINT b,"\n"
RETURN

jrs@laptop:~/bas2nim$ scriba oldschool.bas
Hello
jrs@laptop:~/bas2nim$

« Last Edit: October 14, 2013, 06:45:00 PM by John »