jwo.utils.expression
Class MathParser

java.lang.Object
  extended byjwo.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:
2.2, 16th February, 2001, modified 7th September, 2003.
Author:
Daniel Savarese, modified by Jo Wood.

Constructor Summary
MathParser()
           
 
Method Summary
 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

MathParser

public MathParser()
Method Detail

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.
Throws:
ParseException

usesZ1

public boolean usesZ1()
Reports whether a 'z1' substitution has been made. This is useful if we need to know whether the contents of z1 needs to be explained or error checked.

Returns:
true if a 'z1' substitution has been made.

usesZ2

public boolean usesZ2()
Reports whether a 'z2' substitution has been made. This is useful if we need to know whether the contents of z2 needs to be explained or error checked.

Returns:
true if a 'z2' substitution has been made.


Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005