Expression evaluation

Write a program using concept of trees, to evaluate expression ((5+sin x)-log(cos x))+2?
remember user should enter the expression every time after execution.

The solution is to parse your expression into an expression tree.

A really slick design would be to essentially encapsulate this as a series of Operands supplied to an Operation. That way you expression capabilities are modular. Then you can have each operator essentially self describe. Something like:

Expression sinx = ExpressionFactory.getInstance(“sin”,x);
Expression fivePlusSinZ = ExpressionFactory.getInstance(“5”,"+", sinx);

public class Sin implements Operator {
// essentially have this operator declare how it can be identified.
public Set identifiers() { return new HashSet(Arrays.asList(“sin”,“sinof”));}
}

And continue to put these together. For simplicity sake you can make the expressions strictly binary and use “neutral” operands for essentially unary cases.

give ur source code for this…

//