Search in sources :

Example 36 with Parser

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());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 37 with Parser

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());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 38 with Parser

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());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 39 with Parser

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);
}
Also used : FunctionNode(org.matheclipse.parser.client.ast.FunctionNode) Parser(org.matheclipse.parser.client.Parser)

Example 40 with Parser

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);
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Aggregations

Parser (org.matheclipse.parser.client.Parser)40 ASTNode (org.matheclipse.parser.client.ast.ASTNode)32 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 EvalEngine (org.matheclipse.core.eval.EvalEngine)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 FunctionNode (org.matheclipse.parser.client.ast.FunctionNode)2 BufferedReader (java.io.BufferedReader)1 StringWriter (java.io.StringWriter)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 AST2Expr (org.matheclipse.core.convert.AST2Expr)1 EvalUtilities (org.matheclipse.core.eval.EvalUtilities)1 TimeConstrainedEvaluator (org.matheclipse.core.eval.TimeConstrainedEvaluator)1 WrongNumberOfArguments (org.matheclipse.core.eval.exception.WrongNumberOfArguments)1 OutputFormFactory (org.matheclipse.core.form.output.OutputFormFactory)1 IAST (org.matheclipse.core.interfaces.IAST)1 IStringX (org.matheclipse.core.interfaces.IStringX)1