/** * Get the mathematical expression that is the body of this * {@link FunctionDefinition} object. * * @return the body of this {@link FunctionDefinition} as an Abstract Syntax * Tree, or null if no body is defined. */ public ASTNode getBody() { return isSetMath() ? getMath().getRightChild() : null; }
@Override public ASTNodeValue function(FunctionDefinition function, List<ASTNode> args) throws SBMLException { ASTNode lambda = function.getMath(); HashMap<String, ASTNodeValue> argValues = new HashMap<String, ASTNodeValue>(); for (int i = 0; i < args.size(); i++) { argValues.put(lambda.getChild(i).compile(this).toString(), args .get(i).compile(this)); } try { namesToUnits = argValues; ASTNodeValue value = lambda.getRightChild().compile(this); namesToUnits.clear(); return value; } catch (SBMLException e) { return new ASTNodeValue(this); } }
/** * @param astNode */ private void compileLambda(ASTNode astNode) { try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "lambda"); writer.writeCharacters("\n"); indent += " "; int nbChildren = astNode.getChildCount(); if (nbChildren > 1) { for (int i = 0; i < nbChildren - 1; i++) { ASTNode arg = astNode.getChild(i); compileBvar(arg); } } compile(astNode.getRightChild()); writeEndElement(); } catch (XMLStreamException e) { e.printStackTrace(); } }
indent += " "; compile(astNode.getRightChild());
if ((parent != null) && (parent instanceof ASTNode)) { ASTNode parentNode = (ASTNode) parent; if ((parentNode.getType() == Type.LAMBDA) && (parentNode.getRightChild() != this)) {
/** * Creates brackets if needed. * * @param node * @return * @throws SBMLException */ protected String checkDenominatorBrackets(ASTNode node) throws SBMLException { if ((node.getType() == Type.POWER) && (node.getChildCount() > 1) && node.getRightChild().toString().equals("1")) { return checkDenominatorBrackets(node.getLeftChild()); } String term = node.compile(this).toString(); if (node.isSum() || node.isDifference() || node.isUMinus() || (node.getType() == Type.TIMES) || node.getType() == Type.DIVIDE || node.isRelational() || node.isLogical()) { term = brackets(term).toString(); } return term; }
ASTNode right = node.getRightChild();
value = compiler.pow(getLeftChild(), getRightChild()); break; case PLUS: value = compiler.frac(getLeftChild(), getRightChild()); break; case RATIONAL: break; case FUNCTION_DELAY: value = compiler.delay(getName(), getLeftChild(), getRightChild(), getUnits()); break; value = compiler.log(getLeftChild(), getRightChild()); } else { value = compiler.log(getRightChild()); value = compiler.abs(getRightChild()); break; case FUNCTION_ARCCOS: case FUNCTION_LN: if (getChildCount() > 1) { // TODO - in general, should we throw an SBMLException if we encounter more child than expected ? value = compiler.log(getLeftChild(), getRightChild()); // TODO - temporary fix as we read log(1, 2) as ln(1, 2) currently (07/04/2017) break; break; case FUNCTION_POWER: