31 #define CBOTVERSION 104
68 CBotTypArrayPointer = 10,
69 CBotTypArrayBody = 11,
72 CBotTypNullPointer = 13,
80 #define OBJECTDELETED (reinterpret_cast<void*>(-1))
82 #define OBJECTCREATED (reinterpret_cast<void*>(-2))
114 int GetType(
int mode = 0)
const;
123 int GetLimite()
const;
126 void SetLimite(
int n);
129 void SetArray(
int* max );
138 bool Eq(
int type)
const;
177 #define CBotErrOpenPar 5000 // missing the opening parenthesis
178 #define CBotErrClosePar 5001 // missing the closing parenthesis
179 #define CBotErrNotBoolean 5002 // expression must be a boolean
180 #define CBotErrUndefVar 5003 // undeclared variable
181 #define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... )
182 #define CBotErrNoTerminator 5005 // semicolon expected
183 #define CBotErrCaseOut 5006 // case outside a switch
185 #define CBotErrCloseBlock 5008 // missing " } "
186 #define CBotErrElseWhitoutIf 5009 // else without matching if
187 #define CBotErrOpenBlock 5010 // missing " { "
188 #define CBotErrBadType1 5011 // wrong type for the assignment
189 #define CBotErrRedefVar 5012 // redefinition of the variable
190 #define CBotErrBadType2 5013 // Two operands are incompatible
191 #define CBotErrUndefCall 5014 // routine undefined
192 #define CBotErrNoDoubleDots 5015 // " : " expected
194 #define CBotErrBreakOutside 5017 // break outside of a loop
195 #define CBotErrUndefLabel 5019 // label udnefined
196 #define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here)
197 #define CBotErrNoCase 5020 // missing " case "
198 #define CBotErrBadNum 5021 // expected number
199 #define CBotErrVoid 5022 // " void " not possible here
200 #define CBotErrNoType 5023 // type declaration expected
201 #define CBotErrNoVar 5024 // variable name expected
202 #define CBotErrNoFunc 5025 // expected function name
203 #define CBotErrOverParam 5026 // too many parameters
204 #define CBotErrRedefFunc 5027 // this function already exists
205 #define CBotErrLowParam 5028 // not enough parameters
206 #define CBotErrBadParam 5029 // wrong types of parameters
207 #define CBotErrNbParam 5030 // wrong number of parameters
208 #define CBotErrUndefItem 5031 // element does not exist in the class
209 #define CBotErrUndefClass 5032 // variable is not a class
210 #define CBotErrNoConstruct 5033 // no appropriate constructor
211 #define CBotErrRedefClass 5034 // class already exists
212 #define CBotErrCloseIndex 5035 // " ] " expected
213 #define CBotErrReserved 5036 // reserved word (for a DefineNum)
214 #define CBotErrBadNew 5037 // wrong setting for new
215 #define CBotErrOpenIndex 5038 // " [ " expected
216 #define CBotErrBadString 5039 // expected string
217 #define CBotErrBadIndex 5040 // wrong index type "[ false ]"
218 #define CBotErrPrivate 5041 // protected item
219 #define CBotErrNoPublic 5042 // missing word "public"
224 #define CBotErrZeroDiv 6000 // division by zero
225 #define CBotErrNotInit 6001 // uninitialized variable
226 #define CBotErrBadThrow 6002 // throw a negative value
227 #define CBotErrNoRetVal 6003 // function did not return results
228 #define CBotErrNoRun 6004 // Run() without active function
229 #define CBotErrUndefFunc 6005 // calling a function that no longer exists
230 #define CBotErrNotClass 6006 // this class does not exist
231 #define CBotErrNull 6007 // null pointer
232 #define CBotErrNan 6008 // calculation with a NAN
233 #define CBotErrOutArray 6009 // index out of array
234 #define CBotErrStackOver 6010 // stack overflow
235 #define CBotErrDeletedPtr 6011 // pointer to an object destroyed
237 #define CBotErrFileOpen 6012 // cannot open the file
238 #define CBotErrNotOpen 6013 // channel not open
239 #define CBotErrRead 6014 // error while reading
240 #define CBotErrWrite 6015 // writing error
264 bool IsEmpty()
const;
266 int Find(
const char c);
267 int Find(
const char* lpsz);
268 int ReverseFind(
const char c);
269 int ReverseFind(
const char* lpsz);
270 bool LoadString(
unsigned int id);
276 int Compare(
const char* lpsz)
const;
293 bool operator==(
const char* p);
295 bool operator!=(
const char* p);
297 bool operator>(
const char* p);
299 bool operator>=(
const char* p);
301 bool operator<(
const char* p);
303 bool operator<=(
const char* p);
305 operator const char*()
const;
317 static const std::map<EID,const char *> s_keywordString;
324 static const char * MapIdToString(EID
id);
340 void SetSize(
int nb);
380 bool m_bCompileClass;
399 bool Compile(
const char* program,
CBotStringArray& ListFonctions,
void* pUser = NULL);
406 void SetIdent(
long n);
413 bool GetError(
int& code,
int& start,
int& end);
414 bool GetError(
int& code,
int& start,
int& end,
CBotProgram* &pProg);
423 bool Start(
const char* name);
428 bool Run(
void* pUser = NULL,
int timer = -1);
434 bool GetRunPos(
const char* &FunctionName,
int &start,
int &end);
440 CBotVar* GetStackVars(
const char* &FunctionName,
int level);
453 void SetTimer(
int n);
458 bool AddFunction(
const char* name,
459 bool rExec (
CBotVar* pVar,
CBotVar* pResult,
int& Exception,
void* pUser),
465 bool DefineNum(
const char* name,
long val);
467 bool SaveState(FILE* pf);
471 bool RestoreState(FILE* pf);
475 bool GetPosition(
const char* name,
int& start,
int& stop,
476 CBotGet modestart = GetPosExtern,
477 CBotGet modestop = GetPosBloc);
489 FILE* fOpen(
const char* name,
const char* mode);
490 int fClose(FILE* filehandle);
491 size_t fWrite(
const void *buffer,
size_t elemsize,
size_t length, FILE* filehandle);
492 size_t fRead(
void *buffer,
size_t elemsize,
size_t length, FILE* filehandle);
512 if ( pVar == NULL )
return 6001;
514 while ( pVar != NULL )
516 if ( pVar->GetType() > CBotTypDouble )
return 6002;
517 pVar = pVar -> GetNext();
530 total += pVar->GetValFloat();
531 pVar = pVar->GetNext();
534 pResult->SetValFloat(total/nb);
548 #define IS_UNDEF 0 // undefined variable
549 #define IS_DEF 1 // variable defined
550 #define IS_NAN 999 // variable defined as not a number
553 #define PR_PUBLIC 0 // public variable
554 #define PR_READ 1 // read only
555 #define PR_PROTECT 2 // protected (inheritance)
556 #define PR_PRIVATE 3 // strictly private
585 static long m_identcpt;
611 void SetUserPtr(
void* pUser);
614 virtual void SetIdent(
long UniqId);
623 void SetName(
const char* name);
625 int GetType(
int mode = 0);
635 void SetInit(
int bInit);
639 void SetStatic(
bool bStatic);
642 void SetPrivate(
int mPrivate);
643 bool IsPrivate(
int mode = PR_PROTECT);
647 void ConstructorSet();
652 CBotVar* GetItem(
const char* name);
654 CBotVar* GetItemRef(
int nIdent);
657 CBotVar* GetItem(
int row,
bool bGrow =
false);
664 bool IsElemOfClass(
const char* name);
674 void Copy(
CBotVar* pSrc,
bool bName =
true);
676 virtual void SetValInt(
int val,
const char* name = NULL);
680 virtual void SetValFloat(
float val);
683 virtual void SetValString(
const char* p);
686 virtual int GetValInt();
689 virtual float GetValFloat();
696 virtual void SetClass(
CBotClass* pClass);
700 virtual void SetPointer(
CBotVar* p);
732 virtual bool Save0State(FILE* pf);
733 virtual bool Save1State(FILE* pf);
734 static bool RestoreState(FILE* pf,
CBotVar* &pVar);
742 void Maj(
void* pUser = NULL,
bool bContinue =
true);
744 void SetUniqNum(
long n);
746 static long NextUniqNum();
788 void (*m_rMaj) (
CBotVar* pThis,
void* pUser );
798 CBotClass* pParent,
bool bIntrinsic =
false );
805 bool AddFunction(
const char* name,
811 bool AddUpdateFunc(
void rMaj (
CBotVar* pThis,
void* pUser ) );
841 CBotVar* GetItem(
const char* name);
842 CBotVar* GetItemRef(
int nIdent);
864 bool SaveStaticState(FILE* pf);
867 bool RestoreStaticState(FILE* pf);
878 #define MAXDEFNUM 1000 // limited number of DefineNum
883 #define TokenTypKeyWord 1 // a keyword of the language (see TokenKeyWord)
884 #define TokenTypNum 2 // number
885 #define TokenTypString 3 // string
886 #define TokenTypVar 4 // a variable name
887 #define TokenTypDef 5 // value according DefineNum
889 #define TokenKeyWord 2000 // keywords of the language
890 #define TokenKeyDeclare 2100 // keywords of declarations (int, float,..)
891 #define TokenKeyVal 2200 // keywords representing the value (true, false, null, nan)
892 #define TokenKeyOp 2300 // operators
901 int m_ListIdKeyWords[200];
906 long m_ListKeyNums[MAXDEFNUM];
925 int GetKeyWords(
const char* w);
927 bool GetKeyDefNum(
const char* w,
CBotToken* &token);
942 CBotToken(
const char* mot,
const char* sep = NULL);
996 bool DefineNum(
const char* name,
long val);
997 void SetString(
const char* name);
999 void SetPos(
int start,
int end);
1029 m_pClassPoint =
new CBotClass(
"CPoint", NULL);
1041 m_pClassObject =
new CBotClass(
"CColobotObject", m_pClassBase);
1043 m_pClassObject->AddItem(
"position", m_pClassPoint);
1045 m_pClassObject->AddItem(
"type",
CBotTypResult(CBotTypShort));
1047 m_pClassObject->AddConst(
"ROBOT", CBotTypShort, 1);
1049 m_pClassObject->AddFunction( rCompFind, rDoFind );
1058 m_pClassRobot =
new CBotClass(
"CColobotRobot", m_pClassObject);
1060 m_pClassRobot->AddFunction( rCompGoto, rDoGoto );
1072 CString LeProgramme(
"void main() {GOTO(0, 0); return 0;}" );
1073 if ( !m_pMonRobot->Compile( LeProgramme ) ) {error handling ...};
1081 while(
false = m_pMonRobot->Execute(
"main", pStack ))
1094 if (pVar->GetType() != CBotTypeClass ||
1095 pVar->IsElemOfClas(
"CPoint") ) { exception = 6522;
return false; )
1099 m_PosToGo.Copy( pVar );
1103 temp = pVar->GetItem(
"x");
1104 ASSERT (temp != NULL && temp->GetType() == CBotTypFloat);
1105 m_PosToGo.x = temp->GetValFloat();
1107 temp = pVar->GetItem(
"y");
1108 ASSERT (temp != NULL && temp->GetType() == CBotTypFloat);
1109 m_PosToGo.y = temp->GetValFloat();
1111 return (m_CurentPos == m_PosToGo);
static void Delete(CBotToken *pToken)
releases the list
Definition: CBotToken.cpp:420
Definition: CBotDll.h:895
~CBotToken()
Destructor.
Definition: CBotToken.cpp:95
int GetType()
Returns the type of token.
Definition: CBotToken.cpp:124
bool AddItem(CBotString name, CBotTypResult type, int mPrivate=PR_PUBLIC)
Definition: CBotClass.cpp:175
CBotString & GetString()
makes the string corresponding to this token
Definition: CBotToken.cpp:160
const CBotString & operator=(const CBotString &stringSrc)
Overloaded oprators to work on CBotString classes.
Definition: CBotString.cpp:334
Definition: CBotDll.h:361
CBotToken()
Constructors.
Definition: CBotToken.cpp:35
static CBotToken * NextToken(char *&program, int &error, bool first=false)
Definition: CBotToken.cpp:230
CBotType
CBotType Defines known types. This types are modeled on Java types. Do not change the order of elemen...
Definition: CBotDll.h:55
CBotString Class used to work on strings.
Definition: CBotDll.h:255
Management of the execution stack.
Definition: CBot.h:69
CBotTypResult class to define the complete type of a result.
Definition: CBotDll.h:86
int GetEnd()
end position in the text
Definition: CBotToken.cpp:182
Definition: CBotDll.h:330
CBotString & GetSep()
makes the following separator token
Definition: CBotToken.cpp:165
Definition: CBotDll.h:558
Definition: CBotDll.h:771
CBotToken * GetNext()
gives the next token in the list
Definition: CBotToken.cpp:136
int GetStart()
position of the beginning in the text
Definition: CBotToken.cpp:176
void AddNext(CBotToken *p)
adds a token (a copy)
Definition: CBotToken.cpp:148
static CBotToken * CompileTokens(const char *p, int &error)
transforms the entire program
Definition: CBotToken.cpp:378
CBotToken * GetPrev()
gives the previous token in a list
Definition: CBotToken.cpp:142