Five steps for Python Code Execution

Source: Internet
Author: User

Are you familiar with the five-step Python code execution application? Want to learn more about the actual operation steps of Python code execution in actual operation? If you want to understand it, you can click on our article to get a better understanding of it.

The following process is required for Python code execution:

1. Tokenizer performs lexical analysis and splits the source program into tokens.

2. Parser creates CST based on the Token

3. CST is converted to AST

4. AST is compiled into bytecode

5. Execute the bytecode

When Python code is executed, Python calls the PyParser_ASTFromFile function to convert the code content of the file to AST:

 
  1. mod_ty  
  2. PyParser_ASTFromFile(FILE *fp, const char *filename, 
    int start, char *ps1,  
  3. char *ps2, PyCompilerFlags *flags, int *errcode,  
  4. PyArena *arena)  
  5. {  
  6. mod_ty mod;  
  7. perrdetail err;  
  8. node *n = PyParser_ParseFileFlags(fp, filename, 
    &_PyParser_Grammar,  
  9. start, ps1, ps2, &err, PARSER_FLAGS(flags));  
  10. if (n) {  
  11. mod = PyAST_FromNode(n, flags, filename, arena);PyNode_Free(n);  
  12. return mod;  
  13. }  
  14. else {  
  15. err_input(&err);  
  16. if (errcode)  
  17. *errerrcode = err.error;  
  18. return NULL;  
  19. }  
  20. }      

In

 
  1. PyParser_ParseFileFlags 

After the file is converted to CST in the Python code, the PyAST_FromNode function converts CST to AST. This function is defined in include \ ast. h:

 
  1. PyAPI_FUNC(mod_ty) PyAST_FromNode(const node *, PyCompilerFlags *flags,  
  2. const char *, PyArena *);   

The above is an introduction to the relevant content for Python code execution. I forget you will get something.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.