Skip to content

Workflow description

dours edited this page Jul 6, 2022 · 1 revision

Workflow:

  • The main function parses the command line arguments and (if an existing input file was provided) reads the file
  • The parser module uses the ANTLR parser to build an abstract syntax tree and then maps its tree to our own internal representation (also based on AST).
  • The SimplePass module applies several python-to-python passes to eliminate some constructions which are not supported in eolang. These include:
    • Eliminate if-else statements with > 2 branches (rewrite an if-elsif-else as many if-else statements)
    • Eliminate for: rewrite it as a while + try
    • Prepend each identifier with x, so that no identifier starts with a capital letter
    • Standardize (simplify) quotes for string literals
    • Simplify except clauses for exception handling: change multiple except clauses of a try block to one except:, which catches everything, and a series of if-else, which emulates the behaviour of all the typed except clauses and reraises the exception if it should not be caught
    • Eliminate if-else again (because complex if-else statements appear as a result of the previous pass)
    • Eliminate complex assignments (i.e., translate a = b = c to b = c; a = b)
    • Eliminate simple cases of method calls (that is, substitute pointer to this explicitly)
    • Extract all function calls to the statement level to make the execution order explicit (i.e., translate a = f(1) + g(2) to tmp1 = f(1); tmp2 = g(2); a = tmp1 + tmp2
  • The resulting simplified AST is then translated to the eolang code.

https://github.com/polystat/py2eo/issues/26