use of org.matheclipse.parser.client.operator.PostfixOperator in project symja_android_library by axkr.
the class OutputFormFactory method convertInfixOperator.
public void convertInfixOperator(final Appendable buf, final IAST list, final InfixOperator oper, final int precedence) throws IOException {
final boolean isOr = list.isOr();
String operatorString = oper.getOperatorString();
if (list.isAST2()) {
IExpr arg1 = list.arg1();
IExpr arg2 = list.arg2();
if (oper.getPrecedence() < precedence) {
append(buf, "(");
}
if (oper.getGrouping() == InfixOperator.RIGHT_ASSOCIATIVE && arg1.head().equals(list.head())) {
append(buf, "(");
} else {
if (operatorString.equals("^")) {
final Operator operator = getOperator(arg1.topHead());
if (operator instanceof PostfixOperator) {
append(buf, "(");
}
}
}
if (isOr && arg1.isAnd()) {
append(buf, "(");
}
convert(buf, arg1, oper.getPrecedence(), false);
if (isOr && arg1.isAnd()) {
append(buf, ")");
}
if (oper.getGrouping() == InfixOperator.RIGHT_ASSOCIATIVE && arg1.head().equals(list.head())) {
append(buf, ")");
} else {
if (operatorString.equals("^")) {
final Operator operator = getOperator(arg1.topHead());
if (operator instanceof PostfixOperator) {
append(buf, ")");
}
}
}
appendUnicodeMapped(buf, operatorString);
if (oper.getGrouping() == InfixOperator.LEFT_ASSOCIATIVE && arg2.head().equals(list.head())) {
append(buf, "(");
}
if (isOr && arg2.isAnd()) {
append(buf, "(");
}
convert(buf, arg2, oper.getPrecedence(), false);
if (isOr && arg2.isAnd()) {
append(buf, ")");
}
if (oper.getGrouping() == InfixOperator.LEFT_ASSOCIATIVE && arg2.head().equals(list.head())) {
append(buf, ")");
}
if (oper.getPrecedence() < precedence) {
append(buf, ")");
}
return;
}
if (oper.getPrecedence() < precedence) {
append(buf, "(");
}
if (list.size() > 1) {
if (isOr && list.arg1().isAnd()) {
append(buf, "(");
}
convert(buf, list.arg1(), oper.getPrecedence(), false);
if (isOr && list.arg1().isAnd()) {
append(buf, ")");
}
}
for (int i = 2; i < list.size(); i++) {
appendUnicodeMapped(buf, operatorString);
if (isOr && list.get(i).isAnd()) {
append(buf, "(");
}
convert(buf, list.get(i), oper.getPrecedence(), false);
if (isOr && list.get(i).isAnd()) {
append(buf, ")");
}
}
if (oper.getPrecedence() < precedence) {
append(buf, ")");
}
}
use of org.matheclipse.parser.client.operator.PostfixOperator in project symja_android_library by axkr.
the class MathMLFormFactory method convertOperator.
private boolean convertOperator(final org.matheclipse.parser.client.operator.Operator operator, final IAST list, final StringBuilder buf, final int precedence, ISymbol head) {
if ((operator instanceof PrefixOperator) && (list.isAST1())) {
convertPrefixOperator(buf, list, (PrefixOperator) operator, precedence);
return true;
}
if ((operator instanceof InfixOperator) && (list.size() > 2)) {
InfixOperator infixOperator = (InfixOperator) operator;
// } else
if (list.isAST(S.Apply)) {
if (list.size() == 3) {
convertInfixOperator(buf, list, ASTNodeFactory.APPLY_OPERATOR, precedence);
return true;
}
if (list.size() == 4 && list.arg2().equals(F.CListC1)) {
convertInfixOperator(buf, list, ASTNodeFactory.APPLY_LEVEL_OPERATOR, precedence);
return true;
}
return false;
} else if (list.size() != 3 && infixOperator.getGrouping() != InfixOperator.NONE) {
return false;
}
convertInfixOperator(buf, list, (InfixOperator) operator, precedence);
return true;
}
if ((operator instanceof PostfixOperator) && (list.isAST1())) {
convertPostfixOperator(buf, list, (PostfixOperator) operator, precedence);
return true;
}
return false;
}
use of org.matheclipse.parser.client.operator.PostfixOperator in project symja_android_library by axkr.
the class DoubleFormFactory method convertOperator.
protected boolean convertOperator(final Operator operator, final IAST list, final StringBuilder buf, final int precedence, ISymbol head) {
if ((operator instanceof PrefixOperator) && (list.isAST1())) {
convertPrefixOperator(buf, list, (PrefixOperator) operator, precedence);
return true;
}
if ((operator instanceof InfixOperator) && (list.size() > 2)) {
InfixOperator infixOperator = (InfixOperator) operator;
if (head.equals(S.Plus)) {
if (fPlusReversed) {
convertPlusOperatorReversed(buf, list, infixOperator, precedence);
} else {
convertPlusOperator(buf, list, infixOperator, precedence);
}
return true;
} else if (head.equals(S.Times)) {
convertTimesFraction(buf, list, infixOperator, precedence, NO_PLUS_CALL);
return true;
} else if (list.isPower()) {
convertPowerOperator(buf, list, infixOperator, precedence);
return true;
} else if (list.isAST(S.Apply)) {
if (list.size() == 3) {
convertInfixOperator(head, buf, list, ASTNodeFactory.APPLY_OPERATOR, precedence);
return true;
}
if (list.size() == 4 && list.arg2().equals(F.CListC1)) {
convertInfixOperator(head, buf, list, ASTNodeFactory.APPLY_LEVEL_OPERATOR, precedence);
return true;
}
return false;
} else if (list.size() != 3 && infixOperator.getGrouping() != InfixOperator.NONE) {
return false;
}
convertInfixOperator(head, buf, list, (InfixOperator) operator, precedence);
return true;
}
if ((operator instanceof PostfixOperator) && (list.isAST1())) {
convertPostfixOperator(buf, list, (PostfixOperator) operator, precedence);
return true;
}
return false;
}
Aggregations