Skip to content

Commit 18af8c7

Browse files
committed
Verifier instruction
1 parent 677cdf1 commit 18af8c7

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

src/Essentials/Parser.cpp

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,83 @@
22

33
namespace FPL::Parser {
44

5+
void Parser::VerifierInstruction(Data::Data &data, std::optional<FPL::FonctionDef>& fonction) {
6+
auto possibleVariable = ExpectIdentifiant(data);
7+
if (possibleVariable.has_value()) {
8+
if (data.Map_Variables.contains(possibleVariable->TokenText)) {
9+
if (!ExpectOperator(data, "{").has_value()) {
10+
openNewCode(data);
11+
}
12+
13+
auto variable = data.getVariable(possibleVariable->TokenText);
14+
15+
while (!ExpectOperator(data, "}").has_value()) {
16+
auto cas_title = ExpectIdentifiant(data);
17+
if (cas_title.has_value() && cas_title->TokenText == "cas") {
18+
auto valueToCompare = ExpectValue(data);
19+
if (!valueToCompare.has_value()) {
20+
VERIFIER_needcas(data);
21+
}
22+
23+
if (!ExpectOperator(data, ":").has_value()) {
24+
VERIFIER_openPartOfCode(data);
25+
}
26+
27+
std::vector<std::string> actionVeriferCas_Content;
28+
29+
while (!ExpectOperator(data, ",").has_value()) {
30+
actionVeriferCas_Content.push_back(data.current_token->TokenText);
31+
data.current_token++;
32+
}
33+
34+
std::vector<Tokenizer::Token> FileCode_Tokens = FPL::Tokenizer::TokenBuilder::ParseToken(
35+
FPL::Instruction::FunctionUtils::ReturnStringVector(actionVeriferCas_Content));
36+
37+
int value_variable = stringToInt(variable->VariableValue, "");
38+
int value_double_variable = stringToDouble(variable->VariableValue, "");
39+
if (valueToCompare->StatementType.Type == Types::INT && value_variable == stringToInt(valueToCompare->StatementName, "")) {
40+
auto data_f = executeContentCode(FileCode_Tokens, fonction, std::nullopt, data);
41+
42+
for (auto const& variables : data_f.Map_Variables) {
43+
auto it = std::find(data_f.Map_Variables.begin(), data_f.Map_Variables.end(), variables);
44+
if (it != data_f.Map_Variables.end()) {
45+
if (it->second.IsGlobal) {
46+
data.addVariableToMap(it->second.VariableName,
47+
it->second.VariableValue,
48+
it->second.VariableType,
49+
it->second.NeedDelete,
50+
it->second.IsGlobal);
51+
}
52+
}
53+
}
54+
} else if (valueToCompare->StatementType.Type == Types::DOUBLE && value_double_variable == stringToDouble(valueToCompare->StatementName, "")) {
55+
auto data_f = executeContentCode(FileCode_Tokens, fonction, std::nullopt, data);
56+
57+
for (auto const& variables : data_f.Map_Variables) {
58+
auto it = std::find(data_f.Map_Variables.begin(), data_f.Map_Variables.end(), variables);
59+
if (it != data_f.Map_Variables.end()) {
60+
if (it->second.IsGlobal) {
61+
data.addVariableToMap(it->second.VariableName,
62+
it->second.VariableValue,
63+
it->second.VariableType,
64+
it->second.NeedDelete,
65+
it->second.IsGlobal);
66+
}
67+
}
68+
}
69+
}
70+
} else {
71+
VERIFIER_needcas_title(data);
72+
}
73+
}
74+
} else {
75+
variableDoesNotExist(data);
76+
}
77+
} else {
78+
variableDoesNotExist(data);
79+
}
80+
}
81+
582
void Parser::TantQueInstruction(Data::Data &data, std::optional<FPL::FonctionDef>& fonction) {
683
auto endInstruction = ExpectIdentifiant(data);
784
if (!endInstruction.has_value() || endInstruction->TokenText != "que") {
@@ -46,7 +123,7 @@ namespace FPL::Parser {
46123

47124
while (data.current_token != data.end_token) {
48125
auto currentToken = data.current_token;
49-
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "tant") {
126+
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "verifier" || currentToken->TokenText == "tant") {
50127
totalInstructionInDefinition += 1;
51128
}
52129

@@ -319,7 +396,7 @@ namespace FPL::Parser {
319396

320397
while (data.current_token != data.end_token) {
321398
auto currentToken = data.current_token;
322-
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "tant") {
399+
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "verifier" || currentToken->TokenText == "tant") {
323400
totalInstructionInDefinition += 1;
324401
}
325402

@@ -600,7 +677,7 @@ namespace FPL::Parser {
600677

601678
while (true) {
602679
auto currentToken = data.current_token;
603-
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "tant") {
680+
if (currentToken->TokenText == "definir" || currentToken->TokenText == "paquet" || currentToken->TokenText == "verifier" || currentToken->TokenText == "tant") {
604681
totalInstructionInDefinition += 1;
605682
}
606683

@@ -1145,6 +1222,9 @@ namespace FPL::Parser {
11451222
} else if (Instruction->TokenText == "tant") {
11461223
TantQueInstruction(data, fonction);
11471224
return true;
1225+
} else if (Instruction->TokenText == "verifier") {
1226+
VerifierInstruction(data, fonction);
1227+
return true;
11481228
}
11491229
}
11501230
return false;

src/Essentials/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ namespace FPL::Parser {
5959
static void TypeInstruction(FPL::Data::Data &data, std::optional<FPL::Paquet::Paquet> paquet);
6060

6161
static void TantQueInstruction(FPL::Data::Data &data, std::optional<FPL::FonctionDef>& fonction);
62+
63+
static void VerifierInstruction(Data::Data &data, std::optional<FPL::FonctionDef>& fonction);
6264
};
6365
}

0 commit comments

Comments
 (0)