Search in sources :

Example 1 with ASTMatrix

use of gov.sandia.n2a.language.parse.ASTMatrix in project n2a by frothga.

the class Operator method getFrom.

public static Operator getFrom(SimpleNode node) throws Exception {
    Operator result;
    if (node instanceof ASTOperator) {
        Factory f = operators.get(node.jjtGetValue().toString());
        result = f.createInstance();
    } else if (node instanceof ASTIdentifier) {
        String value = node.jjtGetValue().toString();
        if (value.endsWith("()")) {
            Factory f = operators.get(value.substring(0, value.length() - 2));
            if (// It's either this or an undefined function. In the second case, variable access will fail.
            f == null)
                // It's either this or an undefined function. In the second case, variable access will fail.
                result = new AccessElement();
            else
                result = f.createInstance();
        } else {
            result = new AccessVariable();
        }
    } else if (node instanceof ASTConstant)
        result = new Constant();
    else if (node instanceof ASTMatrix)
        result = new BuildMatrix();
    else if (node instanceof ASTList) {
        if (node.jjtGetNumChildren() == 1)
            return getFrom((SimpleNode) node.jjtGetChild(0));
        // Lists can exist elsewhere besides a $type split, but they should be processed out by getOperandsFrom(SimpleNode).
        result = new Split();
    } else
        result = new Operator();
    result.getOperandsFrom(node);
    return result;
}
Also used : ASTOperator(gov.sandia.n2a.language.parse.ASTOperator) ASTConstant(gov.sandia.n2a.language.parse.ASTConstant) ASTIdentifier(gov.sandia.n2a.language.parse.ASTIdentifier) SimpleNode(gov.sandia.n2a.language.parse.SimpleNode) ASTConstant(gov.sandia.n2a.language.parse.ASTConstant) ASTList(gov.sandia.n2a.language.parse.ASTList) ASTOperator(gov.sandia.n2a.language.parse.ASTOperator) ASTMatrix(gov.sandia.n2a.language.parse.ASTMatrix)

Aggregations

ASTConstant (gov.sandia.n2a.language.parse.ASTConstant)1 ASTIdentifier (gov.sandia.n2a.language.parse.ASTIdentifier)1 ASTList (gov.sandia.n2a.language.parse.ASTList)1 ASTMatrix (gov.sandia.n2a.language.parse.ASTMatrix)1 ASTOperator (gov.sandia.n2a.language.parse.ASTOperator)1 SimpleNode (gov.sandia.n2a.language.parse.SimpleNode)1