Another way to use python in a browser (and not only)

Background

In the spring of 2020, I first tried myself in the development of backend websites, I wrote in python, and on the front, I had to use js and it made me reject (here it is necessary to clarify that I do not consider js a terrible language, I just did not like it). Without hesitation, I started writing a translator from python to javascript (and if I googled I would find this and that ). this translator will be discussed.





Differences from other translators

During the development process, I read about JavaScript and not a lot about other languages ​​(ruby, lua, php) and noticed that they have a lot in common, for example, the presence of conditionals, functions, variables, etc. And then I thought why not add the ability to broadcast not only in js but also in other languages.





Languages ​​are added using handler functions, for example, a math handler for js looks like this:





def bin_op(left, right, op):
    return f"({left}{op}{right})"
      
      



and for lisp it will look like this:





def bin_op(left, right, op):
    return f"({op} {left} {right})"
      
      



And also a distinctive feature is the ability to add macros, such as integer division in js:





signs = {"//": lambda l, r: f"Math.floor({l}/{r})"}
      
      



Who needs it

One of the options for using the project is writing scripts in games, since python is quite heavy for an embedded language, you can use translation into lua.





You can also use it as a python linter with correction of errors in function names.





( js pascal) .





, - . : ( python ) .





, , . - , .





java. Java(jvm) - , , : Kotlin, Java, Clojure .





js, go, hello world (c++).





.





if...elif...else, while, for(C for each), . . .





, python. . .





web :





P.S.

.





Support the project with an asterisk on github





Join the telegram channel








All Articles