Professional Documents
Culture Documents
Evaluating Arithmetic
Expressions
What is Arithmetic Expressions
• An arithmetic expression is an expression built up using numbers,
arithmetic operators (such as +, , -, / and ) and parentheses, "(" and
")".
• Arithmetic expressions may also make use of exponents, for
example, writing 23as an abbreviation for ((2*2)*2).
• An arithmetic expression in which the only operators
are +,*, -,/ and exponentiation, is called a simple arithmetic
expression. Here are some examples:
(3 + 4) -- the sum of numbers is an arithmetic expression
(7 - 3) -- the difference of two numbers is an arithmetic expression
(2 *5) -- a product of two numbers is an arithmetic expression
(23 + 5) -- this is an abbreviation for the arithmetic expression (((2*2*)2) + 5)
(23 + 5)2 -- this is an abbreviation for the arithmetic expression ((23 + 5)*(23 + 5)
Rules for Evaluating Arithmetic Expressions
associativity L to R then pop & print the top of the stack & then push the
incoming operator
associativity R to L then push the incoming operator
Evaluation of Postfix Expression