00001
00002 #ifndef LXR_HH
00003 #define LXR_HH
00004
00005 #include "Translate.hh"
00006 #include <string>
00007 #include <vector>
00008 #include <iosfwd>
00009
00022 class lxr {
00023 public:
00024
00027 typedef int state_type;
00028
00031 typedef char char_type;
00032
00035 typedef int token_type;
00036
00037 public:
00040 enum select_type {
00041 kChar,
00042 kGroup,
00043 kDefault,
00044 kEOF
00045 };
00046
00049 enum flag_bits {
00050 kUnget,
00051 kNoSave,
00052 kReturn
00053 };
00054
00057 class transition {
00058 public:
00061 transition(select_type sel, char_type sel_id, int flags,
00062 state_type next);
00065 bool fTest(flag_bits b) const;
00066
00069 state_type next(void) const;
00070
00073 select_type sType(void) const;
00074
00077 char_type selID(void) const;
00078 private:
00079 select_type _select;
00080 int _selID;
00081 int _flags;
00082 state_type _next;
00083 };
00084
00087 typedef std::vector<transition> trans_list;
00088
00089 public:
00093 lxr(int N);
00094
00101 void check(bool warn) const;
00102
00105 void dump(void) const;
00106
00109 const transition& find(int state, char c) const;
00110
00114 token_type token(std::istream& in, std::string& tkn) const;
00115
00118 int push_state(void);
00119
00122 void addTransition(int state, select_type sel, char_type sel_id, int flags,
00123 int next);
00124
00127 void setState0(int state);
00128
00131 void setTable(const Translate<char>& table);
00132
00133 private:
00134 int mStart;
00135 std::vector<int> mStateInx;
00136 trans_list mTranList;
00137 Translate<char> mTrTable;
00138 };
00139
00140
00141 inline lxr::state_type
00142 lxr::transition::next(void) const {
00143 return _next;
00144 }
00145
00146 inline lxr::select_type
00147 lxr::transition::sType(void) const {
00148 return _select;
00149 }
00150
00151 inline lxr::char_type
00152 lxr::transition::selID(void) const {
00153 return _selID;
00154 }
00155
00156 inline bool
00157 lxr::transition::fTest(flag_bits b) const {
00158 return (_flags & (1 << b)) != 0;
00159 }
00160
00161 #endif // !defined(LXR_HH)