Abstract syntax tree

It is a tree representation of the abstract syntactic structure of text (often source code) written in a formal language.

Likewise, a syntactic construct like an if-condition-then statement may be denoted by means of a single node with three branches.

Parse trees are typically built by a parser during the source code translation and compiling process.

Once built, additional information is added to the AST by means of subsequent processing, e.g., contextual analysis.

However, some language constructs require an arbitrarily large number of children, such as argument lists passed to programs from the command shell.

As a result, an AST used to represent code written in such a language has to also be flexible enough to allow for quick addition of an unknown quantity of children.

The source code produced should be sufficiently similar to the original in appearance and identical in execution, upon recompilation.

The AST is used intensively during semantic analysis, where the compiler checks for correct usage of the elements of the program and the language.

An abstract syntax tree for the following code for the Euclidean algorithm :
while b  0:
    if a > b:
        a := a - b
    else:
        b := b - a
return a