I think a crash course in Regular Expressions may just be what you need.
I find them extremely useful for these kind of purposes.
Basically create a set of Regex patterns for each possible language construct in both languages you want to convert between.
Use named grouping to extract the useful parts from language A and plug it into the patterns for language B.
For example, the for-next loop could be expressed in both languages as shown below.
Basicaly you loop through the basic code and look for the patterns that you defined. This process is a recursive one, because many of the values used in your code may themselves be complete expressions, which in turn contain more expressions etc.
Note that this is just an example, it is by no means a valid and workable regex pattern. There are a host of tings you need to keep in mind. The biggest problem is the source language (basic in this case). My example makes a lot of assumptions about the way you type it. Are you using SuperStrict style coding? or is it very liberal (eg: are you using strict type definitions or not?)?
For example, this will be easy to convert to java:
This will not:
The reason is that the converter does not know what data type 'n' should be declared as.
Java is very strict about it's type definitions. If you don't reflect that in your basic code, then the parser has to guess at what it is you intended it to be. This causes numerous errors. Some may be easy to find as they generate java compiler errors. But others may be more insidious.
So the question is, is it really worth the trouble? If you already have to take great care in the way you type your basic code, it may very well be easier to just type java to begin with.
I find them extremely useful for these kind of purposes.
Basically create a set of Regex patterns for each possible language construct in both languages you want to convert between.
Use named grouping to extract the useful parts from language A and plug it into the patterns for language B.
For example, the for-next loop could be expressed in both languages as shown below.
// BlitzMax Code For n:Int = 0 to 50 If( n = 4 ) Then DrawImage( blah, 5, 2) Else Print("foo") End If Next // BlitzMax Pattern "for (?<vname>\S+):(?<vtype>\S+) = (?<vsval>\S+) to {?<veval>\S+) (Step (?<vstep>\S+))? (?<content>.+) next"
// Java Code for(int n = 0; n < 50; n+=1) { if( n == 4 ) image( blah, 5, 2); else println("foo"); } // Java Pattern "for( (?<vtype>\S+) (?<vname>\S+) = (?<vsval>\S+); (?<vname>\S+) < {?<veval>\S+); (?<vname>\S+) += (?<vstep>\S+)){ (?<content>.+) }"
Basicaly you loop through the basic code and look for the patterns that you defined. This process is a recursive one, because many of the values used in your code may themselves be complete expressions, which in turn contain more expressions etc.
Note that this is just an example, it is by no means a valid and workable regex pattern. There are a host of tings you need to keep in mind. The biggest problem is the source language (basic in this case). My example makes a lot of assumptions about the way you type it. Are you using SuperStrict style coding? or is it very liberal (eg: are you using strict type definitions or not?)?
For example, this will be easy to convert to java:
For n:Int = 0 to 50 ... Next
This will not:
For n = 0 to 50 ... Next
The reason is that the converter does not know what data type 'n' should be declared as.
Java is very strict about it's type definitions. If you don't reflect that in your basic code, then the parser has to guess at what it is you intended it to be. This causes numerous errors. Some may be easy to find as they generate java compiler errors. But others may be more insidious.
So the question is, is it really worth the trouble? If you already have to take great care in the way you type your basic code, it may very well be easier to just type java to begin with.