00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #ifndef __DFA_SOURCE_RE_HH__
00066 #define __DFA_SOURCE_RE_HH__
00067
00068 #include "vbitset.hh"
00069 #include "re_node.hh"
00070
00075 class DfaSourceRe : public ReNode
00076 {
00077 public:
00078
00079 DfaSourceRe (const Position &pos_) :
00080 ReNode(pos_)
00081 {}
00082
00083 ~DfaSourceRe ()
00084 {}
00085
00086 #ifdef DEBUG
00087 static int indent_level;
00088
00089 static void indent()
00090 {
00091 indent_level++;
00092 }
00093
00094 static void unindent ()
00095 {
00096 indent_level--;
00097 }
00098
00099 static ostream& format (ostream &os)
00100 {
00101 for (int i = 0; i < indent_level; i++)
00102 os << " ";
00103 return os;
00104 }
00105
00106 virtual void dump (ostream &os) const;
00107
00108 #endif
00109
00110 public:
00111
00115 bool nullable;
00116
00120 vBitset firstPos;
00121
00125 vBitset lastPos;
00126 };
00127
00128
00134 class ReCatNode : public DfaSourceRe
00135 {
00136 public:
00137
00138 ReCatNode (DfaSourceRe *pre_, DfaSourceRe *post_, const Position &pos_) :
00139 pre(pre_), post(post_), DfaSourceRe(pos_)
00140 {}
00141
00142 ~ReCatNode ()
00143 {
00144 delete pre;
00145 delete post;
00146 }
00147
00148 virtual ReNode* clone ()
00149 {
00150 return new ReCatNode(dynamic_cast<DfaSourceRe*>(pre->clone()),
00151 dynamic_cast<DfaSourceRe*>(post->clone()), getPos());
00152 }
00153
00154 virtual int getChildCount ()
00155 {
00156 return 2;
00157 }
00158
00159 virtual ReNode& operator [] (int index)
00160 {
00161 ASSERT((0 <= index) && (index <= 1),
00162 "Bad index in ReCatNode::operator []");
00163 return index ? *post : *pre;
00164 }
00165
00166 #ifdef DEBUG
00167
00168 virtual void dump (ostream &os) const;
00169
00170 #endif
00171
00172 DfaSourceRe *pre, *post;
00173 };
00174
00175
00181 class ReOrNode : public DfaSourceRe
00182 {
00183 public:
00184
00185 ReOrNode (DfaSourceRe *pre_, DfaSourceRe *post_, const Position &pos_) :
00186 DfaSourceRe(pos_),
00187 pre(pre_), post(post_)
00188 {}
00189
00190 ~ReOrNode ()
00191 {
00192 delete pre;
00193 delete post;
00194 }
00195
00196 virtual ReNode* clone ()
00197 {
00198 return new ReOrNode(dynamic_cast<DfaSourceRe*>(pre->clone()),
00199 dynamic_cast<DfaSourceRe*>(post->clone()), getPos());
00200 }
00201
00202 virtual int getChildCount ()
00203 {
00204 return 2;
00205 }
00206
00207 virtual ReNode& operator [] (int index)
00208 {
00209 ASSERT((0 <= index) && (index <= 1),
00210 "Bad index for ReOrNode::operator []");
00211 return index ? *post : *pre;
00212 }
00213
00214 #ifdef DEBUG
00215
00216 virtual void dump (ostream &os) const;
00217
00218 #endif
00219
00220 DfaSourceRe *pre, *post;
00221 };
00222
00223
00229 class ReStarNode : public DfaSourceRe
00230 {
00231 public:
00232
00233 ReStarNode (DfaSourceRe *in_, const Position &pos_) :
00234 DfaSourceRe(pos_),
00235 in(in_)
00236 {}
00237
00238 ~ReStarNode ()
00239 {
00240 delete in;
00241 }
00242
00243 virtual ReNode* clone ()
00244 {
00245 return new ReStarNode(dynamic_cast<DfaSourceRe*>(in->clone()), getPos());
00246 }
00247
00248 virtual int getChildCount ()
00249 {
00250 return 1;
00251 }
00252
00253 virtual ReNode& operator [] (int index)
00254 {
00255 ASSERT(index == 0, "Bad index for ReStarNode::operator []");
00256 return *in;
00257 }
00258
00259 #ifdef DEBUG
00260
00261 virtual void dump (ostream &os) const;
00262
00263 #endif
00264
00265 DfaSourceRe *in;
00266 };
00267
00268
00273 class ReCharNode : public DfaSourceRe
00274 {
00275 public:
00276
00277 ReCharNode (unsigned char match_, const Position &pos_) :
00278 DfaSourceRe(pos_),
00279 match(match_)
00280 {}
00281
00282 virtual ReNode* clone ()
00283 {
00284 return new ReCharNode(match, getPos());
00285 }
00286
00287 virtual int getChildCount ()
00288 {
00289 return 0;
00290 }
00291
00292 virtual ReNode& operator [] (int index)
00293 {
00294 ASSERT(0, "ReCharNode::operator [] called !");
00295 return * (ReNode*) NULL;
00296 }
00297
00298 #ifdef DEBUG
00299
00300 virtual void dump (ostream &os) const;
00301
00302 #endif
00303
00304 unsigned char match;
00305
00306 int pos;
00307 };
00308
00309
00319 class ReEotNode : public DfaSourceRe
00320 {
00321 public:
00322
00323 ReEotNode (int tokId_, const Position &pos_) :
00324 DfaSourceRe(pos_),
00325 tokId(tokId_)
00326 {}
00327
00328 virtual ReNode* clone ()
00329 {
00330 return new ReEotNode(tokId, getPos());
00331 }
00332
00333 virtual int getChildCount ()
00334 {
00335 return 0;
00336 }
00337
00338 virtual ReNode& operator [] (int index)
00339 {
00340 ASSERT(0, "ReEotNode::operator [] called !");
00341 return * (ReNode*) NULL;
00342 }
00343
00344 #ifdef DEBUG
00345
00346 virtual void dump (ostream &os) const;
00347
00348 #endif
00349
00350 int tokId;
00351
00352 int pos;
00353 };
00354
00355
00359 class ReLambdaNode : public DfaSourceRe
00360 {
00361 public:
00362
00363 ReLambdaNode (const Position &pos_) :
00364 DfaSourceRe(pos_)
00365 {}
00366
00367 virtual ReNode* clone ()
00368 {
00369 return new ReLambdaNode(getPos());
00370 }
00371
00372 virtual int getChildCount ()
00373 {
00374 return 0;
00375 }
00376
00377 virtual ReNode& operator [] (int index)
00378 {
00379 ASSERT(0, "ReLambdaNode::operator [] called !");
00380 return * (ReNode*) NULL;
00381 }
00382
00383 #ifdef DEBUG
00384
00385 virtual void dump (ostream &os) const;
00386
00387 #endif
00388
00389 int pos;
00390 };
00391
00392
00393 #endif