@@ -367,7 +367,6 @@ namespace FPL {
367367 exit (1 );
368368 }
369369 needToIgnore = true ;
370- return true ;
371370 }
372371 } else {
373372 std::cerr << " Vous devez mettre le symbole ':' pour mettre votre code." << std::endl;
@@ -388,6 +387,147 @@ namespace FPL {
388387 return false ;
389388 }
390389
390+ bool Parser::TantQueInstruction (std::optional<FonctionDefinition>& fonction) {
391+ auto queInstruction = CheckerIdentifiant ();
392+ if (queInstruction.has_value () && queInstruction->mText == " que" ) {
393+ auto Variable = CheckerIdentifiant ();
394+ if (Variable.has_value () && isVariable (Variable->mText )) {
395+ VariableDefinition var = mVariables [Variable->mText ];
396+ if (var.VariableType .mType == STRING || var.VariableType .mType == BOOL) {
397+ std::cerr << " Il faut que ce soit un chiffre/nombre." << std::endl;
398+ exit (1 );
399+ }
400+
401+ auto operatorLoop = CheckerOperateur ();
402+ if (operatorLoop.has_value ()) {
403+ auto secondOperatorLoop = CheckerOperateur ();
404+
405+ auto valueCheck = CheckerValue ();
406+ if (valueCheck->StatementType .mType == STRING || valueCheck->StatementType .mType == BOOL) {
407+ std::cerr << " Il faut que ce soit un chiffre/nombre." << std::endl;
408+ exit (1 );
409+ }
410+
411+ if (var.VariableValue == valueCheck->StatementName ) {
412+ return true ;
413+ }
414+
415+ if (CheckerOperateur (" ," ).has_value ()) {
416+ auto IncrDecr = CheckerIdentifiant ();
417+ if (IncrDecr.has_value ()) {
418+ auto numberIncrDesincr = CheckerValue ();
419+ if (numberIncrDesincr->StatementType .mType == STRING || numberIncrDesincr->StatementType .mType == BOOL) {
420+ std::cerr << " Il faut que ce soit un chiffre/nombre." << std::endl;
421+ exit (1 );
422+ }
423+
424+ if (!CheckerOperateur (" {" ).has_value ()) {
425+ std::cerr << " Il faut ouvrir l'instruction pour mettre votre code avec des '{' et fermer avec '}'." << std::endl;
426+ exit (1 );
427+ }
428+
429+ double varValueInt = std::stod (var.VariableValue );
430+
431+ std::vector<std::string> contentLoop;
432+ while (!CheckerOperateur (" }" ).has_value ()) {
433+ if (mCurrentToken ->mType == CHAINE_LITERAL) {
434+ mCurrentToken ->mText += " \" " ;
435+ }
436+
437+ contentLoop.push_back (mCurrentToken ->mText );
438+ ++mCurrentToken ;
439+
440+ if (CheckerOperateur (" }" ).has_value ()) {
441+ break ;
442+ }
443+ }
444+ std::string finalContent;
445+ for (auto const &a : contentLoop) {
446+ finalContent.append (a).append (" " );
447+ }
448+ TokenBuilding t;
449+ std::cout << " " << std::endl;
450+ std::vector<Token> tokens = t.parseToken (finalContent);
451+ auto FCurrToken = tokens.begin ();
452+ auto oldCurrentToken = mCurrentToken ;
453+ std::optional<FonctionDefinition> f = fonction;
454+
455+ if (IncrDecr->mText == " incrementer" ) {
456+ if (operatorLoop->mText == " <" ) {
457+
458+ } else if (operatorLoop->mText == " >" ) {
459+ std::cerr << " Cette operateur conditionnelle est impossible car vous souhaitez retirer une valuer alors que c'est deja superieur." << std::endl;
460+ exit (1 );
461+ } else if (operatorLoop->mText == " >" && secondOperatorLoop.has_value () && secondOperatorLoop->mText == " =" ) {
462+ std::cerr << " Cette operateur conditionnelle est impossible car vous souhaitez retirer une valuer alors que c'est deja superieur ou egal." << std::endl;
463+ exit (1 );
464+ } else if (operatorLoop->mText == " <" && secondOperatorLoop.has_value () && secondOperatorLoop->mText == " =" ) {
465+
466+ } else if (operatorLoop->mText == " =" ) {
467+ while (std::stod (var.VariableValue ) < std::stod (valueCheck->StatementName )) {
468+ parse (tokens, f);
469+ varValueInt += std::stod (numberIncrDesincr->StatementName );
470+ var.VariableValue = std::to_string (varValueInt);
471+ }
472+
473+ mVariables [var.VariableName ].VariableValue = var.VariableValue ;
474+
475+ mCurrentToken = oldCurrentToken;
476+ return true ;
477+ } else {
478+ std::cerr << " L'operateur conditionnelle n'existe pas : ." << operatorLoop->mText << std::endl;
479+ exit (1 );
480+ }
481+ } else if (IncrDecr->mText == " decrementer" ) {
482+ if (operatorLoop->mText == " <" ) {
483+ std::cerr << " Cette operateur conditionnelle est impossible car vous souhaitez retirer une valuer alors que c'est deja inferieur." << std::endl;
484+ exit (1 );
485+ } else if (operatorLoop->mText == " >" ) {
486+
487+ } else if (operatorLoop->mText == " >" && secondOperatorLoop.has_value () && secondOperatorLoop->mText == " =" ) {
488+
489+ } else if (operatorLoop->mText == " <" && secondOperatorLoop.has_value () && secondOperatorLoop->mText == " =" ) {
490+ std::cerr << " Cette operateur conditionnelle est impossible car vous souhaitez retirer une valuer alors que c'est deja inferieur ou egal." << std::endl;
491+ exit (1 );
492+ } else if (operatorLoop->mText == " =" ) {
493+ while (std::stod (var.VariableValue ) > std::stod (valueCheck->StatementName )) {
494+ parse (tokens, f);
495+ varValueInt -= std::stod (numberIncrDesincr->StatementName );
496+ var.VariableValue = std::to_string (varValueInt);
497+ }
498+
499+ mVariables [var.VariableName ].VariableValue = var.VariableValue ;
500+
501+ mCurrentToken = oldCurrentToken;
502+ return true ;
503+ } else {
504+ std::cerr << " L'operateur conditionnelle n'existe pas : ." << operatorLoop->mText << std::endl;
505+ exit (1 );
506+ }
507+ } else {
508+ std::cerr << " Pour poursuivre l'instruction vous devez preciser 'incrementer' ou 'decrementer'." << std::endl;
509+ exit (1 );
510+ }
511+ } else {
512+ std::cerr << " Pour poursuivre l'instruction vous devez preciser 'incrementer' ou 'decrementer'." << std::endl;
513+ exit (1 );
514+ }
515+ } else {
516+ std::cerr << " Vous devez inserer une ',' pour poursuivre l'instruction et preciser une incrementation ou une decrementation." << std::endl;
517+ exit (1 );
518+ }
519+ }
520+ } else {
521+ std::cerr << " Le premier argument doit etre une variable." << std::endl;
522+ exit (1 );
523+ }
524+ } else {
525+ std::cerr << " L'instruction excate est 'tant que'." << std::endl;
526+ exit (1 );
527+ }
528+ return false ;
529+ }
530+
391531 bool Parser::AppelerInstruction () {
392532 auto PossibleFonctionName = CheckerIdentifiant ();
393533 if (PossibleFonctionName.has_value ()) {
@@ -1401,6 +1541,8 @@ namespace FPL {
14011541 if (ConversionInstruction (fonction)) { return true ; } else { return false ; }
14021542 } else if (PeutEtreInstruction->mText == " verifier" ) {
14031543 if (VerifierInstruction (fonction)) { return true ; } else { return false ; }
1544+ } else if (PeutEtreInstruction->mText == " tant" ) {
1545+ if (TantQueInstruction (fonction)) { return true ; } else { return false ; }
14041546 }
14051547 else {
14061548 mCurrentToken = parseStart;
0 commit comments