16#include <StringTokenizer.h>
25using std::stringstream;
61const int StringTokenizer::nb_op=16;
62const int StringTokenizer::nb_op_bis=11;
63const char StringTokenizer::keyword_op[][10] = {
"ADD",
"SUB",
"MUL",
"DIV" ,
"POW",
"LT",
"GT",
"LE",
"GE",
"MOD",
"MAX",
"MIN",
"AND",
"OR",
"EQ",
"NEQ" };
64const char StringTokenizer::keyword_op_bis[][10] = {
"+",
"-",
"*",
"/",
"^",
"<",
">",
"[",
"]",
"%",
"$" };
69 str = std::string(
"0");
91 for (
int i=0; i<StringTokenizer::nb_op; i++)
103 const char* ch = str.c_str();
106 int sz = (int)strlen(ch);
107 for (
int i=0; i<sz; i++)
111 else if (*(ch+i)==
')')
121 int type_sep, length;
122 tmp=find_sep(reste, type_sep, length);
126 if (reste[0] ==
'\0')
132 if ( ((reste[0] >=
'0') && ( reste[0] <=
'9')) || (reste[0] ==
'.') )
135 int ind=(int)strlen(reste)-1;
136 if ( ((reste[ind] <
'0') || (reste[ind] >
'9')) && (reste[ind] !=
'.') )
138 Cerr <<
"The syntax " << reste <<
" is not allowed." << finl;
147 Cerr<<
"Error conversion "<<reste<<
" in number"<<finl;
155 std::transform(sval.begin(), sval.end(), sval.begin(), ::toupper);
157 while ((*reste++) !=
'\0') ;
173 for (
int i=0; i<tmp-reste; i++)
175 if ( reste[i] !=
' ' ) tok[j++] = reste[i];
178 if (((tok[0] >=
'0') && ( tok[0] <=
'9')) || (tok[0] ==
'.') )
185 ind = (int)(tmp-reste-1l);
187 if (tok[ind] ==
'e' || tok[ind] ==
'E' )
197 Cerr<<
"Error conversion "<<tok<<
" in number"<<finl;
206 Cerr <<
"Error while interpreting the string " << str << finl;
209 nval_tmp*=pow(10,-nval);
216 Cerr <<
"Error while interpreting the string " << str << finl;
219 nval_tmp*=pow(10.,nval);
224 nval_tmp*=pow(10.,nval);
233 Cerr <<
"Error while interpreting the string " << str << finl;
237 else if ( ((tok[ind] <
'0') || (tok[ind] >
'9')) && (tok[ind] !=
'.') )
239 Cerr <<
" The syntax " << tok <<
" is not allowed." << finl;
250 Cerr<<
"Error conversion "<<tok<<
" in number"<<finl;
260 std::transform(sval.begin(), sval.end(), sval.begin(), ::toupper);
272void StringTokenizer::init_keyword_op()
274 op_sep =
new char*[nb_op];
277 for (
int i=0; i<nb_op; i++)
279 const char* blanc=
"_";
280 op_sep[i] =
new char[strlen(keyword_op[i])+3];
281 strcpy(op_sep[i],blanc);
282 strcat(op_sep[i], keyword_op[i]);
283 strcat(op_sep[i], blanc);
293char* StringTokenizer::find_sep(
char* ch,
int& type_sep,
int& length)
295 char * trouve=
nullptr;
298 trouve_tmp = strstr(ch,
"(");
300 if (trouve_tmp !=
nullptr)
302 pos = (int)(trouve_tmp-ch);
307 trouve_tmp = strstr(ch,
")");
308 if ((trouve_tmp !=
nullptr) && (trouve_tmp-ch<pos))
310 pos = (int)(trouve_tmp-ch);
315 for (
int i=0; i<StringTokenizer::nb_op; i++)
317 trouve_tmp = strstr(ch, op_sep[i]);
318 if ((trouve_tmp !=
nullptr) && (trouve_tmp-ch<pos))
320 pos = (int)(trouve_tmp-ch);
322 length=(int)strlen(op_sep[i]);
326 for (
int i=0; i<StringTokenizer::nb_op_bis; i++)
328 trouve_tmp = strstr(ch, keyword_op_bis[i]);
329 if ((trouve_tmp !=
nullptr) && ((
int)(trouve_tmp-ch)<pos))
331 pos = (int)(trouve_tmp-ch);
333 length=(int)strlen(keyword_op_bis[i]);
class Char_ptr Une chaine de caractere pour nommer les objets de TRUST
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
static const int MULTIPLY
static const int SUBTRACT