Chapter 7: Intermediate representation and symbol table

Abstract Syntax Tree/DAG

. Condensed form of a parse tree

. useful for representing language constructs

. Depicts the natural hierarchical structure of the source program

- Each internal node represents an operator

- Children of the nodes represent operands

- Leaf nodes represent operands

. DAG is more compact than abstract syntax tree because common sub expressions are eliminated

A syntax tree depicts the natural hierarchical structure of a source program. Its structure has already been discussed in earlier lectures.

DAGs are generated as a combination of trees: operands that are being reused are linked together, and nodes may be annotated with variable names (to denote assignments). This way, DAGs are highly compact, since they eliminate local common sub-expressions. On the other hand, they are not so easy to optimize, since they are more specific tree forms. However, it can be seen that proper building of DAG for a given sequence of instructions can compactly represent the outcome of the calculation.

An example of a syntax tree and DAG has been given in the next slide .