PHP to Java (using PtoJ)

前端 未结 5 2363
感动是毒
感动是毒 2021-02-15 15:32

I would like to transition our codebase from poorly written PHP code to poorly written Java, since I believe Java code is easier to tidy up. What are the pros and cons, and for

5条回答
  •  既然无缘
    2021-02-15 16:36

    P2J appears to be offline now, but I've written a proof-of-concept that converts a subset of PHP into Java. It uses the transpiler library for SWI-Prolog:

    :- use_module(library(transpiler)).
    :- set_prolog_flag(double_quotes,chars).
    :- initialization(main).
    
    main :- 
        Input = "function add($a,$b){ print $a.$b; return $a.$b;} function squared($a){ return $a*$a; } function add_exclamation_point($parameter){return $parameter.\"!\";}",
        translate(Input,'php','java',X),
        atom_chars(Y,X),
        writeln(Y).
    

    This is the program's output:

    public static String add(String a,String b){
            System.out.println(a+b);
            return a+b;
    }
    public static int squared(int a){
            return a*a;
    }
    public static String add_exclamation_point(String parameter){
            return parameter+"!";
    }
    

提交回复
热议问题