| 1 | #ifndef __PARSER_H__ |
| 2 | #define __PARSER_H__ |
| 3 | |
| 4 | /* global variables */ |
| 5 | |
| 6 | extern double answer; |
| 7 | |
| 8 | /* function type */ |
| 9 | |
| 10 | typedef enum { |
| 11 | Val = 0, Sig, |
| 12 | Add, Sub, |
| 13 | Mul, Div, Mod, |
| 14 | Pow, Sqr, |
| 15 | Cos, Sin, Tan, Acos, Asin, Atan, |
| 16 | Log, Exp, |
| 17 | Abs, Ceil, Floor, |
| 18 | Store, Recall, Inc, Dec, Disp, Mem, Clear, |
| 19 | Quit, Help, |
| 20 | Ans, E, Pi, |
| 21 | Equal, Diff, Ge, Le, Gt, Lt, |
| 22 | And, Or, Not, |
| 23 | Cond, While, Code, Print, |
| 24 | Prog, Call, List, Edit, Del |
| 25 | } func_t; |
| 26 | |
| 27 | /* keyword type */ |
| 28 | |
| 29 | typedef struct _keyword_t { |
| 30 | char *keyword; |
| 31 | func_t func; |
| 32 | int nbops; |
| 33 | int offset; |
| 34 | float prio; |
| 35 | } keyword_t; |
| 36 | |
| 37 | /* calculus element type */ |
| 38 | |
| 39 | typedef struct _element_t { |
| 40 | func_t func; |
| 41 | int nbops; |
| 42 | struct _element_t **ops; |
| 43 | double value; |
| 44 | int prio; |
| 45 | int hidden; |
| 46 | char *string; |
| 47 | } element_t; |
| 48 | |
| 49 | #define ERROR_OP ((element_t *)(-1)) |
| 50 | |
| 51 | /* workspace type */ |
| 52 | |
| 53 | typedef struct _workspace_t { |
| 54 | int id; |
| 55 | double answer; |
| 56 | double *storage; |
| 57 | int storage_size; |
| 58 | element_t *root; |
| 59 | char *string; |
| 60 | } workspace_t; |
| 61 | |
| 62 | /* parser function */ |
| 63 | |
| 64 | void delelement (element_t *root); |
| 65 | |
| 66 | element_t *parser (char *str, char **next, int prio); |
| 67 | |
| 68 | void print_element (element_t *root, int level); |
| 69 | |
| 70 | double evaluate_element (element_t *root, char mask); |
| 71 | |
| 72 | /* completion functions */ |
| 73 | |
| 74 | char **generate_completion_list (); |
| 75 | |
| 76 | void free_completion_list (char **list); |
| 77 | |
| 78 | /* print function */ |
| 79 | |
| 80 | void set_format (char *prompt, int precision); |
| 81 | |
| 82 | void free_format (); |
| 83 | |
| 84 | double print (double value); |
| 85 | |
| 86 | #endif /* __PARSER_H__ */ |
| 87 | |
| 88 | /* vim: set ts=4 sw=4 et: */ |