Go to the previous, next section.

Different Approaches to Creating Expression Trees

There are many ways to create expressions.

Using the Parser of the C++ Compiler.

The C++ compiler's parser can be used to create expression trees. This is accomplished in the builder by overloading all the operators for the builder class (the only exception is the * operator). This is an elegant and simple way to express the SUIF structures to be created. Since the C++ compiler performs the parsing at compile time, this method is efficient. C++ compiler will also perform some amount of semantic and type checking. But, since all the operators are overloaded, there can be some subtle bugs (or features in many cases). For example, assigning a builder structure to another structure is not as simple as a = b. Since a and b are block types and the assign operator is overloaded, the above statement generates a new block that will generate a SUIF structure with an assignment in it! See section Constructing Expressions Using Operator Overloading for a full description of operators overloaded in the builder.

Using Builder Functions and Operator Symbols

The builder function op() can be used to construct expression trees. For example block::op(a, "+", b) will generate an add instruction. See section Constructing Expressions Using Explicit Function Calls for a full list of builder functions available.

Using Builder Functions and the Builder's Operator Enumerations

All the unary, binary and assignment operators that can be used have a corresponding enumerated type in the builder. These enumerated types can be used when creating an expression. See section Operators for a list of these enumerated types.

Go to the previous, next section.