16#include <StringTokenizer.h>
30 str = std::string(
"0");
65 for (
int i = 0; i <
ivar; i++)
96 c_pi.setValue(2*asin(1.));
100void destroy(
PNode* p)
104 if (p->
left!=
nullptr) destroy(p->
left);
127 PSTACK(
PNode) st_ob(20);
128 STACK(
int) st_op(20);
132 Cerr <<
"Expression " <<
str <<
" does not contain the same number of opening and closing parenthesis." << finl;
160 std::unordered_map<PNode*, int> nodeToIndex;
161 std::queue<PNode*> queue;
162 int currentIndex = 0;
166 nodeToIndex[
root] = currentIndex++;
168 while (!queue.empty())
170 PNode* current = queue.front();
182 if (nodeToIndex.find(current->
left) == nodeToIndex.end())
184 nodeToIndex[current->
left] = currentIndex++;
185 queue.push(current->
left);
187 pod.
left = nodeToIndex[current->
left];
197 if (nodeToIndex.find(current->
right) == nodeToIndex.end())
199 nodeToIndex[current->
right] = currentIndex++;
200 queue.push(current->
right);
265 node->
type = PNode_type::VAR;
272 const std::string& func = tokenizer->
getSValue();
285 node->
type = PNode_type::VALUE;
286 node->
nvalue = les_cst(trouv).getValue();
292 Cerr <<
"Error in Parser::parserState0 during interpretation of the following string :\n ";
294 Cerr <<
" identifier " << func <<
" unknown " << finl;
297 Cerr <<
"List of known var "<<finl;
310 node->
type = PNode_type::VALUE;
321 node->
type = PNode_type::VALUE;
331 node->
type = PNode_type::VALUE;
352 node->
type = PNode_type::VAR;
359 const std::string& func = tokenizer->
getSValue();
372 node->
type = PNode_type::VALUE;
373 node->
nvalue = les_cst(trouv).getValue();
379 Cerr <<
"Error in Parser::parserState1 during interpretation of the following string :\n ";
381 Cerr <<
" identifier " << func <<
" unknown !! " << finl;
382 Cerr <<
"List of known var "<<finl;
394 node->
type = PNode_type::VALUE;
406 Cerr <<
"state 1 error !! " << finl;
422 op_read = tokenizer->
type;
426 int tmpi = op->peek();
437 node->
type = PNode_type::OP;
447 node->
type=PNode_type::FUNCTION;
458 Cerr <<
"Unknown operation !!! " << finl;
462 if (!op->isEmpty()) tmpi = op->peek();
471 op_read = tokenizer->
type;
482 node->
type = PNode_type::OP;
492 node->
type=PNode_type::FUNCTION;
503 Cerr <<
"Unknown operation !!! " << finl;
508 if (!op->isEmpty()) tmp = op->pop();
516 while (!op->isEmpty())
525 node->
type = PNode_type::OP;
535 node->
type=PNode_type::FUNCTION;
546 Cerr <<
"Unknown operation !!! " << finl;
555 Cerr <<
"Error state 2 !!! " <<tokenizer->
type<<
" "<<tokenizer->
getSValue()<<
" "<<tokenizer->
getNValue()<< finl;
569 Cerr<<
"Warning in Parser::addVar "<< vv <<
" already in Parser"<<finl;
570 if (strcmp(vv,
"x")==0 || strcmp(vv,
"y")==0 || strcmp(vv,
"z")==0 || strcmp(vv,
"t")==0
571 || strcmp(vv,
"X")==0 || strcmp(vv,
"Y")==0 || strcmp(vv,
"Z")==0 || strcmp(vv,
"T")==0)
586 Cerr <<
"Maximum " <<
maxvar <<
" variables !! " << finl;
595 for (
auto& itr : les_cst)
598 std::string ss(cst.
le_nom());
599 std::transform(ss.begin(), ss.end(), ss.begin(), ::toupper);
600 if (nv ==
Nom(ss))
return i;
609 std::string function_name(f);
610 std::transform(function_name.begin(), function_name.end(), function_name.begin(), ::toupper);
613 return it->second + 1;
626 Cout <<
"STRING : " << t->
getSValue() << finl;
628 Cout <<
"NUMBER : " << t->
getNValue() << finl;
630 Cout <<
"END " << finl;
632 Cout <<
"OP : " << (int)t->
type << finl;
Definit une constante dans le jeu de donnees.
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Nom & majuscule()
Transforme le nom en majuscules Seules les lettres 'a'-'z' sont modifiees.
void addVar(const char *)
virtual void setNbVar(int nvar)
std::vector< PNodePod > PNodes
int searchVar(const std::string &s)
void parserState1(StringTokenizer *, PSTACK(PNode) *, STACK(int) *)
void parserState0(StringTokenizer *, PSTACK(PNode) *, STACK(int) *)
int searchFunc(const std::string &v)
int test_op_binaire(int type)
std::map< std::string, int > map_function_
static int precedence(int)
virtual void parseString()
int searchCst(const std::string &v)
void addCst(const Constante &cst)
void parserState2(StringTokenizer *, PSTACK(PNode) *, STACK(int) *)
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
const std::string & getSValue()
static const int MULTIPLY
static const int SUBTRACT