@@ -87,82 +87,92 @@ namespace FPL {
8787 return false ;
8888 }
8989
90- bool Parser::VariableDeclaration () {
90+ bool Parser::ManagerInstruction () {
9191 auto parseStart = mCurrentToken ; // std::vector<Token>::iterator
9292 auto PeutEtreInstruction = CheckerIdentifiant ();
93- if (PeutEtreInstruction.has_value () && PeutEtreInstruction->mText == " variable" ) {
94- auto VarType = CheckerType ();
95- if (VarType.has_value ()) {
96- auto VarName = CheckerIdentifiant ();
97- if (VarName.has_value ()) {
98- if (CheckerOperateur (" -" ).has_value ()) {
99- if (CheckerOperateur (" >" ).has_value ()) {
100- auto VarValue = CheckerValue ();
101- if (VarValue.has_value ()) {
102- if (VarValue->StatementType .mType == VarType->mType ) {
103- VariableDefinition variable;
104- variable.VariableName = VarName->mText ;
105- variable.VariableType = Type (VarType->mName , VarType->mType );
106- variable.VariableValue = VarValue->StatementName ;
107-
108- if (VarType->mType == STRING) {
109- std::replace (variable.VariableValue .begin (), variable.VariableValue .end (), ' "' , ' ' );
110- }
111-
112- mVariables [variable.VariableName ] = variable;
113-
114- std::cout << " La variable '"
115- << mVariables [variable.VariableName ].VariableName << " ' a pour valeur "
116- << mVariables [variable.VariableName ].VariableValue << std::endl;
117-
93+ if (PeutEtreInstruction.has_value ()) {
94+ if (PeutEtreInstruction->mText == " envoyer" ) {
95+ auto Value = CheckerValue ();
96+ if (Value.has_value ()) {
97+ if (Value->StatementType .mType == STRING) {
98+ std::replace (Value->StatementName .begin (), Value->StatementName .end (), ' "' , ' ' );
99+ }
100+ std::cout << Value->StatementName << std::endl;
101+ return true ;
102+ } else {
103+ mCurrentToken = parseStart;
104+ ++mCurrentToken ;
105+ auto value = CheckerIdentifiant ();
106+ if (value.has_value ()) {
107+ if (CheckerOperateur (" <" ).has_value ()) {
108+ if (CheckerOperateur (" -" ).has_value ()) {
109+ if (isVariable (value->mText )) {
110+ std::cout << mVariables [value->mText ].VariableValue << std::endl;
118111 return true ;
119112 } else {
120- std::cerr << " Vous devez donner une valeur qui est de même type que la variable." << std::endl;
113+ mCurrentToken = parseStart;
114+ std::cerr << " La variable n'existe pas." << std::endl;
115+ }
116+ }
117+ }
118+ }
119+ std::cerr << " Vous devez ouvrir les guillements pour transmettre une chaine de caractères ou le nom de votre variable sous ce format : 'envoyer (variable) <-" << std::endl;
120+ return false ;
121+ }
122+ } else if (PeutEtreInstruction->mText == " variable" ) {
123+ auto VarType = CheckerType ();
124+ if (VarType.has_value ()) {
125+ auto VarName = CheckerIdentifiant ();
126+ if (VarName.has_value ()) {
127+ if (CheckerOperateur (" -" ).has_value ()) {
128+ if (CheckerOperateur (" >" ).has_value ()) {
129+ auto VarValue = CheckerValue ();
130+ if (VarValue.has_value ()) {
131+ if (VarValue->StatementType .mType == VarType->mType ) {
132+ VariableDefinition variable;
133+ variable.VariableName = VarName->mText ;
134+ variable.VariableType = Type (VarType->mName , VarType->mType );
135+ variable.VariableValue = VarValue->StatementName ;
136+
137+ if (VarType->mType == STRING) {
138+ std::replace (variable.VariableValue .begin (), variable.VariableValue .end (), ' "' , ' ' );
139+ }
140+
141+ mVariables [variable.VariableName ] = variable;
142+
143+ std::cout << " La variable '"
144+ << mVariables [variable.VariableName ].VariableName << " ' a pour valeur "
145+ << mVariables [variable.VariableName ].VariableValue << std::endl;
146+
147+ return true ;
148+ } else {
149+ std::cerr << " Vous devez donner une valeur qui est de même type que la variable." << std::endl;
150+ mCurrentToken = parseStart;
151+ }
152+ } else {
153+ std::cerr << " Vous devez donner une valeur a la variable qui correspond au type." << std::endl;
121154 mCurrentToken = parseStart;
122155 }
123156 } else {
124- std::cerr << " Vous devez donner une valeur a la variable qui correspond au type ." << std::endl;
157+ std::cerr << " Vous devez utiliser les symboles '->' pour donner une valeur à la variable." << std::endl;
125158 mCurrentToken = parseStart;
126159 }
127160 } else {
128161 std::cerr << " Vous devez utiliser les symboles '->' pour donner une valeur à la variable." << std::endl;
129162 mCurrentToken = parseStart;
130163 }
131164 } else {
132- std::cerr << " Vous devez utiliser les symboles '->' pour donner une valeur à la variable." << std::endl;
165+ std::cerr << " Vous devez indiquer un nom à la variable." << std::endl;
133166 mCurrentToken = parseStart;
134167 }
135168 } else {
136- std::cerr << " Vous devez indiquer un nom à la variable." << std::endl;
137- mCurrentToken = parseStart;
138- }
139- } else {
140- std::cerr << " Vous devez indiquer une type pour la variable." << std::endl;
141- mCurrentToken = parseStart;
142- }
143- }
144- return false ;
145- }
146-
147- bool Parser::Print () {
148- auto parseStart = mCurrentToken ; // std::vector<Token>::iterator
149- auto PeutEtreInstruction = CheckerIdentifiant ();
150- if (PeutEtreInstruction.has_value ()) {
151- if (PeutEtreInstruction->mText == " envoyer" ) {
152- auto Value = CheckerValue ();
153- if (Value.has_value ()) {
154- if (Value->StatementType .mType == STRING) {
155- std::replace (Value->StatementName .begin (), Value->StatementName .end (), ' "' , ' ' );
156- }
157- std::cout << Value->StatementName << std::endl;
158- return true ;
159- } else {
169+ std::cerr << " Vous devez indiquer une type pour la variable." << std::endl;
160170 mCurrentToken = parseStart;
161- std::cerr << " Vous devez mettre des \" pour ouvrir et fermer l'instruction que si le type est texte." << std::endl;
162171 }
163172 } else {
164173 mCurrentToken = parseStart;
165174 }
175+ return false ;
166176 }
167177 return false ;
168178 }
@@ -174,15 +184,7 @@ namespace FPL {
174184 mCurrentToken = tokens.begin ();
175185
176186 while (mCurrentToken != mEndToken ) { // Tant que tout le fichier n'est pas parcouru et qu'on n'a pas analysé tous les éléments.
177- if (FunctionChecker ()) {
178-
179- }
180-
181- if (Print ()) {
182-
183- }
184-
185- if (VariableDeclaration ()) {
187+ if (ManagerInstruction ()) {
186188
187189 } else {
188190 if (mCurrentToken ->mText .empty ()) {
@@ -263,4 +265,11 @@ namespace FPL {
263265 }
264266 }
265267 }
268+
269+ bool Parser::isVariable (std::string &name) {
270+ if (mVariables .contains (name)) {
271+ return true ;
272+ }
273+ return false ;
274+ }
266275}
0 commit comments