|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.hws.jcm.functions.FunctionParserExtension
An object belonging to a concrete subclass of FunctionParserExtesion is a mathematical function that can be registered with a Parser and then used in strings that are parsed by that parser. (See the Function inteface for more information.)
Since a FunctionParserExtension object implements the ParserExtension interface, it has a name and can be registered with a Parser. When the parser encounters the name of a function in a string, it turns control of the parsing process over to the function. When a Function occurs in an ExpressionProgram, the Function is responsible for evaluating itself and for differentiating itself. This functionality is defined in the abstract class FunctionParserExtension. The concrete subclasses of FunctionParserExtension represent actual functions. They must implement the five methods defined in the Function interface, but most of the parser- and expression-related behavior can probably be inherited from this class. (This is good, since the programming is rather tricky.)
(The point of all this is that Parsers and Expressions can deal with Functions, even though there is no reference to Functions in the Parser or ExpressionProgram classes. Everything is done through the ParserExtension interface.)
Field Summary | |
protected java.lang.String |
name
The name of this MathObject, possibly null. |
Constructor Summary | |
FunctionParserExtension()
|
Method Summary | |
void |
appendOutputString(ExpressionProgram prog,
int myIndex,
java.lang.StringBuffer buffer)
Append a string representation of the function and its arguments to the buffer |
void |
apply(StackOfDouble stack,
Cases cases)
Evaluate the function applied to argument values popped from the stack, and leave the result on the stack. |
void |
compileDerivative(ExpressionProgram prog,
int myIndex,
ExpressionProgram deriv,
Variable wrt)
The function object occurs as a command at index myIndex in prog. |
void |
doParse(Parser parser,
ParserContext context)
If this ParserExtension is registered with a parser and the parser encounters the name of the function in the string it is parsing, then the parser will call this routine. |
int |
extent(ExpressionProgram prog,
int myIndex)
Return the number of commands in prog that are part of this function reference, including the space occupied by the commands that compute the values of the function's arguments. |
java.lang.String |
getName()
Get the name of this MathObject. |
void |
setName(java.lang.String name)
Set the name of this object. |
void |
setParensCanBeOptional(boolean b)
Call this function with b = true if this is a function of one variable and you want it to behave like a standard function in that parentheses can be optional around the argument of the function. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface edu.hws.jcm.data.Function |
dependsOn, derivative, derivative, getArity, getVal, getValueWithCases |
Methods inherited from interface edu.hws.jcm.data.ExpressionCommand |
dependsOn |
Field Detail |
protected java.lang.String name
Constructor Detail |
public FunctionParserExtension()
Method Detail |
public void setParensCanBeOptional(boolean b)
b
- set whether parenthesis are optional in one variable functions.public void setName(java.lang.String name)
setName
in interface MathObject
public java.lang.String getName()
getName
in interface MathObject
public void doParse(Parser parser, ParserContext context)
doParse
in interface ParserExtension
parser
- parser that is parsing the string.context
- the ParseContext in effect at the time this method is called.public void apply(StackOfDouble stack, Cases cases)
apply
in interface ExpressionCommand
edu.hws.jcm.data.ExpressionCommand
stack
- contains results of previous commands in the program.cases
- if non-null, any case information generated during evaluation should be recorded here.public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)
compileDerivative
in interface ExpressionCommand
prog
- program this function object occurs in.myIndex
- index at which this function occurs.deriv
- commands for computing the derivative are placed here.wrt
- the derivative is taken with respect to this Variable.public int extent(ExpressionProgram prog, int myIndex)
extent
in interface ExpressionCommand
prog
- program to check commands against.myIndex
- index in program.public void appendOutputString(ExpressionProgram prog, int myIndex, java.lang.StringBuffer buffer)
appendOutputString
in interface ExpressionCommand
prog
- program whose string representation is being generated.myIndex
- index of this ExpressionCommand in prog.buffer
- string representation is placed here.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |