开发者

In plain English, what are the difference between Python, Perl, and Ruby when it comes to translating them to another language? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_开发问答 Closed 12 years ago.

UPDATE: Received a lot of great info, thanks -- went back to read my question again, based on some of the answers stating that it's possible to do XYZ, which is not the question. the core of the question is this: "Main focus of this question is finding an answer in plain English of why Python, Perl, and Ruby are what they are when it comes to porting them to another language."


Been looking at the differences between Perl, Python, and Ruby -- and this to me has been one of the most interesting differences I've found so far, that being that it appears it's possible to transcribe Python into C, but it's not possible to transcribe Perl into any language. Haven't found anything about Ruby, but guessing that it's approach to 99.99% of everything is a object might make this hard if not impossible to do a transcription to another language.

Main focus of this question is finding an answer in plain English of why Python, Perl, and Ruby are what they are when it comes to porting them to another language.


It isn't that it's impossible to translate them, since any Turing-complete language can emulate any other Turing-complete language. The problem is generating an efficient translation, since some languages support features that are either very difficult or very complex to emulate in another.


Your question makes little —if any— sense, especially considering the questions you linked to.

Reading Why not translate Perl to C? might help you make sense of life, universe and everything.


Any Turing-complete language can be translated into any other turing-complete language, it just takes a lot of effort and may look very ugly. Perl is special because its parser is full of special cases, but that does not make translating Perl to anything impossible, just very hard. Python has a pretty nice grammar and is easily parsed. Ruby has some peculiarities from Perl, but is still comparatively clean.

Think of it like this: Every language executes code on your CPU sooner or later. You can always take this machine code and "decompile" it into any higher level language, but depending on the code complexity, your results might just not be very useful for humans to understand.


I understand what you asking, but that's not the right question (I'll get to that in a second).

Answer is because Perl is not defined by a formal language definition. Perl is somewhat in uncommon in that the reference for the language IS the implementation of the interpreter. Other languages such as Python, and C have a language definition. This definition is the reference and the compiler/interpreter is implemented to conform to that definition.

This reference allows someone to take the lexer/parser steps for one language and apply it in reverse to the syntax tree of another language.

ie. Python Lexer -> Python Parson -> AST -> C Parser -> C Lexer

This allows you it easily create a program to transcribe Python to C. Of course it's not that easy, but you get the idea.

For Perl there is no reference other than the Perl interpreter. Because there is a reference, it is possible to create a program that will translate the code, HOWEVER it would be very difficult compared to a language that had their reference in BNF (for example).

The question you wanted to ask is:

Why is it so much more difficult to automatically translate Perl to C and vice-versa, than Python to C?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜