Abstract syntax tree: Difference between revisions

Content deleted Content added
mNo edit summary
No edit summary
Line 1:
{{For|the trees used in linguistics|Concrete syntaxParse tree}}
{{no footnotes|date=February 2013}}
{{Merge from|Abstract syntax|date=Sept 2021}}
[[File:Abstract syntax tree for Euclidean algorithm.svg|thumb|400px|An abstract syntax tree for the following code for the [[Euclidean algorithm]]:{{pre|1='''while''' b ≠ 0<br> '''if''' a > b<br> a := a − b<br> '''else'''<br> b := b − a<br>'''return''' a}}]]
In [[computer science]], an '''abstract syntax tree''' ('''AST'''), or just '''syntax tree''', is a [[directedTree tree(data structure)|tree]] representation of the [[abstract syntax|abstract syntactic]] structure of text (often [[source code]]) written in a [[programmingformal language]]. Each node of the tree denotes a construct occurring in the source codetext.
 
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 [[Bracket#Parentheses|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 expressionstatement may be denoted by means of a single node with three branches.
 
This distinguishes abstract syntax trees from concrete syntax trees, traditionally designated [[parse tree]]s. Parse trees are typically built by a [[parser]] during the source code translation and [[compiler|compiling]] process. Once built, additional information is added to the AST by means of subsequent processing, e.g., [[Semantic analysis (compilers)|contextual analysis]].