Search in sources :

Example 1 with ASTNode

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

the class PatternMatchingTestCase method checkPriority.

public void checkPriority(String patternString, int priority) {
    try {
        ASTNode node = fParser.parse(patternString);
        IExpr pat = AST2Expr.CONST.convert(node);
        PatternMatcher matcher = new PatternMatcher(pat);
        assertEquals(matcher.getPriority(), priority);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(0, priority);
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher)

Example 2 with ASTNode

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

the class PatternMatchingTestCase method checkPattern.

public void checkPattern(String patternString, String evalString, String resultString) {
    try {
        ASTNode node = fParser.parse(patternString);
        IExpr pat = AST2Expr.CONST.convert(node);
        node = fParser.parse(evalString);
        IExpr eval = AST2Expr.CONST.convert(node);
        PatternMatcher matcher = new PatternMatcher(pat);
        if (matcher.test(eval)) {
            ArrayList<IExpr> resultList = new ArrayList<IExpr>();
            matcher.getPatterns(resultList, pat);
            assertEquals(resultList.toString(), resultString);
            return;
        }
        assertEquals("", resultString);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", resultString);
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) ArrayList(java.util.ArrayList) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher)

Example 3 with ASTNode

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

the class PatternMatchingTestCase method comparePriority.

public void comparePriority(String patternString1, String patternString2, int result) {
    try {
        ASTNode node = fParser.parse(patternString1);
        IExpr pat1 = AST2Expr.CONST.convert(node);
        node = fParser.parse(patternString1);
        IExpr pat2 = AST2Expr.CONST.convert(node);
        PatternMatcher matcher1 = new PatternMatcher(pat1);
        PatternMatcher matcher2 = new PatternMatcher(pat2);
        assertEquals(matcher1.compareTo(matcher2), result);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(Integer.MAX_VALUE, result);
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher)

Example 4 with ASTNode

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

the class ParserTestCase method testParser14.

public void testParser14() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("-a-b*c!!+d");
        assertEquals(obj.dependsOn("d"), true);
        assertEquals(obj.dependsOn("x"), false);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 5 with ASTNode

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

the class ParserTestCase method testParser20.

public void testParser20() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("B[[;;, 2]]");
        assertEquals(obj.toString(), "Part(B, Span(1, All), 2)");
    } 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