org.PingOO.DLAI.lib.graph
Class ParseFunction

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.graph.ScanString
        |
        +--org.PingOO.DLAI.lib.graph.ParseFunction

public class ParseFunction
extends ScanString

This class will parse a function definition and solve it returning the value. The function may have upto 3 independent variables in it (x,y,z).

Known Bugs This class is not fool proof. If the answer is wrong then use the parenthesis to force the order of evaluation. The most likely place this will be needed is in the use of the power command. The exponent is not evaluated correctly if it begins with a unary operator.

List of recognised commands

Version:
$Revision: 1.8 $, $Date: 1996/08/12 23:37:08 $
Author:
Leigh Brookshaw

Field Summary
(package private) static int ACOS
           
(package private) static int ACOSH
           
(package private) static int ADD
           
(package private) static int ASIN
           
(package private) static int ASINH
           
(package private) static int ATAN
           
(package private) static int ATAN2
           
(package private) static int ATANH
           
(package private) static int AVOGADRO
           
(package private) static int BOLTZMAN
           
(package private) static int CHISQ
           
(package private) static int CHISQC
           
(package private) static int COMMA
           
(package private) static int COS
           
(package private) static int COSH
           
 boolean debug
          Debug variable.
(package private) static int DIVIDE
           
(package private) static int E
           
(package private) static int ECHARGE
           
(package private) static int EMASS
           
(package private) static int ENDGROUP
           
(package private) static int ERF
           
(package private) static int ERFC
           
(package private) static int EXP
           
(package private) static int FAC
           
(package private) static int GAMMA
           
(package private) static int GASCONSTANT
           
(package private) static int GRAV
           
(package private) static int GRAVACC
           
(package private) static int GROUP
           
(package private) static int IGAM
           
(package private) static int IGAMC
           
private  boolean independent_x
           
private  boolean independent_y
           
private  boolean independent_z
           
(package private) static int J0
           
(package private) static int J1
           
(package private) static int JN
           
(package private) static int LIGHTSPEED
           
(package private) static int LOG
           
(package private) static int LOG10
           
(package private) static int MULTIPLY
           
(package private) static int NORMAL
           
(package private) static int PI
           
(package private) static int PLANCK
           
(package private) static int PMASS
           
(package private) static int POISSON
           
(package private) static int POISSONC
           
(package private) static int POWER
           
(package private) static int RAD
           
(package private) static int RANDOM
           
(package private) static int REMAINDER
           
private  Node root
           
(package private) static int SIN
           
(package private) static int SINH
           
(package private) static int SQRT
           
(package private) static int STEFANBOLTZ
           
(package private) static int SUBTRACT
           
(package private) static int TAN
           
(package private) static int TANH
           
private  double x
           
(package private) static int X
           
private  double y
           
(package private) static int Y
           
(package private) static int Y0
           
(package private) static int Y1
           
(package private) static int YN
           
private  double z
           
(package private) static int Z
           
 
Fields inherited from class org.PingOO.DLAI.lib.graph.ScanString
buffer, count, EOS, ERROR, kwlength, kwords, NUMBER, nval, position, string, sval, UNKNOWN
 
Constructor Summary
ParseFunction()
          Instantiate the class
ParseFunction(java.lang.String s)
          Instantiate the class and define the string to parse.
 
Method Summary
private  double evaluate(Node node)
           
private  double evaluateIntrinsic(Node node)
           
private  double evaluateOp(Node node)
           
 double getResult()
          Return the solution of the function if it has no independent values or they have already been set using the set methods
 double getResult(double x)
          Return the solution of the function given the independent values
 double getResult(double x, double y)
          Return the solution of the function given the independent values
 double getResult(double x, double y, double z)
          Return the solution of the function given the independent values
 double[] getResults(int n, double[] x)
          Return an array of solutions given an array of x values
 double[] getResults(int n, double[] x, double[] y)
          Return an array of solutions given an array of x values and y values
 double[] getResults(int n, double[] x, double[] y, double[] z)
          Return an array of solutions given an array of x values, y values and z values.
 boolean[] getVariables()
          Return a boolean array with index 0 true if the independent variable x was found in the function, index 1 true if y was found, and index 2 true if z was found.
 boolean parse()
          Parse the previously set string
 boolean parse(java.lang.String s)
          Parse the string.
private  int parseString(Node node)
           
private  void reOrderNodes(Node node)
           
 void setX(double x)
          Set the value of the independent variable X.
 void setY(double y)
          Set the value of the independent variable Y.
 void setZ(double z)
          Set the value of the independent variable Z.
 
Methods inherited from class org.PingOO.DLAI.lib.graph.ScanString
addKeyWord, getKeyValue, nextWord, resetKeyWords, setString
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

GROUP

static final int GROUP

ENDGROUP

static final int ENDGROUP

ADD

static final int ADD

SUBTRACT

static final int SUBTRACT

DIVIDE

static final int DIVIDE

MULTIPLY

static final int MULTIPLY

LOG

static final int LOG

POWER

static final int POWER

PI

static final int PI

E

static final int E

SIN

static final int SIN

COS

static final int COS

TAN

static final int TAN

X

static final int X

Y

static final int Y

Z

static final int Z

ASIN

static final int ASIN

ACOS

static final int ACOS

ATAN

static final int ATAN

RAD

static final int RAD

SQRT

static final int SQRT

RANDOM

static final int RANDOM

LOG10

static final int LOG10

EXP

static final int EXP

REMAINDER

static final int REMAINDER

COMMA

static final int COMMA

ATAN2

static final int ATAN2

J0

static final int J0

J1

static final int J1

JN

static final int JN

SINH

static final int SINH

COSH

static final int COSH

TANH

static final int TANH

ASINH

static final int ASINH

ACOSH

static final int ACOSH

ATANH

static final int ATANH

Y0

static final int Y0

Y1

static final int Y1

YN

static final int YN

FAC

static final int FAC

GAMMA

static final int GAMMA

ERF

static final int ERF

ERFC

static final int ERFC

NORMAL

static final int NORMAL

POISSONC

static final int POISSONC

POISSON

static final int POISSON

CHISQC

static final int CHISQC

CHISQ

static final int CHISQ

IGAM

static final int IGAM

IGAMC

static final int IGAMC

BOLTZMAN

static final int BOLTZMAN

ECHARGE

static final int ECHARGE

EMASS

static final int EMASS

PMASS

static final int PMASS

GRAV

static final int GRAV

PLANCK

static final int PLANCK

LIGHTSPEED

static final int LIGHTSPEED

STEFANBOLTZ

static final int STEFANBOLTZ

AVOGADRO

static final int AVOGADRO

GASCONSTANT

static final int GASCONSTANT

GRAVACC

static final int GRAVACC

root

private Node root

independent_x

private boolean independent_x

independent_y

private boolean independent_y

independent_z

private boolean independent_z

x

private double x

y

private double y

z

private double z

debug

public boolean debug
Debug variable. If set true debug output is printed.
Constructor Detail

ParseFunction

public ParseFunction()
Instantiate the class

ParseFunction

public ParseFunction(java.lang.String s)
Instantiate the class and define the string to parse.
Parameters:
s - The string to be parsed.
Method Detail

parse

public boolean parse(java.lang.String s)
Parse the string.
Parameters:
s - The string to parse
Returns:
true if it was successful, false otherwise.

parse

public boolean parse()
Parse the previously set string
Returns:
true if it was successful, false otherwise.

getResult

public double getResult(double x,
                        double y,
                        double z)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
y - indpendent y value
z - indpendent z value
Returns:
solution of the function

getResult

public double getResult(double x,
                        double y)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
y - indpendent y value
Returns:
solution of the function

getResult

public double getResult(double x)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
Returns:
solution of the function

getResult

public double getResult()
                 throws java.lang.Exception
Return the solution of the function if it has no independent values or they have already been set using the set methods
Returns:
solution of the function
See Also:
ParseFunction.setX(), ParseFunction.setY(), ParseFunction.setZ()

getResults

public double[] getResults(int n,
                           double[] x)
                    throws java.lang.Exception
Return an array of solutions given an array of x values
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null.

getResults

public double[] getResults(int n,
                           double[] x,
                           double[] y)
                    throws java.lang.Exception
Return an array of solutions given an array of x values and y values
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
y - Array containing the y values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null, or y is null.

getResults

public double[] getResults(int n,
                           double[] x,
                           double[] y,
                           double[] z)
                    throws java.lang.Exception
Return an array of solutions given an array of x values, y values and z values.
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
y - Array containing the y values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null, or y is null, or z is null.

getVariables

public boolean[] getVariables()
Return a boolean array with index 0 true if the independent variable x was found in the function, index 1 true if y was found, and index 2 true if z was found.

setX

public void setX(double x)
Set the value of the independent variable X.

setY

public void setY(double y)
Set the value of the independent variable Y.

setZ

public void setZ(double z)
Set the value of the independent variable Z.

parseString

private int parseString(Node node)

evaluate

private double evaluate(Node node)
                 throws java.lang.Exception

evaluateOp

private double evaluateOp(Node node)
                   throws java.lang.Exception

evaluateIntrinsic

private double evaluateIntrinsic(Node node)
                          throws java.lang.Exception

reOrderNodes

private void reOrderNodes(Node node)