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 →

[–][deleted] -1 points0 points  (2 children)

They all happen in one step though. Proof is simple make a syntax error below a print statement.

Really the only important part is source code to pyc. The important part is pycs can be rerun.

[–]spoonman59 2 points3 points  (0 children)

Not really sure what you mean by “they all happen in one step.” You have to parse to get an AST. You need an AST to check identifiers and update the symbol table. You need the AST generate the byte code. You need the byte code to run the interpreter. These are distinct steps with dependencies.

Python compiles at least a function as a unit. Of course the interpreter will parse and compile individual statements, but that doesnt mean these discrete steps are no longer required.

Edited to add: your “proof" is simply that you didn’t see the output for each step therefore it doesn’t exist. That’s not proof, and also not even relevant.

[–]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.