home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / Equation Evaluator / EE ƒ / EE.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-13  |  2.5 KB  |  68 lines  |  [TEXT/MPCC]

  1. /* Some of you may choose to define TYPE as a "float" instead... */
  2. #define TYPE            double          /* Type of numbers to work with */
  3.  
  4. #define VARLEN          15              /* Max length of variable names */
  5. #define MAXVARS         50              /* Max user-defined variables */
  6. #define TOKLEN          30              /* Max token length */
  7.  
  8. #define VAR             1
  9. #define DEL             2
  10. #define NUM             3
  11.  
  12.  
  13. typedef struct
  14. {
  15.    char name[VARLEN + 1];               /* Variable name */
  16.    TYPE value;                          /* Variable value */
  17. } VARIABLE;
  18.  
  19. //    April 1995    RMD-    made C++ compatible
  20. typedef float (*FunctionPtr)(float, float, float);
  21.  
  22. typedef struct
  23. {
  24.    char*        name;                    /* Function name */
  25.    short        args;                    /* Number of arguments to expect */
  26.    FunctionPtr  func;                     /* Pointer to function */
  27. //   TYPE  (*func)();                     /* Pointer to function */
  28. } FUNCTION;
  29.  
  30. /* The following macros are ASCII dependant, no EBCDIC here! */
  31. #define iswhite(c)  (c == ' ' || c == '\t')
  32. #define isnumer(c)  ((c >= '0' && c <= '9') || c == '.')
  33. #define isalpha(c)  ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') \
  34.                     || c == '_')
  35. #define isdelim(c)  (c == '+' || c == '-' || c == '*' || c == '/' || c == '%' \
  36.                     || c == '^' || c == '(' || c == ')' || c == ',' || c == '=')
  37.  
  38. /* Codes returned from the evaluator */
  39. #define E_OK           0        /* Successful evaluation */
  40. #define E_SYNTAX       1        /* Syntax error */
  41. #define E_UNBALAN      2        /* Unbalanced parenthesis */
  42. #define E_DIVZERO      3        /* Attempted division by zero */
  43. #define E_UNKNOWN      4        /* Reference to unknown variable */
  44. #define E_MAXVARS      5        /* Maximum variables exceeded */
  45. #define E_BADFUNC      6        /* Unrecognised function */
  46. #define E_NUMARGS      7        /* Wrong number of arguments to funtion */
  47. #define E_NOARG        8        /* Missing an argument to a funtion */
  48. #define E_EMPTY        9        /* Empty expression */
  49.  
  50.  
  51. //    April 1995    RMD-    Add ANSI prototypes
  52.  
  53. double    deg( double x );
  54. double    rad( double x );
  55. short    GetSymbol( char* s, TYPE* v );
  56. void    ClearAllVars(void);
  57. Boolean ClearVar( char* name );
  58. Boolean GetValue( char* name, TYPE* value );
  59. Boolean SetValue( char* name, TYPE* value );
  60.  
  61. static Boolean    Level1( TYPE* r );
  62. static void        Level2( TYPE* r );
  63. static void        Level3( TYPE* r );
  64. static void        Level4( TYPE* r );
  65. static void        Level5( TYPE* r );
  66. static void        Level6( TYPE* r );
  67.  
  68. Boolean Evaluate( char* e, TYPE* result, short* a );