Learn something new every day
More Info... by email
An abstract syntax tree (AST) is a syntactic structure made to represent the functions that occur within a program. It is based on the source code of the programming. Typically hierarchical in design, the abstract syntax tree starts from the basic functions and streams downward to show the more involved functions and code within each basic function. The use of this tree makes it easier for programmers to visualize the code without looking through the source code itself, which is much longer, and may reveal flaws or weaknesses in code. The tree is called abstract, not because it is difficult to understand or has an abstract shape, but because it does not include the coding syntax such as parenthesis marks and other symbols that inevitably appear in the code.
When a programmer builds a program, he or she has to build the functions from such things as "if-then" statements and "or else" statements. When looking at the source code, it can be difficult to see if every statement and condition has been fully met and if all the functions have been created correctly. An abstract syntax tree gives the programmer a quick way to look over the programming to see each condition and how it applies to the program overall.
The tree is made in hierarchical fashion. At the top is one of the main statements and, from that statement, branches flow downward to show what satisfies the conditions. This continues, showing other functions and conditions for the entire program. Variables in the programming are often displayed, as well. Most programming languages have the ability to generate an abstract syntax tree.
Abstract usually means ill-formed, difficult to understand or amorphous. This is not the case with an abstract syntax tree. The reason the word "abstract" is used is because the tree does not display the syntax and programming as it is; rather, it removes implicit symbols that are not important for the display. For example, parentheses are often used quite liberally in programming, but they are not shown on the tree. This is because showing this syntax takes much more room, makes it harder to look at the tree, and the programmer would know about these symbols in the source code.
If a programmer wants to see these ancillary symbols, a concrete syntax tree is often employed. These trees are similar to the abstract variety, only they go into more detail with all the symbols. This tree is better for looking at missing chunks of symbols or code, while the abstract tree is better for checking up on the program’s functions and variables.