Mercurial > hg-old > index.cgi
diff src/expr.h @ 15:1f598d89b9b0
Started creating expression parser
author | lost |
---|---|
date | Thu, 23 Oct 2008 03:37:48 +0000 |
parents | b28d7cb60779 |
children | df0c4a46af8f |
line wrap: on
line diff
--- a/src/expr.h Thu Oct 23 02:44:07 2008 +0000 +++ b/src/expr.h Thu Oct 23 03:37:48 2008 +0000 @@ -19,77 +19,26 @@ */ /* -This file contains definitions associated with the expression evaluator used -by LWASM. - -The core of the entire expression handler is the opaque type LWVAL, pointers -to which are passed around to keep track of values. A value may be a simple -integer or it could be a more complex expression linked by operators or it -could be a polynomial expression. Simple integers are merely a degenerate -case of polynomials. - -The package understands the following operations: - -addition -subtraction -multiplication -division -modulus -parentheses -unary negation -unary "positive" -bitwise and -bitwise or -bitwise not (1's complement) -bitwise exclusive or - -Infix operators can be expressed as LWVAL <op> LWVAL. Thus, the order of -operations is only relevant when initially parsing the expression. The order -of evaluation is determined by what appears on either side of the <op> as -an LWVAL may be an expression. +Definitions for expression evaluator */ #ifndef __expr_h_seen__ #define __expr_h_seen__ -typedef struct lwval LWVAL; - -union lwval_dt -{ - int lwval_int; // integer type data - char *lwval_var; // pointer to variable name -}; - -enum -{ - LWVAL_TYPE_NAN, // not a number - LWVAL_TYPE_INT, // integer - LWVAL_TYPE_VAR, // variable (symbol) - LWVAL_TYPE_EXPR, // expression -}; - -struct lwval -{ - int lwval_type; // data type - union lwval_dt dt; // type specific stuff -}; +#include "lwval.h" #ifndef __expr_c_seen__ -#define EE extern +#define __expr_E__ extern #else -#define EE +#define __expr_E__ #endif -EE LWVAL *lwval_construct_int(int value); -EE void lwval_destroy(LWVAL *value); +// parse an expression +__expr_E__ LWVAL *lwasm_parse_expr(char **ptr); -// operators - operate on v1 and v2 in order, return in v3 -// if v3 is NULL, allocate new LWVAL and return it else just -// return v3 with new value in it -EE LWVAL *lwval_add(LWVAL *v1, LWVAL *v2, LWVAL *v3); -EE LWVAL *lwval_sub(LWVAL *v1, LWVAL *v2, LWVAL *v3); -EE LWVAL *lwval_mul(LWVAL *v1, LWVAL *v2, LWVAL *v3); -EE LWVAL *lwval_div(LWVAL *v1, LWVAL *v2, LWVAL *v3); -EE LWVAL *lwval_mod(LWVAL *v1, LWVAL *v2, LWVAL *v3); +// attempt to evaluate/simplify expression +__expr_E__ int lwasm_eval_expr(LWVAL *expr); -#endif //__expr_h_seen__ +#undef __expr_E__ + +#endif // __expr_h_seen__