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 #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