jwo.utils.expression
Class MathParser
java.lang.Object
|
+--jwo.utils.expression.MathParser
- public final class MathParser
- extends Object
Converts a mathematical expression (using 'normal' infix ordering)
into a postfixed stack. Used for evaluation of mathematical expressions.
Modified from original code described at
www.devx.com/premier/mgznarch/javapro/2001/05may01/ps0105/ps0105.asp.
Modifications allow unary operators (e.g. trig functions) to be parsed.
- Version:
- 1.4, 16th February, 2001, modified 10th April, 2002.
- Author:
- Daniel Savarese, modified by Jo Wood.
Method Summary |
Stack |
parse(String input)
Parses an mathematical infix expression storing the operators and
operands on a postfixed processing stack. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MathParser
public MathParser()
parse
public Stack parse(String input)
throws ParseException
- Parses an mathematical infix expression storing the operators and
operands on a postfixed processing stack.
expr -> term moreterms | term
moreterms -> + term | - term
term -> exponent moreexponents | exponent
moreexponents -> * exponent | / exponent
exponent -> factor morefactors | factor
morefactors -> ** factor
factor -> number | ( expr ) | unary factor
- Parameters:
input
- Mathematical expression to store.
- Returns:
- stack containing postfixed representation of the expression.
ParseException