34 #define CBOTVERSION 104
71 CBotTypArrayPointer = 10,
72 CBotTypArrayBody = 11,
75 CBotTypNullPointer = 13,
83 #define OBJECTDELETED (reinterpret_cast<void*>(-1))
85 #define OBJECTCREATED (reinterpret_cast<void*>(-2))
117 int GetType(
int mode = 0)
const;
126 int GetLimite()
const;
129 void SetLimite(
int n);
132 void SetArray(
int* max );
141 bool Eq(
int type)
const;
180 #define CBotErrOpenPar 5000 // missing the opening parenthesis
181 #define CBotErrClosePar 5001 // missing the closing parenthesis
182 #define CBotErrNotBoolean 5002 // expression must be a boolean
183 #define CBotErrUndefVar 5003 // undeclared variable
184 #define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... )
185 #define CBotErrNoTerminator 5005 // semicolon expected
186 #define CBotErrCaseOut 5006 // case outside a switch
188 #define CBotErrCloseBlock 5008 // missing " } "
189 #define CBotErrElseWhitoutIf 5009 // else without matching if
190 #define CBotErrOpenBlock 5010 // missing " { "
191 #define CBotErrBadType1 5011 // wrong type for the assignment
192 #define CBotErrRedefVar 5012 // redefinition of the variable
193 #define CBotErrBadType2 5013 // Two operands are incompatible
194 #define CBotErrUndefCall 5014 // routine undefined
195 #define CBotErrNoDoubleDots 5015 // " : " expected
197 #define CBotErrBreakOutside 5017 // break outside of a loop
198 #define CBotErrUndefLabel 5019 // label udnefined
199 #define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here)
200 #define CBotErrNoCase 5020 // missing " case "
201 #define CBotErrBadNum 5021 // expected number
202 #define CBotErrVoid 5022 // " void " not possible here
203 #define CBotErrNoType 5023 // type declaration expected
204 #define CBotErrNoVar 5024 // variable name expected
205 #define CBotErrNoFunc 5025 // expected function name
206 #define CBotErrOverParam 5026 // too many parameters
207 #define CBotErrRedefFunc 5027 // this function already exists
208 #define CBotErrLowParam 5028 // not enough parameters
209 #define CBotErrBadParam 5029 // wrong types of parameters
210 #define CBotErrNbParam 5030 // wrong number of parameters
211 #define CBotErrUndefItem 5031 // element does not exist in the class
212 #define CBotErrUndefClass 5032 // variable is not a class
213 #define CBotErrNoConstruct 5033 // no appropriate constructor
214 #define CBotErrRedefClass 5034 // class already exists
215 #define CBotErrCloseIndex 5035 // " ] " expected
216 #define CBotErrReserved 5036 // reserved word (for a DefineNum)
217 #define CBotErrBadNew 5037 // wrong setting for new
218 #define CBotErrOpenIndex 5038 // " [ " expected
219 #define CBotErrBadString 5039 // expected string
220 #define CBotErrBadIndex 5040 // wrong index type "[ false ]"
221 #define CBotErrPrivate 5041 // protected item
222 #define CBotErrNoPublic 5042 // missing word "public"
227 #define CBotErrZeroDiv 6000 // division by zero
228 #define CBotErrNotInit 6001 // uninitialized variable
229 #define CBotErrBadThrow 6002 // throw a negative value
230 #define CBotErrNoRetVal 6003 // function did not return results
231 #define CBotErrNoRun 6004 // Run() without active function
232 #define CBotErrUndefFunc 6005 // calling a function that no longer exists
233 #define CBotErrNotClass 6006 // this class does not exist
234 #define CBotErrNull 6007 // null pointer
235 #define CBotErrNan 6008 // calculation with a NAN
236 #define CBotErrOutArray 6009 // index out of array
237 #define CBotErrStackOver 6010 // stack overflow
238 #define CBotErrDeletedPtr 6011 // pointer to an object destroyed
240 #define CBotErrFileOpen 6012 // cannot open the file
241 #define CBotErrNotOpen 6013 // channel not open
242 #define CBotErrRead 6014 // error while reading
243 #define CBotErrWrite 6015 // writing error
267 bool IsEmpty()
const;
269 int Find(
const char c);
270 int Find(
const char* lpsz);
271 int ReverseFind(
const char c);
272 int ReverseFind(
const char* lpsz);
273 bool LoadString(
unsigned int id);
279 int Compare(
const char* lpsz)
const;
296 bool operator==(
const char* p);
298 bool operator!=(
const char* p);
300 bool operator>(
const char* p);
302 bool operator>=(
const char* p);
304 bool operator<(
const char* p);
306 bool operator<=(
const char* p);
308 operator const char*()
const;
320 static const std::map<EID,const char *> s_keywordString;
327 static const char * MapIdToString(EID
id);
343 void SetSize(
int nb);
383 bool m_bCompileClass;
402 bool Compile(
const char* program,
CBotStringArray& ListFonctions,
void* pUser = NULL);
409 void SetIdent(
long n);
416 bool GetError(
int& code,
int& start,
int& end);
417 bool GetError(
int& code,
int& start,
int& end,
CBotProgram* &pProg);
426 bool Start(
const char* name);
431 bool Run(
void* pUser = NULL,
int timer = -1);
437 bool GetRunPos(
const char* &FunctionName,
int &start,
int &end);
443 CBotVar* GetStackVars(
const char* &FunctionName,
int level);
456 void SetTimer(
int n);
461 bool AddFunction(
const char* name,
462 bool rExec (
CBotVar* pVar,
CBotVar* pResult,
int& Exception,
void* pUser),
468 bool DefineNum(
const char* name,
long val);
470 bool SaveState(FILE* pf);
474 bool RestoreState(FILE* pf);
478 bool GetPosition(
const char* name,
int& start,
int& stop,
479 CBotGet modestart = GetPosExtern,
480 CBotGet modestop = GetPosBloc);
492 FILE* fOpen(
const char* name,
const char* mode);
493 int fClose(FILE* filehandle);
494 size_t fWrite(
const void *buffer,
size_t elemsize,
size_t length, FILE* filehandle);
495 size_t fRead(
void *buffer,
size_t elemsize,
size_t length, FILE* filehandle);
515 if ( pVar == NULL )
return 6001;
517 while ( pVar != NULL )
519 if ( pVar->GetType() > CBotTypDouble )
return 6002;
520 pVar = pVar -> GetNext();
533 total += pVar->GetValFloat();
534 pVar = pVar->GetNext();
537 pResult->SetValFloat(total/nb);
551 #define IS_UNDEF 0 // undefined variable
552 #define IS_DEF 1 // variable defined
553 #define IS_NAN 999 // variable defined as not a number
556 #define PR_PUBLIC 0 // public variable
557 #define PR_READ 1 // read only
558 #define PR_PROTECT 2 // protected (inheritance)
559 #define PR_PRIVATE 3 // strictly private
588 static long m_identcpt;
614 void SetUserPtr(
void* pUser);
617 virtual void SetIdent(
long UniqId);
626 void SetName(
const char* name);
628 int GetType(
int mode = 0);
638 void SetInit(
int bInit);
642 void SetStatic(
bool bStatic);
645 void SetPrivate(
int mPrivate);
646 bool IsPrivate(
int mode = PR_PROTECT);
650 void ConstructorSet();
655 CBotVar* GetItem(
const char* name);
657 CBotVar* GetItemRef(
int nIdent);
660 CBotVar* GetItem(
int row,
bool bGrow =
false);
667 bool IsElemOfClass(
const char* name);
677 void Copy(
CBotVar* pSrc,
bool bName =
true);
679 virtual void SetValInt(
int val,
const char* name = NULL);
683 virtual void SetValFloat(
float val);
686 virtual void SetValString(
const char* p);
689 virtual int GetValInt();
692 virtual float GetValFloat();
699 virtual void SetClass(
CBotClass* pClass);
703 virtual void SetPointer(
CBotVar* p);
735 virtual bool Save0State(FILE* pf);
736 virtual bool Save1State(FILE* pf);
737 static bool RestoreState(FILE* pf,
CBotVar* &pVar);
745 void Maj(
void* pUser = NULL,
bool bContinue =
true);
747 void SetUniqNum(
long n);
749 static long NextUniqNum();
791 void (*m_rMaj) (
CBotVar* pThis,
void* pUser );
801 CBotClass* pParent,
bool bIntrinsic =
false );
808 bool AddFunction(
const char* name,
814 bool AddUpdateFunc(
void rMaj (
CBotVar* pThis,
void* pUser ) );
844 CBotVar* GetItem(
const char* name);
845 CBotVar* GetItemRef(
int nIdent);
867 bool SaveStaticState(FILE* pf);
870 bool RestoreStaticState(FILE* pf);
881 #define MAXDEFNUM 1000 // limited number of DefineNum
886 #define TokenTypKeyWord 1 // a keyword of the language (see TokenKeyWord)
887 #define TokenTypNum 2 // number
888 #define TokenTypString 3 // string
889 #define TokenTypVar 4 // a variable name
890 #define TokenTypDef 5 // value according DefineNum
892 #define TokenKeyWord 2000 // keywords of the language
893 #define TokenKeyDeclare 2100 // keywords of declarations (int, float,..)
894 #define TokenKeyVal 2200 // keywords representing the value (true, false, null, nan)
895 #define TokenKeyOp 2300 // operators
904 int m_ListIdKeyWords[200];
909 long m_ListKeyNums[MAXDEFNUM];
928 int GetKeyWords(
const char* w);
930 bool GetKeyDefNum(
const char* w,
CBotToken* &token);
945 CBotToken(
const char* mot,
const char* sep = NULL);
999 bool DefineNum(
const char* name,
long val);
1000 void SetString(
const char* name);
1002 void SetPos(
int start,
int end);
1032 m_pClassPoint =
new CBotClass(
"CPoint", NULL);
1044 m_pClassObject =
new CBotClass(
"CColobotObject", m_pClassBase);
1046 m_pClassObject->AddItem(
"position", m_pClassPoint);
1048 m_pClassObject->AddItem(
"type",
CBotTypResult(CBotTypShort));
1050 m_pClassObject->AddConst(
"ROBOT", CBotTypShort, 1);
1052 m_pClassObject->AddFunction( rCompFind, rDoFind );
1061 m_pClassRobot =
new CBotClass(
"CColobotRobot", m_pClassObject);
1063 m_pClassRobot->AddFunction( rCompGoto, rDoGoto );
1075 CString LeProgramme(
"void main() {GOTO(0, 0); return 0;}" );
1076 if ( !m_pMonRobot->Compile( LeProgramme ) ) {error handling ...};
1084 while(
false = m_pMonRobot->Execute(
"main", pStack ))
1097 if (pVar->GetType() != CBotTypeClass ||
1098 pVar->IsElemOfClas(
"CPoint") ) { exception = 6522;
return false; )
1102 m_PosToGo.Copy( pVar );
1106 temp = pVar->GetItem(
"x");
1107 ASSERT (temp != NULL && temp->GetType() == CBotTypFloat);
1108 m_PosToGo.x = temp->GetValFloat();
1110 temp = pVar->GetItem(
"y");
1111 ASSERT (temp != NULL && temp->GetType() == CBotTypFloat);
1112 m_PosToGo.y = temp->GetValFloat();
1114 return (m_CurentPos == m_PosToGo);
static void Delete(CBotToken *pToken)
releases the list
Definition: CBotToken.cpp:423
Definition: CBotDll.h:898
~CBotToken()
Destructor.
Definition: CBotToken.cpp:98
int GetType()
Returns the type of token.
Definition: CBotToken.cpp:127
bool AddItem(CBotString name, CBotTypResult type, int mPrivate=PR_PUBLIC)
Definition: CBotClass.cpp:178
CBotString & GetString()
makes the string corresponding to this token
Definition: CBotToken.cpp:163
const CBotString & operator=(const CBotString &stringSrc)
Overloaded oprators to work on CBotString classes.
Definition: CBotString.cpp:365
Definition: CBotDll.h:364
CBotToken()
Constructors.
Definition: CBotToken.cpp:38
static CBotToken * NextToken(char *&program, int &error, bool first=false)
Definition: CBotToken.cpp:233
CBotType
CBotType Defines known types. This types are modeled on Java types. Do not change the order of elemen...
Definition: CBotDll.h:58
CBotString Class used to work on strings.
Definition: CBotDll.h:258
Management of the execution stack.
Definition: CBot.h:72
CBotTypResult class to define the complete type of a result.
Definition: CBotDll.h:89
int GetEnd()
end position in the text
Definition: CBotToken.cpp:185
Definition: CBotDll.h:333
CBotString & GetSep()
makes the following separator token
Definition: CBotToken.cpp:168
Definition: CBotDll.h:561
Definition: CBotDll.h:774
CBotToken * GetNext()
gives the next token in the list
Definition: CBotToken.cpp:139
int GetStart()
position of the beginning in the text
Definition: CBotToken.cpp:179
void AddNext(CBotToken *p)
adds a token (a copy)
Definition: CBotToken.cpp:151
static CBotToken * CompileTokens(const char *p, int &error)
transforms the entire program
Definition: CBotToken.cpp:381
CBotToken * GetPrev()
gives the previous token in a list
Definition: CBotToken.cpp:145