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

token_spec.hh

Go to the documentation of this file.
00001 /*
00002  *  File:       token_spec.hh
00003  *              $Id: token_spec.hh,v 1.3 2002/06/26 20:51:04 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: token_spec.hh,v $
00012  *  Revision 1.3  2002/06/26 20:51:04  alec
00013  *  g++ 3.x happy
00014  *
00015  *  Revision 1.2  2002/06/13 11:43:02  alec
00016  *  added #line stuff
00017  *
00018  *  Revision 1.1  2002/05/04 17:46:53  alec
00019  *  *** empty log message ***
00020  *
00021  */
00022 
00023 
00024 /* 
00025   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00026 
00027   This program is free software; you can redistribute it and/or modify
00028   it under the terms of the GNU General Public License as published by
00029   the Free Software Foundation; either version 2 of the License, or
00030   (at your option) any later version.
00031 
00032   This program is distributed in the hope that it will be useful,
00033   but WITHOUT ANY WARRANTY; without even the implied warranty of
00034   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00035   GNU General Public License for more details.
00036 
00037   You should have received a copy of the GNU General Public License
00038   along with this program; if not, write to the Free Software
00039   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00040 
00041  */
00042 
00043 #ifndef __TOKEN_SPEC_HH__
00044 #define __TOKEN_SPEC_HH__
00045 
00046 #include <string>
00047 #include <vector>
00048 using namespace std;
00049 
00050 
00051 #include "itoken_spec.hh"
00052 
00053 class ReNode;
00054 
00055 class TokenDesc : public ITokenDesc
00056 {
00057 public:
00058 
00062   TokenDesc (const string &name_, int id_, ITokenSpec::Tkinds kind_,
00063              ReNode *regexp_, const string &action_,
00064              const Position &pos_) :
00065     _name(name_), _id(id_), _kind(kind_), _regexp(regexp_),
00066     _pos(pos_), _action(pos_, action_)
00067   {}
00068   
00072   TokenDesc (const string name_, int id_, const Position &pos_) :
00073     _name(name_), _id(id_), _kind(ITokenSpec::special),
00074     _regexp(NULL), _pos(pos_)
00075   {}
00076 
00077   TokenDesc (const TokenDesc &o) :
00078     _name(o._name), _id(o._id), _kind(o._kind), _regexp(o._regexp),
00079     _action(o._action), _pos(o._pos)
00080   {}
00081   
00082   virtual const string& name() const { return _name; }
00083 
00084   virtual int id () const { return _id; }
00085 
00086   virtual ITokenSpec::Tkinds kind() const { return _kind; }
00087   
00088   virtual const Position& pos () const { return _pos; }
00089 
00090   virtual const CodeChunk& tokAction() const { return _action; }
00091 
00092 #ifdef DEBUG
00093   
00098   virtual void dump (ostream &os) const;
00099   
00100 #endif
00101 
00102 private:
00106   string _name;
00107 
00111   ITokenSpec::Tkinds _kind;
00112 
00116   ReNode *_regexp;
00117 
00121   int _id;
00122 
00126   CodeChunk _action;
00127 
00131   Position _pos;
00132 };
00133 
00134 class TokenSpec : public ITokenSpec
00135 {
00136 public:
00137   
00138   virtual void setClassName (const string &className);
00139   
00140   virtual void setInheritance (const string &inheritance,
00141                                const Position &pos);
00142   
00143   virtual void setPreambleCode (const string &preambleCode,
00144                                 const Position &pos);
00145 
00146   virtual void addCodeBlock (const string &block, const Position &pos);
00147 
00148   virtual void addToken (const string &tokName, Tkinds tokKind,
00149                          ReNode *regexp, const string &tokAction,
00150                          const Position &pos) throw (ParseException);
00151 
00152   virtual void addToken (const string &tokName, const Position &pos)
00153     throw (ParseException);
00154 
00155   virtual bool isToken (const string &tokName);
00156 
00157   virtual int getTokenId (const string &tokName);
00158 
00159   virtual TokenDesc& operator [] (int tokid);
00160 
00161   virtual int count ();
00162 
00163 #ifdef DEBUG
00164   virtual void dump (ostream &os) const;
00165 #endif
00166 
00167 private:
00168 
00169   vector<TokenDesc> tokens;
00170 };
00171 
00172 #endif /* #ifndef __TOKEN_SPEC_HH__ */

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