An object that represents a C++ lexical token. CPP_Token objects are usually obtained from token streams. See CPP_Token_Stream's for an example use. More...
#include <cpp_token_stream.h>
Public Types | |
enum | token_types_ { eof = 0x000, eql = 0x100, neq = 0x101, leq = 0x102, geq = 0x103, sle = 0x104, sre = 0x105, dve = 0x106, ple = 0x107, mne = 0x108, tme = 0x109, mde = 0x10a, adr = 0x10b, orr = 0x10c, ore = 0x10d, ade = 0x10e, inc = 0x10f, dec = 0x110, shr = 0x111, shl = 0x112, lan = 0x113, der = 0x114, teq = 0x115, ceq = 0x116, eli = 0x117, ptr = 0x118, nmb = 0x201, aln = 0x202, inv = 0x300, special_tokens } |
A list of names for the multi-character tokens and the end of file situation. More... | |
Public Member Functions | |
operator std::string const & () const | |
Automatic conversion to string. All you get is the token's string text_ value. | |
Static Public Member Functions | |
static std::string | type_name (int type) |
static method giving a string representation of a token's type. | |
Public Attributes | |
std::string | file_ |
what file was the token found in | |
int | line_ |
what line does the token begin on | |
std::string | text_ |
int | type_ |
be the exact text parsed -- including any quotes, \'s etc. |
An object that represents a C++ lexical token. CPP_Token objects are usually obtained from token streams. See CPP_Token_Stream's for an example use.
The fastest way to compare a token to an expected value is to first verify that its 'type_' is correct. Type is an integer so the comparison is quick. Next, verify that that the text_ is correct If the type is wrong, there's no reason to check the string value. To further speed up the comparison, if you want, you can verify that the first character of the text_ equals the desired string. So here is some code that compares a token to some possible known values:
if(token.type_ == ';') return true; // no text comparison is needed if(token.type_ == CPP_Token::aln) return true; // any old identifier if(token.type_ == CPP_Token::der) return true; // its a :: operator if(token.type_ == CPP_Token::aln && token.text_[0] == 'i' && token.text_ == "if" ) return true; // it is the 'if' keyword
Definition at line 58 of file cpp_token_stream.h.
enum token_types_ |
A list of names for the multi-character tokens and the end of file situation.
Definition at line 106 of file cpp_token_stream.h.
operator std::string const & | ( | ) | const |
Automatic conversion to string. All you get is the token's string text_ value.
Definition at line 98 of file cpp_token_stream.h.
std::string type_name | ( | int | type | ) | [static] |
static method giving a string representation of a token's type.
type | specifies the token type whose name should be returned |
Definition at line 39 of file cpp_token_stream.cxx.
std::string file_ |
what file was the token found in
Definition at line 96 of file cpp_token_stream.h.
int line_ |
what line does the token begin on
Definition at line 94 of file cpp_token_stream.h.
std::string text_ |
Definition at line 83 of file cpp_token_stream.h.
int type_ |
be the exact text parsed -- including any quotes, \'s etc.
An integer value definiting the token type. Single character tokens have a type value which equals their character value. Multi-character tokens have named values which are members of the token_types_ nested enumeration.
Definition at line 87 of file cpp_token_stream.h.