Found this: http://www.objecthunter.net/exp4j/ Might be useful.
Jonathan On Wed, May 29, 2013 at 12:45 AM, SpiderPig <spiderpi...@googlemail.com>wrote: > You could just write this yourself. > It's easier than it looks. > First start with an evaluator for rpn (reverse polish notation) > expressions. > "x + sin(y)" in rpn would be "y sin x +". > First you split that string and make it into a list. > Then you can evaluate that with a few lines of code using a stack. Go > through the list and if an element is a number or a variable push it on the > stack. If it's an operator pop the appropriate number of elements from the > stack, apply the operator and push the result back on the stack. At the end > the stack should contain only one element, which is the result. > Evaluating an infix expression is more complicated. One way to do it is by > first converting the infix expression to rpn. Notice that the order of the > operands is the same in infix and rpn. Only the operators change. To do > this conversion you need one list to hold the result and a stack. Go > through all the elements of the infix expression. If it's an operand just > add it to the result list. If it's an operator pop operators from the stack > and add them to the result for as long as the top element on the stack is > an operator with a higher precedence then the current one. Then push the > current operator on the stack. Opening parenthesis are also pushed and when > there is a closing parenthesis you pop operators and add them to the result > until you find an opening one. > There also is another method of evaluating infix expressions using > recursion. This works by first searching for the operator with the lowest > precedence and then recursively evaluating the expressions left and right > from that operator. > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.