use of org.jmathml.TextToASTNodeMathParser2 in project vcell by virtualcell.
the class Libsedml method parseFormulaString.
/**
* Convenience method to parse free text math into an ASTNode. The style of
* math is a C-style syntax, e.g.,<br/>
* . The parsing supports standard arithmetical operations and function
* calls. E.g.,
*
* <ul>
* <li>4 + 2
* <li>sin(pi / 2) // or any other trig function
* <li>log(9,81) // = 2
* <li>root(4,81) //=3
* <li>exp(t)
* </ul>
* <p>
* In addition, the strings <code>pi</code>, <code>NaN</code>,
* <code>infinity</code> and <code>exponentiale</code> are translated into
* constants.
* </p>
*
* Functions not supported by this library ( see ASTFunctionType for
* supported functions ) will be parsed into a function call, which will not
* be evaluable. E.g., <br/>
*
* <pre>
* myfunction(a, b)
* </pre>
*
* can be turned into an ASTNode, but will not be evaluable, unless a symbol
* definition class is supplied. (See the
* <code>org.jlibsedml.mathsymbols</code> package for how the SED-ML
* aggregate functions are supported).
*
* @param math
* A <code>String</code> of math.
* @return An {@link ASTNode}. This will be an {@link ASTRootNode} with the
* math nodes as children. E.g., the string
*
* <pre>
* 2 * (4 / 5)
* </pre>
* will return the structure:
* <pre>
* ASTRootNode
* ASTimes
* ASTCn(2)
* ASTDivide
* ASTCn(4)
* ASTCn(5)
* </pre>
*
* If <code>math</code> is null or empty, returns <code>null</code>.
* @throws RuntimeException
* if mathString cannot be parsed due to incorrect syntax.
*/
public static ASTNode parseFormulaString(String math) {
if (math == null || math.length() == 0) {
return null;
}
ASTRootNode rc = new ASTRootNode();
new TextToASTNodeMathParser2().parseString(math, rc);
return rc;
}
Aggregations