Re: php to python code converter

Discussion in 'Python' started by Pascal Chambon, May 8, 2009.

  1. Hello

    That's funny, I was precisely thinking about a php to python converter,
    some weeks ago.
    Such a tool, allowing for example to convert some CMS like Drupal to
    python, would be a killer app, when we consider the amount of php code
    available.

    But of course, there are lots of issues that'd have to be fixed :
    - translating the php syntax to python syntax
    - forcing scope limitations where php doesn't have any
    - handling differences in semantics (for example, the booleanness of "0"
    or)
    - handling the automatic variable creation and coertion that php features
    - handling the php types like arrays (which are neither python lists nor
    python dicts)
    - providing a whole mirror of the php stdlib (string and file functions,
    access to environment vars...)

    Some things, like PECL modules, would imo be almost impossible to handle
    (there are already so much trouble to make Cpython extensions available
    to other python implementations...), but I guess that 95% of existing
    php websites could be wholly translated "just" with a language
    translator and an incomplete stddlib replacement.

    That's hell a lot of work anyway, so it'd be worth weighing it ^^

    Actually, your module "phppython" might already be rather useful,
    because I've crossed here and there people desperately asking for help
    when translating some php function of their own to python.

    But if the project were to become bigger, I guess some choices would
    have to be rechecked. For example it seems you parse the php code your
    own way, instead of using existing php parsers ; I think the most
    flexible way would be walking some kind of php abstract syntax tree, and
    translating it to python AST on the way. Also, writting the comments in
    english woudl be mandatory :p

    I'd like to have the opinion of people around : do you think that
    complete language translators like php<->python or ruby<->python are
    possible ? Impossible ? Not worth the effort ? Or must be reached by
    another way (eg. Parrot and stuffs) ?

    Regards,
    Pascal

    PS : Am I the only one having most of answers rejected by the antispam
    system of python-list ? That's humiliating :p

    bvidinli a écrit :
    > if anybody needs:
    > http://code.google.com/p/phppython/
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    >
     
    Pascal Chambon, May 8, 2009
    #1
    1. Advertising

  2. Pascal Chambon

    Guest

    On 8 Mai, 17:19, Pascal Chambon <> wrote:
    > Hello
    >
    > That's funny, I was precisely thinking about a php to python converter,
    > some weeks ago.
    > Such a tool, allowing for example to convert some CMS like Drupal to
    > python, would be a killer app, when we consider the amount of php code
    > available.
    >
    > But of course, there are lots of issues that'd have to be fixed :
    > - translating the php syntax to python syntax
    > - forcing scope limitations where php doesn't have any
    > - handling differences in semantics (for example, the booleanness of "0"
    > or)
    > - handling the automatic variable creation and coertion that php features
    > - handling the php types like arrays (which are neither python lists nor
    > python dicts)
    > - providing a whole mirror of the php stdlib (string and file functions,
    > access to environment vars...)


    Some thoughts.

    1) Syntax. Not a big deal.

    2) Semantics. My favourite approach was to create a Python framework
    that represents PHP in Python and enables round-trips. So one could
    translate forth and back. Python code that is compliant to the
    conventions of the framework can also be translated to PHP and for
    each PHP program P following equation holds:

    py2php(php2py(P)) = P

    This makes readable code mandatory.

    3) PHP stdlib via C bindings ( ctypes? )

    4) Corner cases of bindings: cut them off. Not everything has to be
    translated. But produce stubs that raise NotImplementedError
    exceptions.

    Same arguments apply to Javascript. Not sure about Ruby but I do think
    a parser is feasible despite context sensitivities. Ruby is not my
    concern though.

    Personally I'd be interested in Wordpress which I like and use.

    Kay
     
    , May 10, 2009
    #2
    1. Advertising

  3. Pascal Chambon

    bvidinli Guest

    i designed php to python converter a few monthos ago, to translate
    some of my ready made code snippets to python.
    i was experienced with php and was learning python.

    as stated on project home, it is only intended for translating small
    code snippets or small functions to python.

    whole applications, cannot be converted using that...

    only an idea, a very beta/alpha package,

    since there are huge amount of php applications, files, codes all
    around web, this would be a good tool if developed and used
    properly...
     
    bvidinli, May 13, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D'Arcy J.M. Cain

    Re: php to python code converter

    D'Arcy J.M. Cain, May 8, 2009, in forum: Python
    Replies:
    0
    Views:
    467
    D'Arcy J.M. Cain
    May 8, 2009
  2. Dotan Cohen

    Re: php to python code converter

    Dotan Cohen, May 8, 2009, in forum: Python
    Replies:
    3
    Views:
    375
    Diez B. Roggisch
    May 9, 2009
  3. Rajive Narain
    Replies:
    0
    Views:
    1,895
    Rajive Narain
    Sep 18, 2009
  4. news reader
    Replies:
    2
    Views:
    211
    news reader
    Apr 17, 2006
  5. Replies:
    1
    Views:
    138
    Thomas 'PointedEars' Lahn
    Apr 3, 2005
Loading...

Share This Page