Initializing help system before first use

XSLPpreparseformula

XSLPpreparseformula


Purpose
Perform an initial scan of a formula written as a character string, identifying the operators but not attempting to identify the types of the individual tokens
Synopsis
int XPRS_CC XSLPpreparseformula(XSLPprob Prob, char *Formula, int *nToken, int *Type, double *Value, char *StringTable, int *SizeTable);
Arguments
Prob 
The current SLP problem.
Formula 
Character string containing the formula, written in the same free-format style as formulae in Extended MPS format, with spaces separating tokens.
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.
StringTable 
Character buffer to receive the names of the unidentified tokens.
SizeTable 
Address of an integer variable to hold the size of StringTable actually used. May be NULL if not required.
Example
The following example converts the formula "sin(x+y)" into internal parsed format without trying to identify the tokens apart from operands and numbers, and then writes it out as a sequence of tokens.
int n, Type[20];
double Value[20];
char Strings[200];
XSLPpreparseformula(Prob, "sin ( x + y )", NULL,
                    Type, Value, Strings, NULL);
printf("\n");
for (n=0;Type[n] != XSLP_EOF;n++) {
  if (Type[n] == XSLP_UNKNOWN)
    printf("\n? %s",Strings[(int)Value[n]]);
  else {
    XSLPitemname(Prob, Type[n], Value[n], Buffer);
    printf(" %s", Buffer);
  }
}
Further information

Only operands and numbers are identified by XSLPpreparseformula. All other operands, including names of variables, functions are left as strings of type XSLP_UNKNOWN. The Value of such a type is the index in StringTable of the start of the token name.

The parsed formula can be converted into a calculable formula by replacing the XSLP_UNKNOWN tokens by the correct types and values.


Related topics