Search in sources :

Example 36 with ASTNode

use of org.matheclipse.parser.client.ast.ASTNode in project symja_android_library by axkr.

the class PatternMatchingTestCase method check.

public void check(EvalEngine engine, boolean configMode, String strEval, String strResult, boolean relaxedSyntax) {
    try {
        if (strEval.length() == 0 && strResult.length() == 0) {
            return;
        }
        IExpr result;
        StringWriter buf = new StringWriter();
        // configMode;
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            Parser parser = new Parser(relaxedSyntax);
            ASTNode node = parser.parse(strEval);
            IExpr inExpr = AST2Expr.CONST.convert(node);
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER, relaxedSyntax);
            result = utility.constrainedEval(buf, inExpr);
        } else {
            Parser parser = new Parser(relaxedSyntax);
            ASTNode node = parser.parse(strEval);
            IExpr inExpr = AST2Expr.CONST.convert(node);
            result = util.evaluate(inExpr);
            if ((result != null) && !result.equals(F.Null)) {
                OutputFormFactory off = OutputFormFactory.get(relaxedSyntax);
                off.setIgnoreNewLine(true);
                off.convert(buf, result);
            }
        }
        assertEquals(buf.toString(), strResult);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e, "");
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) ASTNode(org.matheclipse.parser.client.ast.ASTNode) IExpr(org.matheclipse.core.interfaces.IExpr) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory) Parser(org.matheclipse.parser.client.Parser)

Example 37 with ASTNode

use of org.matheclipse.parser.client.ast.ASTNode in project symja_android_library by axkr.

the class ParserTestCase method testParser9.

public void testParser9() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("-42424242424242424242.125");
        assertEquals(obj.toString(), "-42424242424242424242.125");
    } 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 ASTNode

use of org.matheclipse.parser.client.ast.ASTNode in project symja_android_library by axkr.

the class ParserTestCase method testParser17.

public void testParser17() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("\\[Alpha]+\\[Alpha]");
        assertEquals(obj.toString(), "Plus(α, α)");
    } 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 ASTNode

use of org.matheclipse.parser.client.ast.ASTNode in project symja_android_library by axkr.

the class ParserTestCase method testParser10.

public void testParser10() {
    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 40 with ASTNode

use of org.matheclipse.parser.client.ast.ASTNode in project symja_android_library by axkr.

the class ParserTestCase method testParser23.

public void testParser23() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("f[x]*f''[x]");
        assertEquals(obj.toString(), "Times(f(x), Derivative(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)

Aggregations

ASTNode (org.matheclipse.parser.client.ast.ASTNode)56 Parser (org.matheclipse.parser.client.Parser)32 IExpr (org.matheclipse.core.interfaces.IExpr)10 FunctionNode (org.matheclipse.parser.client.ast.FunctionNode)8 MathException (org.matheclipse.parser.client.math.MathException)6 PatternMatcher (org.matheclipse.core.patternmatching.PatternMatcher)5 SymbolNode (org.matheclipse.parser.client.ast.SymbolNode)5 IAST (org.matheclipse.core.interfaces.IAST)4 IOException (java.io.IOException)3 AST2Expr (org.matheclipse.core.convert.AST2Expr)3 NumberNode (org.matheclipse.parser.client.ast.NumberNode)3 FileReader (java.io.FileReader)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 ArithmeticMathException (org.matheclipse.parser.client.math.ArithmeticMathException)2 InfixOperator (org.matheclipse.parser.client.operator.InfixOperator)2 PostfixOperator (org.matheclipse.parser.client.operator.PostfixOperator)2 PrefixOperator (org.matheclipse.parser.client.operator.PrefixOperator)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1