use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class ExprParser method getFunction.
/**
* Get a function f[...][...]
*
*/
IAST getFunction(final IExpr head) throws SyntaxError {
final IAST function = F.ast(head, 10, false);
getNextToken();
if (fRelaxedSyntax) {
if (fToken == TT_PRECEDENCE_CLOSE) {
getNextToken();
if (fToken == TT_PRECEDENCE_OPEN) {
return function;
}
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(function);
}
return function;
}
} else {
if (fToken == TT_ARGUMENTS_CLOSE) {
getNextToken();
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(function);
}
return function;
}
}
fRecursionDepth++;
try {
getArguments(function);
} finally {
fRecursionDepth--;
}
if (fRelaxedSyntax) {
if (fToken == TT_PRECEDENCE_CLOSE) {
getNextToken();
if (fToken == TT_PRECEDENCE_OPEN) {
return function;
}
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(function);
}
return function;
}
} else {
if (fToken == TT_ARGUMENTS_CLOSE) {
getNextToken();
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(function);
}
return function;
}
}
if (fRelaxedSyntax) {
throwSyntaxError("')' expected.");
} else {
throwSyntaxError("']' expected.");
}
return null;
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class ExprParser method rewriteLessGreaterAST.
/**
* Convert less or greater relations on input. Example: convert expressions like <code>a<b<=c</code> to
* <code>Less[a,b]&&LessEqual[b,c]</code>.
*
* @param ast
* @param compareHead
* @return
*/
private IExpr rewriteLessGreaterAST(final IAST ast, ISymbol compareHead) {
IExpr temp;
boolean evaled = false;
IAST andAST = F.ast(F.And);
for (int i = 1; i < ast.size(); i++) {
temp = ast.get(i);
if (temp.isASTSizeGE(compareHead, 3)) {
IAST lt = (IAST) temp;
andAST.append(lt);
ast.set(i, lt.get(lt.size() - 1));
evaled = true;
}
}
if (evaled) {
andAST.append(ast);
return andAST;
} else {
return ast;
}
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class OutputFormFactory method convertPart.
/**
* This method will only be called if <code>list.isAST2()==true</code> and the head equals "Part".
*
* @param buf
* @param list
* @throws IOException
*/
public void convertPart(final Appendable buf, final IAST list) throws IOException {
IExpr arg1 = list.arg1();
if (!(arg1 instanceof IAST)) {
append(buf, "(");
}
convert(buf, arg1);
append(buf, "[[");
for (int i = 2; i < list.size(); i++) {
convert(buf, list.get(i));
if (i < list.size() - 1) {
append(buf, ",");
}
}
append(buf, "]]");
if (!(arg1 instanceof IAST)) {
append(buf, ")");
}
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class MathMLContentFormFactory method convert.
public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
if (o instanceof IAST) {
final IAST f = ((IAST) o);
// System.out.println(f.getHeader().toString());
// IConverter converter = (IConverter)
// operTab.get(f.getHeader().toString());
// if (converter == null) {
// converter = reflection(f.getHeader().toString());
// if (converter == null || (converter.convert(buf, f, 0) == false))
// {
// convertHeadList(buf, f);
// }
// } else {
// if (converter.convert(buf, f, precedence) == false) {
// convertHeadList(buf, f);
// }
// }
IAST ast = f;
IAST temp;
if (f.topHead().hasFlatAttribute()) {
// associative
if ((temp = EvalAttributes.flatten(f)).isPresent()) {
ast = temp;
}
}
IExpr h = ast.head();
if (h.isSymbol()) {
IConverter converter = reflection(((ISymbol) h).getSymbolName());
if (converter != null) {
StringBuffer sb = new StringBuffer();
if (converter.convert(sb, ast, precedence)) {
buf.append(sb);
return;
}
}
}
convertAST(buf, ast);
return;
}
if (o instanceof INum) {
convertDouble(buf, (INum) o, precedence);
return;
}
if (o instanceof IComplexNum) {
convertDoubleComplex(buf, (IComplexNum) o, precedence);
return;
}
if (o instanceof IInteger) {
convertInteger(buf, (IInteger) o, precedence);
return;
}
if (o instanceof IFraction) {
convertFraction(buf, (IFraction) o, precedence);
return;
}
if (o instanceof IComplex) {
convertComplex(buf, (IComplex) o, precedence);
return;
}
if (o instanceof ISymbol) {
convertSymbol(buf, (ISymbol) o);
return;
}
convertString(buf, o.toString());
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class MathMLFormFactory method convert.
public void convert(final StringBuffer buf, final IExpr o, final int precedence) {
String str = CONSTANT_EXPRS.get(o);
if (str != null) {
buf.append(str);
return;
}
if (o instanceof IAST) {
final IAST f = ((IAST) o);
IAST ast = f;
IAST temp;
if (f.topHead().hasFlatAttribute()) {
// associative
if ((temp = EvalAttributes.flatten(f)).isPresent()) {
ast = temp;
}
}
IExpr h = ast.head();
if (h.isSymbol()) {
IConverter converter = reflection(((ISymbol) h).getSymbolName());
if (converter != null) {
StringBuffer sb = new StringBuffer();
if (converter.convert(sb, ast, precedence)) {
buf.append(sb);
return;
}
}
}
convertAST(buf, ast);
return;
}
if (o instanceof INum) {
convertDouble(buf, (INum) o, precedence);
return;
}
if (o instanceof IComplexNum) {
convertDoubleComplex(buf, (IComplexNum) o, precedence);
return;
}
if (o instanceof IInteger) {
convertInteger(buf, (IInteger) o, precedence);
return;
}
if (o instanceof IFraction) {
convertFraction(buf, (IFraction) o, precedence);
return;
}
if (o instanceof IComplex) {
convertComplex(buf, (IComplex) o, precedence);
return;
}
if (o instanceof ISymbol) {
convertSymbol(buf, (ISymbol) o);
return;
}
convertString(buf, o.toString());
}
Aggregations