comparison src/expr.h @ 14:b28d7cb60779

checkpoint
author lost
date Thu, 23 Oct 2008 02:44:07 +0000
parents 05d4115b4860
children 1f598d89b9b0
comparison
equal deleted inserted replaced
13:05d4115b4860 14:b28d7cb60779
47 operations is only relevant when initially parsing the expression. The order 47 operations is only relevant when initially parsing the expression. The order
48 of evaluation is determined by what appears on either side of the <op> as 48 of evaluation is determined by what appears on either side of the <op> as
49 an LWVAL may be an expression. 49 an LWVAL may be an expression.
50 */ 50 */
51 51
52 typedef union lwval LWVAL;
53
54 struct lwval_int
55 {
56 int lwval_type; // type of value
57 int lwval_int_value; // integer value
58 };
59
60 union lwval
61 {
62 struct lwval_int lwval_type_int; // integer type
63 };
64
65 enum lwval_types
66 {
67 LWVAL_TYPE_INT
68 };
69
70 #ifndef __expr_h_seen__ 52 #ifndef __expr_h_seen__
71 #define __expr_h_seen__ 53 #define __expr_h_seen__
72 54
55 typedef struct lwval LWVAL;
73 56
57 union lwval_dt
58 {
59 int lwval_int; // integer type data
60 char *lwval_var; // pointer to variable name
61 };
62
63 enum
64 {
65 LWVAL_TYPE_NAN, // not a number
66 LWVAL_TYPE_INT, // integer
67 LWVAL_TYPE_VAR, // variable (symbol)
68 LWVAL_TYPE_EXPR, // expression
69 };
70
71 struct lwval
72 {
73 int lwval_type; // data type
74 union lwval_dt dt; // type specific stuff
75 };
76
77 #ifndef __expr_c_seen__
78 #define EE extern
79 #else
80 #define EE
81 #endif
82
83 EE LWVAL *lwval_construct_int(int value);
84 EE void lwval_destroy(LWVAL *value);
85
86 // operators - operate on v1 and v2 in order, return in v3
87 // if v3 is NULL, allocate new LWVAL and return it else just
88 // return v3 with new value in it
89 EE LWVAL *lwval_add(LWVAL *v1, LWVAL *v2, LWVAL *v3);
90 EE LWVAL *lwval_sub(LWVAL *v1, LWVAL *v2, LWVAL *v3);
91 EE LWVAL *lwval_mul(LWVAL *v1, LWVAL *v2, LWVAL *v3);
92 EE LWVAL *lwval_div(LWVAL *v1, LWVAL *v2, LWVAL *v3);
93 EE LWVAL *lwval_mod(LWVAL *v1, LWVAL *v2, LWVAL *v3);
74 94
75 #endif //__expr_h_seen__ 95 #endif //__expr_h_seen__