Is that a Blue Morpho for the icon ? love the symbolism in that
EDIT : FWIW I pasted in a pretty lengthy (for me) method (80 lines) and it translated it all without crashing. Dont have a real way to test this code in Swift as its just one chunk out of a much larger whole.
Here is another update⦠Its actually interesting what tidbits Iām learning about Swift while writing thisā¦
This version should now be able to translate the 3 variations of a BASIC DO/LOOP into the corresponding Swift version
essentially
// DO | while true {
// LOOP | }
// |
// DO UNTIL (condition) | while !(condition} {
// LOOP | }
// |
// DO | repeat {
// LOOP UNTIL (condition) |} while !(condition}
This version does NOT yet deal properly with EXIT or CONTINUE.
Also the keyword āBREAKā is excluded from the BASIC syntax as it has a totally different meaning in Swift (and this app wonāt be directly supporting break points anyhow)
Example
BASIC
sub test
dim x as integer = 3
dim y as double = 2.5
Do
for i=1 to 10
for j=1 to 10
while j>1
do
do until x=14
exit while
loop
loop until y<3
wend
next j
next i
LOOP
Do Until x > 100 // test
x = x * 2
Loop
Do
x = x * 2
Loop Until x > 100
end sub
Swift Translation
func test() {
var x : Int = 3
var y : Double = 2.5
while true {
for i in(1...10) {
for j in(1...10) {
while j > 1 {
repeat {
while !(x == 14) {
exit while
}
}while !(y < 3)
}
}
}
}
while !(x > 100) {
// test
x = x * 2
}
repeat {
x = x * 2
}while !(x > 100)
}
and Xcode properly compiles except for the (EXIT WHILE as mentioned above)
not sure if there would be a ācodeā activated break (since the keyword ābreakā is what Xojo calls Exit). Plus since my app is a translator⦠there is no ārun timeā mode, at least not one equivalent to Xojo
as far as I know yes ⦠that is true
Iām not entirely surprised since Obj-C doesnt have one either
BUT ⦠Xcode DOES stop at the breakpoints you set
I did some research, and there is no direct equivalent to the āBREAKā command. Seems in Xcode (Swift or ObjC) you manually place breaks by clicking the text editor gutter, same as you can do in Xojo
Here is another updateā¦
This one should properly handle āEXIT xxxā for inner and outer loops (Swift requires labels on outer loop exits). It also detects situations where missing Next, End etc and marks the BASIC line with a ā¦
The next update will require you have Swift installed, as it will take any translated code and run it thru the Swift compiler to test for other errors. This will take a bit more work, as it will need to take a Swift error and relate it back to the BASIC line number.
Wow, that was easier than I thought it would be⦠So here it isā¦
Unless I find (or one of you finds) something way out of wack, this will probably be the last tweek (famous last words I know)
This version requires you have Swift installed (it checks when it starts up).
Once you give it some BASIC code, and it passes the minor structure checks, it then passes it (via Shell) to Swift. And if shows any errors returned (right now, Iām letting warnings slide). NOTE : this part of the process writes the Swift code to your DESKTOP
And my thanks to Hector (HMARROQUINC), he sent some test code that pointed out a few errors that my test code neglected.
thisi s because Swift is ādifferentā
First Loop variables are not "Dim"d or Varād⦠Swift by default is the same as if Xojo said For I As Integer=0 to 10
and i=i+1 in this case is an attempt to assign a āconstantāā¦
Remember, this is for a BASIC dialetic, NOT āXojoā per seā
but all that being said⦠It does give me something to think about
test.swift:3:5: warning: immutable value 'i' was never used; consider replacing with '_' or removing it
for i in(0...10) {
^
_
test.swift:4:4: error: cannot assign to value: 'i' is a 'let' constant
i = i + 1
^