| java.lang.Object edu.hws.jcm.functions.FunctionParserExtension
All known Subclasses: edu.hws.jcm.functions.WrapperFunction, edu.hws.jcm.functions.ExpressionFunction, edu.hws.jcm.functions.TableFunction,
FunctionParserExtension | abstract public class FunctionParserExtension implements Function,ParserExtension,ExpressionCommand(Code) | | 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 String | name The name of this MathObject, possibly null. |
Method Summary | |
public void | appendOutputString(ExpressionProgram prog, int myIndex, StringBuffer buffer) | public void | apply(StackOfDouble stack, Cases cases) Evaluate the function applied to argument values popped from the stack,
and leave the result on the stack. | public void | compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt) The function object occurs as a command at index myIndex in prog. | public 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. | public 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.
Parameters: prog - program to check commands against. Parameters: myIndex - index in program. | public String | getName() Get the name of this MathObject. | public void | setName(String name) Set the name of this object. | public 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. |
name | protected String name(Code) | | The name of this MathObject, possibly null.
|
appendOutputString | public void appendOutputString(ExpressionProgram prog, int myIndex, StringBuffer buffer)(Code) | | Append a string representation of the function and its arguments to the buffer
Parameters: prog - program whose string representation is being generated. Parameters: myIndex - index of this ExpressionCommand in prog. Parameters: buffer - string representation is placed here. |
apply | public void apply(StackOfDouble stack, Cases cases)(Code) | | Evaluate the function applied to argument values popped from the stack,
and leave the result on the stack. The argument values have already been
computed and placed on the stack when this is called. They should be
popped off the stack in reverse order. This general method can't deal
properly with "cases", so it will probably have to be overridden in
subclasses.
|
compileDerivative | public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)(Code) | | The function object occurs as a command at index myIndex in prog. The commands for computing
its arguments can be found in prog in positions preceding myIndex. Generate commands for computing
the derivative of the function reference with respect to the Variable wrt and add them to the deriv program. The
computation of the derivative uses the chain rule.
Parameters: prog - program this function object occurs in. Parameters: myIndex - index at which this function occurs. Parameters: deriv - commands for computing the derivative are placed here. Parameters: wrt - the derivative is taken with respect to this Variable. |
doParse | public void doParse(Parser parser, ParserContext context)(Code) | | 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. This routine parses
the function's parameter list and generates the code for evaluating
the function, applied to those parameters. When this routine is
called, the name of the function has already been read. The code
that is generated consists of code to evalueate each of the parameters,
leaving the results on the stack, followed by an application of the
function.
Parameters: parser - parser that is parsing the string. Parameters: context - the ParseContext in effect at the time this method is called. |
extent | public int extent(ExpressionProgram prog, int myIndex)(Code) | | 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.
Parameters: prog - program to check commands against. Parameters: myIndex - index in program. the number of commands in prog that are part of this function reference. |
getName | public String getName()(Code) | | Get the name of this MathObject.
|
setName | public void setName(String name)(Code) | | Set the name of this object. It is not a good idea to do this
if the object has been registered with a Parser.
|
setParensCanBeOptional | public void setParensCanBeOptional(boolean b)(Code) | | 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. For the parentheses
to be treated as optional, the option Parser.OPTIONAL_PARENS must ALSO
be set in the parser. As an example, if you wanted to define the function
sinh and allow the syntax "sinh x", you would turn this option on in
the Function and turn OTPTIONAL_PARENS on in the Parser.
Parameters: b - set whether parenthesis are optional in one variable functions. |
|
|