Inside ironpython: inronpython ast syntax tree (2/2)

Source: Internet
Author: User

Next part: Inside ironpython: ironpython ast syntax tree (1/2)

ASTs introduction:

When ipy.exe executes demo. py, The ironpython implementation and DLR participate in source code compilation. In basic terms, the compiler is a streamlined job: Starting from the specific data structure that the syntax parser generates to describe the source code. This data structure is an abstract syntax tree (AST. After the code analysis is complete, the compiler converts the ast or creates a new data structure. Based on this result, the compiler generates the machine code or the intermediate language (IL) of the virtual machine ).

Ironpython first generates an abstract syntax tree specific to ironpython, and then converts the syntax tree to a DLR syntax tree. The reason why some languages have their own syntax tree is that it can better support code analysis, it also better supports some tools based on its own AST (tools need an ast that is closer to the source code. The AST in many languages may be similar to the AST in DLR, but the AST in DLR contains more information about the exact semantic meaning. You can think that dlr ast is the one required by the compiler in the later stage of multiple transformations.

It is very interesting that DLR uses a slow compilation technique similar to the clr jit compilation technology: it does not compile all the code at once. In this way, we will experience a little performance loss during the first running, but it can run faster in the future.

View ironpython's AST

Return to vs IDE and press F5 to execute the program and pause it at the breakpoint (in fact, in ironpython you installed, when the breakpoint is reached for the first time, it is not a demo. py file, but a file named site. py file. Because this file does not exist in our .. \ bin \ DEBUG directory, you can directly process the demo. py file ). Next, execute the program in one step by pressing F10 until: AST = parser. parsefile (true); is executed );. Now we can view ironpython's AST in the monitoring window.

Due to space problems, I only show some ast. Body members in the figure. The ast root node is suitestatement, which indicates a series of statements. It has a member: statements. Expand the first member in statements and you will see that this member is a functiondefinition type node. It has a body member (also a suitestatement type): indicates the function definition, we can see that it has a name Member, and its name is bound to the result function object. Expand all the elements in demo. py, as shown in the relationship between them:

In this way, we can intuitively see that most of the nodes have subnodes. The figure shows the type information of each node. For example, a node of the functiondefinition type has a subnode of the suitestatement type. Some nodes contain subnode information described in indentation and curly brackets.

 

Link: http://www.cnblogs.com/Jifangliang/archive/2008/07/30/1256041.html

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.