use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class BasicPatternPropertiesTestCase method setUp.
/**
* The JUnit setup method
*/
protected void setUp() {
try {
// setup the evaluation engine (and bind to current thread)
// EvalEngine.get();
EvalEngine engine = new EvalEngine();
EvalEngine.set(engine);
engine.setSessionID("BasicPatternPropertiesTestCase");
engine.setRecursionLimit(256);
engine.setIterationLimit(1024 * 1024);
fParser = new Parser();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class LowercaseTestCase method testParserFixedPoint.
public void testParserFixedPoint() {
try {
Parser p = new Parser(true);
ASTNode obj = p.parse("{28, 21} /. {a_, b_} /; b != 0 -> {b, Mod(a, b)}");
assertEquals(obj.toString(), "ReplaceAll(List(28, 21), Rule(Condition(List(a_, b_), Unequal(b, 0)), List(b, Mod(a, b))))");
} catch (Exception e) {
e.printStackTrace();
assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class Import method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 3);
if (!(ast.arg1() instanceof IStringX)) {
throw new WrongNumberOfArguments(ast, 1, ast.size() - 1);
}
if (!(ast.arg2() instanceof IStringX)) {
throw new WrongNumberOfArguments(ast, 2, ast.size() - 1);
}
IStringX arg1 = (IStringX) ast.arg1();
IStringX arg2 = (IStringX) ast.arg2();
FileReader reader = null;
try {
reader = new FileReader(arg1.toString());
if (arg2.contentEquals("Table")) {
AST2Expr ast2Expr = AST2Expr.CONST;
if (engine.isRelaxedSyntax()) {
ast2Expr = AST2Expr.CONST_LC;
}
final Parser parser = new Parser(engine.isRelaxedSyntax(), true);
CSVFormat csvFormat = CSVFormat.RFC4180.withDelimiter(' ');
Iterable<CSVRecord> records = csvFormat.parse(reader);
IAST rowList = F.List();
for (CSVRecord record : records) {
IAST columnList = F.List();
for (String string : record) {
final ASTNode node = parser.parse(string);
IExpr temp = ast2Expr.convert(node, engine);
columnList.append(temp);
}
rowList.append(columnList);
}
return rowList;
}
} catch (IOException ioe) {
engine.printMessage("Import: file " + arg1.toString() + " not found!");
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
return F.NIL;
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class RulePreprocessor method parseFileToList.
public static ASTNode parseFileToList(File file) {
try {
final BufferedReader f = new BufferedReader(new FileReader(file));
final StringBuffer buff = new StringBuffer(1024);
String line;
while ((line = f.readLine()) != null) {
buff.append(line);
buff.append('\n');
}
f.close();
String inputString = buff.toString();
Parser p = new Parser(true, false);
return p.parse(inputString);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.matheclipse.parser.client.Parser in project symja_android_library by axkr.
the class RelaxedParserTestCase method testParser0.
public void testParser0() {
try {
Parser p = new Parser(true);
Object obj = p.parse("Integrate(Sin(x)^2+3*x^4, x)");
assertEquals(obj.toString(), "Integrate(Plus(Power(Sin(x), 2), Times(3, Power(x, 4))), x)");
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations