actually in infix or prefix expressions how does operators have high precdence than the other. for example + has high precedence than *.do they compare with ascii value of operator
actually in infix or prefix expressions how does operators have high precdence than the other. for example + has high precedence than *.do they compare with ascii value of operator
Of course not.
* and / are by definition a higher precidence that + and -
ascii value is not related to operator precedence.
actually i reffered a lot of websites for infix,prefix,postfix i dont get a idea at all.each website says different explanations please some one give clear explanation about this
Infix, prefix and postfix are merely notations. For example
1 + 2 : Infix, The '+' operator is written between the operands it applies to.
1 2 + : Postfix (Reverse Polish Notation), the '+' operator follows it's two operands.
+ 1 2 : Prefix (Polish Notation), the '+' operator preceeds it's operands.
Precedence rules ("order of operation") have nothing to do with ASCII values, as mentioned. These are just rules made to clarify unambiguously which procedures should be performed first in a given mathematical expression.
These rules are explained in many places, for example here: http://en.wikipedia.org/wiki/Order_of_operations
e.g. if you have something like the following:
9 / 2 + 5 * 7
Precendence rules result in it having to be interpreted like this:
((9 / 2) + (5 * 7))
Operator associativity is also something to note. More on that could be found here:
http://en.wikipedia.org/wiki/Operator_associativity
In essence it determines how operators with the same precedence are grouped in the absense of parenthesis. For example:
1 + 2 + 3 + 4 + 5
Would have to be interpreted as the following because '+' is (generally) left-associative:
((((1 + 2) + 3) + 4) + 5)
If you're looking to parse mathematical formula's you might want to look at Dijkstra's Shunting Yard algorithm. Information on this can be found here: