I'd like to understand how a Java program like GeoGebra can read a mathematical expression like exp(z^2)
from a textbox and then evaluate it. For those familiar with MatLab: How do you implement function handles in Java?
Asked
Active
Viewed 908 times
0

arney
- 795
- 7
- 20
-
Regarding parsing: Have a look at Antlr -- http://www.antlr.org/ – scravy May 14 '13 at 10:01
-
http://dev.geogebra.org/trac has the sources. read it from there. Your question in current form has no value for future visitor. Please check the sources and comeback with more specific question. – Jayan May 14 '13 at 10:02
-
1Duplicate, yes, but not a real question? You must be kidding. We wouldn't have got as far as Fortran I without questions like these. – user207421 May 14 '13 at 10:54
-
You need to look up 'recursive descent expression parser' and the Dijkstra Shunting-Yard Algorithm. – user207421 May 14 '13 at 10:55
-
I agree this is a perfectly valid question about how to parse expressions in strings, it leads on to lots of compiler writing principles. Pointing at Shunting Yard (http://en.wikipedia.org/wiki/Shunting-yard_algorithm) is a good start. – John Payne May 14 '13 at 11:01
-
Well, if that is not a question for StackOverflow, where do I go with questions like this!? And for yan: Your comment in the current form has no value for future visitors. Please check the sources and come back with a more specific link as to WHERE in the load of code the answer can be found. – arney May 14 '13 at 11:28
-
Around here: http://dev.geogebra.org/trac/browser/trunk/geogebra/common/src/geogebra/common/kernel/commands/AlgebraProcessor.java – assylias May 20 '13 at 06:53
1 Answers
0
If it is like evaluating mathematical expressions (INFIX), using java, I would recommend a simple approach by first converting the expression to POSTFIX notation and then following the basic algorithm for evaluating POSTFIX.
Take a look here
- Expression is A*B+C
- POSTFIX will be AB*C+
- Read the postfix string, if operand, push it into stack. (IN stack -> A,B)
- If operator(*), pop out the two operands, perform the calculation (A*B = E,say).
- PUSH the result E in stack
- Goto step 3.
The End result in the stack would be your answer.

roger_that
- 9,493
- 18
- 66
- 102