|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object vmm.functions.Parser
public class Parser
A Parser can parse a string that holds the definition of a real-valued or complex-valued function or expression.
An expression can use the operators +, -, *, /, and ^, where ^
represents expontiation. Multiplication can also be represented
by juxtaposition. The ternary conditional operator "?:"
can be used, as in "x < 0 ? -x : x
". In the
condition, the relational operators =, !=, <, >, <=, and >=
and the logical operators and, or, and not can be used. Not equal can
be expressed as <> as well as by !=, and the logical operators
can be written as & |, and ~. Parentheses (), braces {}, and brackets []
can be used for grouping.
Names in expressions are not case-sensitive. The constants pi, e, i can be used in expressions (where i is the complex number, square root of minus one. Standard functions that are defined for both real and complex arguments are: abs, sqrt, cubert, exp, log, log2, log10, sin, cos, tan, sec, csc, cot, sinh, cosh, tanh, sech, scsh, coth, arcsin, arccos, arctan, arcsinh, arccosh, arctanh. Log can also be written as ln, and the inverse trig functions can also be written as asin, acos, atan, asinh, acosh, and atahn. Functions defined only for real arguments are: trunc, round, ceiling, floor, and signum. The signum function can also be written as sign or sgn. The real- and imaginary-part functions, re and im, are defined for a complex argument and produce a real result; they will also accept real arguemnts. The function complex(x,y) takes two real arguments and produces the complex value x+i*y; complex(x,y) is just another way to write this complex value, without using the constant i directly.
The definition of an expression or function
can include references to parameters and functions that have
been added to the parser (see add(Variable)
,
add(ComplexVariable)
, add(Function)
,
and add(ComplexFunction)
.
Constructor Summary | |
---|---|
Parser()
Create a parser with no parent. |
|
Parser(Parser parent)
Create a new parser. |
Method Summary | |
---|---|
void |
add(ComplexFunction f)
Add a complex-valued function to the parser so that it can be used in expressions parsed by this parser. |
void |
add(ComplexVariable v)
Add a complex variable that can then be used as a parameter in expressions parsed by this parser. |
void |
add(Function f)
Add a real-valued function to the parser so that it can be used in expressions parsed by this parser. |
void |
add(Variable v)
Add a variable that can then be used as a parameter in expressions parsed by this parser. |
java.lang.Object |
get(java.lang.String name)
Gets the object from the parser's symbol table that has the specified name, or returns null if there is no such object. |
Expression |
parse(java.lang.String str)
Parse an expression. |
ComplexExpression |
parseComplexExpression(java.lang.String str)
Parse a complex-valued expression. |
ComplexFunction |
parseComplexFunction(java.lang.String name,
java.lang.String definition,
java.lang.String... argumentName)
Define a complex-valued function of any number of complex arguments by parsing its definition. |
ComplexFunction1 |
parseComplexFunction1(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName)
Define a complex-valued function of one real argumentsby parsing its definition. |
ComplexFunction2 |
parseComplexFunction2(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName1,
java.lang.String argumentName2)
Define a conplex-valued function of two complex arguments by parsing its definition. |
ComplexFunction3 |
parseComplexFunction3(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName1,
java.lang.String argumentName2,
java.lang.String argumentName3)
Define a conplex-valued function of three complex arguments by parsing its definition. |
Expression |
parseExpression(java.lang.String str)
Parse a real-valued expression. |
Function |
parseFunction(java.lang.String name,
java.lang.String definition,
java.lang.String... argumentName)
Define a real-valued function of any number of real arguments by parsing its definition. |
Function1 |
parseFunction1(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName)
Define a real-valued function of one real argument by parsing its definition. |
Function2 |
parseFunction2(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName1,
java.lang.String argumentName2)
Define a real-valued function of two real arguments by parsing its definition. |
Function3 |
parseFunction3(java.lang.String name,
java.lang.String definition,
java.lang.String argumentName1,
java.lang.String argumentName2,
java.lang.String argumentName3)
Define a real-valued function of three real arguments by parsing its definition. |
void |
remove(java.lang.String objectName)
Removes the object from the parser's symbol table that has the specified name, if there is such an object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Parser()
Parser(Parser)
.)
public Parser(Parser parent)
parent
- if the parent is non-null, then this parser inherits
any symbols that have been added to the parent parser. Symbols that
are added to this parser do not affect the parent, but will hide symbols
in the parent that have the same name making them unavailable for use
by this parser.Method Detail |
---|
public Expression parse(java.lang.String str)
parseExpression(String)
.
ParseError
- if a syntax error is found in the definition of the expression.public Expression parseExpression(java.lang.String str)
ParseError
- if a syntax error is found in the definition of the expression.public Function1 parseFunction1(java.lang.String name, java.lang.String definition, java.lang.String argumentName)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName
- The name of the argument to the function. This must be non-null.
It should be a legal identifier. The argument name can be used in the definition
of the function.
ParseError
- if a syntax error is found in the definition of the function.public Function2 parseFunction2(java.lang.String name, java.lang.String definition, java.lang.String argumentName1, java.lang.String argumentName2)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName1
- The name of the first argument to the function. This must be non-null.
It should be a legal identifier.argumentName2
- The name of the second argument to the function. This must be non-null.
It should be a legal identifier.
ParseError
- if a syntax error is found in the definition of the function.public Function3 parseFunction3(java.lang.String name, java.lang.String definition, java.lang.String argumentName1, java.lang.String argumentName2, java.lang.String argumentName3)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName1
- The name of the first argument to the function. This must be non-null.
It should be a legal identifier.argumentName2
- The name of the second argument to the function. This must be non-null.
It should be a legal identifier.argumentName3
- The name of the third argument to the function. This must be non-null.
It should be a legal identifier.
ParseError
- if a syntax error is found in the definition of the function.public Function parseFunction(java.lang.String name, java.lang.String definition, java.lang.String... argumentName)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName
- The names of the arguments to the function. There can be any number
of argumentNames. They must be non-null and should be legal identifiers.
Function1
, Function2
, or
Function3
, respectively.
ParseError
- if a syntax error is found in the definition of the function.public ComplexExpression parseComplexExpression(java.lang.String str)
ParseError
- if a syntax error is found in the definition of the expression.public ComplexFunction1 parseComplexFunction1(java.lang.String name, java.lang.String definition, java.lang.String argumentName)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName
- The name of the argument to the function. This must be non-null.
It should be a legal identifier.
ParseError
- if a syntax error is found in the definition of the function.public ComplexFunction2 parseComplexFunction2(java.lang.String name, java.lang.String definition, java.lang.String argumentName1, java.lang.String argumentName2)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName1
- The name of the first argument to the function. This must be non-null.
It should be a legal identifier.argumentName2
- The name of the second argument to the function. This must be non-null.
It should be a legal identifier.
ParseError
- if a syntax error is found in the definition of the function.public ComplexFunction3 parseComplexFunction3(java.lang.String name, java.lang.String definition, java.lang.String argumentName1, java.lang.String argumentName2, java.lang.String argumentName3)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName1
- The name of the first argument to the function. This must be non-null.
It should be a legal identifier.argumentName2
- The name of the second argument to the function. This must be non-null.
It should be a legal identifier.argumentName3
- The name of the third argument to the function. This must be non-null.
It should be a legal identifier.
ParseError
- if a syntax error is found in the definition of the function.public ComplexFunction parseComplexFunction(java.lang.String name, java.lang.String definition, java.lang.String... argumentName)
name
- the name of the function. This can be null and really only has to be
non-null if the function will be added to a Parser for use in other expressions.definition
- The string that will be parsed to define the function.argumentName
- The names of the arguments to the function. There can be any number
of argumentNames. They must be non-null and should be legal identifiers.
ComplexFunction1
, ComplexFunction2
, or
ComplexFunction3
, respectively.
ParseError
- if a syntax error is found in the definition of the function.public void add(Variable v)
v
- the variable to be added to the parser. This must be non-null
and must have a non-null name. Furthermore, the name should be
a legal identifier that can be used in expressions; that is, it should
start with a letter and contain only letters, digits, the underscore
character, with one or more apostrophes allowed at the end of the name.public void add(ComplexVariable v)
v
- the variable to be added to the parser. This must be non-null
and must have a non-null name. Furthermore, the name should be
a legal identifier that can be used in expressions; that is, it should
start with a letter and contain only letters, digits, the underscore
character, with one or more apostrophes allowed at the end of the name.public void add(Function f)
f
- the function to be added to the parser. (Note that the only way to get
such a function is from a Parser.) This must be non-null and must
have a non-null name. The name should be a legal identifier; that is, it should
start with a letter and contain only letters, digits, the underscore
character, with one or more apostrophes allowed at the end of the name.public void add(ComplexFunction f)
f
- the function to be added to the parser. (Note that the only way to get
such a function is from a Parser.) This must be non-null and must
have a non-null name. The name should be a legal identifier; that is, it should
start with a letter and contain only letters, digits, the underscore
character, with one or more apostrophes allowed at the end of the name.public java.lang.Object get(java.lang.String name)
public void remove(java.lang.String objectName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |