Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Token.h

Go to the documentation of this file.
00001 /*
00002   File: Token.h
00003 
00004   Copyright(C) C. Kotterink, Computed Graphics
00005 */
00006 #ifndef TOKEN_H
00007 #define TOKEN_H
00008 
00009 #include<iostream.h>
00010 #include<string>
00011 
00015 class ObjectFile;
00016 
00018 typedef enum TokenId {
00019     nosym = 0,          
00020     eofsym,             
00021     // Brackets
00022     lgroupsym,          
00023     rgroupsym,          
00024     lsqbracksym,        
00025     rsqbracksym,        
00026     lbracksym,          
00027     rbracksym,          
00028     // Seperators
00029     commasym,           
00030     colonsym,           
00031     semicolonsym,       
00032     // Comment
00033     commentsym,         
00034     commentOpensym,     
00035     commentClosesym,    
00036     // Operators
00037     multiplysym,        
00038     substractsym,       
00039     addsym,             
00040     dividesym,          
00041     // Variable
00042     directivesym,       
00043     numbersym,          
00044     stringsym,          
00045     classsym,           
00046     lastsym,            
00047 };
00048 
00051 class Token
00052 {
00053     friend ObjectFile;
00054 
00056     friend ostream &operator<<(ostream &stream, const Token &token);
00057 
00058 public:
00060     static const string lookup(TokenId type);
00061 
00063     Token() : id(nosym) {}
00064 
00066     Token &operator=(const Token &t);
00067 
00069     bool operator==(TokenId t) const {
00070         return id == t;
00071     }
00072 
00074     bool operator!=(TokenId t) const {
00075         return id != t;
00076     }
00077 
00079     TokenId getId() { return id; }
00080 
00082     int asInt() { return (int)asDouble(); }
00083 
00085     float asFloat() { return (float)asDouble(); }
00086 
00088     double asDouble() { return value; }
00089 
00091     string &asString() { return data; }
00092     
00093 protected:
00095     static const string stringTable[];
00096 
00098     TokenId id;
00099 
00103     double value;
00104 
00108     string data;
00109 };
00110 #endif

This documentation was generated using doxygen. If you have any comments or additions please mail me.