Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: php to python code converter

Reply
Thread Tools

Re: php to python code converter

 
 
Pascal Chambon
Guest
Posts: n/a
 
      05-08-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

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

bvidinli a écrit :
> if anybody needs:
> http://code.google.com/p/phppython/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>


 
Reply With Quote
 
 
 
 
kay@fiber-space.de
Guest
Posts: n/a
 
      05-10-2009
On 8 Mai, 17:19, Pascal Chambon <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
bvidinli
Guest
Posts: n/a
 
      05-13-2009
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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moyea Video Converter with iPad video converter brntkobe1 Computer Support 0 04-18-2010 08:22 AM
PHP Training Institute In Delhi, Live Projects on PHP. Short TermPHP Courses, PHP Scripts, PHP Training with Live Projects. Rajive Narain Java 0 09-18-2009 10:47 AM
Re: php to python code converter Dotan Cohen Python 3 05-09-2009 02:14 PM
Re: php to python code converter D'Arcy J.M. Cain Python 0 05-08-2009 03:37 PM
php and python: how to unpickle using PHP? Ted Zeng Python 4 10-03-2006 03:07 PM



Advertisments