Skip to content

Commit f6483a2

Browse files
committed
Type bool pour les variables globales et classique.
1 parent 097520f commit f6483a2

File tree

1 file changed

+65
-8
lines changed

1 file changed

+65
-8
lines changed

src/Parser.cpp

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace FPL {
77
mTypes["decimal"] = Type("decimal", DOUBLE);
88
mTypes["texte"] = Type("texte", STRING);
99
mTypes["auto"] = Type("auto", AUTO);
10-
mTypes["bool"] = Type("bool", BOOL); // Deux façon d'avoir le type bool.
10+
mTypes["bool"] = Type("bool", BOOL); // Deux façons d'avoir le type bool.
1111
mTypes["boolean"] = Type("boolean", BOOL);
1212

1313
InstructionsList = {
@@ -26,8 +26,10 @@ namespace FPL {
2626
"vide",
2727
"auto",
2828
"importer",
29-
"requete"
30-
"convertir"
29+
"requete",
30+
"convertir",
31+
"bool",
32+
"booleen"
3133
};
3234
}
3335

@@ -139,7 +141,7 @@ namespace FPL {
139141
std::cerr << "Vous devez mettre le symbole ';' pour mettre fin a l'instruction." << std::endl;
140142
exit(1);
141143
} else {
142-
std::cerr << "Veuillez donner une valeur qui va etre ecrite dans le fichier '" << fichierName->StatementName << "'." << std::endl;
144+
std::cerr << "Veuillez donner une valeur qui va etre mis dans le fichier '" << fichierName->StatementName << "'." << std::endl;
143145
exit(1);
144146
}
145147
} else {
@@ -741,6 +743,61 @@ namespace FPL {
741743
--mCurrentToken;
742744
auto PossibleVariable = CheckerIdentifiant();
743745
if (PossibleVariable.has_value()) {
746+
747+
if (VarType->mType == BOOL) {
748+
749+
if (CheckerOperateur(";").has_value()) {
750+
if (PossibleVariable->mText == "vrai" || PossibleVariable->mText == "faux") {
751+
VariableDefinition variable;
752+
variable.VariableName = VarName->mText;
753+
variable.IsGlobal = true;
754+
variable.HasReturnValue = false;
755+
variable.InFonction = false;
756+
variable.VariableType = Type("bool", BOOL);
757+
758+
if (fonction.has_value() || fonction != std::nullopt) {
759+
variable.InFonction = true;
760+
761+
if (isArgument(fonction->FonctionName, PossibleVariable->mText)) {
762+
variable.VariableValue = mArguments[fonction->FonctionName][PossibleVariable->mText].ArgValue;
763+
764+
if (VarType->mType == AUTO) {
765+
variable.VariableType = Type(
766+
mArguments[fonction->FonctionName][PossibleVariable->mText].ArgType.mName,
767+
mArguments[fonction->FonctionName][PossibleVariable->mText].ArgType.mType);
768+
} else if (VarType->mType != AUTO) {
769+
if (VarType->mType !=
770+
mArguments[fonction->FonctionName][PossibleVariable->mText].ArgType.mType) {
771+
std::cerr
772+
<< "Vous devez donner une valeur a la variable qui correspond au type."
773+
<< std::endl;
774+
exit(1);
775+
}
776+
}
777+
}
778+
} else if (isVariable(PossibleVariable->mText)) {
779+
variable.VariableValue = mVariables[PossibleVariable->mText].VariableValue;
780+
781+
if (VarType->mType == AUTO) {
782+
variable.VariableType = Type(mVariables[PossibleVariable->mText].VariableType.mName,
783+
mVariables[PossibleVariable->mText].VariableType.mType);
784+
} else if (VarType->mType != AUTO) {
785+
if (VarType->mType != mVariables[PossibleVariable->mText].VariableType.mType) {
786+
std::cerr << "Vous devez donner une valeur a la variable qui correspond au type." << std::endl;
787+
exit(1);
788+
}
789+
}
790+
}
791+
792+
mVariables[variable.VariableName] = variable;
793+
return true;
794+
} else {
795+
std::cerr << "Les valeurs ne peuvent que etre 'vrai' ou 'faux' !" << std::endl;
796+
exit(1);
797+
}
798+
}
799+
}
800+
744801
if (CheckerOperateur(";").has_value()) {
745802
if (isVariable(PossibleVariable->mText)) {
746803
auto OldVariable = mVariables[PossibleVariable->mText];
@@ -920,7 +977,7 @@ namespace FPL {
920977
if (NewType->mType == INT && var.VariableType.mType == STRING) {
921978
try {
922979
int v = std::stoi(var.VariableValue);
923-
var.VariableValue = v;
980+
var.VariableValue = std::to_string(v);
924981
var.VariableType = Type("entier", INT);
925982
}
926983
catch (std::invalid_argument const& ex) {
@@ -929,8 +986,8 @@ namespace FPL {
929986
return true;
930987
} else if (NewType->mType == DOUBLE && var.VariableType.mType == STRING) {
931988
try {
932-
int v = std::stod(var.VariableValue);
933-
var.VariableValue = v;
989+
double v = std::stod(var.VariableValue);
990+
var.VariableValue = std::to_string(v);
934991
var.VariableType = Type("decimal", DOUBLE);
935992
}
936993
catch (std::invalid_argument const& ex) {
@@ -1146,7 +1203,7 @@ namespace FPL {
11461203
if (ManagerInstruction(fonction)) {
11471204

11481205
} else {
1149-
if (mCurrentToken->mText.empty() || mCurrentToken->mType == ESPACEVIDE || mCurrentToken->mText == "" || mCurrentToken->mText == " ") {
1206+
if (mCurrentToken->mText.empty() || mCurrentToken->mType == ESPACEVIDE || mCurrentToken->mText == " ") {
11501207
continue;
11511208
}
11521209

0 commit comments

Comments
 (0)