We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可以使用 Js2Py 将 JavaScript 翻译为 Python。它支持整个 JavaScript,您可以使用它来翻译大型 JavaScript 模块,例如 esprima.js(JavaScript 6 解析器)。
Short demo:
这就是翻译后的函数内部的样子(相当难看):
You can translate JavaScript to Python using Js2Py. It supports whole JavaScript and you can use it to translate large JavaScript modules like
esprima.js
(a JavaScript 6 parser).Short demo:
This is how the translated function looks like internally (it's rather ugly):
几(4)年后现在更新
(几乎肯定)可以做到这一点;尽管肯定不是使用正则表达式。
我建议未来的读者查看@Piotr Dabkowski 的答案。
或者其他一些答案。 (我不知道没有尝试过)
原始答案
嗯,这是一个很难的问题。
编译器的定义是从高级语言翻译成低级语言。
例如 python 到机器代码。
或者java到javascript(谷歌在某个地方有一个相当著名的编译器 - 它使谷歌文档更容易制作)
Python 到 javascript 的编译器比比皆是。
从技术上讲,javascript 到 python 是一个反编译器。 (afaik)
我发现了一些关于 javascript-python 转换器的猜测这里: 按照步骤进行操作。它主要讲述的是如何做到这一点不会太难。
我找不到任何东西,但这并不意味着它不存在。
正则表达式不适合,正则表达式仅适合常规语言。
编程语言通常不是常规语言。请参阅此
Updated
Now several (4) years later this (almost certainly) can be done; though certainly not with RegEx.
I suggest future readers look to @Piotr Dabkowski's answer..
Or some of the other answers. (I don't know having not tried them)
Original Answer
Hm this is a hard one.
The definition of a compiler is translates from a higher level language to a lower level language.
eg python to machine-code.
or java to javascript (google has a rather famous compiler for this somewhere - its' what makes google doc easier to make)
Python to javascript compilers abound.
technically javascript to python would be a decompiler. (afaik)
I found some speculation about a javascript-python converter here: follow the tread through. it mostly speaks of how it wouldn't be too hard to do.
I can't find anything , but that doesn't mean it's no out there.
Regex is not suitable, regex is suitable only for regular languages.
programming languages are not normally regular languages. see this
这个答案可能晚了大约 2 年,但是 js 怎么样 -> CoffeeScript -> Python?如果你使用 http://js2.coffee/ 之类的东西来转换为 cs,那么缩进和列表之类的东西就是已经为你做好了。
This answer might be about 2 years late but how about js -> CoffeeScript -> python? If you use something like http://js2.coffee/ to convert to cs, then things like indentation and lists are already done for you.
如果您所要求的是将 javascript 中的一些正则表达式转换为 Python 等效项,那么正则表达式的基础知识大多是相当标准的。查看 Python re 模块文档。查看您所使用的内容是否有记录。您还感兴趣的是此页面。
如果您正在谈论将 javascript 代码转换为等效的 Python 代码,那么最好的转换器就是您。了解Python,然后手动转换它们。没有什么比人类更好的了。循环、变量、数组等编程结构非常常见和标准,您将立即知道如何使用它们。
If what you are asking is converting a few regexs in javascript to Python equivalent, the basics of regular expressions are mostly pretty standard. check out the Python re module doc. See if what you are using is documented. Also of interest to you is this page.
If you are talking about converting javascript code to Python equivalent, the best converter is you. Learn about Python, and then convert them manually. there is nothing else better than the human being. Programming constructs like loops, variables, arrays are pretty common and standard you will recognize instantly how to use them straight away.