Skip to content

Commit 4fbe988

Browse files
committed
Type bool pour les variables globales. (Added)
1 parent eefafec commit 4fbe988

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Parser.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ 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.
11+
mTypes["boolean"] = Type("boolean", BOOL);
1012

1113
InstructionsList = {
1214
"envoyer",
@@ -486,6 +488,59 @@ namespace FPL {
486488
} else {
487489
auto name = CheckerIdentifiant();
488490
if (name.has_value()) {
491+
if (VarType->mType == BOOL) {
492+
if (CheckerOperateur(";").has_value()) {
493+
if (name->mText == "vrai" || name->mText == "faux") {
494+
VariableDefinition variable;
495+
variable.VariableName = VarName->mText;
496+
variable.IsGlobal = true;
497+
variable.HasReturnValue = false;
498+
variable.InFonction = false;
499+
variable.VariableType = Type("bool", BOOL);
500+
501+
if (fonction.has_value() || fonction != std::nullopt) {
502+
variable.InFonction = true;
503+
504+
if (isArgument(fonction->FonctionName, name->mText)) {
505+
variable.VariableValue = mArguments[fonction->FonctionName][name->mText].ArgValue;
506+
507+
if (VarType->mType == AUTO) {
508+
variable.VariableType = Type(
509+
mArguments[fonction->FonctionName][name->mText].ArgType.mName,
510+
mArguments[fonction->FonctionName][name->mText].ArgType.mType);
511+
} else if (VarType->mType != AUTO) {
512+
if (VarType->mType !=
513+
mArguments[fonction->FonctionName][name->mText].ArgType.mType) {
514+
std::cerr
515+
<< "Vous devez donner une valeur a la variable qui correspond au type."
516+
<< std::endl;
517+
exit(1);
518+
}
519+
}
520+
}
521+
} else if (isVariable(name->mText)) {
522+
variable.VariableValue = mVariables[name->mText].VariableValue;
523+
524+
if (VarType->mType == AUTO) {
525+
variable.VariableType = Type(mVariables[name->mText].VariableType.mName,
526+
mVariables[name->mText].VariableType.mType);
527+
} else if (VarType->mType != AUTO) {
528+
if (VarType->mType != mVariables[name->mText].VariableType.mType) {
529+
std::cerr << "Vous devez donner une valeur a la variable qui correspond au type." << std::endl;
530+
exit(1);
531+
}
532+
}
533+
}
534+
535+
mVariables[variable.VariableName] = variable;
536+
return true;
537+
} else {
538+
std::cerr << "Les valeurs ne peuvent que etre 'vrai' ou 'faux' !" << std::endl;
539+
exit(1);
540+
}
541+
}
542+
}
543+
489544
if (CheckerOperateur(";").has_value()) {
490545
VariableDefinition variable;
491546
variable.VariableName = VarName->mText;

src/TypeManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace FPL {
88
INT,
99
DOUBLE,
1010
STRING,
11+
BOOL,
1112
AUTO
1213
// STRUCT -> pour l'oo
1314
};

0 commit comments

Comments
 (0)