Skip to content

kolkol69/js-to-python

Repository files navigation

JS to Python compiler using ANTLR4

Setup

  1. Install java, for mac run: brew cask install java
  2. Install antlr4 referring to the tutorial
  3. After installing antlr4 run: antlr4 -Dlanguage=JavaScript -lib grammars -o lib -visitor -Xexact-output-dir grammars/ECMAScript.g4
  4. your grammar is in grammars folder and inside your lib you can find:
  • ECMAScriptLexer.js splits a source code character stream into a token stream according to the rules specified in the grammar.
  • ECMAScriptParser.js generates an abstract connected tree structure (i.e. parse tree) from the token stream.
  • ECMAScriptVisitor.js is responsible for traversing the generated tree. Technically, we could manually process the tree by depth-first recursive traversal of children. However, if we have a large number of node types and complex processing logic, it is preferable to visit each node type using its special predefined method, as visitor does.

useful links:

  1. https://stackoverflow.com/questions/54816560/how-to-build-a-javascript-antlr-visitor
  2. https://habr.com/ru/post/351906/#Codegeneration

About

JS to Python part of compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published