Class representing one token of a program.
More...
#include <src/CBot/CBotToken.h>
|
| | CBotToken () |
| | Default constructor.
|
| | CBotToken (const CBotToken &pSrc) |
| | Copy constructor.
|
| | CBotToken (const std::string &text, const std::string &sep="", int start=0, int end=0) |
| | Constructor.
|
| | ~CBotToken () |
| | Destructor.
|
| int | GetType () |
| | Return the token type or the keyword id.
|
| const std::string & | GetString () |
| | Return the token string.
|
| void | SetString (const std::string &name) |
| | Set the token string.
|
| int | GetStart () |
| | Return the beginning location of this token in the original program string.
|
| int | GetEnd () |
| | Return the ending location of this token in the original program string.
|
| void | SetPos (int start, int end) |
| | SetPos Set the token position in the CBot program.
|
| long | GetKeywordId () |
| | Get the keyword id.
|
| const CBotToken & | operator= (const CBotToken &src) |
| | Copy operator.
|
| virtual | ~CBotDoublyLinkedList () |
| | Destructor. Be careful, destroys the whole linked list!
|
| CBotToken * | GetNext () |
| | Returns the next variable in the linked list.
|
| CBotToken * | GetPrev () |
| | Returns the previous variable in the linked list.
|
| void | AddNext (CBotToken *elem) |
| | Appends a new element at the end of the linked list.
|
|
| static std::unique_ptr< CBotToken > | CompileTokens (const std::string &prog) |
| | Transforms a CBot program from a string to a list of tokens.
|
| static bool | DefineNum (const std::string &name, long val) |
| | Define a new constant.
|
| static void | ClearDefineNum () |
| | Clear the list of defined constants.
|
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.
Example tokens
This code:
int var = 3 * ( pos.y + x );
string test = "Hello world";
Is decomposed into (each line is a token, separate CBotToken instance):
int
var
=
3
*
(
pos
.
y
+
x
)
;
string
test
=
"Hello world"
;
Example usage
while(token != nullptr)
{
}
T * GetNext()
Returns the next variable in the linked list.
Definition CBotUtils.h:152
static std::unique_ptr< CBotToken > CompileTokens(const std::string &prog)
Transforms a CBot program from a string to a list of tokens.
Definition CBotToken.cpp:466
CBotToken()
Default constructor.
Definition CBotToken.cpp:156
const std::string & GetString()
Return the token string.
Definition CBotToken.cpp:230
◆ CBotToken() [1/3]
| CBot::CBotToken::CBotToken |
( |
| ) |
|
◆ CBotToken() [2/3]
| CBot::CBotToken::CBotToken |
( |
const CBotToken & | pSrc | ) |
|
◆ CBotToken() [3/3]
| CBot::CBotToken::CBotToken |
( |
const std::string & | text, |
|
|
const std::string & | sep = "", |
|
|
int | start = 0, |
|
|
int | end = 0 ) |
Constructor.
- Parameters
-
| 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 |
◆ ~CBotToken()
| 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
◆ GetType()
| int CBot::CBotToken::GetType |
( |
| ) |
|
Return the token type or the keyword id.
- Returns
- A value from ::TokenType. For ::TokenTypKeyWord, returns the keyword ID instead.
◆ GetString()
| const std::string & CBot::CBotToken::GetString |
( |
| ) |
|
Return the token string.
- Returns
- The string associated with this token
◆ SetString()
| void CBot::CBotToken::SetString |
( |
const std::string & | name | ) |
|
Set the token string.
- Parameters
-
| name | The new string to set |
◆ GetStart()
| int CBot::CBotToken::GetStart |
( |
| ) |
|
Return the beginning location of this token in the original program string.
◆ GetEnd()
| int CBot::CBotToken::GetEnd |
( |
| ) |
|
Return the ending location of this token in the original program string.
◆ SetPos()
| void CBot::CBotToken::SetPos |
( |
int | start, |
|
|
int | end ) |
SetPos Set the token position in the CBot program.
- Parameters
-
| start | The start position of the token |
| end | The end position of the token |
◆ GetKeywordId()
| long CBot::CBotToken::GetKeywordId |
( |
| ) |
|
Get the keyword id.
- Returns
- The keyword id, see ::TokenId
◆ operator=()
◆ CompileTokens()
| std::unique_ptr< CBotToken > CBot::CBotToken::CompileTokens |
( |
const std::string & | prog | ) |
|
|
static |
Transforms a CBot program from a string to a list of tokens.
- Parameters
-
- Returns
- The first token in the linked list
◆ DefineNum()
| bool CBot::CBotToken::DefineNum |
( |
const std::string & | name, |
|
|
long | val ) |
|
static |
Define a new constant.
- Parameters
-
| name | Name of the constant |
| val | Value of the constant |
- Returns
- true on success, false if already defined
◆ ClearDefineNum()
| void CBot::CBotToken::ClearDefineNum |
( |
| ) |
|
|
static |
Clear the list of defined constants.
- See also
- DefineNum()
The documentation for this class was generated from the following files:
- src/CBot/CBotToken.h
- src/CBot/CBotToken.cpp