XSLPparseformula
XSLPparseformula |
Purpose
Parse a formula written as an unparsed array of tokens into internal parsed (reverse Polish) format
Synopsis
int XPRS_CC XSLPparseformula(XSLPprob Prob, int *inType, double *inValue, int *nToken, int *Type, double *Value);
Arguments
|
Prob
|
The current SLP problem.
|
|
inType
|
Array of token types providing the unparsed formula.
|
|
inValue
|
Array of values corresponding to the types in
inType.
|
|
nToken
|
Address of an integer to receive the number of tokens in the parsed formula (not counting the terminating
XSLP_EOF token). May be
NULL if not required.
|
|
Type
|
Array of token types providing the parsed formula.
|
|
Value
|
Array of values corresponding to the types in
Type.
|
Example
Assuming that
x and
y are already defined as columns with index
iX and
iY respectively, the following example converts the formula "sin(x+y)" into internal parsed format, and then writes it out as a sequence of tokens.
int n, iSin, iX, iY;
int inType[7], Type[20];
double inValue[7], Value[20];
n = 0;
XSLPgetindex(Prob, XSLP_INTERNALFUNCNAMESNOCASE,
"SIN", &iSin);
Type[n] = XSLP_IFUN; Value[n++] = iSin;
Type[n++] = XSLP_LB;
Type[n] = XSLP_COL; Value[n++] = iX;
Type[n] = XSLP_OP; Value[n++] = XSLP_PLUS;
Type[n] = XSLP_COL; Value[n++] = iY;
Type[n++] = XSLP_RB;
Type[n++] = XSLP_EOF;
XSLPparseformula(Prob, inType, inValue,
NULL, Type, Value);
printf("\n");
for (n=0;Type[n] != XSLP_EOF;n++) {
XSLPitemname(Prob, Type[n], Value[n], Buffer);
printf(" %s", Buffer);
}
Further information
For possible token types and values see the chapter on "Formula Parsing".
Related topics
