4.1. Abstract Syntax Trees

An abstract syntax tree (AST) is a tree that represents an expression, statement or other part of a program.

For example, an AST for expression (2+4)*4 might look as follows.

             *
            / \
           /   \
          +     4
         / \
        /   \
       2     4
I say might because you choose the form of your abstract syntax trees.

Instead of having node kinds * and /, you might have a node kind op with extra information telling the operator.

            op:*
            / \
           /   \
         op:+  num:4
         / \
        /   \
    num:2   num:4


Abstract syntax trees in C

Assignment 3 describes how to create abstract syntax trees in C.