Skip to content

Commit 765df16

Browse files
committed
Fonctions (En progrès)
1 parent eb0ab94 commit 765df16

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

src/Parser.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,24 @@ namespace FPL {
99
mTypes["auto"] = Type("auto", AUTO);
1010
}
1111

12-
bool Parser::AppelerInstruction(auto parseStart) {
12+
bool Parser::AppelerInstruction() {
1313
auto PossibleFonctionName = CheckerIdentifiant();
1414
if (PossibleFonctionName.has_value()) {
1515
if (CheckerOperateur(";").has_value()) {
1616
if (isFonction(PossibleFonctionName->mText)) {
1717
FonctionDefinition fonction = mFonctions[PossibleFonctionName->mText];
18-
auto contentFonction = fonction.FonctionContent;
1918
std::string finalContent;
20-
for (auto a : contentFonction) {
19+
for (auto a : fonction.FonctionContent) {
2120
finalContent += a += " ";
2221
}
22+
std::cout << "IGNORE (" << finalContent << ")" << std::endl;
2323
TokenBuilding t;
2424
std::vector<Token> tokens = t.parseToken(finalContent);
25-
auto FEndToken = tokens.end();
2625
auto FCurrToken = tokens.begin();
27-
28-
while (FCurrToken != FEndToken) { // Tant que tout le fichier n'est pas parcouru et qu'on n'a pas analysé tous les éléments.
29-
if (ManagerInstruction(FCurrToken)) {
30-
31-
} else {
32-
if (FCurrToken->mText.empty()) {
33-
++FCurrToken;
34-
continue;
35-
}
36-
37-
std::cerr << "Identifier inconnu : " << FCurrToken->mText << std::endl;
38-
++FCurrToken;
39-
}
40-
}
26+
auto oldCurrentToken = mCurrentToken;
27+
mCurrentToken = FCurrToken;
28+
parse(tokens);
29+
mCurrentToken = oldCurrentToken;
4130
return true;
4231
}
4332
}
@@ -389,13 +378,13 @@ namespace FPL {
389378
std::cerr << "La variable n'existe pas." << std::endl;
390379
}
391380
}
392-
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;
381+
std::cerr << "Vous devez ouvrir les guillemets pour transmettre une chaine de caracteres ou le nom de votre variable sous ce format : 'envoyer [variable];'." << std::endl;
393382
}
394383
return false;
395384
}
396385

397-
bool Parser::ManagerInstruction(auto& token) {
398-
auto parseStart = token; // std::vector<Token>::iterator
386+
bool Parser::ManagerInstruction() {
387+
auto parseStart = mCurrentToken; // std::vector<Token>::iterator
399388
auto PeutEtreInstruction = CheckerIdentifiant();
400389
if (PeutEtreInstruction.has_value()) {
401390
if (PeutEtreInstruction->mText == "envoyer") {
@@ -407,9 +396,9 @@ namespace FPL {
407396
} else if (PeutEtreInstruction->mText == "definir") {
408397
if (FonctionInstruction(parseStart)) {return true;} else {return false;}
409398
} else if (PeutEtreInstruction->mText == "appeler") {
410-
if (AppelerInstruction(parseStart)) { return true; } else {return false;}
399+
if (AppelerInstruction()) { return true; } else {return false;}
411400
} else {
412-
token = parseStart;
401+
mCurrentToken = parseStart;
413402
}
414403
return false;
415404
}
@@ -423,7 +412,7 @@ namespace FPL {
423412
mCurrentToken = tokens.begin();
424413

425414
while (mCurrentToken != mEndToken) { // Tant que tout le fichier n'est pas parcouru et qu'on n'a pas analysé tous les éléments.
426-
if (ManagerInstruction(mCurrentToken)) {
415+
if (ManagerInstruction()) {
427416

428417
} else {
429418
if (mCurrentToken->mText.empty()) {
@@ -440,9 +429,8 @@ namespace FPL {
440429
std::optional<Token> Parser::CheckerIdentifiant(std::string_view name) {
441430
if (mCurrentToken == mEndToken) { return std::nullopt; }
442431
if (mCurrentToken->mType != IDENTIFIANT) { return std::nullopt; }
443-
if (mCurrentToken->mText != name && !name.empty()) { return std::nullopt; }
432+
if (!name.empty() && mCurrentToken->mText != name) { return std::nullopt; }
444433

445-
std::cout << "1: " << mCurrentToken->mText << std::endl;
446434
auto returnToken = mCurrentToken;
447435
++mCurrentToken;
448436
return *returnToken;

src/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ namespace FPL {
4343

4444
// Fonctions :
4545
bool FonctionInstruction(auto parseStart);
46-
bool AppelerInstruction(auto parseStart);
46+
bool AppelerInstruction();
4747
bool isFonction(std::string &name);
4848
std::map<std::string, FonctionDefinition> mFonctions;
4949

5050

5151
// Utils :
52-
bool ManagerInstruction(auto& token);
52+
bool ManagerInstruction();
5353
std::vector<Token>::iterator mCurrentToken;
5454
std::vector<Token>::iterator mEndToken;
5555
std::map<std::string, Type> mTypes;

0 commit comments

Comments
 (0)