Package org.sbml.jsbml

Examples of org.sbml.jsbml.ASTNode


    }
    return leftChild;
  }

  final private ASTNode TermLvl2() throws ParseException {
  ASTNode rightChild;
  ASTNode leftChild;
  ASTNode node = null;
    leftChild = TermLvl3();
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMES:
      case DIVIDE:
        ;
        break;
      default:
        jj_la1[4] = jj_gen;
        break label_2;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMES:
        jj_consume_token(TIMES);
        rightChild = TermLvl3();
      node = new ASTNode('*');
      node.addChild(leftChild);
      node.addChild(rightChild);
      leftChild = node;
        break;
      case DIVIDE:
        jj_consume_token(DIVIDE);
        rightChild = TermLvl3();
      Integer left, right;
      left = getInteger(leftChild);
      right = getInteger(rightChild);
      if (left != null && right != null)
      {
        node = new ASTNode();
        node.setValue(left, right);
        leftChild = node;
      }
      else
      {
        node = new ASTNode('/');
        node.addChild(leftChild);
        node.addChild(rightChild);
        leftChild = node;
      }
        break;
      default:
        jj_la1[5] = jj_gen;
View Full Code Here


    }
    return leftChild;
  }

  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[6] = 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);
      leftChild = node;
        break;
      case MINUS:
        jj_consume_token(MINUS);
        rightChild = TermLvl2();
      node = new ASTNode('-');
      node.addChild(leftChild);
      node.addChild(rightChild);
      leftChild = node;
        break;
      case BOOLEAN_LOGIC:
        t = jj_consume_token(BOOLEAN_LOGIC);
        rightChild = TermLvl2();
      s = t.image;
      if (s.equalsIgnoreCase("or"))
      {
        type = ASTNode.Type.LOGICAL_OR;
      }
      else if (s.equalsIgnoreCase("and"))
      {
        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);
      leftChild = node;
        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);
      leftChild = node;
        break;
      default:
        jj_la1[7] = jj_gen;
        jj_consume_token(-1);
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);
    node.setValue(i);
    return node;
    case NUMBER:
      t = jj_consume_token(NUMBER);
    d = Double.parseDouble(t.image);
    node.setValue(d);
    return node;
    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);
    return node;
    default:
      jj_la1[9] = 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[8] = 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;
    Properties stringToType = new Properties();
    String path = "cfg/ASTNodeTokens.xml";
    try
    {
      stringToType.loadFromXML(Resource.class.getResourceAsStream(path));
    }
    catch (InvalidPropertiesFormatException e)
    {
      throw new RuntimeException("Invalid configuration file entries in file " + Resource.class.getResource(path), e);
    }
    catch (IOException e)
    {
      throw new RuntimeException("Could not read configuration file " + Resource.class.getResource(path), e);
    }
    if (stringToType.containsKey(s.toLowerCase()))
    {
      type = ASTNode.Type.valueOf(stringToType.getProperty(s.toLowerCase()).toUpperCase());
    }
    if (s.equalsIgnoreCase("pow"))
    {
      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
    {
      node.addChild(child);
    }
    if (type != null)
    {
      node.setType(type);
    }
    else
    {
      node.setName(s);
    }
    for (ASTNode argument : arguments)
    {
      node.addChild(argument);
    }
        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);
    return node;
        case MINUS:
          jj_consume_token(MINUS);
          node = Primary();
    ASTNode uiMinus = new ASTNode('-');
    uiMinus.addChild(node);
    return uiMinus;
        case NOT:
          jj_consume_token(NOT);
          node = TermLvl1();
    ASTNode not = new ASTNode(Type.LOGICAL_NOT);
    not.addChild(node);
    return not;
        case LOG:
          jj_consume_token(LOG);
          child = Primary();
    node = new ASTNode(Type.FUNCTION_LN);
    node.addChild(child);
    return node;
        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"))
    {
      node = new ASTNode(Double.NEGATIVE_INFINITY);
    }
    else if (s.equalsIgnoreCase("infinity"))
    {
      node = new ASTNode(Double.POSITIVE_INFINITY);
    }
    else
    {
      node = new ASTNode(s);
    }
    if (true) {return node;}
          break;
        default:
          jj_la1[10] = jj_gen;
View Full Code Here

     
      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());
View Full Code Here

    }
  }

  public static void main(String[] args) {
   
    ASTNode formula_base = new ASTNode(Double.NaN);
   
    System.out.println(formula_base.toMathML());
    try {
      System.out.println(formula_base.toFormula());
    } catch (SBMLException e) {
      e.printStackTrace();
    }
   
    double x = 0.0050;
View Full Code Here

* @return a piecewise {@link ASTNode} representing the modulo operation between the left and right child given.
* @see http://sbml.org/Documents/FAQ#Why_can.27t_I_use_the_.3Crem.3E_operator_in_SBML_MathML.3F
*/
  private ASTNode createModulo(ASTNode leftChild, ASTNode rightChild)
  {
      ASTNode node = new ASTNode(ASTNode.Type.FUNCTION_PIECEWISE);

          ASTNode floorNode = new ASTNode(ASTNode.Type.FUNCTION_FLOOR);
          ASTNode aDividedByB = new ASTNode(ASTNode.Type.DIVIDE);
          aDividedByB.addChild(leftChild);
          aDividedByB.addChild(rightChild);

          floorNode.addChild(aDividedByB);
          node.addChild(floorNode);

          ASTNode greaterThan = new ASTNode(ASTNode.Type.RELATIONAL_GT);
          greaterThan.addChild(aDividedByB.clone());
          greaterThan.addChild(new ASTNode(0));

          node.addChild(greaterThan);

          ASTNode ceilNode = new ASTNode(ASTNode.Type.FUNCTION_CEILING);
          ceilNode.addChild(aDividedByB.clone());

          node.addChild(ceilNode);

          return node;
  }
View Full Code Here

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

  final public ASTNode parse() throws ParseException {
  ASTNode node = null;
    node = Expression();
    {if (true) return node;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

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

  final private ASTNode Expression() throws ParseException {
  ASTNode value = null;
    value = TermLvl1();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 0:
      jj_consume_token(0);
      break;
View Full Code Here

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

  final private ASTNode TermLvl3() throws ParseException {
  ASTNode rightChild;
  ASTNode leftChild;
  ASTNode node = null;
    leftChild = Primary();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case POWER:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_1;
      }
      jj_consume_token(POWER);
      rightChild = Primary();
      node = new ASTNode(Type.POWER);
      node.addChild(leftChild);
      node.addChild(rightChild);
    }
    if (node == null)
    {
      node = leftChild;
    }
View Full Code Here

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

  final private ASTNode TermLvl2() throws ParseException {
  ASTNode rightChild;
  ASTNode leftChild;
  ASTNode node = null;
    leftChild = TermLvl3();
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMES:
      case DIVIDE:
      case MODULO:
        ;
        break;
      default:
        jj_la1[3] = jj_gen;
        break label_2;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMES:
        jj_consume_token(TIMES);
        rightChild = TermLvl3();
      node = new ASTNode('*');
      node.addChild(leftChild);
      node.addChild(rightChild);
        break;
      case DIVIDE:
        jj_consume_token(DIVIDE);
        rightChild = TermLvl3();
      Integer left, right;
      left = getInteger(leftChild);
      right = getInteger(rightChild);
      if (left != null && right != null)
      {
        node = new ASTNode();
        node.setValue(left, right);
      }
      else
      {
        node = new ASTNode('/');
        node.addChild(leftChild);
        node.addChild(rightChild);
      }
        break;
      case MODULO:
        jj_consume_token(MODULO);
        rightChild = TermLvl3();
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.