use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class ParserTestCase method testParser6.
public void testParser6() {
try {
Parser p = new Parser();
ASTNode obj = p.parse("a+%%%+%3*4!");
assertEquals(obj.toString(), "Plus(a, Out(-3), Times(Out(3), Factorial(4)))");
} catch (Exception e) {
e.printStackTrace();
assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class ParserTestCase method testParser11.
public void testParser11() {
try {
Parser p = new Parser();
ASTNode obj = p.parse("-(3/4)");
assertEquals(obj.toString(), "-3/4");
} catch (Exception e) {
e.printStackTrace();
assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class ParserTestCase method testParser16.
public void testParser16() {
try {
Parser p = new Parser();
ASTNode obj = p.parse("f[[1,2]]");
assertEquals(obj.toString(), "Part(f, 1, 2)");
obj = p.parse("f[[1]][[2]]");
assertEquals(obj.toString(), "Part(Part(f, 1), 2)");
obj = p.parse("f[[1,2,f[x]]]");
assertEquals(obj.toString(), "Part(f, 1, 2, f(x))");
obj = p.parse("f[[1]][[2]][[f[x]]]");
assertEquals(obj.toString(), "Part(Part(Part(f, 1), 2), f(x))");
} catch (Exception e) {
e.printStackTrace();
assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class DoubleEvaluator method evaluate.
/**
* Parse the given <code>expression String</code> and evaluate it to a
* double value
*
* @param expression
* @return
* @throws SyntaxError
*/
public double evaluate(String expression) {
Parser p;
if (fRelaxedSyntax) {
p = new Parser(ASTNodeFactory.RELAXED_STYLE_FACTORY, true);
} else {
p = new Parser(ASTNodeFactory.MMA_STYLE_FACTORY, false);
}
fNode = p.parse(expression);
if (fNode instanceof FunctionNode) {
fNode = optimizeFunction((FunctionNode) fNode);
}
return evaluateNode(fNode);
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class DoubleEvaluator method getVariables.
/**
* Get the variable names from the given expression.
*
* @param expression
* @param result
* a set which contains the variable names
* @param relaxedSyntax
* if <code>true</code> us e function syntax like
* <code>sin(x)</code> otherwise use <code>Sin[x]</code>.
*/
public static void getVariables(String expression, Set<String> result, boolean relaxedSyntax) {
Parser p = new Parser(relaxedSyntax ? ASTNodeFactory.RELAXED_STYLE_FACTORY : ASTNodeFactory.MMA_STYLE_FACTORY, relaxedSyntax);
ASTNode node = p.parse(expression);
getVariables(node, result);
}
Aggregations