Javascript to python translator

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

My attempt to create a translator from simple Javascript to python

License

jiricekcz/javascript-to-python

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

Читайте также:  Sitemap html not found

README.md

A javascript to python translator

My attempt to create a translator from simple Javascript to python

Note: This only translates syntax features, not all native functions will be available.

Note: Python does not nativly support async functions and all functions that would be async in JavaScript run synchronously in python, thus all async/await modifiers will be ignored while translating to python.

Note: You can use native python functions within the JavaScript file. This can be usefull for functions like input(), whose function is, due to the nature of JavaScript, somewhat complicated to replicate in JavaScript.

Currently supported JavaScript syntax features

  • VariableDeclaration
  • VariableDeclarator
  • Identifier
  • Literal
  • BinaryExpression
  • IfStatement
  • BlockStatement
  • ExpressionStatement
  • UpdateExpression
  • AssignmentExpression
  • WhileStatement
  • ForStatement
  • BreakStatement
  • ContinueStatement
  • FunctionDeclaration
  • ReturnStatement
  • CallExpression
  • MemberExpression
  • ClassDeclaration
  • ClassBody
  • MethodDefinition
  • FunctionExpression
  • Super
  • ThisExpression
  • ArrowExpression
  • ArrayExpression
  • ArrayPattern
  • SpreadElement
  • ObjectExpression
  • Property
  • ClassExpression
  • ThrowStatement
  • TryStatement
  • CatchClause
  • ForOfStatement
  • UnaryExpression
  • LogicalExpression
  • TemplateLiteral
  • TemplateElement

Currently translated native JavaScript functions and constants

Currently translated JavaScript native classes and their methods and operators

Currently translated Node.js modules with the functions supported

node . ./myFile.js ./myFile.py

About

My attempt to create a translator from simple Javascript to python

Источник

Javascript to python translator

This free online converter lets you convert code from JavaScript to Python in a click of a button. To use this converter, take the following steps —

  1. Type or paste your JavaScript code in the input box.
  2. Click the convert button.
  3. The resulting Python code from the conversion will be displayed in the output box.

Key differences between JavaScript and Python

Characteristic JavaScript Python
Syntax JavaScript has a C-style syntax with curly braces, while Python has a more readable syntax with whitespace indentation. Python has a more readable syntax with whitespace indentation, while JavaScript has a C-style syntax with curly braces.
Paradigm JavaScript supports both object-oriented and functional programming paradigms. Python supports object-oriented, imperative, and functional programming paradigms.
Typing JavaScript is dynamically typed, meaning that variable types are determined at runtime. Python is dynamically typed, meaning that variable types are determined at runtime.
Performance JavaScript is generally faster than Python due to its just-in-time (JIT) compilation. Python is generally slower than JavaScript due to its interpreted nature.
Libraries and frameworks JavaScript has a vast collection of libraries and frameworks, including React, Angular, and Vue. Python has a vast collection of libraries and frameworks, including Django, Flask, and NumPy.
Community and support JavaScript has a large and active community with many resources and support available. Python has a large and active community with many resources and support available.
Learning curve JavaScript has a moderate learning curve due to its complex syntax and asynchronous programming concepts. Python has a relatively easy learning curve due to its simple syntax and readability.
Читайте также:  Ссылки

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A Javascript-to-Python translation assistant.

License

int3/js2py

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A Javascript-to-Python translation assistant. It does a simple translation from Javascript to Python (as detailed below). You’ll most likely need to make further changes by hand, but this automates part of the work.

I thought it would be nice to be able to import some libraries directly into Python, rather than shelling out to NodeJS. This script is the result of trying to make that a reality.

Читайте также:  Install all python libraries

I’ve successfully used it to port Esprima to Python — the result is PyEsprima.

npm install ./js2py.coffee file.js > out.py 

Transformations and Shims

  • Create global declarations where necessary
  • Transform simple prototype-based classes into corresponding Python classes (but no inheritance)
  • Remove assignment statements from conditional tests
  • Convert switch statements into if-else chains
  • Convert pre-/post-increments into assignment statements
  • Array.prototype.slice and String.prototype.substr are converted to Python’s slice notation
  • Function expressions are hoisted out as fully declared functions since Python’s lambdas are limited
  • Shims for RegExp and JS-style dictionaries
  • Some support for typeof
  • No support for modifying non-global nonlocals (but easy enough to add with the nonlocal keyword in Python 3)
  • a[i] in JS will return undefined if i >= a.length , but in Python it raises an IndexError .
  • No support for call / apply .
  • There many more; pull requests are welcome!

About

A Javascript-to-Python translation assistant.

Источник

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