Php to ruby compiler

Компилятор PHP для Ruby

Кто-нибудь знает о PHP (желательно с открытым исходным кодом) для рубинового компилятора? т.е. программа, которая анализирует PHP-код и создает семантически эквивалентный код ruby?

Я не использовал его сам, но вы можете посмотреть на Phuby . Он позволяет запускать PHP-код в рубине. Затем я попробую блок проверить жизнь из кода (с использованием рубиновых модулей), а затем переписать код в рубине.

Тем не менее, я подозреваю, что Phuby даже не готов к производству.

Это уже довольно сложная задача. И вы выбрали два языка, которые очень разные. Конечно, вы, вероятно, могли бы программно перевести PHP на Ruby, но полученный в результате код был бы очень не-рубиновым.

См. Некоторые связанные вопросы и их ответы:

  • Как перевести язык программирования
  • Почему невозможно создать практический Perl-конвертер исходного кода Python?

Если бы вы могли перевести идиоматический PHP на идиоматический Ruby, вам, вероятно, понадобится человекоподобный интеллект, т. Е. Способность понять, что делает (по сути) код и переписывать его на целевом языке. К сожалению, у нас нет очень умного ИИ в этом фронте. По крайней мере, я не знаю.

Я не думаю, что он существует.

Комбинация Quercus, которая повторно реализует PHP на Java, и JRuby может помочь, в зависимости от того, что вы пытаетесь выполнить.

Читайте также:  Html input title style

Человеческий мозг в тандеме с копией Pick-Ax;)

Используя библиотеку универсального транспилятора для SWI-Prolog, вы можете преобразовать подмножество PHP в Ruby и несколько других языков. Это пример программы с исходным кодом PHP в качестве ее ввода:

:- use_module(library(transpiler)). :- set_prolog_flag(double_quotes,chars). :- initialization(main). main :- Input = "function add($a,$b)function squared($a)function add_exclamation_point($parameter)", translate(Input,'php','ruby',X), atom_chars(Y,X), writeln(Y). 

Это выход программы в Ruby:

def add(a,b) return a+b end def squared(a) return a*a end def add_exclamation_point(parameter) return parameter+"!" end 

Источник

PHP to Ruby compiler

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?

Answers

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.

Phalanger works as a compiler and runtime for PHP.

The easiest way is to install Phalanger Tools for Visual Studio, which allows you to create, build and debug console application.

Anyway, without Visual Studio; first you have to compile the code

phpc hello.php /out:hello.exe 

Optionally, if you have more files in your project, you should list them all, and specify the entering script file

phpc.exe /target.exe /entrypoint:hello.php /root:. /recurse:true /out:hello.exe 

Which compiles everything (*.php) in current directory and subdirectories, and specifies » hello.php » to be the entering script file.

This creates an executable file » hello.exe «.

After you succeed with this basic example, you may be interested in using some PHP extensions (like GD2). This can be done by adding following parameter, «/r:PhpNetGd2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03 which is the full name of the library containing GD2 functionality.

Источник

PHP to Ruby compiler [closed]

Interesting idea, but that sounds like more a way to run PHP code together with Ruby code on the JRuby runtime — not a bad idea as the production Quercus compiler is not open source and JRuby seems to be leading the way in terms of non-Java languages on the JVM. – Ramon Oct 6 ’10 at 15:31 , How do keep pee from splattering from the toilet all around the basin and on the floor on old toilets that are really low and have deep water? ,Using the universal-transpiler library for SWI-Prolog, you can convert a subset of PHP into Ruby and several other languages. This is an example program with PHP source code as its input:,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.

Using the universal-transpiler library for SWI-Prolog, you can convert a subset of PHP into Ruby and several other languages. This is an example program with PHP source code as its input:

:- use_module(library(transpiler)). :- set_prolog_flag(double_quotes,chars). :- initialization(main). main :- Input = "function add($a,$b)function squared($a)function add_exclamation_point($parameter)", translate(Input,'php','ruby',X), atom_chars(Y,X), writeln(Y). 

This is the program’s output in Ruby:

def add(a,b) return a+b end def squared(a) return a*a end def add_exclamation_point(parameter) return parameter+"!" end 

Answer by Brianna Garza

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? ,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.,Using the universal-transpiler library for SWI-Prolog, you can convert a subset of PHP into Ruby and several other languages. This is an example program with PHP source code as its input:,Get answers to millions of questions and give back by sharing your knowledge with others.

Using the universal-transpiler library for SWI-Prolog, you can convert a subset of PHP into Ruby and several other languages. This is an example program with PHP source code as its input:

:- use_module(library(transpiler)). :- set_prolog_flag(double_quotes,chars). :- initialization(main). main :- Input = "function add($a,$b)function squared($a)function add_exclamation_point($parameter)", translate(Input,'php','ruby',X), atom_chars(Y,X), writeln(Y). 

This is the program’s output in Ruby:

def add(a,b) return a+b end def squared(a) return a*a end def add_exclamation_point(parameter) return parameter+"!" end 

Answer by Lacey Harvey

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 had a similar problem, though I had rvm and ruby installed only for one user. For me, the solution was to check that the application files were owned by the same user for which ruby was installed. ,Okay I figured it out. there is a open source program called phc-win. It supports php 5.3.1, compiles scripts to byte code (obfuscation!) and is simple to use (It even has a gui).,All files with ‘php’ anywhere in the extension will be compiled into .phb files.

Encoding is not a variable: $this->Encoding

Encoding is not a variable: $this->Encoding

Answer by Jad Juarez

‘Compiled’ means that a programming language has its own compiler that translates the syntax into machine code before runtime. In contrast, scripting languages are interpreted line by line during runtime by the interpreter of the platform they are running on.,While programming languages are compiled, scripting languages are mostly interpreted — even though there are some scripting languages that are both compiled and interpreted, such as Python and Groovy.,On the other hand, sometimes it’s the scripting language that exists first and it gives birth to its own parent platform — however strange that may sound.,They can’t run on their own but always need an environment (implementation, runtime) with an interpreter for that scripting language.

ECMAScript uses a curly bracket syntax. The following JavaScript code example adds numbers from 1 to 10 together and outputs the result into the console (you can test it in your web browser’s JavaScript console by hitting F12):

let total = 0, count = 1; while (count console.log(total); // 55 

PHP has a C-like syntax. The following PHP code example creates a numeric array with four elements, loops through them, multiples each item by two, and unsets the $value variable when the loop is over.

 // $arr is now array(2, 4, 6, 8) unset($value); ?> 

Python doesn’t use curly brackets and semicolons are optional, so the code is easy to read and write. The following Python code example loops through integers between 0 and 4, and prints them out:

Ruby has a concise syntax similar to Python. The following Ruby code example defines the KaraokeSong class as a subclass of the Song class:

Groovy has a Java-compatible syntax, using curly brackets. The following Groovy code example defines the Coordinates class with the latitude and longitude properties and the getAt() method:

@Immutable class Coordinates < double latitude double longitude double getAt(int idx) < if (idx == 0) latitude else if (idx == 1) longitude else throw new Exception("Wrong coordinate index, use 0 or 1") >> 

Answer by Kennedi Henry

Open-source software development,Programming languages created in 1995,PHP is a general-purpose scripting language geared towards web development.[7] It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994.[8] The PHP reference implementation is now produced by The PHP Group.[9] PHP originally stood for Personal Home Page,[8] but it now stands for the recursive initialism PHP: Hypertext Preprocessor.[10] ,W3Techs reports that, as of April 2021[update], «PHP is used by 79.2% of all the websites whose server-side programming language we know.»[15]

   Hey, you are using Netscape! 

Sorry, that record does not exist

Welcome !

You have credits left in your account.

Answer by Lennox Lester

Stack Overflow: What factors make PHP Unicode-incompatible?,Recursion, a feature that allows a function to call itself, is supported by the language, but most PHP code is focused on iteration.,PHP 5.4 added the ability to bind closures to an object’s scope and also improved support for callables such that they can be used interchangeably with anonymous functions in almost all cases.,A veteran package manager that some PHP developers enjoy is PEAR. It behaves similarly to Composer, but has some notable differences.

Источник

PHP to Ruby compiler [closed]

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?

Solution

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.

OTHER TIPS

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:

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.

A combination of Quercus, which re-implements PHP in Java, and JRuby might be of help, depending on what you are trying to accomplish.

The human brain in tandem with a copy of the Pick-Axe 😉

Using the universal-transpiler library for SWI-Prolog, you can convert a subset of PHP into Ruby and several other languages. This is an example program with PHP source code as its input:

:- use_module(library(transpiler)). :- set_prolog_flag(double_quotes,chars). :- initialization(main). main :- Input = "function add($a,$b)function squared($a)function add_exclamation_point($parameter)", translate(Input,'php','ruby',X), atom_chars(Y,X), writeln(Y). 

This is the program’s output in Ruby:

def add(a,b) return a+b end def squared(a) return a*a end def add_exclamation_point(parameter) return parameter+"!" end 

Источник

Оцените статью