Skip to content

Commit 6c2d0c6

Browse files
committed
Fixs : prints + variables.
Voir doc pour en apprendre plus.
1 parent 39c4c95 commit 6c2d0c6

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

src/Parser.cpp

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace FPL {
9494
auto VarValue = CheckerValue();
9595
if (VarValue.has_value()) {
9696
if (VarValue->StatementType.mType == VarType->mType) {
97-
if (CheckerOperateur("|")) {
97+
if (CheckerOperateur(";")) {
9898
VariableDefinition variable;
9999
variable.VariableName = VarName->mText;
100100
variable.VariableType = Type(VarType->mName, VarType->mType);
@@ -108,6 +108,24 @@ namespace FPL {
108108
} else {
109109
std::cerr << "Vous devez donner une valeur qui est de même type que la variable." << std::endl;
110110
}
111+
} else if (CheckerIdentifiant().has_value()) {
112+
--mCurrentToken;
113+
auto PossibleVariable = CheckerIdentifiant();
114+
if (PossibleVariable.has_value()) {
115+
if (isVariable(PossibleVariable->mText)) {
116+
if (CheckerOperateur(";").has_value()) {
117+
VariableDefinition variable;
118+
variable.VariableName = VarName->mText;
119+
variable.VariableType = Type(VarType->mName, VarType->mType);
120+
variable.VariableValue = mVariables[PossibleVariable->mText].VariableValue;
121+
122+
mVariables[variable.VariableName] = variable;
123+
return true;
124+
} else {
125+
std::cerr << "Merci de signifier la fin de la déclaration de la variable avec '|'." << std::endl;
126+
}
127+
}
128+
}
111129
} else {
112130
std::cerr << "Vous devez donner une valeur a la variable qui correspond au type." << std::endl;
113131
}
@@ -134,8 +152,12 @@ namespace FPL {
134152
auto Value = CheckerValue();
135153
if (Value.has_value()) {
136154
if (Value->StatementType.mType == VarType.mType) {
137-
mVariables[VarName->mText].VariableValue = Value->StatementName;
138-
return true;
155+
if (CheckerOperateur(";").has_value()) {
156+
mVariables[VarName->mText].VariableValue = Value->StatementName;
157+
return true;
158+
} else {
159+
std::cerr << "Vous devez mettre le symbole ';' pour mettre fin à l'instruction." << std::endl;
160+
}
139161
} else {
140162
std::cerr << "Veuillez donner une valeur en rapport avec le type de la variable." << std::endl;
141163
}
@@ -160,26 +182,29 @@ namespace FPL {
160182
bool Parser::PrintInstruction(auto parseStart) {
161183
auto Value = CheckerValue();
162184
if (Value.has_value()) {
163-
if (Value->StatementType.mType == STRING) {
164-
std::replace(Value->StatementName.begin(), Value->StatementName.end(), '"', ' ');
185+
if (CheckerOperateur(";").has_value()) {
186+
if (Value->StatementType.mType == STRING) {
187+
std::replace(Value->StatementName.begin(), Value->StatementName.end(), '"', ' ');
188+
}
189+
std::cout << Value->StatementName << std::endl;
190+
return true;
191+
} else {
192+
std::cerr << "Vous devez mettre le symbole ';' pour mettre fin à l'instruction." << std::endl;
165193
}
166-
std::cout << Value->StatementName << std::endl;
167-
return true;
168194
} else {
169195
mCurrentToken = parseStart;
170196
++mCurrentToken;
171197
auto value = CheckerIdentifiant();
172198
if (value.has_value()) {
173-
if (CheckerOperateur("<").has_value()) {
174-
if (CheckerOperateur("-").has_value()) {
175-
if (isVariable(value->mText)) {
176-
std::cout << mVariables[value->mText].VariableValue << std::endl;
177-
return true;
178-
} else {
179-
mCurrentToken = parseStart;
180-
std::cerr << "La variable n'existe pas." << std::endl;
181-
}
199+
if (isVariable(value->mText)) {
200+
if (CheckerOperateur(";").has_value()) {
201+
std::cout << mVariables[value->mText].VariableValue << std::endl;
202+
return true;
203+
} else {
204+
std::cerr << "Vous devez mettre le symbole ';' pour mettre fin à l'instruction." << std::endl;
182205
}
206+
} else {
207+
std::cerr << "La variable n'existe pas." << std::endl;
183208
}
184209
}
185210
std::cerr << "Vous devez ouvrir les guillemets pour transmettre une chaine de caractères ou le nom de votre variable sous ce format : 'envoyer (variable) <-" << std::endl;
@@ -287,6 +312,12 @@ namespace FPL {
287312
return res;
288313
}
289314

315+
bool Parser::isVariable(std::string &name) {
316+
if (mVariables.contains(name)) {
317+
return true;
318+
}
319+
return false;
320+
}
290321

291322
void Parser::DebugPrint() const {
292323
for (auto &funcPair: mFonctions) {
@@ -295,11 +326,4 @@ namespace FPL {
295326
}
296327
}
297328
}
298-
299-
bool Parser::isVariable(std::string &name) {
300-
if (mVariables.contains(name)) {
301-
return true;
302-
}
303-
return false;
304-
}
305329
}

0 commit comments

Comments
 (0)