Search in sources :

Example 11 with Context

use of org.matheclipse.core.expression.Context in project symja_android_library by axkr.

the class ComplexFormFactory method convertSymbol.

public void convertSymbol(final StringBuilder buf, final ISymbol symbol) {
    if (symbol == S.E) {
        buf.append("Math.E");
        return;
    } else if (symbol == S.Pi) {
        buf.append("Math.PI");
        return;
    } else if (symbol == S.False) {
        buf.append("false");
        return;
    } else if (symbol == S.True) {
        buf.append("true");
        return;
    } else if (symbol == S.Indeterminate) {
        buf.append("Double.NaN");
        return;
    }
    if (symbol.isConstantAttribute()) {
        try {
            double value = EvalEngine.get().evalDouble(symbol);
            buf.append("(" + value + ")");
            return;
        } catch (RuntimeException rex) {
        // 
        }
    }
    Context context = symbol.getContext();
    if (context == Context.DUMMY) {
        append(buf, symbol.getSymbolName());
        return;
    }
    if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS && context.equals(Context.SYSTEM)) {
        String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(symbol.getSymbolName());
        if (str != null) {
            append(buf, str);
            return;
        }
    }
    if (EvalEngine.get().getContextPath().contains(context)) {
        append(buf, symbol.getSymbolName());
    } else {
        append(buf, context.completeContextName() + symbol.getSymbolName());
    }
}
Also used : Context(org.matheclipse.core.expression.Context)

Example 12 with Context

use of org.matheclipse.core.expression.Context in project symja_android_library by axkr.

the class TeXFormFactory method convertSymbol.

public void convertSymbol(final StringBuilder buf, final ISymbol sym) {
    Context context = sym.getContext();
    if (context == Context.DUMMY) {
        buf.append(sym.getSymbolName());
        return;
    }
    String headStr = sym.getSymbolName();
    if (headStr.length() == 1) {
        String c = Characters.unicodeName(headStr.charAt(0));
        if (c != null) {
            final Object convertedSymbol = CONSTANT_SYMBOLS.get(c);
            if (convertedSymbol != null) {
                convertConstantSymbol(buf, sym, convertedSymbol);
                return;
            }
        }
    }
    if (context.equals(Context.SYSTEM) || context.isGlobal()) {
        if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS && context.equals(Context.SYSTEM)) {
            String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(headStr);
            if (str != null) {
                headStr = str;
            }
        }
        final Object convertedSymbol = CONSTANT_SYMBOLS.get(headStr);
        if (convertedSymbol == null) {
            buf.append(headStr);
        } else {
            convertConstantSymbol(buf, sym, convertedSymbol);
        }
        return;
    }
    if (EvalEngine.get().getContextPath().contains(context)) {
        buf.append(sym.getSymbolName());
    } else {
        buf.append(context.toString() + sym.getSymbolName());
    }
}
Also used : Context(org.matheclipse.core.expression.Context)

Example 13 with Context

use of org.matheclipse.core.expression.Context in project symja_android_library by axkr.

the class MathMLFormFactory method convertSymbol.

@Override
public void convertSymbol(final StringBuilder buf, final ISymbol sym) {
    Context context = sym.getContext();
    if (context == Context.DUMMY) {
        tagStart(buf, "mi");
        buf.append(sym.getSymbolName());
        tagEnd(buf, "mi");
        return;
    }
    String headStr = sym.getSymbolName();
    if (context.equals(Context.SYSTEM) || context.isGlobal()) {
        if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS) {
            String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(headStr);
            if (str != null) {
                headStr = str;
            }
        }
        final Object convertedSymbol = CONSTANT_SYMBOLS.get(headStr);
        if (convertedSymbol == null) {
            tagStart(buf, "mi");
            buf.append(headStr);
            tagEnd(buf, "mi");
            return;
        }
        if (convertedSymbol instanceof Operator) {
            ((Operator) convertedSymbol).convert(buf);
            return;
        }
        tagStart(buf, "mi");
        buf.append(convertedSymbol.toString());
        tagEnd(buf, "mi");
        return;
    }
    if (EvalEngine.get().getContextPath().contains(context)) {
        tagStart(buf, "mi");
        buf.append(sym.getSymbolName());
    } else {
        tagStart(buf, "mi");
        buf.append(context.toString() + sym.getSymbolName());
    }
    tagEnd(buf, "mi");
}
Also used : Context(org.matheclipse.core.expression.Context) PostfixOperator(org.matheclipse.parser.client.operator.PostfixOperator) InfixOperator(org.matheclipse.parser.client.operator.InfixOperator) PrefixOperator(org.matheclipse.parser.client.operator.PrefixOperator)

Example 14 with Context

use of org.matheclipse.core.expression.Context in project symja_android_library by axkr.

the class DoubleFormFactory method convertSymbol.

public void convertSymbol(final StringBuilder buf, final ISymbol symbol) {
    if (symbol == S.E) {
        buf.append("Math.E");
        return;
    } else if (symbol == S.Pi) {
        buf.append("Math.PI");
        return;
    } else if (symbol == S.False) {
        buf.append("false");
        return;
    } else if (symbol == S.True) {
        buf.append("true");
        return;
    } else if (symbol == S.Indeterminate) {
        buf.append("Double.NaN");
        return;
    }
    if (symbol.isConstantAttribute()) {
        try {
            double value = EvalEngine.get().evalDouble(symbol);
            buf.append("(" + value + ")");
            return;
        } catch (RuntimeException rex) {
        // 
        }
    }
    Context context = symbol.getContext();
    if (context == Context.DUMMY) {
        append(buf, symbol.getSymbolName());
        return;
    }
    if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS && context.equals(Context.SYSTEM)) {
        String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(symbol.getSymbolName());
        if (str != null) {
            append(buf, str);
            return;
        }
    }
    if (EvalEngine.get().getContextPath().contains(context)) {
        append(buf, symbol.getSymbolName());
    } else {
        append(buf, context.completeContextName() + symbol.getSymbolName());
    }
}
Also used : Context(org.matheclipse.core.expression.Context)

Aggregations

Context (org.matheclipse.core.expression.Context)14 ContextPath (org.matheclipse.core.expression.ContextPath)7 IExpr (org.matheclipse.core.interfaces.IExpr)3 ISymbol (org.matheclipse.core.interfaces.ISymbol)3 IOException (java.io.IOException)2 AST2Expr (org.matheclipse.core.convert.AST2Expr)2 IAST (org.matheclipse.core.interfaces.IAST)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EvalEngine (org.matheclipse.core.eval.EvalEngine)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 ASTNode (org.matheclipse.parser.client.ast.ASTNode)1 InfixOperator (org.matheclipse.parser.client.operator.InfixOperator)1