use of org.matheclipse.core.parser.ExprParser in project symja_android_library by axkr.
the class MathMLUtilities method toMathML.
/**
* Converts the inputExpression string into a MathML expression and writes
* the result to the given <code>Writer</code>
*
* @param inputExpression
* @param out
*/
public synchronized void toMathML(final String inputExpression, final Writer out) {
IExpr parsedExpression = null;
// ASTNode node;
if (inputExpression != null) {
try {
ExprParser parser = new ExprParser(fEvalEngine);
parsedExpression = parser.parse(inputExpression);
// node = fEvalEngine.parseNode(inputExpression);
// parsedExpression = AST2Expr.CONST.convert(node, fEvalEngine);
} catch (final Throwable e) {
return;
// parsedExpression == null ==> fError occured
}
}
toMathML(parsedExpression, out);
}
use of org.matheclipse.core.parser.ExprParser in project symja_android_library by axkr.
the class MathMLUtilities method toJava.
public synchronized void toJava(final String inputExpression, final Writer out, boolean strictJava) {
IExpr parsedExpression = null;
// ASTNode node;
if (inputExpression != null) {
try {
ExprParser parser = new ExprParser(fEvalEngine);
parsedExpression = parser.parse(inputExpression);
// node = fEvalEngine.parseNode(inputExpression);
// parsedExpression = AST2Expr.CONST.convert(node, fEvalEngine);
out.write(parsedExpression.internalFormString(strictJava, 0));
} catch (final Throwable e) {
return;
// parsedExpression == null ==> fError occured
}
}
}
use of org.matheclipse.core.parser.ExprParser in project symja_android_library by axkr.
the class SymjaInterpreter method interpreter.
/**
* Evaluate the expression assigned to this interpreter.
*
* @param function
* <code>null</code> if you like to evaluate in symbolic mode;
* "N" if you like to evaluate in numeric mode
* @return
*/
public String interpreter(String function) {
String evalStr = codeString;
IExpr expr;
EvalEngine engine = EvalEngine.get();
try {
ExprParser p = new ExprParser(engine, true);
// throws SyntaxError exception, if syntax isn't valid
if (function != null) {
evalStr = function + "(" + codeString + ")";
}
expr = p.parse(evalStr);
} catch (SyntaxError e1) {
try {
ExprParser p = new ExprParser(engine);
// throws SyntaxError exception, if syntax isn't valid
if (function != null) {
evalStr = function + "[" + codeString + "]";
}
expr = p.parse(evalStr);
} catch (Exception e2) {
outStream.println(e2.getMessage());
return "";
}
}
IExpr result;
final StringBuilder buf = new StringBuilder();
try {
result = evaluate(expr);
if (result.isPresent()) {
if (result.equals(F.Null)) {
return buf.toString();
}
OutputFormFactory.get(true).convert(buf, result);
}
return buf.toString();
} catch (final RuntimeException re) {
Throwable me = re.getCause();
if (me instanceof MathException) {
Validate.printException(buf, me);
} else {
Validate.printException(buf, re);
}
} catch (final Exception ex) {
Validate.printException(buf, ex);
} catch (final StackOverflowError soe) {
Validate.printException(buf, soe);
} catch (final OutOfMemoryError oome) {
Validate.printException(buf, oome);
}
return buf.toString();
}
use of org.matheclipse.core.parser.ExprParser in project symja_android_library by axkr.
the class ExprEvaluator method toScalaForm.
/**
* Converts the inputExpression string into a Scala expression and writes the result to the given
* <code>Writer</code>string.
*
* @param inputExpression
* @param out
*/
public String toScalaForm(final String inputExpression) throws MathException {
IExpr parsedExpression;
if (inputExpression != null) {
ExprParser parser = new ExprParser(engine);
parsedExpression = parser.parse(inputExpression);
return parsedExpression.internalScalaString(false, 0);
}
return "";
}
use of org.matheclipse.core.parser.ExprParser in project symja_android_library by axkr.
the class ExprEvaluator method toJavaForm.
/**
* Converts the inputExpression string into a Java Symja expression string.
*
* @param inputExpression
* @param out
*/
public String toJavaForm(final String inputExpression) throws MathException {
IExpr parsedExpression;
if (inputExpression != null) {
ExprParser parser = new ExprParser(engine);
parsedExpression = parser.parse(inputExpression);
return parsedExpression.internalFormString(false, 0);
}
return "";
}
Aggregations