Mercurial > hg > dmlib
annotate dmeval.h @ 664:57fc2ec4efdc
Some more work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 16 Apr 2013 09:06:34 +0300 |
parents | 05eb24a608f0 |
children | 0d37fe455b86 |
rev | line source |
---|---|
0 | 1 #ifndef DMEVAL_H |
2 #define DMEVAL_H | |
3 | |
4 #include "dmlib.h" | |
5 | |
6 | |
7 typedef double DMValue; | |
8 #define DMCONVTYPE (int) | |
9 | |
10 | |
11 enum | |
12 { | |
13 OP_NONE, | |
14 | |
15 OP_ADD, | |
16 OP_SUB, | |
17 OP_MUL, | |
18 OP_DIV, | |
19 OP_MOD, | |
20 | |
21 OP_LSHIFT, | |
22 OP_RSHIFT, | |
23 | |
24 OP_AND, | |
25 OP_OR, | |
26 OP_XOR, | |
27 | |
28 OP_FUNC, | |
29 OP_VAR, | |
30 OP_SUBEXPR, | |
31 OP_CONST, | |
32 | |
33 OP_NOPERS | |
34 } DMOperType; | |
35 | |
36 enum | |
37 { | |
38 ID_FUNC, | |
39 ID_VAR | |
40 } DMEvalIdType; | |
41 | |
42 | |
43 typedef struct | |
44 { | |
45 char *name; | |
46 int type; | |
663
05eb24a608f0
Some minor touches to evaluator code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 int args; |
05eb24a608f0
Some minor touches to evaluator code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 DMValue (*func)(DMValue *); |
0 | 49 DMValue *var; |
50 } DMEvalId; | |
51 | |
52 | |
53 typedef struct DMEvalNode | |
54 { | |
55 int op; | |
56 DMValue val; | |
57 DMEvalId *id; | |
58 | |
59 struct DMEvalNode *subexpr, *next, *prev; | |
60 } DMEvalNode; | |
61 | |
62 | |
63 typedef struct | |
64 { | |
65 BOOL err; | |
66 char *errStr; | |
67 | |
68 int nids; | |
69 DMEvalId *ids; | |
70 | |
71 int mode, prev, expect; | |
72 } DMEvalContext; | |
73 | |
74 | |
75 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name); | |
76 DMEvalId *dm_eval_add_var(DMEvalContext *ev, const char *name, DMValue *var); | |
664 | 77 DMEvalId *dm_eval_add_func(DMEvalContext *ev, const char *name, DMValue (*func)(DMValue *)); |
0 | 78 |
79 DMEvalContext *dm_eval_new(void); | |
80 void dm_eval_close(DMEvalContext *ev); | |
81 void dm_eval_free(DMEvalNode *node); | |
82 void dm_eval_clear_err(DMEvalContext *ev); | |
83 | |
84 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result); | |
85 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result); | |
86 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult); | |
87 | |
88 void dm_print_optree(DMEvalContext *ev, DMEvalNode *node); | |
89 | |
90 | |
91 #endif // DMEVAL_H |