jigcell.sbml2.math
Class InfixExpression

java.lang.Object
  extended by jigcell.sbml2.math.InfixExpression

public class InfixExpression
extends java.lang.Object

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

Author:
Jason Zwolak, Nicholas Allen

Field Summary
private static java.util.Hashtable associative
           
static int DONT_LOOKUP_SYMBOLS
           
private  java.util.ArrayList expression
           
private  SymbolTable localSymbols
           
private  boolean lookupSymbols
           
private static java.util.Hashtable map
           
static int NORMAL
           
private static java.util.Hashtable order
           
private  SymbolTable symbolTable
           
 
Constructor Summary
InfixExpression(MathMLExpression mathML)
           
InfixExpression(Node parseTree)
           
InfixExpression(Node parseTree, int mode)
           
InfixExpression(SymbolTable st, MathMLExpression mathML)
           
InfixExpression(SymbolTable st, Node parseTree)
           
InfixExpression(SymbolTable ls, SymbolTable st, MathMLExpression mathML)
           
InfixExpression(SymbolTable ls, SymbolTable st, Node parseTree)
           
InfixExpression(SymbolTable ls, SymbolTable st, Node parseTree, int mode)
           
 
Method Summary
private  java.util.ArrayList genExpression(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(Node node)
           
private static 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.
static void modifyMap(java.lang.String function, java.lang.String targetFunction)
          Changes the function map to map function to targetFunction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lookupSymbols

private boolean lookupSymbols

expression

private java.util.ArrayList expression

symbolTable

private SymbolTable symbolTable

localSymbols

private SymbolTable localSymbols

map

private static java.util.Hashtable map

order

private static java.util.Hashtable order

associative

private static java.util.Hashtable associative

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

InfixExpression

public InfixExpression(SymbolTable ls,
                       SymbolTable st,
                       Node parseTree,
                       int mode)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(SymbolTable ls,
                       SymbolTable st,
                       Node parseTree)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(SymbolTable ls,
                       SymbolTable st,
                       MathMLExpression mathML)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(SymbolTable st,
                       MathMLExpression mathML)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(SymbolTable st,
                       Node parseTree)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(MathMLExpression mathML)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(Node parseTree)
                throws java.lang.Exception
Throws:
java.lang.Exception

InfixExpression

public InfixExpression(Node parseTree,
                       int mode)
                throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

initMaps

private static void initMaps()

modifyMap

public static void modifyMap(java.lang.String function,
                             java.lang.String targetFunction)
                      throws java.lang.Exception
Changes the function map to map function to targetFunction. For example: if you have the ln function its default map is to the log function. You can call this function to change its map to be something else like the ln function. The call looks like: modifyMap("ln","ln"). To change it back call modifyMap("ln","log"). NOTE: map is static so the changes affect all InfixExpressions.

Throws:
java.lang.Exception

genExpression

private java.util.ArrayList genExpression(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 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

getOrder

public java.lang.Integer getOrder(Node node)
                           throws java.lang.Exception
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. Indent will be added at the begining of each new line (but not the first line).


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)