00001 #if !defined( __INTERPRET_H__ ) 00002 #define __INTERPRET_H__ 00003 00004 #pragma warning( disable: 4786 ) 00005 00006 class Lexer { 00007 private: 00008 00009 const string &buffer; 00010 string::size_type at , bufLen; 00011 00012 string constantStr; 00013 bool realConstant; 00014 00015 public: 00016 00017 int lineno; 00018 00019 std::map<string,int,greater<string> > symbol; 00020 00021 Lexer( const string &aBuffer ); 00022 00023 ~Lexer( void ) {}; 00024 00025 virtual const int GetTopSymbol( void ); 00026 00027 virtual const char atSr( const int ati , const int atj ) = 0; 00028 virtual const int EofId( void ) const = 0; 00029 virtual const int IdentifierId( void ) const = 0; 00030 virtual const int NumberId( void ) const = 0; 00031 00032 const bool IsReal( void ) const { return realConstant; } 00033 const string &GetConstant( void ) const { return constantStr; } 00034 00035 protected: 00036 00037 virtual const bool isSeparator( void ); 00038 virtual const int SkipComment( void ); 00039 00040 virtual const int LexNext( void ); 00041 virtual const int GetIdentifier( void ); 00042 virtual const int GetNumber( void ); 00043 }; 00044 00045 00046 class TreeNode { 00047 public: 00048 00049 int symbolId; 00050 string constant; 00051 00052 TreeNode *next , *child; 00053 00054 TreeNode( const int aSymbolId = -1 , const string aConstant = "" ) 00055 : constant( aConstant ) , symbolId( aSymbolId ) , next( 0 ) , child( 0 ) 00056 {}; 00057 00058 virtual ~TreeNode( void ) 00059 { 00060 if( next ) delete next; next = 0; 00061 if( child ) delete child; child = 0; 00062 } 00063 00064 }; 00065 00066 class Interpret : public deque<TreeNode *> { 00067 private: 00068 00069 Lexer &duraLex; 00070 00071 public: 00072 00073 Interpret( Lexer &SedLex ); 00074 00075 ~Interpret( void ) 00076 { 00077 for( deque<TreeNode *>::iterator it = begin() ; it != end() ; ++it ) 00078 delete (*it); 00079 clear(); 00080 }; 00081 00082 const bool Run( void ); 00083 00084 protected: 00085 00086 virtual void Initialize( void ); 00087 virtual void ShiftRule( const int TopSymbol ); 00088 virtual const bool ReduceRule( const int TopSymbol ); 00089 }; 00090 00091 #endif 00092