home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / IRITS.ZIP / INPTPRSL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  8.6 KB  |  255 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. *   General, local to module, definitions for the Input Parser module.         *
  7. *   Note this module actually consists of InptPrsr/InptEval/OverLoad modules.*
  8. *****************************************************************************/
  9.  
  10. #ifndef    INPT_PRSR_LH
  11. #define    INPT_PRSR_LH
  12.  
  13. /* #define DEBUG        Print some intermediate results (InptPrsr/InptEval). */
  14.  
  15. #define MAX_PARSER_STACK    200         /* Depth of expression nesting. */
  16.  
  17. #define GEOMETRIC_EXPR    GEOMETRIC_OBJ
  18. #define NUMERIC_EXPR    NUMERIC_OBJ
  19. #define VECTOR_EXPR    VECTOR_OBJ
  20. #define MATRIX_EXPR    MATRIX_OBJ
  21. #define    STRING_EXPR    STRING_OBJ
  22. #define OBJ_LIST_EXPR    OBJ_LIST_OBJ
  23.  
  24. #define NON_EXPR    99              /* Nothing should be returned! */
  25. #define ERROR_EXPR    -1                     /* Error... */
  26.  
  27. #define ANY_OBJ        100     /* Match any object type, in type checking. */
  28.  
  29. extern int IPGlblEvalError;             /* Global used by EvalTree. */
  30.  
  31. /*****************************************************************************
  32. * The expression parse tree node definition:                     *
  33. *****************************************************************************/
  34. typedef    struct ParseTree {
  35.     struct ParseTree *Right, *Left;
  36.     int NodeKind;
  37.     int ObjType;
  38.     union {
  39.     RealType R;
  40.     struct ObjectStruct *PObj;
  41.     } U;
  42. } ParseTree;
  43.  
  44. /* See Irit.h file for the different object possible: */
  45. #define IS_GEOM_NODE(Node)    ((Node)->ObjType == GEOMETRIC_OBJ)
  46. #define IS_NUM_NODE(Node)    ((Node)->ObjType == NUMERIC_OBJ)
  47. #define IS_VEC_NODE(Node)    ((Node)->ObjType == VECTOR_OBJ)
  48. #define IS_MAT_NODE(Node)    ((Node)->ObjType == MATRIX_OBJ)
  49. #define IS_STR_NODE(Node)    ((Node)->ObjType == STRING_OBJ)
  50. #define IS_OLST_NODE(Node)    ((Node)->ObjType == OBJ_LIST_OBJ)
  51.  
  52. /*****************************************************************************
  53. * The include file stack - nesting is allowed up to FILE_STACK_SIZE.         *
  54. *****************************************************************************/
  55. typedef struct FileStackStruct {
  56.     char Name[FILE_NAME_LEN];
  57.     FILE *f;
  58. } FileStackStruct;
  59.  
  60. #define FILE_STACK_SIZE    10
  61.  
  62. /*****************************************************************************
  63. * Aliases are simple strings substitution - each entry holds alias Name and  *
  64. * alias Value, which replaces Name. Name id not NULL if active.             *
  65. *****************************************************************************/
  66. typedef struct OneAliasStruct {
  67.     char *Name, *Value;
  68. } OneAliasStruct;
  69.  
  70. #define NUM_OF_ALIASES    10
  71.  
  72. typedef struct AliasesStruct {
  73.     OneAliasStruct Aliases[NUM_OF_ALIASES];
  74. } AliasesStruct;
  75.  
  76. /*****************************************************************************
  77. * Function entry table looks like this (for table see InptPrsr.c module):    *
  78. *****************************************************************************/
  79. #define FUNC_NAME_LEN    11                /* 10 + NULL terminator. */
  80. #define NUM_FUNC_MAX_PARAM 2 /* Max. of 2 params. for real returned function.*/
  81. #define OBJ_FUNC_MAX_PARAM 4 /* Max. of 4 params. for obj. returned function.*/
  82. #define GEN_FUNC_MAX_PARAM 4 /* Max. of 4 params. for gen. returned function.*/
  83.  
  84. #define ANY_PARAM_NUM    127
  85.  
  86. typedef struct NumFuncTableType {
  87.     char FuncName[FUNC_NAME_LEN];
  88.     int FuncToken;
  89.     double (*Func)();
  90.     ByteType NumOfParam;
  91.     ByteType ParamObjType[NUM_FUNC_MAX_PARAM];
  92. } NumFuncTableType;
  93.  
  94. typedef struct ObjFuncTableType {
  95.     char FuncName[FUNC_NAME_LEN];
  96.     int FuncToken;
  97.     ObjectStruct *(*Func)();
  98.     ByteType NumOfParam;
  99.     ByteType ParamObjType[OBJ_FUNC_MAX_PARAM];
  100. } ObjFuncTableType;
  101.  
  102. typedef struct GenFuncTableType {
  103.     char FuncName[FUNC_NAME_LEN];
  104.     int FuncToken;
  105.     void (*Func)();
  106.     ByteType NumOfParam;
  107.     ByteType ParamObjType[GEN_FUNC_MAX_PARAM];
  108. } GenFuncTableType;
  109.  
  110. typedef struct ConstantTableType {
  111.     char FuncName[FUNC_NAME_LEN];
  112.     RealType Value;
  113. } ConstantTableType;
  114.  
  115. /* The followings are defined in the InptEval.c module and are globals so   */
  116. /* InptPrsr.c module will be able to access them...                */
  117. extern NumFuncTableType NumFuncTable[];
  118. extern int NumFuncTableSize;
  119. extern ObjFuncTableType ObjFuncTable[];
  120. extern int ObjFuncTableSize;
  121. extern GenFuncTableType GenFuncTable[];
  122. extern int GenFuncTableSize;
  123. extern ConstantTableType ConstantTable[];
  124. extern int ConstantTableSize;
  125.  
  126. /*****************************************************************************
  127. * Tokens used in the expression    to tree    conversion and tree definition.         *
  128. *****************************************************************************/
  129.  
  130. #define    TOKENERROR  0
  131. #define TOKENSTART  1
  132. #define TOKENEND    2
  133.  
  134. #define    OPENPARA    10                         /* Paranthesis. */
  135. #define    CLOSPARA    11
  136.  
  137. #define    NUMBER        20                        /* Numeric Data. */
  138. #define    PARAMETER   30                 /* Point on new/old object. */
  139. #define STRING        40         /* Sequence of characters within double quotes. */
  140.  
  141. /* Warning - changing the order of these constants, needs updating the order */
  142. /* of them, in the tables in the begining of InptPrsr.c & OverLoad.c modules.*/
  143.  
  144. #define    ARCCOS        100               /* Real value returned functions. */
  145. #define    ARCSIN        101
  146. #define    ARCTAN2        102
  147. #define    ARCTAN        103
  148. #define    COS        104
  149. #define    EXP        105
  150. #define    FABS        106
  151. #define    LN        107
  152. #define    LOG        108
  153. #define    SIN        109
  154. #define    SQRT        110
  155. #define    TAN        111
  156. #define CPOLY        112
  157. #define AREA        113
  158. #define VOLUME      114
  159. #define TIME        115
  160.  
  161. #define NUM_FUNC_OFFSET    100
  162. #define IS_NUM_PROCEDURE(Token)        (Token >= 100 && Token < 200)
  163.  
  164. #define VECTOR        200                   /* Object returned Functions. */
  165. #define ROTX        201
  166. #define ROTY        202
  167. #define ROTZ        203
  168. #define TRANS        204
  169. #define SCALE        205
  170. #define BOX        206
  171. #define GBOX        207
  172. #define CONE        208
  173. #define CYLIN        209
  174. #define SPHERE        210
  175. #define TORUS        211
  176. #define PLANE        212
  177. #define POLY        213
  178. #define CROSSEC        214
  179. #define SURFREV     215
  180. #define EXTRUDE     216
  181. #define LIST        217
  182. #define LOAD        218
  183. #define CONVEX        219
  184.  
  185. #define OBJ_FUNC_OFFSET    200
  186. #define IS_OBJ_PROCEDURE(Token)        (Token >= 200 && Token < 300)
  187.  
  188. #define EXIT        300      /* General Functions/No value returned procedures. */
  189. #define VIEW        301
  190. #define DIR        302
  191. #define CHDIR        303
  192. #define NORMAL        304
  193. #define INCLUDE        305
  194. #define GDUMP       306
  195. #define MDUMP       307
  196. #define FREEOBJ     308
  197. #define INTERACT    309
  198. #define PAUSE        310
  199. #define IFCOND        311
  200. #define FORLOOP        312
  201. #define PRHELP        313
  202. #define VARLIST        314
  203. #define ALIAS        315
  204. #define BEEP        316
  205. #define EDIT        317
  206. #define SYSTEM        318
  207. #define LOGFILE        319
  208. #define COLOR        320
  209.  
  210. #define COMMENT        399
  211.  
  212. #define GEN_FUNC_OFFSET    300
  213. #define IS_GEN_PROCEDURE(Token)        (Token >= 300 && Token < 400)
  214.  
  215. #define IS_PROCEDURE(Token)        (Token >= 100 && Token < 400)
  216. #define IS_NO_PARAM_PROC(Token)        (Token == EXIT || Token == SYSTEM || \
  217.                      Token == VARLIST)
  218.  
  219.  
  220. #define    PLUS        400                           /* Operators. */
  221. #define    MINUS        401
  222. #define    MULT        402
  223. #define    DIV        403
  224. #define    POWER        404
  225. #define    UNARMINUS   405
  226. #define EQUAL        406
  227. #define COMMA        407
  228. #define COLON        408
  229. #define SEMICOLON   409
  230.  
  231. #define OPERATORS_OFFSET    400
  232.  
  233. /*****************************************************************************
  234. *   The local function (static) prototypes:                     *
  235. *   Note that if DEBUG is defined for the preprocessor, few more function    *
  236. * become available:                                 *
  237. *   Also note that some of the routines are defined globals as both the      *
  238. * InptPrsr.c and InptEval.c modules needs them.                     *
  239. *****************************************************************************/
  240. /* Main parser routine (operator preceedence): Input stream to bin-tree. */
  241. ParseTree *MyExprMalloc(void);
  242. void MyExprFree(ParseTree *Ptr);
  243. void UpdateCharError(char *StrMsg, int Token);
  244. void AliasEdit(char *Name, char *Value);
  245. void AliasExpand(char *Line);
  246. void FileInclude(char *FileName);
  247. int InptPrsrTypeCheck(ParseTree *Root, int Level);     /* Type check tree. */
  248. struct ParseTree *InptPrsrEvalTree(ParseTree *Root,
  249.                            int Level); /* Evaluate tree. */
  250. void InptPrsrFreeTree(ParseTree *Root);               /* Free all tree. */
  251. void InptPrsrPrintTree(ParseTree *Root, char *str);          /* print it... */
  252. ParseTree *InptPrsrCopyTree(ParseTree *Root);             /* Copy it. */
  253.  
  254. #endif    /* INPT_PRSR_LH */
  255.