Mercurial > hg > dmlib
annotate dmeval.h @ 742:aba7dde79a04
Add associativity types enum.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 22 Apr 2013 17:00:01 +0300 |
parents | 48c48e94d87f |
children | faf43d8aa841 |
rev | line source |
---|---|
0 | 1 #ifndef DMEVAL_H |
2 #define DMEVAL_H | |
3 | |
4 #include "dmlib.h" | |
5 | |
6 | |
7 typedef double DMValue; | |
670 | 8 #define DMCONVTYPE (int) |
9 #define DM_MAX_ARGS 8 | |
0 | 10 |
11 enum | |
12 { | |
674 | 13 // No-op |
0 | 14 OP_NONE, |
15 | |
16 OP_ADD, | |
17 OP_SUB, | |
18 OP_MUL, | |
19 OP_DIV, | |
20 OP_MOD, | |
21 | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
22 OP_SUB_UNARY, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
23 OP_COMPLEMENT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
24 |
0 | 25 OP_LSHIFT, |
26 OP_RSHIFT, | |
27 | |
28 OP_AND, | |
29 OP_OR, | |
30 OP_XOR, | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
31 |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
32 OP_GT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
33 OP_LT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
34 OP_GT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
35 OP_LT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
36 |
674 | 37 // Special ops |
0 | 38 OP_FUNC, |
39 OP_VAR, | |
40 OP_SUBEXPR, | |
41 OP_CONST, | |
42 | |
674 | 43 // Total number of operators |
0 | 44 OP_NOPERS |
742
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
45 } DMOper; |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
46 |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
47 |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
48 enum |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
49 { |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
50 OT_LEFT, // Left-associative |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
51 OT_RIGHT, // Right-associative |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
52 OT_UNARY, |
0 | 53 } DMOperType; |
54 | |
685 | 55 |
0 | 56 enum |
57 { | |
58 ID_FUNC, | |
670 | 59 ID_VAR, |
60 ID_CVAR, | |
0 | 61 } DMEvalIdType; |
62 | |
63 | |
64 typedef struct | |
65 { | |
66 char *name; | |
67 int type; | |
670 | 68 int nargs; |
69 DMValue (*func)(DMValue arg[DM_MAX_ARGS]); | |
70 DMValue *var, cvalue; | |
0 | 71 } DMEvalId; |
72 | |
73 | |
74 typedef struct DMEvalNode | |
75 { | |
693
837ad9dcc348
More work on evaluator reordering pass.
Matti Hamalainen <ccr@tnsp.org>
parents:
685
diff
changeset
|
76 BOOL ok; |
0 | 77 int op; |
78 DMValue val; | |
79 DMEvalId *id; | |
80 | |
670 | 81 struct DMEvalNode *args[DM_MAX_ARGS]; |
0 | 82 struct DMEvalNode *subexpr, *next, *prev; |
83 } DMEvalNode; | |
84 | |
85 | |
86 typedef struct | |
87 { | |
88 BOOL err; | |
89 char *errStr; | |
90 | |
91 int nids; | |
92 DMEvalId *ids; | |
93 | |
94 int mode, prev, expect; | |
95 } DMEvalContext; | |
96 | |
97 | |
98 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name); | |
99 DMEvalId *dm_eval_add_var(DMEvalContext *ev, const char *name, DMValue *var); | |
670 | 100 DMEvalId *dm_eval_add_const(DMEvalContext *ev, const char *name, DMValue value); |
101 DMEvalId *dm_eval_add_func(DMEvalContext *ev, const char *name, DMValue (*func)(DMValue *), int nargs); | |
0 | 102 |
103 DMEvalContext *dm_eval_new(void); | |
104 void dm_eval_close(DMEvalContext *ev); | |
105 void dm_eval_free(DMEvalNode *node); | |
106 void dm_eval_clear_err(DMEvalContext *ev); | |
107 | |
108 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result); | |
680 | 109 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result); |
0 | 110 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult); |
111 | |
112 | |
113 #endif // DMEVAL_H |