Class Parser
- java.lang.Object
-
- jv.thirdParty.expr.Parser
-
public class Parser extends java.lang.ObjectParses strings representing mathematical formulas with variables. The following operators, in descending order of precedence, are defined:- ^ (raise to a power such as 17^2 or sin(x)^2)
- * /
- Unary minus (-x)
- + -
These functions are defined: abs, acos(==arccos), asin(==arcsin), atan(==arctan), acot(==arccot), ceil, floor, exp, log(==ln), round, sign, sqrt, sin, cos, tan, cot, sinh, cosh, tanh, coth, asinh(==arcsinh), acosh(==arccosh), atanh(==arctanh), acoth(==arccoth). Lowercase and uppercase writing is ignored.
Each function requires one argument enclosed in parentheses. Whitespaces outside identifiers are ignored.
The syntax-error messages aren't very informative, unfortunately. IWBNI it indicated where in the input string the parse failed, but that'd be kind of a pain since our scanner is a StreamTokenizer. A hook for that info should've been built into StreamTokenizer.
Examples:
- 42
- 2-3
- cos(x^2) + sin(x^2)
- sqrt(y)^3
- Author:
- Darius Bacon
- Version:
- 03.06.06 (kp) Alternative writings allowed such as log=ln, asin=arcsin.
06.08.99 (kp) StringBufferInputStream replaced with StringReader according to Java1.1.
07.07.99 (kp) New functions added: cot, acot, acosh, asinh, atanh, acoth, sign.
31.01.99 (kp) New functions added: cosh, sinh, tanh, coth.
00.00.96 (Darius Bacon) Original version.
-
-
Constructor Summary
Constructors Constructor and Description Parser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static Exprparse(java.lang.String input)
-
-
-
Method Detail
-
parse
public static Expr parse(java.lang.String input) throws Syntax_error
- Throws:
Syntax_error
-
-
"