For my current project which will be a developement system that will write a Swift/Xcode project complete with GUI… I was going to need code to translate a dialetic of BASIC into Swift for Xcode to compile.
Well last night I realized that I had spent days copying code from my Xojo proof of concept and then manually changing case and syntax so it would compile in Swift.
Doh! Since the end project needed to be able to translate, and I needed said translation to help write the program that would translate (catch-22?)… I wrote this today
It is not 100% accurate (yet)… but I figure it will save me hundreds of hours of drudge work over the next few weeks, and I’ll tweek this as I use it.
If anyone is interested…let me know and I’ll compile this and post it…
And if you play with it, and find situations that are translated incorrectly, let me know
This is a work in progress… I’ll be fine tuning it as I find situations during actual use.
Right now it UPPERCASES things it isn’t sure about… I’ll be adding a dynamic dictionary that will be prepopulated with some keywords, and add variiable and function names in order to preserve case (case will be what ever the DIM or SUB/FUNCTION defines it as). Xojo doesn’t care… but Swift is very strict in that regard.
To use… either type (or Paste) code in the left pane
Hit [Translate]
copy code from Right Pane.
There is NO file system behind this as the intent if to copy/paste code from my Xojo project, translate it, then copy/paste into my Swift project
It is a brute force translator … as in it examines a scope of one line… with no regard to items that came before or after… meaning the BASIC code is assumed to be in good format.
i did look at Swift at some point previously – looking at this i am reminded why i liked the language so much.
I do think Swift has done a much better job at being approachable for beginners that XOJO and the recent changes have done…
I would REALLY appreciate if some of you could take that download. Run some valid BASIC scenarios thru it and see if it creates valid results.
Not expecting it to translate database, or custom class stuff… just standard syntax for now… IF/THEN, FOR/NEXT, WHILE/WEND and anything else I forgot
A long time ago I was able to write a bit of C so I thought: “I’ll learn this IOS stuff”, purchased a book, opened it and got a headache at around page 3
Ok here is an updated version.
This one uses a dictionary to make sure all variable names, and function names stay a consistent case (based on where first define)
It also should properly handle Arrays (single dimension only). Unlike Xojo, Swift uses square brackets to denote an array
So in BASIC you’d have this
Dim x as integer = 42
dim y(14) as string ="Fred"
Dim z() as double
dim q(-1) as Boolean
dim aa(3) as Integer
dim bb(5) as Double = 99
dim ss(32) as String
//
x=sin(y(aa(bb((3*7)))))
in Swift you’d have this
var x : Int = 42
var y =[String](repeating : "Fred",count : 14)
var z =[Double]()
var q =[Bool]()
var aa =[Int](repeating : 0,count : 3)
var bb =[Double](repeating : 99,count : 5)
var ss =[String](repeating : "",count : 32)
//
x = sin(y[aa[bb[(3 * 7)]]])
Probably nice application, but it needs 10;14 (I think) to run: it was rejected on El Capitan (both a bas icon and an alert window that confirm the bad icon [no run icon]).