CS 1104 Introduction to Computer ScienceCOMPILERS AND TRANSLATORS |
Expression Analyzers
Given the expression:
Start by adding the hierarchy value to each operator:
The order of evaluation is simply defined as - evaluate the operator with the highest hierarchy (with its adjacent operand(s)) and replace that sub-expression with the result. If two operators have the same hierarchy evaluate that on the left first. Repeat until the process until only a single value remains.
Thus:
NOTE the difference between the unary minus operator (~) applied to the representation of the value 5 and the negative sign associated with the result of the evaluation of that subexpression.
Last updated 00/11/28
© J.A.N. Lee, 2000.