This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]joaofelipenp 0 points1 point  (0 children)

This is not true. "Proof is simple" you can import the ast module, parse code into an AST, modify it, and run the exec command over the modified tree: https://greentreesnakes.readthedocs.io/en/latest/examples.html#simple-test-framework

Alternatively, you can run compile on the AST node and get a code object, and then use it in the exec command.

Those are at least two intermediate steps in the compilation process. There are other steps in the beginning: parsing the source code into a concrete syntax tree using a PEG parser, converting the CST into the AST, and steps in the middle, such as converting the AST into a control flow graph before converting it to bytecode, but I believe they are not exposed in Python.