540f1c81ce46cc61965a58f1348d41550deba89f
[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, Atan,
16 Log, Exp,
17 Store, Recall, Inc, Dec, Disp,
18 Quit, Help,
19 Ans, E, Pi,
20 Equal, Diff, Ge, Le, Gt, Lt,
21 And, Or, Not,
22 Cond
23 } func_t;
24
25 /* keyword type */
26
27 typedef struct _keyword_t {
28 char *keyword;
29 func_t func;
30 int nbops;
31 int offset;
32 float prio;
33 } keyword_t;
34
35 /* calculus element type */
36
37 #define MAX_OPERANDS 10
38 typedef struct _element_t {
39 func_t func;
40 int nbops;
41 struct _element_t *ops[MAX_OPERANDS];
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 #endif /* __PARSER_H__ */
59
60 /* vim: set ts=4 sw=4 et: */