* @param cTree the c tree
* @param skip the skip
* @param hasMinus the has minus
*/
public void convertCommonTreeToEUnit( EDBUnit eq, CommonTree cTree, boolean skip, boolean hasMinus ){
EDBUnit echild = eq;
//if cTree is "-", then check its child.
//if its child is a character such as "X", then put "*" and put "-1" and "X" as child.
//if its child is a number such as "3, then change it as "-3"
//EX] 1-X => 1 + -1 * X
//if it has child1 and child2, put +, set MinusOne command. And then next iteration of child2
//use the command
//EX] -X => -1 * X
//if it has just one child1, do MinusOne command
//EX] -0.5*X => -0.5 * X
//
if( cTree.toString().equalsIgnoreCase("-") ){
//iteration
CommonTree child1 = (CommonTree) cTree.getChild(0);
CommonTree child2 = (CommonTree) cTree.getChild(1);
if( child1 != null && child2 == null && CPSMath.isNum(child1.toString())){
if( CPSMath.isNum(child1.toString()) ){
echild = eq.createDummy( "-" + child1.toString() );
convertCommonTreeToEUnit( echild, child1, true, false );
return;
}
}
if( child1 != null && child2 != null && CPSMath.isNum(child2.toString())){
EDBUnit eNew = eq.createDummy( "+" );
echild = eNew.createDummy( "-" + child2.toString() );
convertCommonTreeToEUnit( eNew, child1, false, false );
convertCommonTreeToEUnit( echild, child2, true, false );
return;
}
if( child1 != null && child2 != null && isOperater(child2.toString())){
EDBUnit eNew = eq.createDummy( "+" );
convertCommonTreeToEUnit( eNew, child1, false, false );
convertCommonTreeToEUnit( eNew, child2, false, true );
return;
}
}
if( hasMinus ){
EDBUnit eNew = eq.createDummy(cTree.toString());
CommonTree child1 = (CommonTree) cTree.getChild(0);
CommonTree child2 = (CommonTree) cTree.getChild(1);
if( CPSMath.isNum(child1.toString())){
echild = eNew.createDummy( "-" + child1.toString() );
convertCommonTreeToEUnit( echild, child1, true, false );
convertCommonTreeToEUnit( eNew, child2, false, false );
return;
}
}