Expression Evaluation in python | What is Expression Evaluation |
Expression Evaluation –
Evaluate an expression represented by a string .expression can contain parentheses you can assume parentheses are well matched .for simplicity you can assume only binary operation allowed are + , - , * , & , / arithmetic.
Expression can be written in one of three forms.
1) Infix Notation –
Operators are written between the operands they operate on
Example -> 3+4 Or A+b
2) Prefix Notation –
Operators are written before the operands.
Example -> +34 or +AB
3) Postfix Notation –
Operators are written after operands .
Example -> 34+ or AB+
To simplify the evaluation of mathematical expression we need representation for the expression.
A representation in which the order the operators are performed is the order they are specified. Representation of string would allow for a single Left-to-Right scan of the expression string.
Expression precedence of operator is determine by BODMAS rule .
Consider Operation -> Addition , Subtraction, Multiplication, Division, Exponential.
We assume three level of precedence this is five binary operators in such notation.
1) Highest -> Exponent
2) Next -> Multiplication and Division
3) Lowest -> Addition and subtraction
Post a Comment