16#include <StringTokenizer.h>
25using std::stringstream;
60const int StringTokenizer::nb_op=16;
61const int StringTokenizer::nb_op_bis=11;
62const char StringTokenizer::keyword_op[][10] = {
"ADD",
"SUB",
"MUL",
"DIV" ,
"POW",
"LT",
"GT",
"LE",
"GE",
"MOD",
"MAX",
"MIN",
"AND",
"OR",
"EQ",
"NEQ" };
63const char StringTokenizer::keyword_op_bis[][10] = {
"+",
"-",
"*",
"/",
"^",
"<",
">",
"[",
"]",
"%",
"$" };
68 str = std::string(
"0");
90 for (
int i=0; i<StringTokenizer::nb_op; i++)
102 const char* ch = str.c_str();
105 int sz = (int)strlen(ch);
106 for (
int i=0; i<sz; i++)
110 else if (*(ch+i)==
')')
120 int type_sep, length;
121 tmp=find_sep(reste, type_sep, length);
125 if (reste[0] ==
'\0')
131 if ( ((reste[0] >=
'0') && ( reste[0] <=
'9')) || (reste[0] ==
'.') )
134 int ind=(int)strlen(reste)-1;
135 if ( ((reste[ind] <
'0') || (reste[ind] >
'9')) && (reste[ind] !=
'.') )
137 Cerr <<
"The syntax " << reste <<
" is not allowed." << finl;
146 Cerr<<
"Error conversion "<<reste<<
" in number"<<finl;
154 std::transform(sval.begin(), sval.end(), sval.begin(), ::toupper);
156 while ((*reste++) !=
'\0') ;
172 for (
int i=0; i<tmp-reste; i++)
174 if ( reste[i] !=
' ' ) tok[j++] = reste[i];
177 if (((tok[0] >=
'0') && ( tok[0] <=
'9')) || (tok[0] ==
'.') )
184 ind = (int)(tmp-reste-1l);
186 if (tok[ind] ==
'e' || tok[ind] ==
'E' )
196 Cerr<<
"Error conversion "<<tok<<
" in number"<<finl;
205 Cerr <<
"Error while interpreting the string " << str << finl;
208 nval_tmp*=pow(10,-nval);
215 Cerr <<
"Error while interpreting the string " << str << finl;
218 nval_tmp*=pow(10.,nval);
223 nval_tmp*=pow(10.,nval);
232 Cerr <<
"Error while interpreting the string " << str << finl;
236 else if ( ((tok[ind] <
'0') || (tok[ind] >
'9')) && (tok[ind] !=
'.') )
238 Cerr <<
" The syntax " << tok <<
" is not allowed." << finl;
249 Cerr<<
"Error conversion "<<tok<<
" in number"<<finl;
259 std::transform(sval.begin(), sval.end(), sval.begin(), ::toupper);
271void StringTokenizer::init_keyword_op()
273 op_sep =
new char*[nb_op];
276 for (
int i=0; i<nb_op; i++)
278 const char* blanc=
"_";
279 op_sep[i] =
new char[strlen(keyword_op[i])+3];
280 strcpy(op_sep[i],blanc);
281 strcat(op_sep[i], keyword_op[i]);
282 strcat(op_sep[i], blanc);
292char* StringTokenizer::find_sep(
char* ch,
int& type_sep,
int& length)
294 char * trouve=
nullptr;
297 trouve_tmp = strstr(ch,
"(");
299 if (trouve_tmp !=
nullptr)
301 pos = (int)(trouve_tmp-ch);
306 trouve_tmp = strstr(ch,
")");
307 if ((trouve_tmp !=
nullptr) && (trouve_tmp-ch<pos))
309 pos = (int)(trouve_tmp-ch);
314 for (
int i=0; i<StringTokenizer::nb_op; i++)
316 trouve_tmp = strstr(ch, op_sep[i]);
317 if ((trouve_tmp !=
nullptr) && (trouve_tmp-ch<pos))
319 pos = (int)(trouve_tmp-ch);
321 length=(int)strlen(op_sep[i]);
325 for (
int i=0; i<StringTokenizer::nb_op_bis; i++)
327 trouve_tmp = strstr(ch, keyword_op_bis[i]);
328 if ((trouve_tmp !=
nullptr) && ((
int)(trouve_tmp-ch)<pos))
330 pos = (int)(trouve_tmp-ch);
332 length=(int)strlen(keyword_op_bis[i]);
class Char_ptr A character string to name TRUST objects.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static const int MULTIPLY
static const int SUBTRACT