22
33namespace FPL {
44 Parser::Parser () {
5- mTypes [" vide" ] = Type (" vide" , VOID );
5+ mTypes [" vide" ] = Type (" vide" , VIDE );
66 mTypes [" entier" ] = Type (" entier" , INT);
77 mTypes [" decimal" ] = Type (" decimal" , DOUBLE);
88 mTypes [" texte" ] = Type (" texte" , STRING);
@@ -22,7 +22,9 @@ namespace FPL {
2222 " decimal" ,
2323 " texte" ,
2424 " vide" ,
25- " auto"
25+ " auto" ,
26+ " importer" ,
27+ " requete"
2628 };
2729 }
2830
@@ -71,10 +73,6 @@ namespace FPL {
7173 mVariables [variable.VariableName ] = variable;
7274 }
7375
74-
75-
76-
77-
7876 bool Parser::ImportInstruction (std::optional<FonctionDefinition>& fonction) {
7977 auto fichierName = CheckerValue ();
8078 if (fichierName.has_value ()) {
@@ -236,7 +234,7 @@ namespace FPL {
236234 while (!CheckerOperateur (" )" ).has_value ()) {
237235 auto type = CheckerType ();
238236
239- if (type->mType == VOID ) { // Si aucun paramètre ou l'utilisateur a utilisé l'argument 'vide' ou juste fermer.
237+ if (type->mType == VIDE ) { // Si aucun paramètre ou l'utilisateur a utilisé l'argument 'vide' ou juste fermer.
240238 if (CheckerOperateur (" )" ).has_value ()) {
241239 break ;
242240 } else {
@@ -849,6 +847,57 @@ namespace FPL {
849847 return false ;
850848 }
851849
850+ bool Parser::ConversionInstruction (std::optional<FonctionDefinition>& fonction) {
851+ auto VarName = CheckerIdentifiant ();
852+ if (VarName.has_value ()) {
853+ if (isVariable (VarName->mText )) {
854+ auto var = mVariables [VarName->mText ];
855+ auto NewType = CheckerType ();
856+ if (NewType.has_value ()) {
857+ if (CheckerOperateur (" ;" ).has_value ()) {
858+ if (NewType->mType == INT && var.VariableType .mType == STRING) {
859+ try {
860+ int v = std::stoi (var.VariableValue );
861+ var.VariableValue = v;
862+ var.VariableType = Type (" entier" , INT);
863+ }
864+ catch (std::invalid_argument const & ex) {
865+ std::cout << " Ca ne peut pas devenir une valeur de type entier !" << " Erreur final : " << ex.what () << std::endl;
866+ }
867+ return true ;
868+ } else if (NewType->mType == DOUBLE && var.VariableType .mType == STRING) {
869+ try {
870+ int v = std::stod (var.VariableValue );
871+ var.VariableValue = v;
872+ var.VariableType = Type (" decimal" , DOUBLE);
873+ }
874+ catch (std::invalid_argument const & ex) {
875+ std::cout << " Ca ne peut pas devenir une valeur de type entier !" << " Erreur final : " << ex.what () << std::endl;
876+ }
877+ return true ;
878+ } else {
879+ std::cerr << " La valeur de la variable ne permet une conversion." << std::endl;
880+ exit (1 );
881+ }
882+ } else {
883+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin a l'instruction." << std::endl;
884+ exit (1 );
885+ }
886+ } else {
887+ std::cerr << " Vous devez specifier le nouveau type de votre variable." << std::endl;
888+ exit (1 );
889+ }
890+ } else {
891+ std::cerr << " La variable est inexistante." << std::endl;
892+ exit (1 );
893+ }
894+ } else {
895+ std::cerr << " Vous devez specifier le nom de votre variable." << std::endl;
896+ exit (1 );
897+ }
898+ return false ;
899+ }
900+
852901 bool Parser::ChangerInstruction (std::optional<FonctionDefinition>& fonction) {
853902 auto VarName = CheckerIdentifiant ();
854903 if (VarName.has_value ()) {
@@ -915,7 +964,7 @@ namespace FPL {
915964 exit (1 );
916965 }
917966 } else {
918- std::cerr << " Vous devez spécifier le nom de votre variable." << std::endl;
967+ std::cerr << " Vous devez specifier le nom de votre variable." << std::endl;
919968 exit (1 );
920969 }
921970 return false ;
@@ -998,8 +1047,8 @@ namespace FPL {
9981047 }
9991048
10001049 bool Parser::ManagerInstruction (std::optional<FonctionDefinition>& fonction) {
1001- auto parseStart = mCurrentToken ; // std::vector<Token>::iterator
1002- auto PeutEtreInstruction = CheckerIdentifiant ();
1050+ auto const parseStart = mCurrentToken ; // std::vector<Token>::iterator
1051+ auto const PeutEtreInstruction = CheckerIdentifiant ();
10031052 if (PeutEtreInstruction.has_value ()) {
10041053 if (PeutEtreInstruction->mText == " envoyer" ) {
10051054 if (PrintInstruction (parseStart, fonction)) { return true ; } else { return false ; }
@@ -1010,13 +1059,15 @@ namespace FPL {
10101059 } else if (PeutEtreInstruction->mText == " definir" ) {
10111060 if (FonctionInstruction (parseStart)) {return true ;} else {return false ;}
10121061 } else if (PeutEtreInstruction->mText == " appeler" ) {
1013- if (AppelerInstruction ()) { return true ; } else {return false ;}
1062+ if (AppelerInstruction ()) { return true ; } else { return false ; }
10141063 } else if (PeutEtreInstruction->mText == " saisir" ) {
10151064 if (SaisirInstruction (fonction)) { return true ; } else { return false ; }
10161065 } else if (PeutEtreInstruction->mText == " fichier" ) {
1017- if (FichierInstruction (fonction)) {return true ;} else {return false ;}
1066+ if (FichierInstruction (fonction)) {return true ;} else { return false ; }
10181067 } else if (PeutEtreInstruction->mText == " importer" ) {
10191068 if (ImportInstruction (fonction)) { return true ; } else { return false ; }
1069+ } else if (PeutEtreInstruction->mText == " convertir" ) {
1070+ if (ConversionInstruction (fonction)) { return true ; } else { return false ; }
10201071 }
10211072 else {
10221073 mCurrentToken = parseStart;
0 commit comments