The kexpr library (libkexpr.a) provides the routines that make up Expression services. It provides a symbolic mathematical expression parser implemented using Lex and YACC. It contains routines to set variables, to parse mathematical expressions utilizing variables that have been previously set, and to evaluate these expressions. The expression parser supports a full variety of data types, including byte, unsigned byte, short, unsigned short, integer, unsigned integer, long, unsigned long, float, double, complex, double complex, and string.
The expression parser is used by cantata visual language to handle the functions used with control loops, and by the xprism plotting package to evaluate user-defined functions. It is also by the image object to allow the user to display functions of map columns as red, green, and blue.
Any application that implements interactive mathematical computation would find the functions provided by math services invaluable. In such an application, the user might want to define a variable i with some integer value, a variable j with another integer value, and then ask for the value of i*2+j. Math services is designed specifically to solve equations like this. Variables may be defined, set, and reset; expressions using those variables may be evaluated; a list of the current variables and their values may be obtained.
The expression parser can evaluate a variety of the mathematical functions provided by math services; thus, mathematical functions such as cos, sin, and tan can all be evaluated by the expression parser. Note that the expression parser is only capable of supporting those functions available in math services that (1) take double precision arguments, and (2) return a double precision result.
The expression parser defines the scope of variables with an identification number, or id. This id is of type long, and must be passed to all expression services routines. It can defined by the calling routine to be any number that is deemed suitable. The value of the id itself is not important; the key issue is that it be used consistently. The id number, when used properly by the calling routine, defines the domain of variables set and used. For instance, if all variables set by the user are to be considered global, the application program would use the same id for all calls to expression services. However, if a set of variable definitions and expression evaluations were to be local to a particular module, a different id must be used for calls to the exprssion parser in that module. For instance, the same variables with different values might be employed by the user in three different areas of an application, provided that the application used a different identification number in each of the three areas.
$BOOTSTRAP/objects/library/kexpr/src
$BOOTSTRAP/include/kexpr/kexpr.h
#include <bootstrap.h>