6.0 Introduction

6.1 Static Checking

6.2 Attribute Grammars

6.3 Translation to an IR

6.4 Semantic Analyzer Generators

6.5 More on Attribute Grammars

6.6 Attribute Evaluation

6.7 Summary

Web References

Exercises

6.3.2 Abstract Syntax Tree (AST)

An abstract syntax tree is a parse tree stripped of unnecessary information such as singleton productions (e.g., ETF). Each nonleaf represents an operator and each leaf represents an operand.

Thus A + B might have the following parse tree and abstract syntax tree:

S := A + B * C has abstract syntax tree:

which can be represented in parenthesized form as

    (:= ("S" + ("A" * ("B" "C") ) ) )

The parenthesized form is often used by the compiler designer for debugging output. It is essentially a preorder transversal of the tree.

IF A<B THEN Max := B is represented

and A[i]:=B is

Even though ASt's are more convenient for optimization, there is a one-one correspondence between AST's and Polish postfix:

Thus, AST's can be easily converted to Polish prefix if desired. The "tree" can be seen by starting at the right-hand end and taking the upper of the two arrows as the left child and the lower as the right child.

Send questions and comments to: Karen Lemone