@@ -33,6 +33,9 @@ namespace FPL {
3333
3434 auto parametre = getArgument (PossibleFonctionName->mText , name->mText );
3535 if (parametre->ArgType .mType == value->StatementType .mType && parametre->ArgType .mType != AUTO) {
36+ if (value->StatementType .mType == STRING) {
37+ std::replace (value->StatementName .begin (), value->StatementName .end (), ' "' , ' ' );
38+ }
3639 parametre->ArgValue = value->StatementName ;
3740 } else if (parametre->ArgType .mType == AUTO && parametre->ArgType .mType != value->StatementType .mType ) {
3841 parametre->ArgType = Type (" auto" , AUTO);
@@ -41,6 +44,12 @@ namespace FPL {
4144 std::cerr << " Le type de votre valeur doit être identique a celui de l'argument." << std::endl;
4245 }
4346
47+ ArgumentDefinition argument;
48+ argument.ArgName = parametre->ArgName ;
49+ argument.ArgType = Type (parametre->ArgType .mName , parametre->ArgType .mType );
50+ argument.ArgValue = parametre->ArgValue ;
51+ mArguments [argument.ArgName ] = argument;
52+
4453 if (fonction.NumberArgument > 1 && !CheckerOperateur (" ," ).has_value ()) {
4554 std::cerr << " Veuillez separer les different arguments par le symbole ','." << std::endl;
4655 }
@@ -65,16 +74,17 @@ namespace FPL {
6574
6675 auto FCurrToken = tokens.begin ();
6776 auto oldCurrentToken = mCurrentToken ;
68- parse (tokens, " fonction" );
77+ std::optional<FonctionDefinition> f = fonction;
78+ parse (tokens, f);
6979 mCurrentToken = oldCurrentToken;
7080
7181 std::vector<std::string> toErase;
72- for (auto var: mVariables ) {
82+ for (auto const & var: mVariables ) {
7383 if (var.second .InFonction && !var.second .IsGlobal ) {
7484 toErase.push_back (var.first );
7585 }
7686 }
77- for (auto it: toErase)
87+ for (auto const & it: toErase)
7888 {
7989 mVariables .erase (it);
8090 }
@@ -157,7 +167,7 @@ namespace FPL {
157167 return false ;
158168 }
159169
160- bool Parser::VariableInstruction (std::optional<std::string> argument ) {
170+ bool Parser::VariableInstruction (std::optional<FonctionDefinition>& fonction ) {
161171 auto VarType = CheckerType ();
162172 if (VarType.has_value ()) {
163173 auto VarName = CheckerIdentifiant ();
@@ -189,7 +199,7 @@ namespace FPL {
189199 variable.VariableType = Type (VarType->mName , VarType->mType );
190200 variable.IsGlobal = false ;
191201 variable.InFonction = false ;
192- if (argument == " fonction" ) {
202+ if (fonction. has_value () || fonction != std:: nullopt ) {
193203 variable.InFonction = true ;
194204 }
195205
@@ -223,7 +233,7 @@ namespace FPL {
223233 variable.VariableType = Type (VarType->mName , VarType->mType );
224234 variable.IsGlobal = false ;
225235 variable.InFonction = false ;
226- if (argument == " fonction" ) {
236+ if (fonction. has_value () || fonction != std:: nullopt ) {
227237 variable.InFonction = true ;
228238 }
229239
@@ -271,7 +281,7 @@ namespace FPL {
271281 }
272282 variable.IsGlobal = true ;
273283 variable.InFonction = false ;
274- if (argument == " fonction" ) {
284+ if (fonction. has_value () || fonction != std:: nullopt ) {
275285 variable.InFonction = true ;
276286 }
277287 if (VarValue->StatementType .mType == STRING) {
@@ -311,7 +321,7 @@ namespace FPL {
311321 }
312322 variable.IsGlobal = false ;
313323 variable.InFonction = false ;
314- if (argument == " fonction" ) {
324+ if (fonction. has_value () || fonction != std:: nullopt ) {
315325 variable.InFonction = true ;
316326 }
317327 if (VarValue->StatementType .mType == STRING) {
@@ -338,7 +348,7 @@ namespace FPL {
338348 variable.VariableType = Type (VarType->mName , VarType->mType );
339349 variable.IsGlobal = false ;
340350 variable.InFonction = false ;
341- if (argument == " fonction" ) {
351+ if (fonction. has_value () || fonction != std:: nullopt ) {
342352 variable.InFonction = true ;
343353 }
344354 variable.VariableValue = OldVariable.VariableValue ;
@@ -422,7 +432,7 @@ namespace FPL {
422432 return false ;
423433 }
424434
425- bool Parser::PrintInstruction (auto parseStart) {
435+ bool Parser::PrintInstruction (auto parseStart, std::optional<FonctionDefinition>& fonction ) {
426436 auto Value = CheckerValue ();
427437 if (Value.has_value ()) {
428438 --mCurrentToken ;
@@ -466,30 +476,35 @@ namespace FPL {
466476 ++mCurrentToken ;
467477 auto value = CheckerIdentifiant ();
468478 if (value.has_value ()) {
469- if (isVariable (value-> mText )) {
470- if (CheckerOperateur ( " ; " ). has_value ( )) {
479+ if (CheckerOperateur ( " ; " ). has_value ( )) {
480+ if (isVariable (value-> mText )) {
471481 std::cout << mVariables [value->mText ].VariableValue << std::endl;
472482 return true ;
473- } else {
474- std::cerr << " Vous devez mettre le symbole ';' pour mettre fin à l'instruction." << std::endl;
483+ } else if (fonction != std::nullopt ) {
484+ if (isArgument (value->mText )) {
485+ std::cout << mArguments [value->mText ].ArgValue << std::endl;
486+ return true ;
487+ }
475488 }
489+ std::cerr << " Vous devez specifier une argument d'une fonction ou une variable." << std::endl;
490+ return false ;
476491 } else {
477- std::cerr << " La variable n'existe pas ." << std::endl;
492+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin à l'instruction ." << std::endl;
478493 }
479494 }
480495 std::cerr << " Vous devez ouvrir les guillemets pour transmettre une chaine de caracteres ou le nom de votre variable sous ce format : 'envoyer [variable];'." << std::endl;
481496 }
482497 return false ;
483498 }
484499
485- bool Parser::ManagerInstruction (std::optional<std::string> argument ) {
500+ bool Parser::ManagerInstruction (std::optional<FonctionDefinition>& fonction ) {
486501 auto parseStart = mCurrentToken ; // std::vector<Token>::iterator
487502 auto PeutEtreInstruction = CheckerIdentifiant ();
488503 if (PeutEtreInstruction.has_value ()) {
489504 if (PeutEtreInstruction->mText == " envoyer" ) {
490- if (PrintInstruction (parseStart)) { return true ; } else { return false ; }
505+ if (PrintInstruction (parseStart, fonction )) { return true ; } else { return false ; }
491506 } else if (PeutEtreInstruction->mText == " variable" ) {
492- if (VariableInstruction (argument )) { return true ; } else { return false ; }
507+ if (VariableInstruction (fonction )) { return true ; } else { return false ; }
493508 } else if (PeutEtreInstruction->mText == " changer" ) {
494509 if (ChangerInstruction ()) { return true ; } else { return false ; }
495510 } else if (PeutEtreInstruction->mText == " definir" ) {
@@ -506,12 +521,12 @@ namespace FPL {
506521
507522
508523
509- void Parser::parse (std::vector<Token> &tokens, std::optional<std::string> argument ) {
524+ void Parser::parse (std::vector<Token> &tokens, std::optional<FonctionDefinition>& fonction ) {
510525 mEndToken = tokens.end ();
511526 mCurrentToken = tokens.begin ();
512527
513528 while (mCurrentToken != mEndToken ) { // Tant que tout le fichier n'est pas parcouru et qu'on n'a pas analysé tous les éléments.
514- if (ManagerInstruction (argument )) {
529+ if (ManagerInstruction (fonction )) {
515530
516531 } else {
517532 if (mCurrentToken ->mText .empty () || mCurrentToken ->mType == ESPACEVIDE ) {
@@ -594,6 +609,11 @@ namespace FPL {
594609 return false ;
595610 }
596611
612+ bool Parser::isArgument (std::string &name) const {
613+ if (mArguments .contains (name)) { return true ; }
614+ return false ;
615+ }
616+
597617 bool Parser::isFonctionArgument (std::string &fonction, std::string &argument) {
598618 if (isFonction (fonction)) {
599619 FonctionDefinition f = mFonctions [fonction];
0 commit comments