Does anyone know of a (preferably open source) PHP to ruby compiler? i.e. a program which parses PHP code and produces semantically equivalent ruby code?
I don't think one exists.
A combination of Quercus, which re-implements PHP in Java, and JRuby might be of help, depending on what you are trying to accomplish.
This is a pretty daunting task already. And you picked two languages that are very dissimilar. Sure, you could probably programatically translate PHP to Ruby, but the resulting code would be very un-ruby-like.
See some related questions and their answers:
- How to translate between programming languages
- Why is it not possible to create a practical Perl to Python source code converter?
If you could translate idiomatic PHP to idiomatic Ruby you probably need human-like intelligence - ie: the ability to understand what code does (in essence) and rewrite it in the target language. Unfortunately we don't have very smart AI in this front. At least not that I'm aware of.
http://railsforphp.com/reference/ can be a handy reference when you're just getting started going from PHP to Ruby. You can look up a PHP function and find its Ruby equivalent.
I haven't used it myself, but you may want to look at Phuby. It allows you to run PHP code within ruby. Then I'd try to unit test the life out of the code (using ruby unit tests), and then re-write the code in ruby.
However, I suspect Phuby isn't even remotely production-ready.
Stick to one language why do you need converters? just suffer it out and convert that damn php code into ruby visa versa, unless you are planning to make a service? then good luck.