private Ptg getFunction(String name,byte numArgs) {
Ptg retval = null;
- retval = new FuncVarPtg(name,numArgs);
- /** if (numArgs == 1 && name.equals("SUM")) {
+ //retval = new FuncVarPtg(name,numArgs);
+ if (name.equals("IF")) {
AttrPtg ptg = new AttrPtg();
- ptg.setData((short)1); //sums don't care but this is what excel does.
- ptg.setSum(true);
+ ptg.setData((short)6); //sums don't care but this is what excel does.
+ ptg.setOptimizedIf(true);
retval = ptg;
} else {
retval = new FuncVarPtg(name,numArgs);
- }*/
+ }
return retval;
}
/** Parse and Translate a Math Term */
private void Term(){
Factor();
- while (Look == '*' || Look == '/' || Look == '^' || Look == '&') {
+ while (Look == '*' || Look == '/' || Look == '^' || Look == '&' || Look == '=' ) {
///TODO do we need to do anything here??
if (Look == '*') Multiply();
if (Look == '/') Divide();
if (Look == '^') Power();
if (Look == '&') Concat();
+ if (Look == '=') Equal();
}
}
tokens.add(new AddPtg());
}
- /** Recognize and Translate an Add */
+ /** Recognize and Translate a Concatination */
private void Concat() {
Match('&');
Term();
tokens.add(new ConcatPtg());
}
-
+ /** Recognize and Translate a test for Equality */
+ private void Equal() {
+ Match('=');
+ Term();
+ tokens.add(new EqualPtg());
+ }
/** Recognize and Translate a Subtract */
private void Subtract() {
protected byte field_1_num_args;
protected short field_2_fnc_index;
-
-
+
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer
}
public String getName() {
+ if(field_2_fnc_index != 1) {
return lookupName(field_2_fnc_index);
+ } else {
+ return "Funky case of formula recombinating";
+ }
}
public String toFormulaString(SheetReferences refs) {
public String toFormulaString(String[] operands) {
StringBuffer buf = new StringBuffer();
- buf.append(getName()+"(");
- if (operands.length >0) {
- for (int i=0;i<operands.length;i++) {
- buf.append(operands[i]);
- buf.append(',');
- }
- buf.deleteCharAt(buf.length()-1);
- }
+ if (field_2_fnc_index != 1) {
+ buf.append(getName()+"(");
+ if (operands.length >0) {
+ for (int i=0;i<operands.length;i++) {
+ buf.append(operands[i]);
+ buf.append(',');
+ }
+ buf.deleteCharAt(buf.length()-1);
+ }
buf.append(")");
+ } else {
+ throw new RuntimeException("FUNKY CASE OF FORMULA RECOMBINATION NOT "+
+ "YET IMPLEMENTED");
+
+ }
return buf.toString();
}
field_1_options=sum.setByteBoolean(field_1_options,bsum);
}
+ public void setOptimizedIf(boolean bif) {
+ field_1_options=optiIf.setByteBoolean(field_1_options,bif);
+ }
+
// lets hope no one uses this anymore
public boolean isBaxcel()
{
public String toFormulaString(String[] operands) {
if(space.isSet(field_1_options)) {
return operands[ 0 ];
- }
- else {
+ } else if (optiIf.isSet(field_1_options)) {
+ return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] +")";
+ } else {
return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")";
}
}
case PowerPtg.sid :
retval = new PowerPtg(data, offset);
break;
+
+ case EqualPtg.sid:
+ retval = new EqualPtg(data, offset);
+ break;
case ConcatPtg.sid :
retval = new ConcatPtg(data, offset);