|
2 | 2 |
|
3 | 3 | namespace FPL::Parser { |
4 | 4 |
|
| 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 | + |
5 | 82 | void Parser::TantQueInstruction(Data::Data &data, std::optional<FPL::FonctionDef>& fonction) { |
6 | 83 | auto endInstruction = ExpectIdentifiant(data); |
7 | 84 | if (!endInstruction.has_value() || endInstruction->TokenText != "que") { |
@@ -46,7 +123,7 @@ namespace FPL::Parser { |
46 | 123 |
|
47 | 124 | while (data.current_token != data.end_token) { |
48 | 125 | 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") { |
50 | 127 | totalInstructionInDefinition += 1; |
51 | 128 | } |
52 | 129 |
|
@@ -319,7 +396,7 @@ namespace FPL::Parser { |
319 | 396 |
|
320 | 397 | while (data.current_token != data.end_token) { |
321 | 398 | 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") { |
323 | 400 | totalInstructionInDefinition += 1; |
324 | 401 | } |
325 | 402 |
|
@@ -600,7 +677,7 @@ namespace FPL::Parser { |
600 | 677 |
|
601 | 678 | while (true) { |
602 | 679 | 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") { |
604 | 681 | totalInstructionInDefinition += 1; |
605 | 682 | } |
606 | 683 |
|
@@ -1145,6 +1222,9 @@ namespace FPL::Parser { |
1145 | 1222 | } else if (Instruction->TokenText == "tant") { |
1146 | 1223 | TantQueInstruction(data, fonction); |
1147 | 1224 | return true; |
| 1225 | + } else if (Instruction->TokenText == "verifier") { |
| 1226 | + VerifierInstruction(data, fonction); |
| 1227 | + return true; |
1148 | 1228 | } |
1149 | 1229 | } |
1150 | 1230 | return false; |
|
0 commit comments