Changeset 3588
 Timestamp:
 Mar 28, 2008, 4:46:36 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

toimperative/trunk/opents/samples/trefal.hh
r3562 r3588 8 8 class Expr; 9 9 10 typedef ts::TVar<Expr> TExpr; 10 class TExpr : public ts::TVar<Expr> 11 { 12 public: 13 bool operator== (TExpr& _e); 14 }; 11 15 12 16 struct Term { … … 17 21 int i; 18 22 TExpr e; 23 24 void init (char _c) { 25 type = CHAR; 26 c = _c; 27 i = 0; 28 (Expr&)e; 29 } 30 31 void init (int _i) { 32 type = INT; 33 c = 0; 34 i = _i; 35 (Expr&)e; 36 } 37 38 void init (const TExpr& _e) { 39 type = EXPR; 40 c = 0; 41 i = 0; 42 e = _e; 43 } 19 44 }; 45 46 inline bool operator== (Term& _t1, Term& _t2) { 47 return _t1.type == _t2.type && _t1.c == _t2.c && _t1.i == _t2.i && _t1.e == _t2.e; 48 } 49 50 inline bool operator!= (Term& _t1, Term& _t2) { 51 return !(_t1 == _t2); 52 } 20 53 21 54 class Expr : private ts::TExtData … … 59 92 60 93 void init_str (const char* str, size_t len) { 61 assert(!terms); 62 terms = new Term[len]; 63 extDataSize() = len * sizeof(Term); 64 for (unsigned i = 0; i < len; i++) { 65 terms[i].type = Term::CHAR; 66 terms[i].c = str[i]; 67 ((Expr&)terms[i].e).init(0); 68 } 94 init(len); 95 for (unsigned i = 0; i < len; i++) 96 terms[i].init(str[i]); 69 97 } 70 98 71 99 void init_subexpr (const Expr& e, size_t start, size_t len) { 72 assert(!terms); 73 terms = new Term[len]; 74 extDataSize() = len * sizeof(Term); 100 init(len); 75 101 copyFrom(e, start, len); 76 102 } 77 103 78 104 void init_paren (const TExpr& te) { 79 assert(!terms); 80 terms = new Term[1]; 81 extDataSize() = sizeof(Term); 82 terms>type = Term::EXPR; 83 terms>e = te; 105 init(1); 106 terms>init(te); 84 107 } 85 108 … … 122 145 } 123 146 124 Expr operator() () const { 125 Expr e; 126 e.init(1); 127 Term* p = (Term *)e; 128 p>type = Term::EXPR; 129 p>e = *this; 130 return e; 131 } 147 // Expr operator() () const { 148 // Expr e; 149 // e.init(1); 150 // Term* p = (Term *)e; 151 // p>type = Term::EXPR; 152 // p>e = *this; 153 // p>c = 0; 154 // p>i = 0; 155 // return e; 156 // } 132 157 133 158 size_t get_len () const { … … 179 204 t.type = Term::CHAR; 180 205 is >> t.c; 181 ((Expr &)(t.e)).init(0); 206 t.i = 0; 207 (Expr &)(t.e); 182 208 } else if ('0' <= c && c <= '9') { 183 209 t.type = Term::INT; 184 210 is >> t.i; 185 ((Expr &)(t.e)).init(0); 211 t.c = 0; 212 (Expr &)(t.e); 186 213 } else if (c == '(') { 187 214 t.type = Term::EXPR; 215 t.c = 0; 216 t.i = 0; 188 217 is >> (Expr &)(t.e); 189 218 } else { … … 227 256 return e; 228 257 } 258 259 inline bool operator== (Expr& _e1, Expr& _e2) { 260 size_t len = _e1.get_len(); 261 if (len != _e2.get_len()) 262 return false; 263 Term* p = _e1; 264 Term* q = _e2; 265 for (unsigned i = 0; i < len; i++) 266 if (*p++ != *q++) 267 return false; 268 return true; 269 } 270 271 bool TExpr::operator== (TExpr& _e) { 272 return d.cellOffset == _e.d.cellOffset  (Expr&)*this == (Expr&)_e; 273 } 274
Note: See TracChangeset
for help on using the changeset viewer.