522adba9dec018d88493f1e6e977cadce30e835c
[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 Log, Exp,
17 Abs, Ceil, Floor,
18 Store, Recall, Inc, Dec, Disp,
19 Quit, Help,
20 Ans, E, Pi,
21 Equal, Diff, Ge, Le, Gt, Lt,
22 And, Or, Not,
23 Cond, While, Prog, Print
24 } func_t;
25
26 /* keyword type */
27
28 typedef struct _keyword_t {
29 char *keyword;
30 func_t func;
31 int nbops;
32 int offset;
33 float prio;
34 } keyword_t;
35
36 /* calculus element type */
37
38 typedef struct _element_t {
39 func_t func;
40 int nbops;
41 struct _element_t **ops;
42 double value;
43 int prio;
44 } element_t;
45
46 #define ERROR_OP ((element_t *)(-1))
47
48 /* parser function */
49
50 void delelement (element_t *root);
51
52 element_t *parser (char *str, char **next, int prio);
53
54 void print_element (element_t *root, int level);
55
56 double evaluate_element (element_t *root, char mask);
57
58 /* completion functions */
59
60 char **generate_completion_list ();
61
62 void free_completion_list (char **list);
63
64 /* print function */
65
66 void set_format (char *prompt, int precision);
67
68 void free_format ();
69
70 double print (double value);
71
72 #endif /* __PARSER_H__ */
73
74 /* vim: set ts=4 sw=4 et: */