Page 217 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 217

194                                        Chapter 7 Arithmetic Operations

        to evaluate the formula from its tree representation will be virtually the same one that we
        use to scan that tree from the left in Chapter 10. Any operation with two operands, such
        as +, has a tree with two branches and nodes whose values are the operands for the
        operation. For example, the result of x + y and x * y are represented by the trees








            If the operation has only one operand, the operation is displayed as a tree with only
        one branch. For example, sin(y) and sqrt(x) (for "square root of x") have trees








        If your formula is more complicated than those shown above, you just plug in the
        results of one tree where the operand appears in the other tree. For instance, if you want
        the tree for sqrt(x + y), just substitute the tree for x + y into the node, for example,












            The tree for the formula (8) is shown in Figure 7.12. Notice how the formula is like
        a projection onto a horizontal line below the tree and how the tree can be built up from
        the bottom following the "plug in" technique just described.




















                  Figure 7.12. Finding a Parsing Tree for (8) from the Bottom Up
   212   213   214   215   216   217   218   219   220   221   222