SPRAAK
|
Evaluation of expressions and handling of variables. More...
Data Structures | |
struct | SprVarlist |
Typedefs | |
typedef float | SprFevalReal |
Functions | |
SprVarlist * | spr_feval_var_init (SprVarlist *var_ptr, const char *name) |
SprVarlist * | spr_feval_var_clear (SprVarlist *var_ptr) |
int | spr_feval_result_set (SprVarlist *res_ptr, int type,...) |
SprVarlist * | spr_feval_var_new (const char *name, int type,...) |
SprVarlist * | spr_feval_var_add (SprVarlist *varlist, SprVarlist *argptr) |
Add an item to the list of known variables. More... | |
void | spr_feval_var_free (SprVarlist *var_ptr) |
SprVarlist * | spr_feval_var_rm (SprVarlist *varlist, SprVarlist *var_ptr) |
SprVarlist * | spr_feval_varlist_free (SprVarlist *varlist, SprVarlist *upto) |
SprVarlist * | spr_feval_var_get (SprVarlist *varlist, const char *name, int length) |
int | spr_feval_var_set (SprVarlist *var_ptr, int type,...) |
SprVarlist * | spr_feval_var_assign (SprVarlist *varlist, const char *name, int type,...) |
void | spr_feval_whos (SprStream *fd, SprVarlist *varlist, const char *name) |
void | spr_feval_var_print (SprStream *fd, const SprVarlist *var_ptr, const char *rm) |
Print a variable. More... | |
char * | spr_feval (const char *eval_str, const char *eval_end, SprVarlist *varlist, SprVarlist *res, int flags) |
SprFevalReal | spr_feval_num (const char *eval_str, const char *eval_end, SprVarlist *varlist, int *err_ret) |
char * | spr_feval_var_substitute (const char *str, SprVarlist *list, int flags) |
Variables | |
const SprVarlist | spr_feval_empty_res |
SprVarlist * | spr_feval_global_var |
Evaluation of expressions and handling of variables.
The feval module is an expandable expression evaluator for both scalars and vectors. Next to the expression evaluator, routines are provided to faciliate the use of the expression evaluator in existing programs, and to handle the variable lists used by the expression evaluator.
Except for some vector extensions, the syntax of the expressions is the same as in the program language C. Also the C-convention for indexing is used (the first element has index 0). Strings are stored and handled as vectors. Functions are treated as variables. The only allowable operators for functions are function evaluations (e.g. "f(x)") and assignements (e.g. "f=sin").
The following operators are specific for vector operations:
Examples: 1:10 == [1,2,3,4,5,6,7,8,9,10] 0:-1:10 == [0,-1,-2,-3,-4,-5,-6,-7,-8,-9] 1:0:10 == [1,1,1,1,1,1,1,1,1,1] [0,8]:2:4 == [0,8,2,10,4,12,6,14]
All other operators are expanded to work with vectors.
Examples: (assume x=[0,1,2,4], y=[9,1,0,4] and z=[1,2]) x+y == [9,2,2,8] x+1 == [1,2,3,5] x+z results in an error x == y == [0,1,0,1] x == z results in an error x[z] = y[z] set x[1] to y[1] and x[2] to y[2] x[z] = 1 results in an error sqrt(y) == [3,1,0,2] "abcd"[z] == "bc"
The priority of the operands is:
brackets and vectors (), [] functions and indexing (), [] unary operators -, ~, ! power ^ multiplicative operations *, /, % additive operations +, - matrix step and repeat operator : relational operators ==, !=, >=, <= ,> ,< binary and & binary or | logical and && logical or || matrix concatenation operator , function argument separator , assignment operators =, ^=, *=, /=, %=, +=, -=, &=, |= left to rigth evaluation ,
Assignments and unary operators are evaluated from right to left, all other operators are evaluated from left to right.
At this moment, the following constants and functions are defined:
- E base of natural logarithms - PI 3.1415926535897... - EPS floating point relative accuracy - MIN minimal floating point value - MAX maximal floating point value - sin, cos, tan triogoniometric functions - asin, acos, atan inv. triogoniometric functions - exp, log, log10 exponent and logarithms - sqrt square root - floor, ceil, round conversion to integer values - abs absolute value - sum, prod sum/product of a vector - cumsum, cumprod cumulative sum/product - norm euclidian length of a vector - max, min, imax, imin find maximum or minimum - sort, isort sort the elements in a vector - size the size of a vector - isscalar, isvec, isvar, type/attributes of a variable isstr, isfun, isundef - strcmp(str1,str2) compare two strings