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 22871 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
BAS2NIM
« on: October 11, 2013, 02:39:42 AM »
I would like to propose that the members here contribute to a general purpose BASIC to C converter with a Nimrod twist. The bas2nim translator would take BASIC text and convert it to Nimrod text which would be converted to C and finally compiled by gcc to a binary. ScriptBasic is the best language for the converter and it runs on the same platforms as Nimrod does.

The goal with this project is to save BASIC dialects that people liked to program in and compile them to the platform of choice. Once a core BASIC translator is done, it could be extended with SB modules that handle specific features of the dialect of BASIC it's designed to translate.

Here is the first ScriptBasic to Nimrod translation.

SB
Code: [Select]
PRINT "Hello World!\n"

jrs@laptop:~/bas2nim$ scriba hello.sb
Hello World!
jrs@laptop:~/bas2nim$

Nimrod
Code: [Select]
echo("Hello World!")
jrs@laptop:~/bas2nim$ nimrod c hello.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
gcc -c -w -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/hello.o /home/jrs/bas2nim/nimcache/hello.c
gcc -c -w -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/system.c
gcc   -o /home/jrs/bas2nim/hello  /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/hello.o  -ldl
Hint: operation successful (7440 lines compiled; 1.064 sec total; 12.122MB) [SuccessX]
jrs@laptop:~/bas2nim$ ./hello
Hello World!
jrs@laptop:~/bas2nim$

jrs@laptop:~/bas2nim$ ls -l
total 164
-rwxrwxr-x 1 jrs jrs 153525 Oct 11 02:22 hello
-rw-rw-r-- 1 jrs jrs     22 Oct 11 02:21 hello.nim
-rw-rw-r-- 1 jrs jrs     24 Oct 11 02:20 hello.sb
drwx--x--x 2 jrs jrs   4096 Oct 11 02:22 nimcache
jrs@laptop:~/bas2nim$ nimrod c -d:release hello.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/hello.o /home/jrs/bas2nim/nimcache/hello.c
gcc -c -w -O3 -fno-strict-aliasing -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/system.c
gcc   -o /home/jrs/bas2nim/hello  /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/hello.o  -ldl
Hint: operation successful (7440 lines compiled; 0.476 sec total; 7.768MB) [SuccessX]
jrs@laptop:~/bas2nim$ strip -s hello
jrs@laptop:~/bas2nim$ ls -l
total 28
-rwxrwxr-x 1 jrs jrs 14432 Oct 11 02:45 hello
-rw-rw-r-- 1 jrs jrs    22 Oct 11 02:21 hello.nim
-rw-rw-r-- 1 jrs jrs    24 Oct 11 02:20 hello.sb
drwx--x--x 2 jrs jrs  4096 Oct 11 02:45 nimcache
jrs@laptop:~/bas2nim$
« Last Edit: November 07, 2013, 09:52:34 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #1 on: October 11, 2013, 03:36:11 AM »
One idea that might be cool is a use language directive so multiple dialects of BASIC code can be used.

Code: [Select]
USE SB
...

USE O2

---


Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #2 on: October 11, 2013, 11:01:48 AM »
Nimrod also works as an console mode (interactive) interpreter.

Code: [Select]
jrs@laptop:~/bas2nim$ nimrod i hello.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
Hello World!
Hint: operation successful (3133 lines compiled; 0.070 sec total; 2.256MB) [SuccessX]

jrs@laptop:~/bas2nim$ nimrod i
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: stdin [Processing]
>>> echo("Hello World!")
Hello World!
>>> quit()
stdin(3, 5) Hint: quit() called [QuitCalled]
jrs@laptop:~/bas2nim$


« Last Edit: October 11, 2013, 11:06:02 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #3 on: October 11, 2013, 11:49:32 AM »
I have setup a Cloud9 IDE and github project to support the BAS2NIM effort.

« Last Edit: October 11, 2013, 12:54:58 PM by John »

kryton9

  • Guest
Re: BAS2NIM
« Reply #4 on: October 11, 2013, 04:13:09 PM »
John you are a powerhouse. How do you do so much in little time is amazing.

Charles posted that eventually Oxygen will be in C, after things are finalized. So no need to do Oxygen, I would think.

Which other BASIC languages would you recommend for such a project?

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #5 on: October 11, 2013, 04:19:32 PM »
Quote
Which other BASIC languages would you recommend for such a project?

The plan is to use ScriptBasic for the translator as it uses traditional BASIC for the most part. I would like to see core BASIC syntax translated to Nimrod as verbatim as possible. As this moves along, other dialects (PowerBASIC, FreeBASIC, ...) can be translated. (or a combination of BASIC language syntax, in-line ASM or C)

I'm just getting started with this so nothing is cast in stone in my mind.

« Last Edit: October 11, 2013, 04:25:54 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #6 on: October 11, 2013, 06:26:14 PM »
I think this first BASIC translation round should include the DIM directive as it will help define what areis variables are in the code with a matrix table storing the name, type, size (if string) and array bounds. Even thought SB doesn't require DIM or $ for stings or their functions, I think they should be included for readability and ease of translation.


kryton9

  • Guest
Re: BAS2NIM
« Reply #7 on: October 11, 2013, 06:51:20 PM »
I will check out your code to see how you are going about this cool stuff John.

I loaded the 3 hello programs, sb, nimrod and php and I see a compiled hello(I assume from nimrod).
I am not sure what we are to do John.  Are you on google+, perhaps we could conference?
« Last Edit: October 11, 2013, 07:02:58 PM by kryton9 »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #8 on: October 11, 2013, 07:12:34 PM »
I started the party with a Hello World! conversion. How about doing a FOR/NEXT conversion to Nimrod. Until we know what we are facing, there is no need to start writing code for the translator yet. This will also have the benefit of showing how Nimrod works in BASIC lingo.


kryton9

  • Guest
Re: BAS2NIM
« Reply #9 on: October 11, 2013, 07:22:24 PM »
So you just want to write the equivalent code in Nimrod as it is in Scriptbasic and php?

This is fun!
« Last Edit: October 11, 2013, 07:29:10 PM by kryton9 »

kryton9

  • Guest
Re: BAS2NIM
« Reply #10 on: October 11, 2013, 07:31:33 PM »
John how is scriptbasic running from the cloud9 nimrod site?

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #11 on: October 11, 2013, 07:49:14 PM »
I don't understand the question.

Make sure you set the SCRIBACONF environment variable to point to the ~/etc/basic.conf file. You also need to export PATH to include the path to the Ninrod/bin directory. See the README.md in the workspace root directory.

If you mean how did I get SB running on Cloud9 IDE that was simple. They are running Red Hat 64 bit Linux and I just uploaded scriba and extensions modules from the CentOS (Red Hat clone) up to the workspace bin, include and module directories. Anything put in workspace bin is like /usr/bin on other Linux systems.

Quote
So you just want to write the equivalent code in Nimrod as it is in Scriptbasic and php?

The hello.php file is there to test the Cloud9 IDE local Apache webserver. Bring it into the editor and click RUN. A C9 web browser will appear showing the results of your script. (web scripting is the primary focus on Cloud9 IDE)
« Last Edit: October 11, 2013, 07:57:17 PM by John »

kryton9

  • Guest
Re: BAS2NIM
« Reply #12 on: October 11, 2013, 07:59:00 PM »
Quote
If you mean how did I get SB running on Cloud9 IDE that was simple.
That is what I meant John.  Thanks for the explanation.

I don't have to setup a windows development anymore. It is so much fun the way you have things setup!

I did a for file for Nimrod:  for.nim
Is this OK and what you had in mind?
« Last Edit: October 11, 2013, 08:05:11 PM by kryton9 »

kryton9

  • Guest
Re: BAS2NIM
« Reply #13 on: October 11, 2013, 08:06:57 PM »
Quote
The hello.php file is there to test the Cloud9 IDE local Apache webserver. Bring it into the editor and click RUN. A C9 web browser will appear showing the results of your script. (web scripting is the primary focus on Cloud9 IDE)

Oops, I edited the php file to say Hello World to match the other examples :)

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #14 on: October 11, 2013, 08:07:53 PM »
Excellent! Keep it coming.

Code: [Select]
# For Loop in Nimrod

# This is how you comment in Nimrod

# Nimrod uses indentations for code blocking.

# Hence you will see at times # at the front of the line and
# another later in the line to align things nicely.


#                         #BASIC equivalent
echo("Counting to ten: ") #print "Counting to ten: "
for i in countup(1, 10):  #for i = 1 to 10
    echo($i)              #print str$(i)
                          #no next command in Nimrod


#                          #BASIC equivalent
echo("Counting to one: ")  #print "Counting to one: "
for i in countdown(10, 1): #for i = 10 to 1
    echo($i)               #print str$(i)
                           #no next command in Nimrod

                           
#shortcut for                       #BASIC equivalent
echo("Shortcut counting to ten: ")  #print "Shortcut counting to ten: "
for i in 1..10:                     #for i = 1 to 10
    echo($i)                        #print str$(i)
                                    #no next command in Nimrod


#this does not work                           
#shortcut for                       #BASIC equivalent
echo("Shortcut counting to one: ")  #print "Shortcut counting to one: "
for i in 10..1:                     #for i = 10 to 1
    echo($i)                        #print str$(i)
                                    #no next command in Nimrod                           
echo("This does not work with shortcut.")                               

scriptbasic@nimrod:~/639761/BAS2NIM $ ./for
Counting to ten:
1
2
3
4
5
6
7
8
9
10
Counting to one:
10
9
8
7
6
5
4
3
2
1
Shortcut counting to ten:
1
2
3
4
5
6
7
8
9
10
Shortcut counting to one:
This does not work with shortcut.
scriptbasic@nimrod:~/639761/BAS2NIM $
« Last Edit: October 11, 2013, 08:49:44 PM by John »