Abstract Syntax (Cont.)


Abstract Syntax Trees
Abstract syntax tree can be thought of as a tree representation of abstract syntax, much as a parse tree is a representation for the structure of ordinary syntax (concrete syntax). In an abstract syntax tree for an expression, each interior node represents an operator; the children of the node represent the operands of the operator. More generally, any programming construct can be handled by making up an operator for the construct and treating as operands the semantically meaningful components of that construct.

A parse tree for the expression “5*a-(b+1)” of Wren is given on the right. Two possible abstract syntax trees for the expression are given below.

In transforming a derivation tree into an abstract syntax tree, we generally pull the terminal symbols representing operations and commands up to the root nodes of subtrees, leaving the operands as their children. The second tree in the figure varies slightly from this principle in the interest of regularity in expressions. Using this approach, this expression can be thought of as a binary operation and two subexpressions.