Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

symmath.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      symmath.h
00004  *
00005  *      Copyright (C) 2001, 2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __SYMMATH_H__
00022 #define __SYMMATH_H__
00023 
00024 #include "htdata.h"
00025 
00026 enum c_op {
00027     c_invalid,
00028     c_eq,
00029     c_ne,
00030     c_gt,
00031     c_ge,
00032     c_lt,
00033     c_le
00034 };
00035 
00036 #define NUM_VALID_LOPS          8
00037 
00038 enum l_op {
00039     l_invalid=-1,
00040     l_and=0,
00041     l_or,
00042     l_eq,
00043     l_ne,
00044     l_gt,
00045     l_ge,
00046     l_lt,
00047     l_le
00048 };
00049 
00050 enum n_op {
00051     n_null,
00052     n_not
00053 };
00054 
00055 #define NUM_VALID_BOPS          8
00056 
00057 enum b_op {
00058     b_invalid=-1,
00059     b_mul=0,
00060     b_div,
00061     b_mod,
00062     b_add,
00063     b_sub,
00064     b_and,
00065     b_or,
00066     b_xor
00067 };
00068 
00069 enum u_op {
00070     u_null,
00071     u_minus,
00072     u_not
00073 };
00074 
00075 /* C bin operator precedence (for output) */
00076 
00077 extern b_op *c_op_prec[];
00078 
00079 /*
00080  *      CLASS sym_int_token
00081  */
00082 
00083 class sym_int_token: public Object {
00084 public:
00085 /* new */
00086         virtual bool compare_eq(sym_int_token *t)=0;
00087         virtual bool evaluate(UINT *i);
00088         virtual void simplify();
00089         virtual int nstrfy(char *buf, int n)=0;
00090 };
00091 
00092 /*
00093  *      CLASS sym_int
00094  */
00095 
00096 class sym_int: public sym_int_token {
00097 protected:
00098         void clear();
00099         bool simplify_reduce_const(b_op oa, sym_int_token *a, b_op ob, sym_int_token *b, b_op *res_op, sym_int_token **res_token);
00100         sym_int_token *simplify_reduce_destructive(b_op o, sym_int_token *x);
00101         bool simplify_reduce_inverse(b_op oa, sym_int_token *a, b_op ob, sym_int_token *b, sym_int_token **repl);
00102         bool simplify_reduce_neutral(b_op o, sym_int_token *x);
00103 public:
00104         ht_list *tokens;
00105 
00106         sym_int();
00107         ~sym_int();
00108 /* overwritten */
00109         virtual bool compare_eq(sym_int_token *t);
00110         virtual Object *duplicate();
00111         virtual bool evaluate(UINT *i);
00112         virtual int nstrfy(char *buf, int n);
00113         virtual OBJECT_ID object_id() const;
00114         virtual void simplify();
00115 /* new */
00116                    void b_operate(b_op bop, sym_int_token *t);
00117                    bool comp_eq(sym_int_token *a, sym_int_token *b);
00118                    void set(sym_int_token *t);
00119                    void u_operate(u_op uop);
00120                    void replace(sym_int_token *token, sym_int_token *by);
00121 }; 
00122 
00123 /*
00124  *      CLASS sym_int_symbol
00125  */
00126 
00127 class sym_int_symbol: public sym_int_token {
00128 public:
00129         char *name;
00130 
00131         sym_int_symbol(char *name);
00132         ~sym_int_symbol();
00133 /* overwritten */
00134         virtual bool compare_eq(sym_int_token *t);
00135         virtual Object *duplicate();
00136         virtual bool evaluate(UINT *i);
00137         virtual int nstrfy(char *buf, int n);
00138         virtual OBJECT_ID object_id() const;
00139 };
00140 
00141 /*
00142  *      CLASS sym_int_const
00143  */
00144 
00145 class sym_int_const: public sym_int_token {
00146 public:
00147         UINT value;
00148 
00149         sym_int_const(UINT value);
00150 /* overwritten */
00151         virtual bool compare_eq(sym_int_token *t);
00152         virtual Object *duplicate();
00153         virtual bool evaluate(UINT *i);
00154         virtual int nstrfy(char *buf, int n);
00155         virtual OBJECT_ID object_id() const;
00156 };
00157 
00158 /*
00159  *      CLASS sym_bool_token
00160  */
00161 
00162 class sym_bool_token: public Object {
00163 public:
00164 /* new */
00165         virtual bool compare_eq(sym_bool_token *t)=0;
00166         virtual bool evaluate(bool *i);
00167         virtual int nstrfy(char *buf, int n)=0;
00168         virtual void simplify();
00169 };
00170 
00171 /*
00172  *      CLASS sym_bool_symbol
00173  */
00174 
00175 class sym_bool_symbol: public sym_bool_token {
00176 public:
00177         char *name;
00178 
00179         sym_bool_symbol(char *name);
00180         ~sym_bool_symbol();
00181 /* overwritten */
00182         virtual bool compare_eq(sym_bool_token *t);
00183         virtual Object *duplicate();
00184         virtual bool evaluate(bool *i);
00185         virtual int nstrfy(char *buf, int n);
00186         virtual OBJECT_ID object_id() const;
00187 };
00188 
00189 /*
00190  *      CLASS sym_bool_const
00191  */
00192 
00193 class sym_bool_const: public sym_bool_token {
00194 public:
00195         bool value;
00196 
00197         sym_bool_const(bool value);
00198 /* new */
00199         virtual bool compare_eq(sym_bool_token *t);
00200         virtual bool evaluate(bool *i);
00201         virtual int nstrfy(char *buf, int n);
00202 };
00203 
00204 /*
00205  *      CLASS sym_bool_intcmp
00206  */
00207 
00208 class sym_bool_intcmp: public sym_bool_token {
00209 public:
00210         sym_int_token *int1;
00211         c_op cop;
00212         sym_int_token *int2;
00213 
00214         sym_bool_intcmp(sym_int_token *int1, c_op cop, sym_int_token *int2);
00215 /* overwritten */       
00216         virtual bool compare_eq(sym_bool_token *t);
00217         virtual Object *duplicate();
00218         virtual bool evaluate(bool *i);
00219         virtual int nstrfy(char *buf, int n);
00220         virtual OBJECT_ID object_id() const;
00221         virtual void simplify();
00222 };
00223 
00224 /*
00225  *      CLASS sym_bool
00226  */
00227 
00228 class sym_bool: public sym_bool_token {
00229 protected:
00230         ht_list *tokens;
00231 
00232         void clear();
00233 public:
00234         sym_bool();
00235         ~sym_bool();
00236 /* overwritten */
00237         virtual bool compare_eq(sym_bool_token *t);
00238         virtual Object *duplicate();
00239         virtual bool evaluate(bool *i);
00240         virtual int nstrfy(char *buf, int n);
00241         virtual OBJECT_ID object_id() const;
00242         virtual void simplify();
00243 /* new */
00244                    void l_operate(l_op l, sym_bool_token *t);
00245                    void set(sym_bool_token *t);
00246                    void n_operate(n_op n);
00247 }; 
00248 
00249 #endif /* __SYMMATH_H__ */

Generated on Fri May 7 21:15:44 2004 by doxygen 1.3.5