summaryrefslogtreecommitdiffstats
path: root/src/CBot/CBotToken.cpp
diff options
context:
space:
mode:
authorKrzysztof H <krzys_h@interia.pl>2012-03-19 12:44:39 +0100
committerKrzysztof H <krzys_h@interia.pl>2012-03-19 12:44:39 +0100
commitf7d892cf4ef6bfce3747c4b6a810d4828b79833d (patch)
tree8311c7057b5f861c387ecc8c96cd778abc47c8d8 /src/CBot/CBotToken.cpp
parent343cb0ce660136ac034e6106c0f151466b751398 (diff)
downloadcolobot-f7d892cf4ef6bfce3747c4b6a810d4828b79833d.tar.gz
colobot-f7d892cf4ef6bfce3747c4b6a810d4828b79833d.tar.bz2
colobot-f7d892cf4ef6bfce3747c4b6a810d4828b79833d.zip
Last coding fix ;)
Diffstat (limited to 'src/CBot/CBotToken.cpp')
-rw-r--r--src/CBot/CBotToken.cpp101
1 files changed, 52 insertions, 49 deletions
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index bd81b70..8fd6dbd 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -1,4 +1,4 @@
-// * This file is part of the COLOBOT source code
+// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
@@ -12,10 +12,13 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see http://www.gnu.org/licenses/.
+// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////
+// Gestion des Tokens
+// le texte d'un programme est d'abord transformé
+// en une suite de tokens pour facilité l'interprétation
// il faudra traiter le seul cas d'erreur possible
-// qui est un caract�re ill�gal dans une string
+// qui est un caractère illégal dans une string
#include "CBot.h"
@@ -31,7 +34,7 @@ CBotToken::CBotToken()
m_next = NULL;
m_prev = NULL;
- m_type = TokenTypVar; // � priori un nom d'une variable
+ m_type = TokenTypVar; // à priori un nom d'une variable
m_IdKeyWord = -1;
}
@@ -64,14 +67,14 @@ CBotToken::CBotToken(const CBotToken* pSrc)
CBotToken::CBotToken(CBotString& mot, CBotString& sep, int start, int end)
{
- m_Text = mot; // mot trouv� comme token
- m_Sep = sep; // s�parateurs qui suivent
+ m_Text = mot; // mot trouvé comme token
+ m_Sep = sep; // séparateurs qui suivent
m_next = NULL;
m_prev = NULL;
m_start = start;
m_end = end;
- m_type = TokenTypVar; // � priori un nom d'une variable
+ m_type = TokenTypVar; // à priori un nom d'une variable
m_IdKeyWord = -1;
}
@@ -82,13 +85,13 @@ CBotToken::CBotToken(const char* mot, const char* sep)
m_next = NULL;
m_prev = NULL;
- m_type = TokenTypVar; // � priori un nom d'une variable
+ m_type = TokenTypVar; // à priori un nom d'une variable
m_IdKeyWord = -1;
}
CBotToken::~CBotToken()
{
- delete m_next; // r�cursif
+ delete m_next; // récursif
m_next = NULL;
}
@@ -210,54 +213,54 @@ BOOL Char2InList(const char c, const char cc, const char* list)
}
static char* sep1 = " \r\n\t,:()[]{}-+*/=;><!~^|&%.";
-static char* sep2 = " \r\n\t"; // s�parateurs pures
-static char* sep3 = ",:()[]{}-+*/=;<>!~^|&%."; // s�parateurs op�rationnels
-static char* num = "0123456789"; // le point (unique) est test� s�par�ment
+static char* sep2 = " \r\n\t"; // séparateurs pures
+static char* sep3 = ",:()[]{}-+*/=;<>!~^|&%."; // séparateurs opérationnels
+static char* num = "0123456789"; // le point (unique) est testé séparément
static char* hexnum = "0123456789ABCDEFabcdef";
-static char* nch = "\"\r\n\t"; // refus� dans les chaines
+static char* nch = "\"\r\n\t"; // refusé dans les chaines
-//static char* duo = "+=-=*=/===!=<=>=++--///**/||&&";// les op�rateurs doubles
+//static char* duo = "+=-=*=/===!=<=>=++--///**/||&&";// les opérateurs doubles
// cherche le prochain token dans une phrase
-// ne doit pas commencer par des s�parateurs
-// qui sont pris avec le token pr�c�dent
+// ne doit pas commencer par des séparateurs
+// qui sont pris avec le token précédent
CBotToken* CBotToken::NextToken(char* &program, int& error, BOOL first)
{
- CBotString mot; // le mot trouv�
- CBotString sep; // les s�parateurs qui le suivent
+ CBotString mot; // le mot trouvé
+ CBotString sep; // les séparateurs qui le suivent
char c;
BOOL stop = first;
if (*program == 0) return NULL;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
if (!first)
{
mot = c; // construit le mot
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
- // cas particulier pour les cha�nes de caract�res
+ // cas particulier pour les chaînes de caractères
if ( mot[0] == '\"' )
{
while (c != 0 && !CharInList(c, nch))
{
mot += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
if ( c == '\\' )
{
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
if ( c == 'n' ) c = '\n';
if ( c == 'r' ) c = '\r';
if ( c == 't' ) c = '\t';
mot += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
}
if ( c == '\"' )
{
- mot += c; // cha�ne compl�te
- c = *(program++); // prochain caract�re
+ mot += c; // chaîne complète
+ c = *(program++); // prochain caractère
}
stop = TRUE;
}
@@ -265,30 +268,30 @@ CBotToken* CBotToken::NextToken(char* &program, int& error, BOOL first)
// cas particulier pour les nombres
if ( CharInList(mot[0], num ))
{
- BOOL bdot = FALSE; // trouv� un point ?
- BOOL bexp = FALSE; // trouv� un exposant ?
+ BOOL bdot = FALSE; // trouvé un point ?
+ BOOL bexp = FALSE; // trouvé un exposant ?
char* liste = num;
- if (mot[0] == '0' && c == 'x') // valeur hexad�cimale ?
+ if (mot[0] == '0' && c == 'x') // valeur hexadécimale ?
{
mot += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
liste = hexnum;
}
cw:
while (c != 0 && CharInList(c, liste))
{
cc: mot += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
- if ( liste == num ) // pas pour les exad�cimaux
+ if ( liste == num ) // pas pour les exadécimaux
{
if ( !bdot && c == '.' ) { bdot = TRUE; goto cc; }
if ( !bexp && ( c == 'e' || c == 'E' ) )
{
bexp = TRUE;
mot += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
if ( c == '-' ||
c == '+' ) goto cc;
goto cw;
@@ -298,13 +301,13 @@ cc: mot += c;
stop = TRUE;
}
- if (CharInList(mot[0], sep3)) // un s�parateur op�rationnel ?
+ if (CharInList(mot[0], sep3)) // un séparateur opérationnel ?
{
CBotString motc = mot;
- while (motc += c, c != 0 && GivKeyWords(motc)>0) // cherche l'op�rande le plus long possible
+ while (motc += c, c != 0 && GivKeyWords(motc)>0) // cherche l'opérande le plus long possible
{
mot += c; // construit le mot
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
stop = TRUE;
@@ -321,7 +324,7 @@ cc: mot += c;
bis:
while (CharInList(c, sep2))
{
- sep += c; // tous les s�parateurs qui suivent
+ sep += c; // tous les séparateurs qui suivent
c = *(program++);
}
if (c == '/' && *program == '/') // un commentaire dans le tas ?
@@ -329,7 +332,7 @@ bis:
while( c != '\n' && c != 0 )
{
sep += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
goto bis;
}
@@ -339,14 +342,14 @@ bis:
while( c != 0 && (c != '*' || *program != '/'))
{
sep += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
if ( c != 0 )
{
sep += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
sep += c;
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
goto bis;
}
@@ -367,7 +370,7 @@ bis:
}
mot += c; // construit le mot
- c = *(program++); // prochain caract�re
+ c = *(program++); // prochain caractère
}
}
@@ -390,12 +393,12 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
char* pp = p;
while (NULL != (nxt = NextToken(p, error)))
{
- prv->m_next = nxt; // ajoute � la suite
+ prv->m_next = nxt; // ajoute à la suite
nxt->m_prev = prv;
prv = nxt; // avance
nxt->m_start = pos;
-/* pos += nxt->m_Text.GivLength(); // la cha�ne peut �tre plus courte (BOA supprim�s)
+/* pos += nxt->m_Text.GivLength(); // la chaîne peut être plus courte (BOA supprimés)
nxt->m_end = pos;
pos += nxt->m_Sep.GivLength();*/
pos += (p - pp); // taille totale
@@ -404,10 +407,10 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
}
// ajoute un token comme terminateur
- // ( utile pour avoir le pr�c�dent )
+ // ( utile pour avoir le précédent )
nxt = new CBotToken();
nxt->m_type = 0;
- prv->m_next = nxt; // ajoute � la suite
+ prv->m_next = nxt; // ajoute à la suite
nxt->m_prev = prv;
return tokenbase;
@@ -428,7 +431,7 @@ int CBotToken::GivKeyWords(const char* w)
if (l == 0)
{
- LoadKeyWords(); // prend la liste la premi�re fois
+ LoadKeyWords(); // prend la liste la première fois
l = m_ListKeyWords.GivSize();
}
@@ -522,8 +525,8 @@ BOOL IsOfType(CBotToken* &p, int type1, int type2)
return FALSE;
}
-// idem avec un nombre ind�fini d'arguments
-// il faut mettre un z�ro comme dernier argument
+// idem avec un nombre indéfini d'arguments
+// il faut mettre un zéro comme dernier argument
BOOL IsOfTypeList(CBotToken* &p, int type1, ...)
{
int i = type1;