vec_math
Class ExpressionParser

java.lang.Object
  extended by vec_math.ExpressionParser

public class ExpressionParser
extends Object

A class providing arithmetics for expressions. For right-hand acting operators, like sin, no brackets are required, but their use is encouraged. Note that boolean operators only act on true booleans, not on longs. All the operators supported are (sorted for precedence):

Please note that parenthesis on the unary operators are not required, i.e. sin5 does also work as sin(5). The format for the binary operators min, max, over, and confine may look a little bit strange at first: (78)min(63) or 78min63 is the correct format for depicting the smaller of the two numbers. If a string obeying the above rules is passed to the class's #valueOf method, it is parsed and the result is returned as a Double. Parsing errors result in a ParseException to be thrown. Please note that a ParseException is not a runtime exception, therefore it must be caught in calling routines.


Nested Class Summary
static class ExpressionParser.Test
          Mainly test purpose.
 
Field Summary
private static double THETA0
          The lower boundary on zonal harmonics.
private static double THETA1
          The upper boundary on zonal harmonics.
private static List<Operator<String>> valid
          All valid operators.
 
Constructor Summary
ExpressionParser()
           
 
Method Summary
static Boolean evaluateBoolean(String expression)
          Parses the node and returns the expression as a Boolean object.
private static String evaluateNode(Node<String> root)
          Evaluates a node.
static Number evaluateNumber(String expression)
          Parses the expresion into a number, if possible.
private static String evaluateSingle(Operator<String> tie, String left, String right)
          Evaluates a single boolean expression.
protected static List<Operator<String>> getValid()
          Returns all valid operator in this parsers context.
private static boolean isFloat(Object check)
          Checks if the argument is a float.
private static boolean isInteger(Object check)
          Checks if the argument object is an integer.
static String parseExpression(String expression)
          Parses the given string to obtain a single boolean value.
private static Number parseNumber(String s)
          Tries to parse the input string as a Number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valid

private static final List<Operator<String>> valid
All valid operators.


THETA0

private static final double THETA0
The lower boundary on zonal harmonics.


THETA1

private static final double THETA1
The upper boundary on zonal harmonics.

Constructor Detail

ExpressionParser

public ExpressionParser()
Method Detail

parseExpression

public static String parseExpression(String expression)
                              throws ParseException
Parses the given string to obtain a single boolean value. Note that no variables are allowed within the String. Presedence of the operators follows JAVA standard rules and can be altered with parentheses.

Parameters:
expression - A String combining double constants
Throws:
ParseException - If the argument does not obey the specified grammar.

evaluateNumber

public static Number evaluateNumber(String expression)
                             throws ParseException
Parses the expresion into a number, if possible.

Throws:
ParseException

evaluateBoolean

public static Boolean evaluateBoolean(String expression)
                               throws ParseException
Parses the node and returns the expression as a Boolean object.

Throws:
ParseException

getValid

protected static List<Operator<String>> getValid()
Returns all valid operator in this parsers context.


evaluateNode

private static String evaluateNode(Node<String> root)
                            throws ParseException
Evaluates a node. Branches recursevely into sub-nodes until all dependencies are removed.

Throws:
ParseException

evaluateSingle

private static String evaluateSingle(Operator<String> tie,
                                     String left,
                                     String right)
                              throws ParseException
Evaluates a single boolean expression. Care must be taken to obtain a match in this routine with the static initializer.

Throws:
ParseException

parseNumber

private static final Number parseNumber(String s)
Tries to parse the input string as a Number. If successful, either a long or a double object is returned, otherwise the string probably refers to a boolean.


isInteger

private static final boolean isInteger(Object check)
Checks if the argument object is an integer. Returns true, if the argument is a Long, an Intger, a Short or a Byte.


isFloat

private static final boolean isFloat(Object check)
Checks if the argument is a float. Returns true, if the arguemnt is a Float or a Double.