edu.neu.ccs.parser
Class BaseParser

java.lang.Object
  extended byedu.neu.ccs.parser.BaseParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
JPTParser

public class BaseParser
extends Object
implements Parser

The class BaseParser is the base class for classes of objects that provide functionality for evaluating strings into primitive types and objects using a language with a simple syntactic structure.

Revisions in 2.5.0:

Further comments:

BaseParser contains all fundamental parsing algorithms but has no installed abstract functions, operations, or constants.

BaseParser has the ability to define special forms and five such forms are introduced: set, let, if, eval, and random. Here is a brief synopsis of these special forms.

Special Form Typical Usage
set set(identifier,expression)
let let(identifier,expression)
if if(test,expression-1,expression-2)
eval eval(expression-1,...,expression-n)
random random() or random(x) or random(x,y)

The special forms are interpreted as follows.

random is introduced as a special form since in our simple parsing scheme ordinary functions cannot be overloaded to take different numbers of arguments.

Version:
2.5

Field Summary
protected  String ARGUMENT_LIST_END
          String token representing the end of an argument list.
protected  String ARGUMENT_LIST_START
          String token representing the start of an argument list.
protected  String ARGUMENT_SEPARATOR
          String token representing the argument separator.
protected  String ASSIGNMENT_BY_LET
          The reserved keyword "let" to indicate variable assignment that is temporary, that is, one that affects only the current invocation of the parse method.
protected  String ASSIGNMENT_BY_SET
          The reserved keyword "set" to indicate variable assignment that is persistent across invocations of the parse method.
private  Hashtable constants
          Table of constant identifiers and their corresponding values.
protected  String data
          The current String to be evaluated by the current call of parse.
protected  String EVAL
          The reserved keyword "eval" to indicate the special function that evaluates its arguments from left to right and then returns the value of the rightmost argument.
protected static int FLOATING
          Value designating string data that has form of a floating number.
private  Hashtable functions
          Table of function names and their corresponding functions.
static Operation IDENTITY
          The IDENTITY operation, equivalent to the function f(x,y)=y.
protected  String IF_THEN_ELSE
          The reserved keyword "if" to indicate if-then-else.
protected static int INTEGRAL
          Value designating string data that has form of an integer number.
private  Hashtable let_variables
          Table of variable identifiers defined by "let" in the current invocation of the parse method and their corresponding values.
protected  String NESTED_EXPRESSION_END
          String token representing the end of a nested expression.
protected  String NESTED_EXPRESSION_START
          String token representing the start of a nested expression.
protected  int next
          The index of the next character to examine in the current String to be evaluated by the current call of parse.
static Operation OPERATION_PREFIX
          The singleton operation object which designates that a symbol is a prefix for a known operation.
private  Hashtable operations
          Table of operation symbols and their corresponding operations.
private  Vector parserContextStack
          The vector that operates as a stack to save and restore the parser context in each call of parse.
private  Vector precedence
          List of hashtables storing the precedence relationship between operations.
private  Hashtable prefixes
          Table of prefixes of operation symbols.
protected  String RADIX_POINT
          String token representing the radix point.
protected  String RANDOM
          The reserved keyword "random" to indicate the special function that takes 0, 1, or 2 numeric arguments and has the following interpretation.
private  Hashtable reserved
          Table of reserved identifiers for special functions or operations.
private  Hashtable set_variables
          Table of variable identifiers defined by "set" and their corresponding values.
protected  int suspend
          The member data to control whether the parser should be evaluating operations, functions, and special functions or should rather be parsing formally in order to extract the next expression that is to be parsed as a string.
protected  char UNDERSCORE
          Char with UNDERSCORE character for identifiers.
 
Constructor Summary
BaseParser()
          Constructs a new parser by initializing structures and by adding the standard operations, functions, and constants available for this parser.
 
Method Summary
 void addConstant(String id, Object value)
          Adds the given constant to the table of constants using the given identifier and value.
protected  void addConstants()
          Adds the standard constants for this parser to the environment.
 void addFunction(AbstractFunction function)
          Adds the given function to the table of recognized functions.
protected  void addFunctions()
          Adds the standard functions for this parser to the function table.
protected  void addOperation(Operation op, int pos)
          Adds the given operation to the operation table at the given index in the precedence list.
 Operation addOperationAfterPrecedenceOf(Operation compare, Operation op)
          Adds the given operation op to the table of recognized operations, at a level of precedence immediately after the precendence of the existing operation compare installed in this parser.
 Operation addOperationAtPrecedenceOf(Operation compare, Operation op)
          Adds the given operation op to the table of recognized operations, at the same level of precedence as the existing operation compare installed in this parser.
 Operation addOperationBeforePrecedenceOf(Operation compare, Operation op)
          Adds the given operation op to the table of recognized operations, at a level of precedence immediately before the precendence of the existing operation compare installed in this parser.
protected  void addOperations()
          Adds the standard operations for this parser to the operation table.
protected  void addReserved()
          Installs the reserved identifiers for the special functions.
protected  int afterDigits(int start)
          Return the first character position at or after start that is not a digit.
protected  int afterSign(int start)
          If the character at position start is '+' or '-' return (start + 1) otherwise return start.
 void assignArgumentList(String[] ids, Object[] values)
          This method takes id-value pairs from corresponding positions in the lists ids and values and performs the assignment using assignLetVariable.
 Object assignLetVariable(String id, Object value)
          Assigns the given value to the given identifier as a temporary "let" variable in the context of the current call to the parse method of this parser, replacing any previous "let" variable associated with the same identifier in this same context.
 Object assignSetVariable(String id, Object value)
          Assigns the given value to the given identifier as a persistant "set" variable for this parser, replacing any previous "set" variable associated with the same identifier.
protected  Object assignVariable(String id, Object value, Hashtable binding)
          Assigns the given value to the given identifier in the given binding environment, replacing any previous value in the environment associated with the same identifier.
static double call(AbstractFunction f, double x)
          Call the given abstract function using the given double x as the argument and return a double value.
static double call(AbstractFunction f, double[] arguments)
          Call the given abstract function using the given double data as arguments and return a double value.
static double call(AbstractFunction f, double x, double y)
          Call the given abstract function using the given doubles x,y as arguments and return a double value.
static double call(AbstractFunction f, double x, double y, double z)
          Call the given abstract function using the given doubles x,y,z as arguments and return a double value.
static double call(AbstractFunction f, double x, double y, double z, double w)
          Call the given abstract function using the given doubles x,y,z,w as arguments and return a double value.
 double call(String name, double x)
          Call the function with the given name that is installed in this parser using the given double x as the argument and return a double value.
 double call(String name, double[] arguments)
          Call the function with the given name that is installed in this parser using the given double data as arguments and return a double value.
 double call(String name, double x, double y)
          Call the function with the given name that is installed in this parser using the given doubles x,y as arguments and return a double value.
 double call(String name, double x, double y, double z)
          Call the function with the given name that is installed in this parser using the given doubles x,y,z as arguments and return a double value.
 double call(String name, double x, double y, double z, double w)
          Call the function with the given name that is installed in this parser using the given doubles x,y,z,w as arguments and return a double value.
 String[] constants()
          Returns an array of the constant id's.
protected  boolean evaluate()
          Controls whether or not the parser evaluates or simply parses formally without evaluation.
protected  Object evaluateIdentifier(String identifier)
          Evaluate a constant or variable identifier and return its value.
protected  String extractExpression()
          Extracts the next pending expression as a string without performing any operations or evaluations.
 String[] functionNames()
          Returns an array of all function names.
 AbstractFunction[] functions()
          Returns an array of all functions.
 AbstractFunction getFunction(String name)
          Returns the function with the given name or null if no such function is defined.
 Operation getOperation(String symbol)
          Returns the operation with the given symbol or null if no such operation is defined.
 Object getValue(String id)
          Returns the value associated with a constant or variable with the given id or null if no such value is defined.
protected  void initializeStructures()
          Initialize the operation and precedence structures prior to any additions defined in derived classes by adding the IDENTITY operation at precedence 0.
 boolean isConstantID(String id)
          Returns whether or not the given id is associated with a constant.
 boolean isEnvironmentID(String id)
          Returns whether or not the given id is associated with a constant or variable.
protected  boolean isExponentAt(int start)
          Return true if the character at start is 'E' or 'e'.
 boolean isFunctionName(String name)
          Returns whether or not the given name is associated with a function.
 boolean isLetVariableID(String id)
          Returns whether or not the given id is associated with a "let" variable in the current invocation of the parse method.
protected  Operation isOperationOrPrefix(String symbol)
          Performs a lookup in the operation and prefix tables to determine if the given String symbol represents an existing operation or is a prefix of the symbol for an existing operation.
 boolean isOperationSymbol(String symbol)
          Returns whether or not the given symbol is associated with an operation.
 boolean isOrdinaryFunctionName(String name)
          Returns whether or not the given name is associated with a function whose class does NOT extend SimpleFunction.
static boolean isPossibleIdentifier(String id)
          Returns true if the given id is a possible identifier for a constant, variable, function or reserved function.
static boolean isPossibleOperation(String string)
          Returns true if the given string is a possible symbol for an operation.
 boolean isPossibleVariableID(String id)
          Returns true if the given string is a possible variable id in the current parser context.
 boolean isReservedID(String id)
          Returns whether or not the given id is associated with a constant.
 boolean isSetVariableID(String id)
          Returns whether or not the given id is associated with a "set" variable.
protected  boolean isSignAt(int start)
          Return true if the character at start is '+' or '-'.
 boolean isSimpleFunctionName(String name)
          Returns whether or not the given name is associated with a function whose class is or extends SimpleFunction.
static XPoint2D[] makeTable(AbstractFunction f, double endpointA, double endpointB, int divisions)
          Make an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions.
static XPoint2D[] makeTable(AbstractFunction f, XInterval limits, int divisions)
          Make an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions.
 XPoint2D[][] makeTable(String names, double endpointA, double endpointB, int divisions)
          Views the given String as a comma separated list of names of AbstractFunction objects installed in this parser; for each such function object f, makes an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions; all such arrays are collected and returned in a 2-dimensional array.
 XPoint2D[][] makeTable(String names, XInterval limits, int divisions)
          Views the given String as a comma separated list of names of AbstractFunction objects installed in this parser; for each such function object f, makes an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions; all such arrays are collected and returned in a 2-dimensional array.
protected  String nextIdentifier()
          Gets the next identifier in the data String and returns it.
protected  Operation nextOperation()
          If the next token in the data represents an operation then return the corresponding Operation otherwise return null.
protected  Object nextSimpleTerm()
          Returns the next simple term in the data string or throws a ParseException if no term is present.
protected  Object nextTerm()
          Returns the next term in the data string with all leading unary operations already applied or throws a ParseException if no term is present.
protected  boolean nextTokenIs(String pattern)
          Returns true if the given String exactly matches the next non-whitespace characters in the data, or false if it does not.
protected  boolean nextTokenIs(String pattern, int start)
          Returns true if the given String exactly matches the characters in the data starting at the given index, or false if it does not.
protected  Operation[] nextUnaryOperations()
          Returns the array of unary operations that occur after the current position in the data string and throws a ParseException if an operation is encountered that is binary but not unary.
 Operation[] operations()
          Returns an array of the operations.
 String[] operationSymbols()
          Returns an array of the operation symbols.
 String[] ordinaryFunctionNames()
          Returns an array of the function names that correspond to functions whose class does NOT extend SimpleFunction.
 AbstractFunction[] ordinaryFunctions()
          Returns an array of the ordinary functions, that is, functions whose class does NOT extend SimpleFunction.
 Object parse(String d)
          Parses the given string d and returns the Object it represents, given this parsing scheme.
protected  Object[] parseArgumentList()
          Parses the next argument list in the data String assuming that each argument is to be evaluated and returns an array of objects representing the list.
protected  Object parseAssignment(Hashtable binding)
          Parse assignment, that is, "set" or "let".
protected  Object parseEval()
          Parse the "eval" operation.
protected  Object parseExpression()
          Returns the result of parsing the next expression in the data string.
protected  ObjectOperationPair parseExpression(ObjectOperationPair pending)
          Recursive method that parses the next expression in the data string.
protected  Object parseFunctionCall(String identifier)
          Parse a function with arguments and return its value.
protected  Object parseIdentifierExpression()
          Parse an expression that is introduced by an identifier.
protected  Object[] parseIdentifierExpressionList()
          Parses the next argument list that consists of an identifier that is to be returned literally and a value expression to be evaluated.
protected  Object parseIfThenElse()
          Parse if-then-else, that is, "if".
protected  Object parseNestedExpression()
          Parse an expression in parentheses, that is, a nested expression, and return its value.
protected  Object parseNumber()
          Parses the next numeric token in the data String and returns an object representation of its value.
protected  Object parseRandom()
          The "random" function is a special function that takes 0, 1, or 2 numeric arguments and has the following interpretation.
protected  Object parseSpecialFunction(String identifier)
          Parse a special function whose parameter list may not be completely evaluated.
 Object parseWithArgumentList(String d, String[] ids, Object[] values)
          Parses the given string d in the context of a symbolic argument list and associated values and returns the Object represented by the string d given this parsing scheme.
protected  void popContext()
          Pop and restore the previous parser context.
protected  int precedenceOf(Operation op)
          Returns the index in the precedence list corresponding to the precedence of the given operation, or -1 if the given operation is null or is not in the precedence list.
protected  void pushContext(String d)
          Save the current parser context and initialize a new context to parse the string d.
 AbstractFunction removeFunction(String name)
          Removes the function with the given name from this parser.
 String[] reserved()
          Returns an array of the reserved id's.
 void reserveID(String id)
          Add this identifier to the table of reserved identifiers so it may not be used for a constant or variable id or a function name.
 String[] set_variables()
          Returns an array of the set variable id's.
protected  void setArgumentSeparatorToken(String token)
          Sets the token representing the argument separator in this parsing scheme to the given String token.
protected  void setLeftParenthesisToken(String token)
          Sets the token representing the start of an argument list in this parsing scheme to the given String token.
protected  void setRadixPointToken(String token)
          Sets the token representing the radix point in this parsing scheme to the given String token.
protected  void setRightParenthesisToken(String token)
          Sets the token representing the end of an argument list in this parsing scheme to the given String token.
 String[] simpleFunctionNames()
          Returns an array of the function names that correspond to functions whose class is or extends SimpleFunction.
 SimpleFunction[] simpleFunctions()
          Returns an array of the simple functions, that is, functions whose class is or extends SimpleFunction.
 String simpleFunctionsToString()
          Returns a String representation of all Simple Function objects currently installed in this parser.
protected  void skipWhitespace()
          Skips over whitespace characters starting at the current parse position, until a non-whitespace character or the end of the data String is found.
protected  void specialPush(String d)
          Save the current parser context and prepare to parse the string d using the current "let" variable context.
protected  boolean startsIdentifier()
          Returns true if the next non-whitespace character starts an identifier.
protected  boolean startsNumber()
          Returns true if the next non-whitespace character starts a number.
 void stringToSimpleFunctions(String string)
          Treats the given String as a representation for a list of SimpleFunction objects, builds those objects, and installs them in this parser.
protected  void throwAgainAndPop(String message, String d)
          Throws a ParseException with information about the string d being parsed and the parser position appended to the given exception message.
protected  boolean withinIdentifier()
          Returns true if the next character is within an identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTITY

public static final Operation IDENTITY

The IDENTITY operation, equivalent to the function f(x,y)=y.

This operation is inserted with the lowest level of precedence and is used as the base for evaluation of an expression.

This object is identical to Operation.IDENTITY.


OPERATION_PREFIX

public static final Operation OPERATION_PREFIX

The singleton operation object which designates that a symbol is a prefix for a known operation.

This operation operates as a return flag and may not be inserted into the precedence structure of this class.

This object is identical to Operation.OPERATION_PREFIX.


INTEGRAL

protected static final int INTEGRAL
Value designating string data that has form of an integer number.

See Also:
Constant Field Values

FLOATING

protected static final int FLOATING
Value designating string data that has form of a floating number.

See Also:
Constant Field Values

NESTED_EXPRESSION_START

protected String NESTED_EXPRESSION_START
String token representing the start of a nested expression.


NESTED_EXPRESSION_END

protected String NESTED_EXPRESSION_END
String token representing the end of a nested expression.


ARGUMENT_LIST_START

protected String ARGUMENT_LIST_START
String token representing the start of an argument list.


ARGUMENT_LIST_END

protected String ARGUMENT_LIST_END
String token representing the end of an argument list.


RADIX_POINT

protected String RADIX_POINT
String token representing the radix point.


ARGUMENT_SEPARATOR

protected String ARGUMENT_SEPARATOR
String token representing the argument separator.


UNDERSCORE

protected char UNDERSCORE
Char with UNDERSCORE character for identifiers.


ASSIGNMENT_BY_SET

protected final String ASSIGNMENT_BY_SET
The reserved keyword "set" to indicate variable assignment that is persistent across invocations of the parse method.

See Also:
Constant Field Values

ASSIGNMENT_BY_LET

protected final String ASSIGNMENT_BY_LET
The reserved keyword "let" to indicate variable assignment that is temporary, that is, one that affects only the current invocation of the parse method.

See Also:
Constant Field Values

IF_THEN_ELSE

protected final String IF_THEN_ELSE
The reserved keyword "if" to indicate if-then-else.

See Also:
Constant Field Values

EVAL

protected final String EVAL
The reserved keyword "eval" to indicate the special function that evaluates its arguments from left to right and then returns the value of the rightmost argument.

See Also:
Constant Field Values

RANDOM

protected final String RANDOM

The reserved keyword "random" to indicate the special function that takes 0, 1, or 2 numeric arguments and has the following interpretation.

Function Name Typical Usage Interpretation
random random() Random number between 0 and 1
random random(x) Random number between 0 and x
random random(x,y) Random number between x and y

See Also:
Constant Field Values

reserved

private Hashtable reserved
Table of reserved identifiers for special functions or operations.


constants

private Hashtable constants
Table of constant identifiers and their corresponding values.


set_variables

private Hashtable set_variables
Table of variable identifiers defined by "set" and their corresponding values.


let_variables

private Hashtable let_variables
Table of variable identifiers defined by "let" in the current invocation of the parse method and their corresponding values.


functions

private Hashtable functions
Table of function names and their corresponding functions.


operations

private Hashtable operations
Table of operation symbols and their corresponding operations.


prefixes

private Hashtable prefixes
Table of prefixes of operation symbols.


precedence

private Vector precedence
List of hashtables storing the precedence relationship between operations. Operations with the same precedence are placed in the same hashtable. The list is ordered from lowest precedence to highest.


parserContextStack

private Vector parserContextStack
The vector that operates as a stack to save and restore the parser context in each call of parse.


data

protected String data
The current String to be evaluated by the current call of parse.


next

protected int next
The index of the next character to examine in the current String to be evaluated by the current call of parse.


suspend

protected int suspend

The member data to control whether the parser should be evaluating operations, functions, and special functions or should rather be parsing formally in order to extract the next expression that is to be parsed as a string.

The default value is 0.

A value of 0 or negative signals that the parser should proceed to evaluate.

A positive value signals that the parser should suspend evaluation and parse formally.

Normally, methods that wish to suspend evaluation should increment suspend on entry and decrement suspend prior to exit. This protocol will make it easy for such methods to be recursive and to interact well with similar methods.

Constructor Detail

BaseParser

public BaseParser()

Constructs a new parser by initializing structures and by adding the standard operations, functions, and constants available for this parser.

Calls the following 5 methods in turn:

Normally the last 3 methods should be overridden in a derived class.

Method Detail

parse

public final Object parse(String d)
                   throws ParseException

Parses the given string d and returns the Object it represents, given this parsing scheme.

This implementation proceeds as follows.

Checks that the data is not null.

To enable recursive calls of this method, pushes the current parsing context on a stack.

Calls the recursive method parseExpression together with a default ObjectOperationPair to initiate the parsing operation on this data.

Checks for errors:

Requires the value returned by the call to parseExpression to be non-null.

Requires that the parse operation consumed all of the characters in the data.

Restores the original parsing context.

Returns the value returned by the call to parseExpression.

Implementation note: This method simply calls parseWithArgumentList with the last 2 parameters null.

Specified by:
parse in interface Parser
Parameters:
d - the String to be parsed
Throws:
ParseException - if the data is malformed

parseWithArgumentList

public final Object parseWithArgumentList(String d,
                                          String[] ids,
                                          Object[] values)
                                   throws ParseException

Parses the given string d in the context of a symbolic argument list and associated values and returns the Object represented by the string d given this parsing scheme.

This implementation proceeds as follows.

To enable recursive calls of this method, pushes the current parsing context on a stack.

Checks that the data is not null.

Assigns the values to corresponding ids. Will ignore the lists ids and values if both lists are null.

Calls the recursive method parseExpression together with a default ObjectOperationPair to initiate the parsing operation on this data.

Checks for errors.

Requires the value returned by the call to parseExpression to be non-null.

Requires that the parse operation consumed all of the characters in the data.

Restores the original parsing context.

Returns the value returned by the call to parseExpression.

Parameters:
d - the string data to be parsed
ids - the argument list ids
values - the argument list values
Throws:
ParseException - if the data is malformed

call

public final double call(String name,
                         double[] arguments)
                  throws ParseException

Call the function with the given name that is installed in this parser using the given double data as arguments and return a double value.

The function should in effect expect doubles as arguments and should return a number.

The length of the arguments array must equal the number of arguments expected by the function.

Throws ParseException if an error occurs.

Parameters:
name - the name of the function installed in this parser
arguments - the arguments given as an array of double
Throws:
ParseException

call

public final double call(String name,
                         double x)
                  throws ParseException

Call the function with the given name that is installed in this parser using the given double x as the argument and return a double value.

The function should in effect expect 1 double as an argument and should return a number.

Throws ParseException if an error occurs.

Parameters:
name - the name of the function of 1 argument installed in this parser
x - argument 1
Throws:
ParseException

call

public final double call(String name,
                         double x,
                         double y)
                  throws ParseException

Call the function with the given name that is installed in this parser using the given doubles x,y as arguments and return a double value.

The function should in effect expect 2 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
name - the name of the function of 2 arguments installed in this parser
x - argument 1
y - argument 2
Throws:
ParseException

call

public final double call(String name,
                         double x,
                         double y,
                         double z)
                  throws ParseException

Call the function with the given name that is installed in this parser using the given doubles x,y,z as arguments and return a double value.

The function should in effect expect 3 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
name - the name of the function of 3 arguments installed in this parser
x - argument 1
y - argument 2
z - argument 3
Throws:
ParseException

call

public final double call(String name,
                         double x,
                         double y,
                         double z,
                         double w)
                  throws ParseException

Call the function with the given name that is installed in this parser using the given doubles x,y,z,w as arguments and return a double value.

The function should in effect expect 4 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
name - the name of the function of 4 arguments installed in this parser
x - argument 1
y - argument 2
z - argument 3
w - argument 4
Throws:
ParseException

makeTable

public final XPoint2D[][] makeTable(String names,
                                    double endpointA,
                                    double endpointB,
                                    int divisions)
                             throws ParseException

Views the given String as a comma separated list of names of AbstractFunction objects installed in this parser; for each such function object f, makes an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions; all such arrays are collected and returned in a 2-dimensional array.

If names is null, returns null.

Otherwise, assume that the string names contains N function names for some N>=0.

If divisions is less than 1, it will be set to 1.

The 2 dimensions of the output array will be N by (divisions+1).

Throws ParseException if an error occurs.

See also the makeTable methods in DataTables2D.

Parameters:
names - a comma separated list of names of functions installed in this parser
endpointA - an endpoint of the interval
endpointB - an endpoint of the interval
divisions - the number of subdivisions of the interval
Returns:
the 2-dimensional array of (x,f(x)) pairs
Throws:
ParseException

makeTable

public final XPoint2D[][] makeTable(String names,
                                    XInterval limits,
                                    int divisions)
                             throws ParseException

Views the given String as a comma separated list of names of AbstractFunction objects installed in this parser; for each such function object f, makes an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions; all such arrays are collected and returned in a 2-dimensional array.

If names is null or limits is null, returns null.

Otherwise, assume that the string names contains N function names for some N>=0.

If divisions is less than 1, it will be set to 1.

The 2 dimensions of the output array will be N by (divisions+1).

Throws ParseException if an error occurs.

See also the makeTable methods in DataTables2D.

Parameters:
names - a comma separated list of names of functions installed in this parser
limits - the interval
divisions - the number of subdivisions of the interval
Returns:
the 2-dimensional array of (x,f(x)) pairs
Throws:
ParseException

call

public static double call(AbstractFunction f,
                          double[] arguments)
                   throws ParseException

Call the given abstract function using the given double data as arguments and return a double value.

The function should in effect expect doubles as arguments and should return a number.

The length of the arguments array must equal the number of arguments expected by the function.

Throws ParseException if an error occurs.

Parameters:
f - the abstract function
arguments - the arguments given as an array of double
Throws:
ParseException

call

public static double call(AbstractFunction f,
                          double x)
                   throws ParseException

Call the given abstract function using the given double x as the argument and return a double value.

The function should in effect expect 1 double as an argument and should return a number.

Throws ParseException if an error occurs.

Parameters:
f - the abstract function of 1 argument
x - argument 1
Throws:
ParseException

call

public static double call(AbstractFunction f,
                          double x,
                          double y)
                   throws ParseException

Call the given abstract function using the given doubles x,y as arguments and return a double value.

The function should in effect expect 2 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
f - the abstract function of 2 arguments
x - argument 1
y - argument 2
Throws:
ParseException

call

public static double call(AbstractFunction f,
                          double x,
                          double y,
                          double z)
                   throws ParseException

Call the given abstract function using the given doubles x,y,z as arguments and return a double value.

The function should in effect expect 3 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
f - the abstract function of 3 arguments
x - argument 1
y - argument 2
z - argument 3
Throws:
ParseException

call

public static double call(AbstractFunction f,
                          double x,
                          double y,
                          double z,
                          double w)
                   throws ParseException

Call the given abstract function using the given doubles x,y,z,w as arguments and return a double value.

The function should in effect expect 4 doubles as an arguments and should return a number.

Throws ParseException if an error occurs.

Parameters:
f - the abstract function of 4 arguments
x - argument 1
y - argument 2
z - argument 3
w - argument 4
Throws:
ParseException

makeTable

public static XPoint2D[] makeTable(AbstractFunction f,
                                   double endpointA,
                                   double endpointB,
                                   int divisions)
                            throws ParseException

Make an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions.

If the given function is null, returns null.

If divisions is less than 1, it will be set to 1. The size of the output array will be (divisions+1).

See also the makeTable methods in DataTables2D.

Parameters:
f - the function of one argument to evaluate
endpointA - an endpoint of the interval
endpointB - an endpoint of the interval
divisions - the number of subdivisions of the interval
Returns:
the array of (x,f(x)) pairs
Throws:
ParseException

makeTable

public static XPoint2D[] makeTable(AbstractFunction f,
                                   XInterval limits,
                                   int divisions)
                            throws ParseException

Make an XPoint2D array of pairs (x,f(x)) where x is sampled on the given interval divided into the given number of divisions.

If the given function is null or limits is null, returns null.

If divisions is less than 1, it will be set to 1. The size of the output array will be (divisions+1).

See also the makeTable methods in DataTables2D.

Parameters:
f - the function of one argument to evaluate
limits - the interval
divisions - the number of subdivisions of the interval
Returns:
the array of (x,f(x)) pairs
Throws:
ParseException

reserveID

public final void reserveID(String id)

Add this identifier to the table of reserved identifiers so it may not be used for a constant or variable id or a function name.

A reserved identifier is intended to be the identifier for a special function that may have an indefinite number of arguments and may not fully evaluate the arguments.

Reserving an identifier does not define the special function or implement the test that makes that behavior accessible to the parser. For examples of how to do this, see the source for this class and examine how the special functions set,