jigcell.xpp
Class CPPExpression

java.lang.Object
  extended by jigcell.xpp.CPPExpression

public class CPPExpression
extends java.lang.Object

This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.

Author:
Jason Zwolak, Pengyuan Wang

Field Summary
private static java.util.Hashtable associative
           
private static boolean DEBUG
           
static int DONT_LOOKUP_SYMBOLS
           
private  java.util.ArrayList expression
           
private  SymbolTable localSymbols
           
static int LOOKUP_BY_ID
           
static int LOOKUP_BY_NAME
           
private static java.util.Hashtable map
           
private  int mode
           
private  java.lang.String modeString
           
static int NORMAL
           
private static java.util.Hashtable order
           
private  SymbolTable symbolTable
           
 
Constructor Summary
CPPExpression(jigcell.sbml2.math.MathMLExpression mathML)
           
CPPExpression(jigcell.sbml2.math.Node parseTree)
           
CPPExpression(jigcell.sbml2.math.Node parseTree, int mode)
           
CPPExpression(SymbolTable st, jigcell.sbml2.math.MathMLExpression mathML)
           
CPPExpression(SymbolTable st, jigcell.sbml2.math.Node parseTree)
           
CPPExpression(SymbolTable st, jigcell.sbml2.math.Node parseTree, int mode)
           
CPPExpression(SymbolTable ls, SymbolTable st, jigcell.sbml2.math.MathMLExpression mathML)
           
CPPExpression(SymbolTable ls, SymbolTable st, jigcell.sbml2.math.Node parseTree)
           
CPPExpression(SymbolTable ls, SymbolTable st, jigcell.sbml2.math.Node parseTree, int mode)
           
 
Method Summary
static java.lang.String formatReal(double number)
           
static java.lang.String formatReal(java.lang.String number)
          Takes a number in a string and ensures it ends in "_R8" and has a decimal place.
private  java.util.ArrayList genExpression(jigcell.sbml2.math.Node current)
          Convert a parse tree into Fortran 90 code.
 java.lang.String getExpression()
           
 java.lang.String getExpression(java.lang.String indent, int width)
           
 java.lang.String getExpression(java.lang.String indent, int width, java.lang.String prefix)
           
 java.lang.Integer getOrder(jigcell.sbml2.math.Node node)
           
private  java.lang.String getSymbol(java.lang.String name)
          Follows the correct logic for this CPPExpression to get a symbol for name.
private  void initMaps()
           
static java.lang.String mergeExpression(java.util.ArrayList expression, java.lang.String indent, int width, java.lang.String prefix)
          Merges strings in expression and addes line breaks to maintain a width no greater than width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expression

private java.util.ArrayList expression

localSymbols

private SymbolTable localSymbols

mode

private int mode

modeString

private java.lang.String modeString

symbolTable

private SymbolTable symbolTable

map

private static java.util.Hashtable map

order

private static java.util.Hashtable order

associative

private static java.util.Hashtable associative

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

LOOKUP_BY_ID

public static final int LOOKUP_BY_ID
See Also:
Constant Field Values

LOOKUP_BY_NAME

public static final int LOOKUP_BY_NAME
See Also:
Constant Field Values

DONT_LOOKUP_SYMBOLS

public static final int DONT_LOOKUP_SYMBOLS
See Also:
Constant Field Values

NORMAL

public static final int NORMAL
See Also:
Constant Field Values
Constructor Detail

CPPExpression

public CPPExpression(SymbolTable ls,
                     SymbolTable st,
                     jigcell.sbml2.math.Node parseTree,
                     int mode)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(SymbolTable ls,
                     SymbolTable st,
                     jigcell.sbml2.math.Node parseTree)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(SymbolTable ls,
                     SymbolTable st,
                     jigcell.sbml2.math.MathMLExpression mathML)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(SymbolTable st,
                     jigcell.sbml2.math.MathMLExpression mathML)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(SymbolTable st,
                     jigcell.sbml2.math.Node parseTree,
                     int mode)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(SymbolTable st,
                     jigcell.sbml2.math.Node parseTree)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(jigcell.sbml2.math.MathMLExpression mathML)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(jigcell.sbml2.math.Node parseTree)
              throws java.lang.Exception
Throws:
java.lang.Exception

CPPExpression

public CPPExpression(jigcell.sbml2.math.Node parseTree,
                     int mode)
              throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

initMaps

private void initMaps()

genExpression

private java.util.ArrayList genExpression(jigcell.sbml2.math.Node current)
                                   throws java.lang.Exception
Convert a parse tree into Fortran 90 code. The Fortran 90 code is returned as a list of strings. The list can then be merged and line breaks added to ensure the Fortran 90 line length limit is not exceeded.

When identifiers are reached they are looked up in the symbol table. If a Fortran identifier is not found then an Exception is thrown.

case 1 cn, ci, true, false, exponentiale These are terminal nodes and will return a literal, identifier, or constant.

case 2 eq, neq, gt, lt, geq, leq, divide, power, and, or, times, plus These are nodes with 2 operands. Recursion will be performed on the operands and the first will be placed left of the operator and the second will be placed right of the operator. Parenthesis will be added around a child if it is an operator of lower precidence than the current one.

case 3 minus These are nodes with 1 or 2 operands. If there is only one then the operand is placed to the right of the operator. Otherwise this node is treated like a binary node.

case 4 root, log, xor Special functions that are builtin. Sometimes these are implemented inline because they have no Fortran equivalent.

case 5 abs, exp, ln, floor, ceiling, not, and all Fortran supported trig functions Generate the appropriate Fortran function and pass as an argument the child.

case 6 erf User defined functions with one of these as their name are replaced with a Biopack builtin or Fortran builtin function. This is specific to Biopack and will not work with other simulators.

case 7 function A user defined function with arbitrary arguments. Generate "USERFUNC( ARGS )".

default case csymbol, nan, inf, piecewise, piece, otherwise, diff, pi, factorial These nodes are unrecognized, unhandlable, or not yet implemented and will cause an Exception.

Throws:
java.lang.Exception

getSymbol

private java.lang.String getSymbol(java.lang.String name)
                            throws java.lang.Exception
Follows the correct logic for this CPPExpression to get a symbol for name. Uses the mode to determine how to get the symbol.

Throws:
java.lang.Exception

mergeExpression

public static java.lang.String mergeExpression(java.util.ArrayList expression,
                                               java.lang.String indent,
                                               int width,
                                               java.lang.String prefix)
Merges strings in expression and addes line breaks to maintain a width no greater than width. This method is specific to Fortran code as it adds ampersands at the end of lines.(NOT TRUE NOW) Indent will be added at the begining of each new line (but not the first line). prefix will be added to the very begining of the string before all the strings in expression.


getExpression

public java.lang.String getExpression()

getExpression

public java.lang.String getExpression(java.lang.String indent,
                                      int width)

getExpression

public java.lang.String getExpression(java.lang.String indent,
                                      int width,
                                      java.lang.String prefix)

getOrder

public java.lang.Integer getOrder(jigcell.sbml2.math.Node node)
                           throws java.lang.Exception
Throws:
java.lang.Exception

formatReal

public static java.lang.String formatReal(java.lang.String number)
Takes a number in a string and ensures it ends in "_R8" and has a decimal place. The number could be otherwise illformed and formatReal will not notice.


formatReal

public static java.lang.String formatReal(double number)