Mercurial > hg-old > index.cgi
annotate src/expr.h @ 17:df0c4a46af8f
Started adding expression handling infrastructure
author | lost |
---|---|
date | Thu, 01 Jan 2009 02:26:26 +0000 |
parents | 1f598d89b9b0 |
children | 218aabbc3b1a |
rev | line source |
---|---|
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
1 /* |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
2 expr.h |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
3 Copyright © 2008 William Astle |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
4 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
5 This file is part of LWASM. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
6 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
10 version. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
11 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
15 more details. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
16 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
19 */ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
20 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
21 /* |
15 | 22 Definitions for expression evaluator |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
23 */ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
24 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
25 #ifndef __expr_h_seen__ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
26 #define __expr_h_seen__ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
27 |
14 | 28 #ifndef __expr_c_seen__ |
15 | 29 #define __expr_E__ extern |
14 | 30 #else |
15 | 31 #define __expr_E__ |
14 | 32 #endif |
33 | |
17 | 34 // term types |
35 #define LWASM_TERM_NONE 0 | |
36 #define LWASM_TERM_OPER 1 // an operator | |
37 #define LWASM_TERM_INT 2 // 32 bit signed integer | |
38 #define LWASM_TERM_SYM 3 // symbol reference | |
39 | |
40 // operator types | |
41 #define LWASM_OPER_NONE 0 | |
42 #define LWASM_OPER_PLUS 1 // + | |
43 #define LWASM_OPER_MINUS 2 // - | |
44 #define LWASM_OPER_TIMES 3 // * | |
45 #define LWASM_OPER_DIVIDE 4 // / | |
46 #define LWASM_OPER_MOD 5 // % | |
47 #define LWASM_OPER_INTDIV 6 // \ | |
48 #define LWASM_OPER_BWAND 7 // bitwise AND | |
49 #define LWASM_OPER_BWOR 8 // bitwise OR | |
50 #define LWASM_OPER_BWXOR 9 // bitwise XOR | |
51 #define LWASM_OPER_AND 10 // boolean AND | |
52 #define LWASM_OPER_OR 11 // boolean OR | |
53 #define LWASM_OPER_NEG 12 // unary negation (2's complement) | |
54 #define LWASM_OPER_COM 13 // unary 1's complement | |
55 | |
14 | 56 |
17 | 57 // term structure |
58 typedef struct lwasm_expr_term_s | |
59 { | |
60 int term_type; // type of term (see above) | |
61 char *symbol; // name of a symbol | |
62 int value; // value of the term (int) or operator number (OPER) | |
63 } lwasm_expr_term_t; | |
64 | |
65 // type for an expression evaluation stack | |
66 typedef struct lwasm_expr_stack_node_s lwasm_expr_stack_node_t; | |
67 struct lwasm_expr_stack_node_s | |
68 { | |
69 lwasm_expr_term_t *term; | |
70 lwasm_expr_stack_node_t *prev; | |
71 lwasm_expr_stack_node_t *next; | |
72 }; | |
73 | |
74 typedef struct lwasm_expr_stack_s | |
75 { | |
76 lwasm_expr_stack_node_t *head; | |
77 lwasm_expr_stack_node_t *tail; | |
78 } lwasm_expr_stack_t; | |
79 | |
80 __expr_E__ void lwasm_expr_term_free(lwasm_expr_term_t *t); | |
81 __expr_E__ lwasm_expr_term_t *lwasm_expr_term_create_oper(int oper); | |
82 __expr_E__ lwasm_expr_term_t *lwasm_expr_term_create_sym(char *sym); | |
83 __expr_E__ lwasm_expr_term_t *lwasm_expr_term_create_int(int val); | |
84 __expr_E__ lwasm_expr_term_t *lwasm_expr_term_dup(lwasm_expr_term_t *t); | |
85 | |
86 __expr_E__ void lwasm_expr_stack_free(lwasm_expr_stack_t *s); | |
87 __expr_E__ lwasm_expr_stack_t *lwasm_expr_stack_create(void); | |
88 | |
89 __expr_E__ void lwasm_expr_stack_push(lwasm_expr_stack_t *s, lwasm_expr_term_t *t); | |
90 __expr_E__ lwasm_expr_term_t *lwasm_expr_stack_pop(lwasm_expr_stack_t *s); | |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
91 |
15 | 92 #undef __expr_E__ |
93 | |
94 #endif // __expr_h_seen__ |