Search in sources :

Example 21 with Parser

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

the class ParserTestCase method testParser13.

public void testParser13() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("a*b*c*d");
        assertEquals(obj.toString(), "Times(a, b, c, d)");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 22 with Parser

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

the class ParserTestCase method testParser.

public void testParser() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("-a-b*c!!+d");
        assertEquals(obj.toString(), "Plus(Plus(Times(-1, a), Times(-1, Times(b, Factorial2(c)))), d)");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 23 with Parser

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

the class ParserTestCase method testParser0.

public void testParser0() {
    try {
        Parser p = new Parser();
        ASTNode obj = p.parse("(#^3)&[x][y,z].{a,b,c}");
        assertEquals(obj.toString(), "Dot(Function(Power(Slot(1), 3))[x][y, z], List(a, b, c))");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 24 with Parser

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

the class Get method parseReader.

/**
	 * <p>
	 * Parse the <code>reader</code> input.
	 * </p>
	 * <p>
	 * This method ignores the first line of the script if it starts with the
	 * <code>#!</code> characters (i.e. Unix Script Executables)
	 * </p>
	 * <p>
	 * <b>Note</b>: uses the <code>ASTNode</code> parser and not the
	 * <code>ExprParser</code>, because otherwise the symbols couldn't be
	 * assigned to the contexts.
	 * </p>
	 * 
	 * @param reader
	 * @param engine
	 * @return
	 * @throws IOException
	 */
public static List<ASTNode> parseReader(final BufferedReader reader, final EvalEngine engine) throws IOException {
    String record;
    StringBuilder builder = new StringBuilder(2048);
    if ((record = reader.readLine()) != null) {
        // characters (i.e. Unix Script Executables)
        if (!record.startsWith("!#")) {
            builder.append(record);
            builder.append('\n');
        }
    }
    while ((record = reader.readLine()) != null) {
        builder.append(record);
        builder.append('\n');
    }
    final Parser parser = new Parser(engine.isRelaxedSyntax(), true);
    final List<ASTNode> node = parser.parsePackage(builder.toString());
    return node;
}
Also used : ASTNode(org.matheclipse.parser.client.ast.ASTNode) Parser(org.matheclipse.parser.client.Parser)

Example 25 with Parser

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

the class DoubleEvaluator method parse.

/**
	 * Parse the given <code>expression String</code> and store the resulting
	 * ASTNode in this DoubleEvaluator
	 * 
	 * @param expression
	 * @return
	 * @throws SyntaxError
	 */
public ASTNode parse(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 fNode;
}
Also used : FunctionNode(org.matheclipse.parser.client.ast.FunctionNode) 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