An Abstract Syntax Tree, or AST, is a tree representation of the source code of a computer program that conveys the structure of the source code. Each node in the syntax tree represents a construct occurring in the source code.
During conversion to it’s abstract syntax tree, only the structural and content-related details of the source code are preserved, and any additional details are discarded. Information that are preserved, and are vital to the syntax tree purpose, are:
Abstract syntax trees are used to represent the structure of a program’s source code for the compiler to use. An abstract syntax tree is usually the result of the syntax analysis phase of a compiler. It often serves as an intermediate representation of the program through several stages that the compiler requires, and has a strong impact on the final output of the compiler.
ASTs are also used for uses cases like static code analysis. Automated tools can traverse the AST of a program to find syntax errors and bad patterns in the code without actually executing it.