clean some tests
[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, Arg, Call, List, Edit, Del,
26 Get, Length, Pop, Push, Put, Set, Show,
27 Max, Mean, Median, Min, Order, Prod, Sum, Variance
28 } func_t;
29
30 /* keyword type */
31
32 typedef struct _keyword_t {
33 char *keyword;
34 func_t func;
35 int nbops;
36 int offset;
37 float prio;
38 } keyword_t;
39
40 /* calculus element type */
41
42 typedef struct _element_t {
43 func_t func;
44 int nbops;
45 struct _element_t **ops;
46 double value;
47 int prio;
48 int hidden;
49 char *string;
50 } element_t;
51
52 #define ERROR_OP ((element_t *)(-1))
53
54 /* workspace type */
55
56 typedef struct _workspace_t {
57 int id;
58 double answer;
59 double *storage;
60 int storage_size;
61 double *argument;
62 int argument_size;
63 element_t *root;
64 double *stack;
65 int stack_size;
66 char *string;
67 } workspace_t;
68
69 /* parser function */
70
71 void delelement (element_t *root);
72
73 element_t *parser (char *str, char **next, int prio);
74
75 void print_element (element_t *root, int level);
76
77 double evaluate_element (element_t *root, char mask);
78
79 /* completion functions */
80
81 char **generate_completion_list ();
82
83 void free_completion_list (char **list);
84
85 /* print function */
86
87 void set_format (char *prompt, int precision);
88
89 void free_format ();
90
91 double print (double value);
92
93 #endif /* __PARSER_H__ */
94
95 /* vim: set ts=4 sw=4 et: */