Colobot
|
Class representing one token of a program. More...
#include <CBotToken.h>
Public Member Functions | |
CBotToken () | |
Default constructor. More... | |
CBotToken (const CBotToken &pSrc) | |
Copy constructor. More... | |
CBotToken (const std::string &text, const std::string &sep="", int start=0, int end=0) | |
Constructor. More... | |
~CBotToken () | |
Destructor. More... | |
int | GetType () |
Return the token type or the keyword id. More... | |
std::string | GetString () |
Return the token string. More... | |
void | SetString (const std::string &name) |
Set the token string. More... | |
int | GetStart () |
Return the beginning location of this token in the original program string. More... | |
int | GetEnd () |
Return the ending location of this token in the original program string. More... | |
void | SetPos (int start, int end) |
SetPos Set the token position in the CBot program. More... | |
long | GetKeywordId () |
Get the keyword id. More... | |
const CBotToken & | operator= (const CBotToken &src) |
Copy operator. More... | |
![]() | |
virtual | ~CBotDoublyLinkedList () |
Destructor. Be careful, destroys the whole linked list! More... | |
CBotToken * | GetNext () |
Returns the next variable in the linked list. More... | |
CBotToken * | GetPrev () |
Returns the previous variable in the linked list. More... | |
void | AddNext (CBotToken *elem) |
Appends a new element at the end of the linked list. More... | |
Static Public Member Functions | |
static std::unique_ptr< CBotToken > | CompileTokens (const std::string &prog) |
Transforms a CBot program from a string to a list of tokens. More... | |
static bool | DefineNum (const std::string &name, long val) |
Define a new constant. More... | |
static void | ClearDefineNum () |
Clear the list of defined constants. More... | |
Additional Inherited Members | |
![]() | |
CBotToken * | m_next |
CBotToken * | m_prev |
Class representing one token of a program.
A CBot program starts as a text string. This string is first transformed into a list of tokens.
This code:
Is decomposed into (each line is a token, separate CBotToken instance):
CBot::CBotToken::CBotToken | ( | ) |
Default constructor.
CBot::CBotToken::CBotToken | ( | const CBotToken & | pSrc | ) |
Copy constructor.
CBot::CBotToken::CBotToken | ( | const std::string & | text, |
const std::string & | sep = "" , |
||
int | start = 0 , |
||
int | end = 0 |
||
) |
Constructor.
text | The string this token represents |
sep | All separators that appeared after this token |
start | Beginning location in the source code of this token |
end | Ending location in the source code of this token |
CBot::CBotToken::~CBotToken | ( | ) |
Destructor.
Be careful! This destroys the whole linked list of tokens
Never call in the middle of the sequence - always on the first token in the list
int CBot::CBotToken::GetType | ( | ) |
Return the token type or the keyword id.
std::string CBot::CBotToken::GetString | ( | ) |
Return the token string.
void CBot::CBotToken::SetString | ( | const std::string & | name | ) |
Set the token string.
name | The new string to set |
int CBot::CBotToken::GetStart | ( | ) |
Return the beginning location of this token in the original program string.
int CBot::CBotToken::GetEnd | ( | ) |
Return the ending location of this token in the original program string.
void CBot::CBotToken::SetPos | ( | int | start, |
int | end | ||
) |
SetPos Set the token position in the CBot program.
start | The start position of the token |
end | The end position of the token |
long CBot::CBotToken::GetKeywordId | ( | ) |
Get the keyword id.
|
static |
Transforms a CBot program from a string to a list of tokens.
prog | The program string |
|
static |
Define a new constant.
name | Name of the constant |
val | Value of the constant |
|
static |
Clear the list of defined constants.