Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

cxxScanner.h

00001 #ifndef CXXSCANNER_H
00002 #define CXXSCANNER_H
00003 #include <stdio.h>
00004 #include <string>
00005 #include <vector>
00006 #include "obstack.h"
00007 enum TOKEN_t { OTHER=-1, ENDFILE = 0, ATS=1, AMPERSTAND, ARRAY_DELETE, ARRAY_NEW, ARROW,
00008                ARROWSTAR, BIT_AND_EQUALS, BIT_OR, BIT_OR_EQUALS, BRACKET_PAIR, BSLASH, CLASS, 
00009                COLON, COMMA, CONST, CPPELIF, CPPIF, CXXCMNT, DCOLON, DEFINE, DELETE, DIV,
00010                DIVEQUALS, DQSTR, ECMNT, ENUM, EQUAL, EQUALITY, GREATERTHAN, GREATERTHAN_EQUALS, 
00011                ICMNT, ID, LBRACE, LBRACKET, LESSTHAN, LESSTHAN_EQUALS, LOGICAL_AND, 
00012                LOGICAL_NOT, LOGICAL_NOT_EQUALS, LOGICAL_OR, LPAREN, LSHIFT, LSHIFT_ASSIGN,
00013                MINUS, MINUSEQUALS, MINUSMINUS, NAMESPACE, NEW, NLSPACE, OPERATOR, PAREN_PAIR,
00014                PERCENT, PERCENTEQUALS, PLUS, PLUSEQUALS, PLUSPLUS, RBRACE, RETURN, RPAREN,
00015                RSHIFT, RSHIFT_ASSIGN, SCMNT, SEMICOLON, SPACE, SQSTR, STRUCT, TEMPLATE, TILDE, 
00016                TIMES, TIMESEQUALS, USING, XOR, XOREQUALS};
00017 
00018 //====================================================
00022 //====================================================
00023 class Token
00024 {
00025  public:
00027   Token(TOKEN_t a = ENDFILE, const char* b = 0, int len = 0, int lineIn = -1, int colIn = -1);
00028 
00029   Token(const Token& t);
00030 
00031   ~Token();    
00032 
00033   void assign(TOKEN_t a, const char* b, int len, int lineIn, int colIn);
00034 
00035   TOKEN_t             tokenType() const  { return m_tokenType; } 
00036   const char*         text()      const  { return mp_text;     }
00037   int                 textLen()   const  { return m_len;       } 
00038   int                 lineNo()    const  { return m_line;      } 
00039   int                 column()    const  { return m_column;    } 
00040 
00041   static void  setObstack(Obstack* s)    { msp_obstack = s;    } 
00042   static void  resetObstack();                                   
00043  protected:
00044   TOKEN_t     m_tokenType;   
00045   int         m_len;         
00046   int         m_line;        
00047   int         m_column;      
00048   const char* mp_text;       
00049   static Obstack* msp_obstack;
00050 };
00051 
00052 //====================================================
00073 //====================================================
00074 class CxxScanner
00075 {
00076  public:
00077   enum {HSIZE=128, HMASK=127};
00078   //====================================================
00083   //====================================================
00084   CxxScanner(const char* fileName);
00085 
00086   //====================================================
00090   //====================================================
00091   ~CxxScanner();
00092 
00093 
00094   static const char* filename() { return mp_fileName; }  
00095   static int lineNo();                                   
00096   static int column(int icol);                           
00097 
00098   //====================================================
00106   //====================================================
00107   Token read(const char* errStr = 0);
00108 
00109   //====================================================
00114   //====================================================
00115   void  pushBack(Token& t);
00116 
00117   //====================================================
00121   //====================================================
00122   Token prevToken(int i);
00123 
00124 
00125  private:
00126   static char*       mp_fileName;         
00127   int                m_current;           
00128   std::vector<Token> m_tokens;            
00129   int                m_stackCnt;          
00130   int                m_stdin;             
00131   Obstack            m_s;
00132 };
00133 
00134 
00135 
00136 #endif // CXXSCANNER_H
00137 



Project Hosted By:
SourceForge.net Logo