9458aec699e7029931dc29398f7aa490f1a31a20
[calc.git] / parser.h
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 Ln, Log, Exp,
17 Erfc, Erf,
18 Abs, Ceil, Floor,
19 Store, Recall, Inc, Dec, Disp, Mem, Clear,
20 Quit, Help,
21 Ans, E, Pi,
22 Equal, Diff, Ge, Le, Gt, Lt,
23 And, Or, Not,
24 Cond, While, Code, Print,
25 Prog, Call, List, Edit, Del,
26 Get, Length, Pop, Push, Put, Set, Show
27 } func_t;
28
29 /* keyword type */
30
31 typedef struct _keyword_t {
32 char *keyword;
33 func_t func;
34 int nbops;
35 int offset;
36 float prio;
37 } keyword_t;
38
39 /* calculus element type */
40
41 typedef struct _element_t {
42 func_t func;
43 int nbops;
44 struct _element_t **ops;
45 double value;
46 int prio;
47 int hidden;
48 char *string;
49 } element_t;
50
51 #define ERROR_OP ((element_t *)(-1))
52
53 /* workspace type */
54
55 typedef struct _workspace_t {
56 int id;
57 double answer;
58 double *storage;
59 int storage_size;
60 element_t *root;
61 double *stack;
62 int stack_size;
63 char *string;
64 } workspace_t;
65
66 /* parser function */
67
68 void delelement (element_t *root);
69
70 element_t *parser (char *str, char **next, int prio);
71
72 void print_element (element_t *root, int level);
73
74 double evaluate_element (element_t *root, char mask);
75
76 /* completion functions */
77
78 char **generate_completion_list ();
79
80 void free_completion_list (char **list);
81
82 /* print function */
83
84 void set_format (char *prompt, int precision);
85
86 void free_format ();
87
88 double print (double value);
89
90 #endif /* __PARSER_H__ */
91
92 /* vim: set ts=4 sw=4 et: */