Algorithm for Expression Evaluator

Hi,Can any one help me in finding out the algo of Expression Evaluator,Changing Pre fix to Post Fix and vise versa.Tx in advance.fromgomes_deb
[177 byte] By [gomes_deba] at [2007-9-28 9:12:25]
# 1
Do you want to build the evaluator completely new?if so you have to build a scanner and a parser. What kind of expressions should be processed? Numeric with/out Variables...?Please give me some details.
jvl_de2a at 2007-7-11 22:08:00 > top of Java-index,Other Topics,Algorithms...
# 2
http://christophe.delord.free.fr/soft/tpg/doc/tpgch10.htmlCheck it out
dharmesh_amitya at 2007-7-11 22:08:00 > top of Java-index,Other Topics,Algorithms...
# 3
there is standard algorihm to do this. I am sure you can find algorithm to do this on compiler design, which uses stacks. I think there should be a function that does it too... Just search for it, that it solve your prob
dharmesh_amitya at 2007-7-11 22:08:00 > top of Java-index,Other Topics,Algorithms...
# 4

There is a math expression parser at http://www.bestcode.com. It forms a tree structure where nodes are operators, functions, variables, numbers. Each node of the tree has children (for example parameters of a function are it's children in this tree). So, if you have a "x+sin(y)", the tree is like this:

+

__/\

_xsin

\

_y

Then when it is time to evaluate, you set the values of X and Y and call evaluate() method and it tells you what the result is.

The java bean is called JbcParser. It's features are:

*Easy to use, simple class API.

*Comes with predefined functions.

*Users can create custom functions/variables.

*Optimization: Constant expression elimination for repeated tasks.

*Analytical Operators: +, -, /, *, ^(power)

*Logical Operators: =(equals),&(and),|(or),!(not), <>(not equals), <=(less than or equals), >=(greater than or equals)

*Paranthesis: (, {, [

*Functions in the form of: f(x, y, z, ...)

*Function parameters are not calculated until needed.

*List of predefined functions is available in the documentation.

*Java source code is included.

An example of a simple expression is : LN(X)+SIN(10/2-5)

When parsed, this expression will be represented as: since the SIN(10/2-5) is in fact SIN(0) which is a constant and is 0.

Thus, in a loop, if you change the value of X and ask for the value of the expression, it will be evaluated quite fast since SIN(10/2-5) is not dependent on X.

X and Y are predefined variables. You can create your own variables as needed.

There are many predefined mathematical functions. They are listed in documentation. You can create your functions as needed. IF logic is implemented through a predefined IF(A,B,C) function. Similar logical functions can be created as needed.

It is located at: http://www.bestcode.com/html/jbcparser.html

alidemira at 2007-7-11 22:08:00 > top of Java-index,Other Topics,Algorithms...