|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.expression.MathParser
public final class MathParser
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 and arbitrary variable substitutions to be added.
Constructor Summary | |
---|---|
MathParser()
Creates a new math parser that can process a mathematical expression. |
|
MathParser(boolean useVars)
Creates a new math parser that can process a mathematical expression. |
Method Summary | |
---|---|
void |
addCommand(String cmdName)
Adds a permitted command/function name to those looked for when parsing expression. |
void |
addVariable(String varName)
Adds a permitted variable name to those looked for when parsing expression. |
Stack |
parse(String input)
Parses an mathematical infix expression storing the operators and operands on a postfixed processing stack. |
boolean |
usesZ1()
Reports whether a 'z1' substitution has been made. |
boolean |
usesZ2()
Reports whether a 'z2' substitution has been made. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathParser()
addVariable()
and implement a
Substitutable
interface. Variable substitution should
use one or other of these approaches and not both.
public MathParser(boolean useVars)
useVars
to true. The
preferred and more general solution is to use addVariable()
and implement a Substitutable
interface. Variable
substitution should use one or other of these approaches and not both.
useVars
- If true, the shortcut variables 'x', 'y', 'z1' and 'z2'
can be substituted at evaluation time.Method Detail |
---|
public void addVariable(String varName)
varName
- Name of permitted variable.public void addCommand(String cmdName)
cmdName
- Name of permitted command or function.public Stack parse(String input) throws ParseException
input
- Mathematical expression to store.
ParseException
- If problem parsing text.public boolean usesZ1()
public boolean usesZ2()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |