Package org.sbml.jsbml

Examples of org.sbml.jsbml.ASTNode


    {if (true) return node;}
    throw new Error("Missing return statement in function");
  }

  final private ASTNode TermLvl1() throws ParseException {
  ASTNode rightChild = null;
  ASTNode leftChild;
  ASTNode node = null;
  Token t;
  String s;
  Type type = null;
    leftChild = TermLvl2();
    label_3:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
      case MINUS:
      case COMPARISON:
      case BOOLEAN_LOGIC:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_3;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
        jj_consume_token(PLUS);
        rightChild = TermLvl2();
      node = new ASTNode('+');
      node.addChild(leftChild);
      node.addChild(rightChild);
        break;
      case MINUS:
        jj_consume_token(MINUS);
        rightChild = TermLvl2();
      node = new ASTNode('-');
      node.addChild(leftChild);
      node.addChild(rightChild);
        break;
      case BOOLEAN_LOGIC:
        t = jj_consume_token(BOOLEAN_LOGIC);
        rightChild = TermLvl2();
      s = t.image;
      if (s.equalsIgnoreCase("or") || s.equalsIgnoreCase("||"))
      {
        type = ASTNode.Type.LOGICAL_OR;
      }
      else if (s.equalsIgnoreCase("and") || s.equalsIgnoreCase("&&"))
      {
        type = ASTNode.Type.LOGICAL_AND;
      }
      else if (s.equalsIgnoreCase("xor"))
      {
        type = ASTNode.Type.LOGICAL_XOR;
      }
      node = new ASTNode(type);
      node.addChild(leftChild);
      node.addChild(rightChild);
        break;
      case COMPARISON:
        t = jj_consume_token(COMPARISON);
        rightChild = TermLvl2();
      s = t.image;
      if (s.equalsIgnoreCase("<"))
      {
        type = ASTNode.Type.RELATIONAL_LT;
      }
      else if (s.equalsIgnoreCase(">"))
      {
        type = ASTNode.Type.RELATIONAL_GT;
      }
      else if (s.equalsIgnoreCase("=="))
      {
        type = ASTNode.Type.RELATIONAL_EQ;
      }
      else if (s.equalsIgnoreCase("!="))
      {
        type = ASTNode.Type.RELATIONAL_NEQ;
      }
      else if (s.equalsIgnoreCase(">="))
      {
        type = ASTNode.Type.RELATIONAL_GEQ;
      }
      else if (s.equalsIgnoreCase("<="))
      {
        type = ASTNode.Type.RELATIONAL_LEQ;
      }
      node = new ASTNode(type);
      node.addChild(leftChild);
      node.addChild(rightChild);
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
View Full Code Here


  final private ASTNode Primary() throws ParseException, NumberFormatException {
  Token t;
  double d;
  int i;
  ASTNode node = new ASTNode();
  ASTNode child, furtherChild;
  String s;
  String vals [ ];
  ArrayList < ASTNode > arguments = new ArrayList < ASTNode > ();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case INTEGER:
      t = jj_consume_token(INTEGER);
    i = Integer.parseInt(t.image); // Could use StringTools.parseXXX methods here but not doing so allow to support different locale ??
    node.setValue(i);
    {if (true) return node;}
      break;
    case NUMBER:
      t = jj_consume_token(NUMBER);
    d = Double.parseDouble(t.image);
    node.setValue(d);
    {if (true) return node;}
      break;
    case EXPNUMBER:
      t = jj_consume_token(EXPNUMBER);
    s = t.image;
    vals = s.toLowerCase().split("e");
    if (vals [ 1 ].startsWith("+"))
    {
      i = Integer.parseInt(vals [ 1 ].substring(1));
    }
    else
    {
      i = Integer.parseInt(vals [ 1 ]);
    }
    node.setValue(Double.parseDouble(vals [ 0 ]), i);
    {if (true) return node;}
      break;
    default:
      jj_la1[8] = jj_gen;
      if (jj_2_1(2)) {
        t = string();
        jj_consume_token(OPEN_PAR);
        child = TermLvl1();
        label_4:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case SLPITTER:
            ;
            break;
          default:
            jj_la1[7] = jj_gen;
            break label_4;
          }
          jj_consume_token(SLPITTER);
          furtherChild = TermLvl1();
      arguments.add(furtherChild);
        }
        jj_consume_token(CLOSE_PAR);
    s = t.image;
    Type type = null;

    if (stringToType.containsKey(s.toLowerCase()))
    {
      type = ASTNode.Type.valueOf(stringToType.getProperty(s.toLowerCase()).toUpperCase());
    }
    if (s.equalsIgnoreCase("pow") || s.equalsIgnoreCase("power"))
    {
      checkSize(arguments, 1);
      node.addChild(child);
    }
    else if (s.equalsIgnoreCase("sqr"))
    {
      checkSize(arguments, 0);
      node.addChild(child);
      node.addChild(new ASTNode(2));
    }
    else if (s.equalsIgnoreCase("sqrt"))
    {
      checkSize(arguments, 0);
      node.addChild(new ASTNode(2));
      node.addChild(child);
    }
    else if (s.equalsIgnoreCase("not"))
    {
      checkSize(arguments, 0);
      node.addChild(child);
      type = Type.LOGICAL_NOT;
    }
    else if (s.equalsIgnoreCase("ln"))
    {
      checkSize(arguments, 0);
      node.addChild(child);
      type = Type.FUNCTION_LN;
    }
    else if (s.equalsIgnoreCase("lambda"))
    {
      node.addChild(child);
      type = Type.LAMBDA;
    }
    else if (s.equalsIgnoreCase("piecewise"))
    {
      node.addChild(child);
      type = Type.FUNCTION_PIECEWISE;
    }
    else if (s.equalsIgnoreCase("modulo") || s.equalsIgnoreCase("mod"))
    {
      checkSize(arguments, 1);
      ASTNode rightChild = arguments.get(0);
      arguments.clear();

          node = createModulo(child, rightChild);
          {if (true) return node;}
    }
    else
    {
      node.addChild(child);
    }
    if (type != null)
    {
      node.setType(type);
    }
    else
    {
      node.setName(s);
    }
    for (ASTNode argument : arguments)
    {
      node.addChild(argument);
    }
    {if (true) return node;}
      } else {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case OPEN_PAR:
          jj_consume_token(OPEN_PAR);
          node = TermLvl1();
          jj_consume_token(CLOSE_PAR);
    {if (true) return node;}
          break;
        case MINUS:
          jj_consume_token(MINUS);
          node = Primary();
    ASTNode uiMinus = new ASTNode('-');
    uiMinus.addChild(node);
    {if (true) return uiMinus;}
          break;
        case NOT:
          jj_consume_token(NOT);
          node = TermLvl1();
    ASTNode not = new ASTNode(Type.LOGICAL_NOT);
    not.addChild(node);
    {if (true) return not;}
          break;
        case LOG:
          jj_consume_token(LOG);
          child = Primary();
    node = new ASTNode(Type.FUNCTION_LN);
    node.addChild(child);
    {if (true) return node;}
          break;
        case STRING:
          t = jj_consume_token(STRING);
    s = t.image;
    if (s.equalsIgnoreCase("true"))
    {
      node = new ASTNode(Type.CONSTANT_TRUE);
    }
    else if (s.equalsIgnoreCase("false"))
    {
      node = new ASTNode(Type.CONSTANT_FALSE);
    }
    else if (s.equalsIgnoreCase("pi"))
    {
      node = new ASTNode(Type.CONSTANT_PI);
    }
    else if (s.equalsIgnoreCase("avogadro"))
    {
      node = new ASTNode(Type.NAME_AVOGADRO);
    }
    else if (s.equalsIgnoreCase("time"))
    {
      node = new ASTNode(Type.NAME_TIME);
    }
    else if (s.equalsIgnoreCase("exponentiale"))
    {
      node = new ASTNode(Type.CONSTANT_E);
    }
    else if (s.equalsIgnoreCase("-infinity") || s.equalsIgnoreCase("-INF"))
    {
      node = new ASTNode(Double.NEGATIVE_INFINITY);
    }
    else if (s.equalsIgnoreCase("infinity") || s.equalsIgnoreCase("INF"))
    {
      node = new ASTNode(Double.POSITIVE_INFINITY);
    }
    else if (s.equalsIgnoreCase("NotANumber") || s.equalsIgnoreCase("NaN"))
    {
      node = new ASTNode(Double.NaN);
    }
    else
    {
      node = new ASTNode(s);
    }
    {if (true) return node;}
          break;
        default:
          jj_la1[9] = jj_gen;
View Full Code Here

  /* (non-Javadoc)
   * @see org.sbml.jsbml.ASTNodeCompiler#function(org.sbml.jsbml.FunctionDefinition, org.sbml.jsbml.ASTNodeValue[])
   */
  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 {
      this.namesToUnits = argValues;
      ASTNodeValue value = lambda.getRightChild().compile(this);
      this.namesToUnits.clear();
      return value;
    } catch (SBMLException e) {
      return new ASTNodeValue(this);
    }
View Full Code Here

    int level = 3;
    int version = 1;
    SBMLDocument doc = new SBMLDocument(level, 1);
    Model m = doc.createModel("id");
    FunctionDefinition fd = m.createFunctionDefinition("fd");
    ASTNode math = new ASTNode(Type.LAMBDA, fd);
    math.addChild(new ASTNode("x", fd));
    ASTNode pieces = ASTNode.piecewise(new ASTNode(3, fd), ASTNode.lt("x",
        ASTNode.abs(Double.NEGATIVE_INFINITY, fd)), ASTNode.times(
        new ASTNode(5.3, fd), ASTNode.log(new ASTNode(8, fd))));
    pieces = ASTNode.times(pieces, ASTNode.root(new ASTNode(2, fd),
        new ASTNode(16, fd)));
    math.addChild(pieces);
    fd.setMath(math);
    System.out.println(math.toMathML());
   
    Species species = m.createSpecies("spec");
    Reaction r = m.createReaction("r");
    r.addReactant(new SpeciesReference(species));
    KineticLaw kl = new KineticLaw(level, version);
    math = new ASTNode(fd, kl);
    math.addChild(new ASTNode(species, kl));
    math = ASTNode.times(math, new ASTNode(3.7, 8, kl));
    kl.setMath(math);
    r.setKineticLaw(kl);
   
    System.out.println(math.toMathML());
View Full Code Here

     
    }
   
    @Test public void test_Event_setDelayCopy()
    {
      ASTNode math1 = null;
    try {
      math1 = ASTNode.parseFormula("0");
    } catch (ParseException e) {
      assertTrue(false);
    }
View Full Code Here

      }
    }

    @Test public void test_Event_setTriggerCopy()
    {
      ASTNode math1 = null;
      try {
        math1 = ASTNode.parseFormula("0");
      } catch (ParseException e) {
        assertTrue(false);
      }
View Full Code Here

      }
    }

    @Test public void test_FormulaOutput()
    {
      ASTNode math = null;
      try {
        math = ASTNode.parseFormula("k1 * S1");
      } catch (ParseException e) {
        assertTrue(false);
      }

      try {
      assertTrue(math.toFormula().equals("k1*S1"));
      assertTrue(math.toFormula().equals("k1 * S1")); // We are not putting the same space in the formula

    } catch (SBMLException e) {
      assertTrue(false);    }
     
    }
View Full Code Here

   */
  public ASTNode readMathML(String mathML, TreeNodeChangeListener listener)
    throws XMLStreamException  {
    Object object = readXMLFromString(mathML, listener);   
    if (object != null && object instanceof Constraint) {
      ASTNode math = ((Constraint) object).getMath();     
      if (math != null) {
        return math;
      }
    }   
    return null;
View Full Code Here

  {
    this.astNodeParent = parent;
   
    Object object = readXMLFromString(mathML, listener);   
    if (object != null && object instanceof Constraint) {
      ASTNode math = ((Constraint) object).getMath();     
      if (math != null) {
        return math;
      }
    }   
    return null;
View Full Code Here

   
    model.createParameter("k");
   
    KineticLaw kl = r.createKineticLaw();
    kl.createLocalParameter("k");
    ASTNode node = ASTNode.readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> <apply><times/><ci> k </ci><ci> S1 </ci></apply></math>");
    kl.setMath(node);
   
    if (!(kl.getMath().getChild(0).getVariable() instanceof LocalParameter)) {
      System.out.println("The local parameter k is not found!");
    }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.ASTNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.