php to python code converter

Pascal Chambon chambon.pascal at gmail.com
Fri May 8 17:19:13 CEST 2009


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
>
>
>   




More information about the Python-list mailing list