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());
}
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations