📄 tokenformulaparser.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: TokenFormulaParser.java
package jxl.biff.formula;
import common.Assert;
import common.Logger;
import java.util.Stack;
import jxl.Cell;
import jxl.WorkbookSettings;
import jxl.biff.WorkbookMethods;
// Referenced classes of package jxl.biff.formula:
// ParseItem, FormulaException, CellReference, CellReferenceError,
// SharedFormulaCellReference, CellReference3d, Area, SharedFormulaArea,
// Area3d, Name, NameRange, IntegerValue,
// DoubleValue, BooleanValue, StringValue, MissingArg,
// UnaryPlus, UnaryMinus, Percent, Subtract,
// Add, Multiply, Divide, Concatenate,
// Power, LessThan, LessEqual, GreaterThan,
// GreaterEqual, NotEqual, Equal, Parenthesis,
// Attribute, BuiltInFunction, VariableArgFunction, MemFunc,
// Parser, Token, Function, Operator,
// ExternalSheet
class TokenFormulaParser
implements Parser
{
private static Logger logger;
private byte tokenData[];
private Cell relativeTo;
private int pos;
private ParseItem root;
private Stack tokenStack;
private ExternalSheet workbook;
private WorkbookMethods nameTable;
private WorkbookSettings settings;
static Class class$jxl$biff$formula$TokenFormulaParser; /* synthetic field */
public TokenFormulaParser(byte data[], Cell c, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws)
{
tokenData = data;
pos = 0;
relativeTo = c;
workbook = es;
nameTable = nt;
tokenStack = new Stack();
settings = ws;
Assert.verify(nameTable != null);
}
public void parse()
throws FormulaException
{
parseSubExpression(tokenData.length);
root = (ParseItem)tokenStack.pop();
Assert.verify(tokenStack.empty());
}
private void parseSubExpression(int len)
throws FormulaException
{
int tokenVal = 0;
Token t = null;
Stack ifStack = new Stack();
int endpos = pos + len;
do
{
if(pos >= endpos)
break;
tokenVal = tokenData[pos];
pos++;
t = Token.getToken(tokenVal);
if(t == Token.UNKNOWN)
throw new FormulaException(FormulaException.UNRECOGNIZED_TOKEN, tokenVal);
Assert.verify(t != Token.UNKNOWN);
if(t == Token.REF)
{
CellReference cr = new CellReference(relativeTo);
pos += cr.read(tokenData, pos);
tokenStack.push(cr);
} else
if(t == Token.REFERR)
{
CellReferenceError cr = new CellReferenceError();
pos += cr.read(tokenData, pos);
tokenStack.push(cr);
} else
if(t == Token.REFV)
{
SharedFormulaCellReference cr = new SharedFormulaCellReference(relativeTo);
pos += cr.read(tokenData, pos);
tokenStack.push(cr);
} else
if(t == Token.REF3D)
{
CellReference3d cr = new CellReference3d(relativeTo, workbook);
pos += cr.read(tokenData, pos);
tokenStack.push(cr);
} else
if(t == Token.AREA)
{
Area a = new Area();
pos += a.read(tokenData, pos);
tokenStack.push(a);
} else
if(t == Token.AREAV)
{
SharedFormulaArea a = new SharedFormulaArea(relativeTo);
pos += a.read(tokenData, pos);
tokenStack.push(a);
} else
if(t == Token.AREA3D)
{
Area3d a = new Area3d(workbook);
pos += a.read(tokenData, pos);
tokenStack.push(a);
} else
if(t == Token.NAME)
{
Name n = new Name();
pos += n.read(tokenData, pos);
tokenStack.push(n);
} else
if(t == Token.NAMED_RANGE)
{
NameRange nr = new NameRange(nameTable);
pos += nr.read(tokenData, pos);
tokenStack.push(nr);
} else
if(t == Token.INTEGER)
{
IntegerValue i = new IntegerValue();
pos += i.read(tokenData, pos);
tokenStack.push(i);
} else
if(t == Token.DOUBLE)
{
DoubleValue d = new DoubleValue();
pos += d.read(tokenData, pos);
tokenStack.push(d);
} else
if(t == Token.BOOL)
{
BooleanValue bv = new BooleanValue();
pos += bv.read(tokenData, pos);
tokenStack.push(bv);
} else
if(t == Token.STRING)
{
StringValue sv = new StringValue(settings);
pos += sv.read(tokenData, pos);
tokenStack.push(sv);
} else
if(t == Token.MISSING_ARG)
{
MissingArg ma = new MissingArg();
pos += ma.read(tokenData, pos);
tokenStack.push(ma);
} else
if(t == Token.UNARY_PLUS)
{
UnaryPlus up = new UnaryPlus();
pos += up.read(tokenData, pos);
addOperator(up);
} else
if(t == Token.UNARY_MINUS)
{
UnaryMinus um = new UnaryMinus();
pos += um.read(tokenData, pos);
addOperator(um);
} else
if(t == Token.PERCENT)
{
Percent p = new Percent();
pos += p.read(tokenData, pos);
addOperator(p);
} else
if(t == Token.SUBTRACT)
{
Subtract s = new Subtract();
pos += s.read(tokenData, pos);
addOperator(s);
} else
if(t == Token.ADD)
{
Add s = new Add();
pos += s.read(tokenData, pos);
addOperator(s);
} else
if(t == Token.MULTIPLY)
{
Multiply s = new Multiply();
pos += s.read(tokenData, pos);
addOperator(s);
} else
if(t == Token.DIVIDE)
{
Divide s = new Divide();
pos += s.read(tokenData, pos);
addOperator(s);
} else
if(t == Token.CONCAT)
{
Concatenate c = new Concatenate();
pos += c.read(tokenData, pos);
addOperator(c);
} else
if(t == Token.POWER)
{
Power p = new Power();
pos += p.read(tokenData, pos);
addOperator(p);
} else
if(t == Token.LESS_THAN)
{
LessThan lt = new LessThan();
pos += lt.read(tokenData, pos);
addOperator(lt);
} else
if(t == Token.LESS_EQUAL)
{
LessEqual lte = new LessEqual();
pos += lte.read(tokenData, pos);
addOperator(lte);
} else
if(t == Token.GREATER_THAN)
{
GreaterThan gt = new GreaterThan();
pos += gt.read(tokenData, pos);
addOperator(gt);
} else
if(t == Token.GREATER_EQUAL)
{
GreaterEqual gte = new GreaterEqual();
pos += gte.read(tokenData, pos);
addOperator(gte);
} else
if(t == Token.NOT_EQUAL)
{
NotEqual ne = new NotEqual();
pos += ne.read(tokenData, pos);
addOperator(ne);
} else
if(t == Token.EQUAL)
{
Equal e = new Equal();
pos += e.read(tokenData, pos);
addOperator(e);
} else
if(t == Token.PARENTHESIS)
{
Parenthesis p = new Parenthesis();
pos += p.read(tokenData, pos);
addOperator(p);
} else
if(t == Token.ATTRIBUTE)
{
Attribute a = new Attribute(settings);
pos += a.read(tokenData, pos);
if(a.isSum())
addOperator(a);
else
if(a.isIf())
ifStack.push(a);
} else
if(t == Token.FUNCTION)
{
BuiltInFunction bif = new BuiltInFunction(settings);
pos += bif.read(tokenData, pos);
addOperator(bif);
} else
if(t == Token.FUNCTIONVARARG)
{
VariableArgFunction vaf = new VariableArgFunction(settings);
pos += vaf.read(tokenData, pos);
if(vaf.getFunction() != Function.ATTRIBUTE)
{
addOperator(vaf);
} else
{
vaf.getOperands(tokenStack);
Attribute ifattr = null;
if(ifStack.empty())
ifattr = new Attribute(settings);
else
ifattr = (Attribute)ifStack.pop();
ifattr.setIfConditions(vaf);
tokenStack.push(ifattr);
}
} else
if(t == Token.MEM_FUNC)
{
MemFunc memFunc = new MemFunc();
pos += memFunc.read(tokenData, pos);
Stack oldStack = tokenStack;
tokenStack = new Stack();
parseSubExpression(memFunc.getLength());
ParseItem subexpr[] = new ParseItem[tokenStack.size()];
for(int i = 0; !tokenStack.isEmpty(); i++)
subexpr[i] = (ParseItem)tokenStack.pop();
memFunc.setSubExpression(subexpr);
tokenStack = oldStack;
tokenStack.push(memFunc);
}
} while(true);
}
private void addOperator(Operator o)
{
o.getOperands(tokenStack);
tokenStack.push(o);
}
public String getFormula()
{
StringBuffer sb = new StringBuffer();
root.getString(sb);
return sb.toString();
}
public void adjustRelativeCellReferences(int colAdjust, int rowAdjust)
{
root.adjustRelativeCellReferences(colAdjust, rowAdjust);
}
public byte[] getBytes()
{
return root.getBytes();
}
public void columnInserted(int sheetIndex, int col, boolean currentSheet)
{
root.columnInserted(sheetIndex, col, currentSheet);
}
public void columnRemoved(int sheetIndex, int col, boolean currentSheet)
{
root.columnRemoved(sheetIndex, col, currentSheet);
}
public void rowInserted(int sheetIndex, int row, boolean currentSheet)
{
root.rowInserted(sheetIndex, row, currentSheet);
}
public void rowRemoved(int sheetIndex, int row, boolean currentSheet)
{
root.rowRemoved(sheetIndex, row, currentSheet);
}
static Class class$(String x0)
{
return Class.forName(x0);
ClassNotFoundException x1;
x1;
throw new NoClassDefFoundError(x1.getMessage());
}
static
{
logger = Logger.getLogger(class$jxl$biff$formula$TokenFormulaParser != null ? class$jxl$biff$formula$TokenFormulaParser : (class$jxl$biff$formula$TokenFormulaParser = class$("jxl.biff.formula.TokenFormulaParser")));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -