Source Code Abstract Syntax Tree (AST)
An Source Code Abstract Syntax Tree (AST) is a tree representation of the abstract syntactic structure of source code (written in a programming language).
- Example(s):
- a Java Source Code AST, ...
- …
- Counter-Example(s):
- See: Program Transformation, Abstract Syntax, Programming Language, Parse Tree, Compiler, Program Analysis.
References
2021
- (Wikipedia, 2021) ⇒ https://en.wikipedia.org/wiki/Abstract_syntax_tree Retrieved:2021-2-20.
- In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code.
The syntax is "abstract" in the sense that it does not represent every detail appearing in the real syntax, but rather just the structural or content-related details. For instance, grouping parentheses are implicit in the tree structure, so these do not have to be represented as separate nodes. Likewise, a syntactic construct like an if-condition-then expression may be denoted by means of a single node with three branches.
This distinguishes abstract syntax trees from concrete syntax trees, traditionally designated parse trees. 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.
Abstract syntax trees are also used in program analysis and program transformation systems.
- In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code.
2018
- (Alon et al., 2018) ⇒ Uri Alon, Shaked Brody, Omer Levy, and Eran Yahav. (2018). “code2seq: Generating Sequences from Structured Representations of Code.” In: International Conference on Learning Representations.
- QUOTE: ... An Abstract Syntax Tree (AST) uniquely represents a source code snippet in a given language and grammar. The leaves of the tree are called terminals, and usually refer to user-defined values which represent identifiers and names from the code. The non-leaf nodes are called nonterminals and represent a restricted set of structures in the language, e.g., loops, expressions, and variable declarations. For example, Figure 2c shows a partial AST for the code snippet of Figure 2a. Names (such as
num
) and types (such asint
) are represented as values of terminals; syntactic structures such as variable declaration(VarDec
) and a do-while loop (DoStmt
) are represented as nonterminals. ...
- QUOTE: ... An Abstract Syntax Tree (AST) uniquely represents a source code snippet in a given language and grammar. The leaves of the tree are called terminals, and usually refer to user-defined values which represent identifiers and names from the code. The non-leaf nodes are called nonterminals and represent a restricted set of structures in the language, e.g., loops, expressions, and variable declarations. For example, Figure 2c shows a partial AST for the code snippet of Figure 2a. Names (such as
2018
- (MediaWiki) ⇒ https://www.mediawiki.org/wiki/Alternative_parsers Last Edited: 23 December 2018.
- QUOTE: ... Parsers that build an abstract syntax tree (AST) and provide access to it are listed under Parsers providing an AST; parsers that don't build an AST but extract some information are listed under Parsers extracting some information; the rest of the parsers are listed under Other parsers.