Kent merged his BASIC to Nimrod translation maps into the ScriptBasic proof of concept example I posted. This example is to show how common BASIC syntax converts to Nimrod and not an example of a real BASIC program. (BASIC functions are part of a directive not standalone)
BASIC code example
LET A = "Hello BAS2NIM"
PRINT A,"\n"
ASC "Z"
VAL "123"
STR 321
MID "One Two Three Four", 1, 3
MID "One Two Three Four", 5, 3
MID "One Two Three Four", 9, 5
MID "One Two Three Four", 15, 4
LEFT "One Two Three Four", 3
INSTR "One Two Three Four", "One"
INSTR "One Two Three Four", "Two"
INSTR "One Two Three Four", "Three"
INSTR "One Two Three Four", "Four"
UCASE "aLl mIxEd cAsE"
LCASE "aLl mIxEd cAsE"
ScriptBasic translator
'b2nV2.sb
'renamed don't want to mess up the original copy
PRINT "# output from command line: scriba b2nV2.sb test2.bas > test2.nim \n"
PRINT "# compile from command line: nimrod c test2.nim \n"
PRINT "# execute from command line: ./test2 \n"
PRINT "import strutils \n"
' BAS2NIM - ScriptBasic
' Last Update: 2013-10-15
' Contributors: John Spikowski & Kent Sarikaya
' BASIC keyword dictionary
keywords{"DIM"}[0]=ADDRESS(Convert_DIM())
keywords{"FOR"}[0]=ADDRESS(Convert_FOR())
keywords{"NEXT"}[0]=ADDRESS(Convert_NEXT())
keywords{"IF"}[0]=ADDRESS(Convert_IF())
keywords{"WHILE"}[0]=ADDRESS(Convert_WHILE())
keywords{"WEND"}[0]=ADDRESS(Convert_WEND())
keywords{"LET"}[0]=ADDRESS(Convert_LET())
' keywords{"GOTO"}[0]=ADDRESS(Convert_GOTO())
' keywords{"GOSUB"}[0]=ADDRESS(Convert_GOSUB())
' keywords{"RETURN"}[0]=ADDRESS(Convert_RETURN())
keywords{"PRINT"}[0]=ADDRESS(Convert_PRINT())
keywords{"END"}[0]=ADDRESS(Convert_END())
keywords{"ASC"}[0]=ADDRESS(Convert_ASC())
keywords{"VAL"}[0]=ADDRESS(Convert_VAL())
keywords{"STR"}[0]=ADDRESS(Convert_STR())
keywords{"MID"}[0]=ADDRESS(Convert_MID())
keywords{"LEFT"}[0]=ADDRESS(Convert_LEFT())
keywords{"INSTR"}[0]=ADDRESS(Convert_INSTR())
keywords{"UCASE"}[0]=ADDRESS(Convert_UCASE())
keywords{"LCASE"}[0]=ADDRESS(Convert_LCASE())
keywords{"UBOUND"}[0]=ADDRESS(Convert_UBOUND())
keywords{"LBOUND"}[0]=ADDRESS(Convert_LBOUND())
' BASIC Directives
SUB Convert_DIM
END SUB
SUB Convert_FOR
IF BASIC LIKE "FOR * = * TO *" THEN
expr[1] = JOKER(1)
expr[2] = JOKER(2)
expr[3] = JOKER(3)
' Translate
PRINT Nimrod
ELSE IF BASIC LIKE "FOR * = * TO * STEP *" THEN
expr[1] = JOKER(1)
expr[2] = JOKER(2)
expr[3] = JOKER(3)
expr[4] = JOKER(4)
' Translate
PRINT Nimrod
ELSE
END
END IF
END SUB
SUB Convert_NEXT
'no NEXT in nimrod
END SUB
SUB Convert_IF
END SUB
SUB Convert_WHILE
END SUB
SUB Convert_WEND
'no WEND in nimrod
END SUB
SUB Convert_LET
IF BASIC LIKE "LET *" THEN
PRINT "var ", JOKER(1), "\n"
ELSE
END
END IF
END SUB
' SUB Convert_GOTO
'no GOTO in nimrod
' END SUB
' SUB Convert_GOSUB
' END SUB
' SUB Convert_RETURN
' END SUB
SUB Convert_PRINT
IF BASIC LIKE "PRINT *" THEN
PRINT "stdout.write(", JOKER(1), ")\n"
ELSE
END
END IF
END SUB
SUB Convert_END
END SUB
' BASIC Functions
SUB Convert_ASC
IF BASIC LIKE "ASC *" THEN
S = MID(JOKER(1), 2, LEN(JOKER(1))-2)
PRINT "echo(", "ord('", S, "'))\n"
ELSE
END
END IF
END SUB
SUB Convert_VAL
IF BASIC LIKE "VAL *" THEN
PRINT "echo(", "parseInt(", JOKER(1), "))\n"
ELSE
END
END IF
END SUB
SUB Convert_STR
IF BASIC LIKE "STR *" THEN
PRINT "echo(", "$", JOKER(1), ")\n"
ELSE
END
END IF
END SUB
SUB Convert_MID
IF BASIC LIKE "MID *, *, *" THEN
PRINT "echo(", JOKER(1),"[",JOKER(2)-1,"..",JOKER(2)+JOKER(3)-2,"])\n"
ELSE
END
END IF
END SUB
SUB Convert_LEFT
IF BASIC LIKE "LEFT *, *" THEN
PRINT "echo(", JOKER(1),"[0..",JOKER(2) - 1,"])\n"
ELSE
END
END IF
END SUB
SUB Convert_INSTR
IF BASIC LIKE "INSTR *, *" THEN
PRINT "echo(find(", JOKER(1), ",", JOKER(2), ")+1)\n"
ELSE
END
END IF
END SUB
SUB Convert_UCASE
IF BASIC LIKE "UCASE *" THEN
PRINT "echo(", JOKER(1),".toUpper())\n"
ELSE
END
END IF
END SUB
SUB Convert_LCASE
IF BASIC LIKE "LCASE *" THEN
PRINT "echo(", JOKER(1),".toLower())\n"
ELSE
END
END IF
END SUB
SUB Convert_UBOUND
END SUB
SUB Convert_LBOUND
END SUB
' MAIN
filename_argument = COMMAND()
OPEN filename_argument FOR INPUT AS #1
WHILE NOT(EOF(1))
LINE INPUT #1, BASIC
BASIC = CHOMP(BASIC)
sp = INSTR(BASIC, " ")
test_keyword = LEFT(BASIC, sp -1)
IF keywords{test_keyword}[0] <> undef THEN
success = ICALL(keywords{test_keyword}[0])
ELSE
END
END IF
WEND
Output
scriptbasic@nimrod:~/639761/projects/John $ scriba b2nV2.sb test2.bas
# output from command line: scriba b2nV2.sb test2.bas > test2.nim
# compile from command line: nimrod c test2.nim
# execute from command line: ./test2
import strutils
var A = "Hello BAS2NIM"
stdout.write(A,"\n")
echo(ord('Z'))
echo(parseInt("123"))
echo($321)
echo("One Two Three Four"[0..2])
echo("One Two Three Four"[4..6])
echo("One Two Three Four"[8..12])
echo("One Two Three Four"[14..17])
echo("One Two Three Four"[0..2])
echo(find("One Two Three Four","One")+1)
echo(find("One Two Three Four","Two")+1)
echo(find("One Two Three Four","Three")+1)
echo(find("One Two Three Four","Four")+1)
echo("aLl mIxEd cAsE".toUpper())
echo("aLl mIxEd cAsE".toLower())
scriptbasic@nimrod:~/639761/projects/John $ scriba b2nV2.sb test2.bas > test2.nim
scriptbasic@nimrod:~/639761/projects/John $ nimrod c test2.nim
config/nimrod.cfg(36, 2) Hint: added path: '/var/lib/stickshift/525387a75973caafd40003a0/app-root/data/.babel/pkgs/babel-0.1.0' [Path]
config/nimrod.cfg(36, 2) Hint: added path: '/var/lib/stickshift/525387a75973caafd40003a0/app-root/data/.babel/pkgs/' [Path]
Hint: used config file '/var/lib/stickshift/525387a75973caafd40003a0/app-root/data/639761/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test2 [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: operation successful (9446 lines compiled; 1.955 sec total; 16.163MB) [SuccessX]
scriptbasic@nimrod:~/639761/projects/John $ ./test2
Hello BAS2NIM
90
123
321
One
Two
Three
Four
One
1
5
9
15
ALL MIXED CASE
all mixed case
scriptbasic@nimrod:~/639761/projects/John $