home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / DRAWFN3S.ZIP / EXPR2TRG.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-06  |  4.1 KB  |  97 lines

  1. /*****************************************************************************
  2. * General, visible to others, definitions of Expr2Tre.c module.             *
  3. *****************************************************************************/
  4.  
  5. #ifndef EXPR_2_TREE_GH
  6. #define EXPR_2_TREE_GH
  7.  
  8. #define  DERIVATIVE       /* Uncomment if derivative evaluations is needed. */
  9.  
  10. /*****************************************************************************
  11. * The global constants - should    be available to    every body using expr2tre    *
  12. *****************************************************************************/
  13.  
  14. #define    PARAMETER_A    0               /* Make life easier in usage. */
  15. #define    PARAMETER_B    1
  16. #define    PARAMETER_C    2
  17. #define    PARAMETER_D    3
  18. #define    PARAMETER_E    4
  19. #define    PARAMETER_F    5
  20. #define    PARAMETER_G    6
  21. #define    PARAMETER_H    7
  22. #define    PARAMETER_I    8
  23. #define    PARAMETER_J    9
  24. #define    PARAMETER_K    10
  25. #define    PARAMETER_L    11
  26. #define    PARAMETER_M    12
  27. #define    PARAMETER_N    13
  28. #define    PARAMETER_O    14
  29. #define    PARAMETER_P    15
  30. #define    PARAMETER_Q    16
  31. #define    PARAMETER_R    17
  32. #define    PARAMETER_S    18
  33. #define    PARAMETER_T    19
  34. #define    PARAMETER_U    20
  35. #define    PARAMETER_V    21
  36. #define    PARAMETER_W    22
  37. #define    PARAMETER_X    23
  38. #define    PARAMETER_Y    24
  39. #define    PARAMETER_Z    25
  40. #define    PARAMETER_Z1   26                 /* Number of variables. */
  41. #define    PARAMETER_ALL  -1        /* Match all parameters is searches. */
  42.  
  43. /*****************************************************************************
  44. * The basic expression tree node definition:                     *
  45. *****************************************************************************/
  46. typedef    struct ExprNode {
  47.      struct ExprNode *Right, *Left;
  48.      int NodeKind;
  49.      double Data;
  50. } ExprNode;
  51.  
  52. /*****************************************************************************
  53. * The function definitions as in expr2tre module:                 *
  54. * Note the following explainations are not full    and give only brief scan...  *
  55. *****************************************************************************/
  56. ExprNode *Expr2Tree(char *str);  /* Main routine - conv. string to bin-tree. */
  57. int ParserError(void);          /* Return last error found in Expr2Tree(). */
  58. void PrintTree(ExprNode *Root, char *str);  /* Print bin-tree in infix form. */
  59. ExprNode *CopyTree(ExprNode *Root);    /* Create a totally new copy of tree. */
  60. double EvalTree(ExprNode *Root);           /* Numerically evaluate tree. */
  61. int EvalError(void);           /* Return last error found in EvalTree(). */
  62. #ifdef DERIVATIVE
  63. ExprNode *DerivTree(ExprNode *Root, int prm);       /* Symbolic der. of tree. */
  64. int DerivError(void);          /* Return last error found in DerivTree(). */
  65. #endif DERIVATIVE
  66. void SetParamValue(double Value, int Num);    /* Assign Value to param. Num. */
  67. int CmpTree(ExprNode *Root1, ExprNode *Root2);    /* Cmp. symbol. two trees. */
  68. int ParamInTree(ExprNode *Root, int Param); /* Return if Param in tree Root. */
  69. void FreeTree(ExprNode *Root);     /* Release dynamic memory occupied by tree. */
  70.  
  71. /*****************************************************************************
  72. * Error numbers as located during the parsing process:                 *
  73. *****************************************************************************/
  74. #define P_ERR_WrongSyntax    1
  75. #define P_ERR_ParamExpect    2
  76. #define P_ERR_OneOperand    3
  77. #define P_ERR_TwoOperand    4
  78. #define P_ERR_StackOV        5
  79. #define P_ERR_ParaMatch        6
  80. #define P_ERR_UndefToken    7
  81.  
  82. /*****************************************************************************
  83. * Error numbers as located during the derivation creation:             *
  84. *****************************************************************************/
  85. #define    D_ERR_NoneConstExp    1
  86. #define    D_ERR_NoAbsDeriv    2
  87. #define    D_ERR_NoMinDeriv    3
  88. #define    D_ERR_NoMaxDeriv    4
  89. #define    D_ERR_NoModDeriv    5
  90.  
  91. /*****************************************************************************
  92. * Error numbers as located during the evaluation process:             *
  93. *****************************************************************************/
  94. #define    E_ERR_DivByZero 1
  95.  
  96. #endif EXPR_2_TREE_GH
  97.