Open s777s opened 8 years ago
1) It's not for production use, becouse it can translate a very small subset of php (all maintained grammers in Backus-Naur Form (BNF) notation you can see in readme.md). 2) Main Class: src/generator/Main.java - need one input argument from command line - filename (with .php extention) - must be near src folder. 3) Output in: src/generated/filename.java
For example input.php:
$a=3;
$b=$a;
$c=$a+$b;
echo $a."\n";
print $c."\n";
echo "Text1\n";
for($t = 0; $t < 5; $t++) {
echo $t."\n";
}
while($a < 5) {
echo $a."\n";
$a++;
}
if ($a == 0) {
echo "Text1\n";
}
else if ($a == 1) {
echo "Text2\n";
}
else {
echo "Text3\n";
}
echo "String 1\n";
$string_var = "String 2\n";
echo $string_var."\n";
echo "String 1"." ".$string_var."\n";
f(2);
function f($a) {
echo $a."\n";
}
input.java:
public class Input {
public static void main(String[] args) {
int a = 3;
int b = a;
int c = a+b;
System.out.print(a + "\n");
System.out.print(c + "\n");
System.out.print("Text1\n");
for (int t = 0;t<5;t++){
System.out.print(t + "\n");
}
while (a<5){
System.out.print(a + "\n");
a++;
}
if (a==0){
System.out.print("Text1\n");
}
else if (a==1){
System.out.print("Text2\n");
}
else {
System.out.print("Text3\n");
}
System.out.print("String 1\n");
String string_var = "String 2\n";
System.out.print(string_var + "\n");
System.out.print("String 1" + " " + string_var + "\n");
f(2);
}
private static void f(int a){
System.out.print(a + "\n");
}
}
I need to convert simple php code to java for one project (and I know only php), so I think, you translator is interesting. For example I can check difference in code in 2 languages instead of reading whole large book or googling for long hours. Thank you.
2016-03-09 21:57 GMT+03:00 Rostunov Sergey notifications@github.com:
1) It's not for production use, becouse it can translate a very small subset of php (all maintained grammers in Backus-Naur Form (BNF) notation you can see in readme.md). 2) Main Class: src/generator/Main.java - need one input argument from command line - filename (with .php extention) - must be near src folder. 3) Output in: src/generated/filename.java
For example input.php:
$a=3; $b=$a; $c=$a+$b;
echo $a."\n"; print $c."\n"; echo "Text1\n";
for($t = 0; $t < 5; $t++) { echo $t."\n"; }
while($a < 5) { echo $a."\n"; $a++; }
if ($a == 0) { echo "Text1\n"; } else if ($a == 1) { echo "Text2\n"; } else { echo "Text3\n"; }
echo "String 1\n"; $string_var = "String 2\n"; echo $string_var."\n"; echo "String 1"." ".$string_var."\n"; f(2);
function f($a) { echo $a."\n"; }
input.java:
public class Input {
public static void main(String[] args) {
int a = 3; int b = a; int c = a+b; System.out.print(a + "\n"); System.out.print(c + "\n"); System.out.print("Text1\n"); for (int t = 0;t<5;t++){ System.out.print(t + "\n"); } while (a<5){ System.out.print(a + "\n"); a++; } if (a==0){ System.out.print("Text1\n"); } else if (a==1){ System.out.print("Text2\n"); } else { System.out.print("Text3\n"); } System.out.print("String 1\n"); String string_var = "String 2\n"; System.out.print(string_var + "\n"); System.out.print("String 1" + " " + string_var + "\n"); f(2); } private static void f(int a){ System.out.print(a + "\n"); } }
— Reply to this email directly or view it on GitHub https://github.com/stdex/PHP2Java/issues/1#issuecomment-194451560.
FWIIW, I've started a more advanced "php to java" converter. It can really compile and run unit tests.
It is a commercial product (not open source), but the current pricing is pretty trivial.
https://php2java.com/#/home/main http://www.runtimeconverter.com/ https://github.com/RuntimeConverter/runtimeconverter-lib-docs
May you explain please, how does it work? I'm noobie in java, but I know php pretty well and I want to try to convert few scripts to java...