@@ -12,26 +12,61 @@ namespace FPL {
1212 bool Parser::AppelerInstruction () {
1313 auto PossibleFonctionName = CheckerIdentifiant ();
1414 if (PossibleFonctionName.has_value ()) {
15- if (CheckerOperateur (" ;" ).has_value ()) {
16- if (isFonction (PossibleFonctionName->mText )) {
17- FonctionDefinition const fonction = mFonctions [PossibleFonctionName->mText ];
18- if (!fonction.FonctionContent .empty ()) {
19- std::string finalContent;
20- for (auto const &a : fonction.FonctionContent ) {
21- finalContent.append (a).append (" " );
22- }
23- TokenBuilding t;
24- std::cout << " " << std::endl; // IGNORE (finalContent) -> sans le print, cela ne marche plus.
25- std::vector<Token> tokens = t.parseToken (finalContent);
15+ if (isFonction (PossibleFonctionName->mText )) {
16+ FonctionDefinition fonction = mFonctions [PossibleFonctionName->mText ];
17+ if (fonction.HasArgument ) {
18+ if (CheckerOperateur (" :" ).has_value ()) {
19+ while (fonction.NumberArgument > 0 ) {
20+ auto name = CheckerIdentifiant ();
21+ if (!name.has_value ()) {
22+ std::cerr << " Veuillez specifier le nom du parametre." << std::endl;
23+ }
2624
27- auto FCurrToken = tokens.begin ();
28- auto oldCurrentToken = mCurrentToken ;
29- parse (tokens);
30- mCurrentToken = oldCurrentToken;
25+ if (!isFonctionArgument (PossibleFonctionName->mText , name->mText )) {
26+ std::cerr << " Ce parametre n'existe pas dans la fonction " << PossibleFonctionName->mText << " ." << std::endl;
27+ }
3128
32- return true ;
29+ auto value = CheckerValue ();
30+ if (!value.has_value ()) {
31+ std::cerr << " Veuillez donner une valeur au parametre << " << name->mText << " ." << std::endl;
32+ }
33+
34+ auto parametre = getArgument (PossibleFonctionName->mText , name->mText );
35+ if (parametre->ArgType .mType == value->StatementType .mType && parametre->ArgType .mType != AUTO) {
36+ parametre->ArgValue = value->StatementName ;
37+ } else if (parametre->ArgType .mType == AUTO && parametre->ArgType .mType != value->StatementType .mType ) {
38+ parametre->ArgType = Type (" auto" , AUTO);
39+ parametre->ArgValue = value->StatementName ;
40+ } else {
41+ std::cerr << " Le type de votre valeur doit être identique a celui de l'argument." << std::endl;
42+ }
43+
44+ if (fonction.NumberArgument > 1 && !CheckerOperateur (" ," ).has_value ()) {
45+ std::cerr << " Veuillez separer les different arguments par le symbole ','." << std::endl;
46+ }
47+ fonction.NumberArgument -= 1 ;
48+ }
49+ if (!CheckerOperateur (" ;" ).has_value ()) {
50+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin à l'instruction." << std::endl;
51+ }
52+ } else {
53+ std::cerr << " La fonction a des parametres, vous devez obligatoirement leur donner une valeur." << std::endl;
54+ }
55+ }
56+ if (!fonction.FonctionContent .empty ()) {
57+ std::string finalContent;
58+ for (auto const &a : fonction.FonctionContent ) {
59+ finalContent.append (a).append (" " );
3360 }
34- return false ;
61+ TokenBuilding t;
62+ std::cout << " " << std::endl; // IGNORE (finalContent) -> sans le print, cela ne marche plus.
63+ std::vector<Token> tokens = t.parseToken (finalContent);
64+
65+ auto FCurrToken = tokens.begin ();
66+ auto oldCurrentToken = mCurrentToken ;
67+ parse (tokens);
68+ mCurrentToken = oldCurrentToken;
69+ return true ;
3570 }
3671 }
3772 }
@@ -68,6 +103,8 @@ namespace FPL {
68103 param.ArgType .mName = type->mName ;
69104 param.ArgType .mType = type->mType ;
70105 param.ArgName = possibleArg->mText ;
106+ fonction.HasArgument = true ;
107+ fonction.NumberArgument += 1 ;
71108 fonction.ArgsFonction .push_back (param);
72109
73110 if (CheckerOperateur (" )" ).has_value ()) {
@@ -499,6 +536,39 @@ namespace FPL {
499536 return false ;
500537 }
501538
539+ bool Parser::isFonctionArgument (std::string &fonction, std::string &argument) {
540+ if (isFonction (fonction)) {
541+ FonctionDefinition f = mFonctions [fonction];
542+ if (f.HasArgument ) {
543+ for (auto const & a : f.ArgsFonction ) {
544+ if (a.ArgName == argument) {
545+ return true ;
546+ }
547+ }
548+ }
549+ }
550+ return false ;
551+ }
552+
553+ std::optional<FonctionDefinition> Parser::getFonction (std::string& fonction) {
554+ if (isFonction (fonction)) {
555+ return mFonctions [fonction];
556+ }
557+ return std::nullopt ;
558+ }
559+
560+ std::optional<ArgumentDefinition> Parser::getArgument (std::string &fonction, std::string &name) {
561+ if (isFonctionArgument (fonction, name)) {
562+ auto f = getFonction (fonction);
563+ for (auto const &arg : f->ArgsFonction ) {
564+ if (arg.ArgName == name) {
565+ return arg;
566+ }
567+ }
568+ }
569+ return std::nullopt ;
570+ }
571+
502572 [[maybe_unused]] void Parser::DebugPrint () const {
503573 for (auto &funcPair: mFonctions ) {
504574 for (auto &e: funcPair.second .FonctionContent ) {
0 commit comments