Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

dfa_source_re.hh

Go to the documentation of this file.
00001 /*
00002  *  File:       dfa_source_re.hh
00003  *              $Id: dfa_source_re.hh,v 1.10 2002/06/05 21:32:14 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: dfa_source_re.hh,v $
00012  *  Revision 1.10  2002/06/05 21:32:14  alec
00013  *  g++ happy
00014  *
00015  *  Revision 1.9  2002/05/27 02:59:39  alec
00016  *  doc update
00017  *
00018  *  Revision 1.8  2002/05/22 01:32:05  alec
00019  *  cleaned up firstpo/followpos/nullable computation
00020  *
00021  *  Revision 1.7  2002/05/16 21:30:44  alec
00022  *  firstPos/lastPos caching
00023  *
00024  *  Revision 1.6  2002/05/01 16:32:14  alec
00025  *  dfa ok. huh !
00026  *
00027  *  Revision 1.5  2002/05/01 09:18:26  alec
00028  *  - vBitset fixes
00029  *  - FOLLOWPOS written (not tested yet)
00030  *
00031  *  Revision 1.4  2002/04/30 16:24:38  alec
00032  *  tested the scanner ptree & vBitVector implementation -> ok
00033  *
00034  *  Revision 1.3  2002/04/30 09:22:32  alec
00035  *  bitset fixes
00036  *
00037  *  Revision 1.2  2002/04/29 17:55:41  alec
00038  *  regexps almost done
00039  *
00040  *  Revision 1.1  2002/04/29 09:40:01  alec
00041  *  *** empty log message ***
00042  *
00043  */
00044 
00045 
00046 /* 
00047   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00048 
00049   This program is free software; you can redistribute it and/or modify
00050   it under the terms of the GNU General Public License as published by
00051   the Free Software Foundation; either version 2 of the License, or
00052   (at your option) any later version.
00053 
00054   This program is distributed in the hope that it will be useful,
00055   but WITHOUT ANY WARRANTY; without even the implied warranty of
00056   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00057   GNU General Public License for more details.
00058 
00059   You should have received a copy of the GNU General Public License
00060   along with this program; if not, write to the Free Software
00061   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* #ifndef __DFA_SOURCE_RE_HH__ */

Generated at Tue Jul 9 21:05:43 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001