This repository has been archived by the owner on May 17, 2024. It is now read-only.
forked from Feelzor/InterpreteurCpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-procedures: ajout des procédures
- Loading branch information
Showing
17 changed files
with
228 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "Procedure.h" | ||
|
||
Procedure::Procedure(TableSymboles table, Noeud* sequence, std::vector<SymboleValue*> parametres) | ||
: m_table(table), m_sequence(sequence), m_params(parametres) {} | ||
|
||
void Procedure::accepter(Visiteur& visiteur) { | ||
m_sequence->accepter(visiteur); | ||
} | ||
|
||
void Procedure::empiler(std::vector<Valeur*> parametres) { | ||
for (int i = 0; i < parametres.size() && i < m_params.size(); i++) { | ||
m_params[i]->setValeur(parametres[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef PROCEDURE_H | ||
#define PROCEDURE_H | ||
|
||
#include "ArbreAbstrait.h" | ||
#include "TableSymboles.h" | ||
#include "SymboleValue.h" | ||
#include <vector> | ||
|
||
class Procedure : public Noeud { | ||
public: | ||
Procedure(TableSymboles table, Noeud* sequence, std::vector<SymboleValue*> parametres); | ||
void accepter(Visiteur& visiteur) override; | ||
void empiler(std::vector<Valeur*> parametres); | ||
private: | ||
TableSymboles m_table; | ||
Noeud* m_sequence; | ||
std::vector<SymboleValue*> m_params; | ||
}; | ||
|
||
#endif /* PROCEDURE_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "TableProcedures.h" | ||
#include "Procedure.h" | ||
#include <algorithm> | ||
|
||
TableProcedures* TableProcedures::table = nullptr; | ||
|
||
TableProcedures::TableProcedures() {} | ||
|
||
TableProcedures* TableProcedures::getTable() { | ||
if (table == nullptr) { | ||
table = new TableProcedures(); | ||
} | ||
|
||
return table; | ||
} | ||
|
||
void TableProcedures::ajoutProcedure(Symbole nom, Procedure* procedure) { | ||
std::string nomProcedure(nom.getChaine()); | ||
m_procedures.push_back(procedure); | ||
m_noms.push_back(nom.getChaine()); | ||
} | ||
|
||
void TableProcedures::executerProcedure(Symbole nom, std::vector<Noeud*> parametres, VisiteurExecuter& v) { | ||
long i = std::distance(m_noms.begin(), std::find(m_noms.begin(), m_noms.end(), nom.getChaine())); | ||
Procedure* p = m_procedures[i]; | ||
std::vector<Valeur*> params; | ||
for (Noeud* noeud : parametres) { | ||
noeud->accepter(v); | ||
params.push_back(v.getDerniereValeur()); | ||
} | ||
p->empiler(params); | ||
p->accepter(v); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef TABLEPROCEDURES_H | ||
#define TABLEPROCEDURES_H | ||
|
||
#include <map> | ||
#include <vector> | ||
#include <string> | ||
#include "Symbole.h" | ||
#include "Procedure.h" | ||
#include "VisiteurExecuter.h" | ||
|
||
class TableProcedures { | ||
public: | ||
static TableProcedures* getTable(); | ||
void ajoutProcedure(Symbole nom, Procedure* procedure); | ||
void executerProcedure(Symbole nom, std::vector<Noeud*> parametres, VisiteurExecuter& v); | ||
private: | ||
TableProcedures(); | ||
static TableProcedures* table; | ||
|
||
std::vector<Procedure*> m_procedures; | ||
std::vector<std::string> m_noms; | ||
}; | ||
|
||
#endif /* TABLEPROCEDURES_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ ecrire | |
et | ||
ou | ||
non | ||
appel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Résultat attendu : 9 | ||
|
||
procedure carre(a) | ||
ecrire(a * a); | ||
finproc | ||
|
||
procedure principale() | ||
appel carre(3); | ||
finproc |