Home| general |src.lib|eval| Eval Index

Eval

Syntax
int Eval(char *sum,double *ptr,int (*dvar)(char *ptr,double *val,void *data),void *vdata,int (*dfun)(char *ptr,int argnum,double *argptr,double *val,void *data),void *fdata);
Header
general/reval.h
Library
reval
Description

The Eval function evaluates a mathematical expression.

The zero terminated string pointed to by the argument sum contains the expression to evaluate. The result is stored at the location pointed to by the argument result.

The argument dvar is a pointer to a function of the form:

int (*dvar) (char *str,double *val,void *data);

This function returns the value of each operand in the expression. The zero terminated string pointed to by str contains the operand. If the operand is a simple numeric value, the function should evaluate it and store the value at the location pointed to by val. If the operand is a variable name the function should set val to the value of this variable.

The vdata argument of the eval function is passed directly as the data argument of the dvar function.

If the operand is successfully evaluated the function should return zero, otherwise a non-zero value should be returned.

The argument dfun is a pointer to a function of the form:

int (*dfun) (char *str,int argnum,double *argptr,double *val,void *data);

This function evaluates a function call within an expression. The zero terminated string pointed to by str contains the name of the function. The argument argnum gives the number of arguments passed to the function, and the argument argptr contains an array of pointers to the actual arguments. The function should be evaluated and the value returned stored at the location pointed to by val.

The fdata argument of the eval function is passed directly as the data argument of the dfun function.

If the function is successfully evaluated then zero should be returned, otherwise a non-zero value should be returned.

Returns
Returns zero on success. On error, a non-zero value indicating the error is returned.
Errors

On error, a non-zero value indicating the error is returned:

Return ValueMeaning
0Success.
2Mismatched parentheses.
3Unrecognized operand or variable.
4Unrecognize function.
Example

Source Code: Eval.c