public class FormulaParser extends Object
Modifier and Type | Field and Description |
---|---|
private Workbook |
book |
private static char |
CR |
static int |
FORMULA_TYPE_ARRAY |
static int |
FORMULA_TYPE_CELL |
static int |
FORMULA_TYPE_CONDFOMRAT |
static int |
FORMULA_TYPE_NAMEDRANGE |
static int |
FORMULA_TYPE_SHARED |
private int |
formulaLength |
private String |
formulaString |
private List |
functionTokens
Using an unsynchronized linkedlist to implement a stack since we're not multi-threaded.
|
private char |
look |
private int |
pointer |
private static char |
TAB |
private List |
tokens |
Constructor and Description |
---|
FormulaParser(String formula,
Workbook book)
Create the formula parser, with the string that is to be
parsed against the supplied workbook.
|
Modifier and Type | Method and Description |
---|---|
private void |
Abort(String s)
Report Error and Halt
|
private void |
Add()
Recognize and Translate an Add
|
private void |
addArgumentPointer()
Adds a pointer to the last token to the latest function argument list.
|
private int |
Arguments()
get arguments to a function
|
private void |
Concat()
Recognize and Translate a Concatination
|
private Node |
createTree()
Create a tree representation of the RPN token array
used to run the class(RVA) change algo
|
private void |
Divide()
Recognize and Translate a Divide
|
private void |
Emit(String s)
Output a String with Tab
|
private void |
EmitLn(String s)
Output a String with Tab and CRLF
|
private void |
Equal()
Recognize and Translate a test for Equality
|
private void |
Error(String s)
Report an Error
|
private void |
Expected(String s)
Report What Was Expected
|
private void |
Expression()
Parse and Translate an Expression
|
private void |
Factor()
Parse and Translate a Math Factor
|
private void |
function(String name) |
private void |
GetChar()
Read New Character From Input Stream
|
private AbstractFunctionPtg |
getFunction(String name,
byte numArgs)
Generates the variable function ptg for the formula.
|
private String |
GetName()
Get an Identifier
|
private String |
GetNameAsIs()
Get an Identifier AS IS, without stripping white spaces or
converting to uppercase; used for literals
|
private String |
GetNum()
Get a Number
|
private Ptg |
getNumberPtgFromString(String number1,
String number2,
String exponent)
Get a PTG for an integer from its string representation.
|
private int |
getPtgSize(int index)
Adds the size of all the ptgs after the provided index (inclusive).
|
private int |
getPtgSize(int start,
int end) |
Ptg[] |
getRPNPtg()
API call to retrive the array of Ptgs created as
a result of the parsing
|
Ptg[] |
getRPNPtg(int formulaType) |
private void |
GreaterEqual()
Recognize and translate Greater than or Equal
|
private void |
GreaterThan()
Recognize and Translate a Greater Than
|
private void |
Ident()
Parse and Translate a String Identifier
|
private void |
init()
Initialize
|
private boolean |
IsAddop(char c)
Recognize an Addop
|
private boolean |
IsAlNum(char c)
Recognize an Alphanumeric
|
private boolean |
IsAlpha(char c)
Recognize an Alpha Character
|
private boolean |
IsDigit(char c)
Recognize a Decimal Digit
|
private boolean |
IsSpecialChar(char c)
Determines special characters;primarily in use for definition of string literals
|
private boolean |
IsWhite(char c)
Recognize White Space
|
private void |
LessEqual()
Recognize and translate Less than or Equal
|
private void |
LessThan()
Recognize and Translate a Less Than
|
private void |
Match(char x)
Match a Specific Input Character
|
private void |
Multiply()
Recognize and Translate a Multiply
|
private void |
NotEqual()
Recognize and not Equal
|
void |
parse()
API call to execute the parsing of the formula
|
private void |
Power() |
private void |
setClass(Node n,
byte theClass) |
private void |
setParameterRVA(Node n,
int formulaType) |
private void |
setParameterRVA(Node n,
int expectedClass,
int formulaType) |
private void |
setRootLevelRVA(Node n,
int formulaType) |
private void |
SkipWhite()
Skip Over Leading White Space
|
private void |
StringLiteral() |
private void |
Subtract()
Recognize and Translate a Subtract
|
private void |
Term()
Parse and Translate a Math Term
|
String |
toFormulaString(List lptgs)
Convience method which takes in a list then passes it to the
other toFormulaString signature.
|
String |
toFormulaString(Ptg[] ptgs)
Static method to convert an array of Ptgs in RPN order
to a human readable string format in infix mode.
|
static String |
toFormulaString(Workbook book,
List lptgs)
Convience method which takes in a list then passes it to the
other toFormulaString signature.
|
static String |
toFormulaString(Workbook book,
Ptg[] ptgs)
Static method to convert an array of Ptgs in RPN order
to a human readable string format in infix mode.
|
String |
toString()
toString on the parser instance returns the RPN ordered list of tokens
Useful for testing
|
public static int FORMULA_TYPE_CELL
public static int FORMULA_TYPE_SHARED
public static int FORMULA_TYPE_ARRAY
public static int FORMULA_TYPE_CONDFOMRAT
public static int FORMULA_TYPE_NAMEDRANGE
private String formulaString
private int pointer
private int formulaLength
private List tokens
private List functionTokens
private static char TAB
private static char CR
private char look
private Workbook book
public FormulaParser(String formula, Workbook book)
private void GetChar()
private void Error(String s)
private void Abort(String s)
private void Expected(String s)
private boolean IsAlpha(char c)
private boolean IsDigit(char c)
private boolean IsAlNum(char c)
private boolean IsAddop(char c)
private boolean IsWhite(char c)
private boolean IsSpecialChar(char c)
c
- private void SkipWhite()
private void Match(char x)
private String GetName()
private String GetNameAsIs()
private String GetNum()
private void Emit(String s)
private void EmitLn(String s)
private void Ident()
private void addArgumentPointer()
private void function(String name)
private int getPtgSize(int index)
Initially used to count a goto
index
- private int getPtgSize(int start, int end)
private AbstractFunctionPtg getFunction(String name, byte numArgs)
For IF Formulas, additional PTGs are added to the tokens
name
- numArgs
- private int Arguments()
private void Factor()
private Ptg getNumberPtgFromString(String number1, String number2, String exponent)
private void StringLiteral()
private void Multiply()
private void Divide()
private void Term()
private void Add()
private void Concat()
private void Equal()
private void Subtract()
private void Power()
private void Expression()
private void GreaterThan()
private void LessThan()
private void GreaterEqual()
private void LessEqual()
private void NotEqual()
private void init()
public void parse()
public Ptg[] getRPNPtg()
public Ptg[] getRPNPtg(int formulaType)
private void setRootLevelRVA(Node n, int formulaType)
private void setParameterRVA(Node n, int formulaType)
private void setParameterRVA(Node n, int expectedClass, int formulaType)
private void setClass(Node n, byte theClass)
public static String toFormulaString(Workbook book, List lptgs)
book
- workbook for 3D and named referenceslptgs
- list of Ptg, can be null or emptypublic String toFormulaString(List lptgs)
lptgs
- list of Ptg, can be null or emptypublic static String toFormulaString(Workbook book, Ptg[] ptgs)
book
- workbook for named and 3D referencesptgs
- array of Ptg, can be null or emptypublic String toFormulaString(Ptg[] ptgs)
ptgs
- array of Ptg, can be null or emptyprivate Node createTree()
Copyright © 2015 Open Microscopy Environment