home *** CD-ROM | disk | FTP | other *** search
- /* Some of you may choose to define TYPE as a "float" instead... */
- #define TYPE double /* Type of numbers to work with */
-
- #define VARLEN 15 /* Max length of variable names */
- #define MAXVARS 50 /* Max user-defined variables */
- #define TOKLEN 30 /* Max token length */
-
- #define VAR 1
- #define DEL 2
- #define NUM 3
-
-
- typedef struct
- {
- char name[VARLEN + 1]; /* Variable name */
- TYPE value; /* Variable value */
- } VARIABLE;
-
- // April 1995 RMD- made C++ compatible
- typedef float (*FunctionPtr)(float, float, float);
-
- typedef struct
- {
- char* name; /* Function name */
- short args; /* Number of arguments to expect */
- FunctionPtr func; /* Pointer to function */
- // TYPE (*func)(); /* Pointer to function */
- } FUNCTION;
-
- /* The following macros are ASCII dependant, no EBCDIC here! */
- #define iswhite(c) (c == ' ' || c == '\t')
- #define isnumer(c) ((c >= '0' && c <= '9') || c == '.')
- #define isalpha(c) ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') \
- || c == '_')
- #define isdelim(c) (c == '+' || c == '-' || c == '*' || c == '/' || c == '%' \
- || c == '^' || c == '(' || c == ')' || c == ',' || c == '=')
-
- /* Codes returned from the evaluator */
- #define E_OK 0 /* Successful evaluation */
- #define E_SYNTAX 1 /* Syntax error */
- #define E_UNBALAN 2 /* Unbalanced parenthesis */
- #define E_DIVZERO 3 /* Attempted division by zero */
- #define E_UNKNOWN 4 /* Reference to unknown variable */
- #define E_MAXVARS 5 /* Maximum variables exceeded */
- #define E_BADFUNC 6 /* Unrecognised function */
- #define E_NUMARGS 7 /* Wrong number of arguments to funtion */
- #define E_NOARG 8 /* Missing an argument to a funtion */
- #define E_EMPTY 9 /* Empty expression */
-
-
- /*************************************************************************
- ** **
- ** PROTOTYPES FOR CUSTOM MATH FUNCTIONS **
- ** **
- *************************************************************************/
- #ifndef M_PI
- #define M_PI 3.14159265358979323846
- #endif
- #ifndef M_E
- #define M_E 2.71828182845904523536
- #endif
-
- double deg( double x );
- double rad( double x );
-
- // April 1995 RMD- Add ANSI prototypes
- class CEquation {
- public:
- CEquation();
- ~CEquation();
- Boolean Evaluate( char* e, TYPE* result, short* a );
- void ClearAllVars(void);
- void ListVariables(void);
- void ListConstants(void);
- void ReportError( void );
-
- protected:
- void Parse(void);
- short GetSymbol( char* s, TYPE* v );
- Boolean ClearVar( char* name );
- Boolean GetValue( char* name, TYPE* value );
- Boolean SetValue( char* name, TYPE* value );
- Boolean Level1( TYPE* r );
- void Level2( TYPE* r );
- void Level3( TYPE* r );
- void Level4( TYPE* r );
- void Level5( TYPE* r );
- void Level6( TYPE* r );
-
- char* mEquation[256]; //
- char* mSource; // Pointer to the expression
- char mToken[TOKLEN + 1]; // Holds the current token
- short mTokenType; // Type of the current token
- VARIABLE mVars[MAXVARS]; // Array for user-defined variables
-
- static FUNCTION Funcs[];
- static VARIABLE Consts[];
- static char* ErrMsgs[];
-
- short mErrorCode;
- char* mErrorFrom;
- };
-
-
-