Parsed and unparsed formulae
All formulae input into Xpress NonLinear are parsed into a reverse-Polish execution stack. Tokens are identified by their type and a value. The table below shows the values used in interface functions.
All formulae are provided in the interface functions as two parallel arrays:
  an integer array of token types;
  a double array of token values. 
The last token type in the array should be an end-of-formula token (XSLP_EOF, which evaluates to zero).
If the value required is an integer, it should still be provided in the array of token values as a double precision value.
Even if a token type requires no token value, it is best practice to initialize such values as zeros.
| Type | Description | Value | 
|---|---|---|
| XSLP_COL | column | index of matrix column. | 
| XSLP_CON | constant | (double) value. | 
| XSLP_CONSTRAINT | constraint | index of constraint. Note that constraints count from 1, so that the index of matrix row n is n + 1. | 
| XSLP_CV | character variable | index of character variable. | 
| XSLP_DEL | delimiter | XSLP_COMMA (1) = comma (",") | 
| XSLP_COLON (2) = colon (":") | ||
| XSLP_EOF | end of formula | not required: use zero | 
| XSLP_FUN | user function | index of function | 
| XSLP_IFUN | internal function | index of function | 
| XSLP_LB | left bracket | not required: use zero | 
| XSLP_OP | operator | XSLP_UMINUS (1) = unary minus ("-") | 
| XSLP_EXPONENT (2) = exponent ("**" or "^") | ||
| XSLP_MULTIPLY (3) = multiplication ("*") | ||
| XSLP_DIVIDE (4) = division ("/") | ||
| XSLP_PLUS (5) = addition ("+") | ||
| XSLP_MINUS (6) = subtraction ("-") | ||
| XSLP_RB | right bracket | not required: use zero | 
| XSLP_ROW | row | index of matrix row. | 
| XSLP_STRING | character string | internal index of character string | 
| XSLP_UNKNOWN | unidentified token | internal index of character string | 
| XSLP_VAR | variable | index of variable. Note that variables count from 1, so that the index of matrix column n is n + 1. | 
| XSLP_VARREF | reference to variable | index of variable. Note that variables count from 1, so that the index of matrix column n is n + 1. | 
| XSLP_UFARGTYPE | requirements and types of argument for a user function | bitmap of types (see below). | 
| XSLP_UFEXETYPE | linkage of a user function | bitmap of linkage information (see below). | 
Argument types for user function definition are stored as a bit map. Each type is stored in 3 bits: bits 0-2 for argument 1, bits 3-5 for argument 2 and so on. The possible values for each argument are as follows:
| 0 | omitted | 
| 1 | NULL | 
| 2 | INTEGER | 
| 3 | DOUBLE | 
| 4 | VARIANT | 
| 6 | CHAR | 
The linkage type and other function information are stored as a bit map as follows:
| Bits 0-2 | type of linkage: | 
| 1 = User library or DLL | |
| 2 = Excel spreadsheet | |
| 3 = Excel macro | |
| 5 = MOSEL | |
| 7 = COM | |
| Bits 3-4 | re-evaluation flags: | 
| 0 = default | |
| 1 (Bit 3) = re-evaluation at each SLP iteration | |
| 2 (Bit 4) = re-evaluation when independent variables are outside tolerance | |
| Bits 6-7 | derivative flags: | 
| 0 = default | |
| 1 (Bit 6) = tangential derivatives | |
| 2 (Bit 7) = forward derivatives | |
| Bit 8 | calling mechanism: | 
| 0 = standard | |
| 1 = CDECL (Windows only) | |
| Bit 24 | set if the function is multi-valued | 
| Bit 28 | set if the function is not differentiable | 
Token types XSLP_ROW and XSLP_COL are used only when passing formulae into Xpress NonLinear. Any formulae recovered from Xpress NonLinear will use the XSLP_CONSTRAINT and XSLP_VAR token types which always count from 1.
When a formula is passed to Xpress NonLinear in "internal unparsed format" — that is, with the formula already converted into tokens — the full range of token types is permitted.
When a formula is passed to Xpress NonLinear in "parsed format" — that is, in reverse Polish — the following rules apply:
 
| XSLP_DEL | comma is optional. | 
| XSLP_FUN | implies a following left-bracket, which is not included explicitly. | 
| XSLP_IFUN | implies a following left-bracket, which is not included explicitly. | 
| XSLP_LB | never used. | 
| XSLP_RB | only used to terminate the list of arguments to a function. | 
Brackets are not used in the reverse Polish representation of the formula: the order of evaluation is determined by the order of the items on the stack. Functions which need the brackets — for example XSLPgetccoef — fill in brackets as required to achieve the correct evaluation order. The result may not match the formula as originally provided.
Token type XSLP_UNKNOWN is returned by the parsing routines when a string cannot be identified as any other type of token. Token type XSLP_STRING is returned by the parsing routine where the token has been specifically identified as being a character string: the only case where this occurs at present is in the names of return arguments from user-defined multi-valued functions. The "value" field for both these token types is an index into the Xpress NonLinear string table and can be accessed using the XSLPgetstring function.
 
