Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
fix-gros-grains : fix de l'arbre non vide après une erreur de syntaxe
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsKrattinger committed Oct 25, 2019
1 parent 11138b6 commit 0691ae4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Interpreteur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
using namespace std;

Interpreteur::Interpreteur(ifstream & fichier) :
m_lecteur(fichier), m_table(), m_arbre(nullptr) {
m_lecteur(fichier), m_table(), m_arbre(nullptr),m_erreur(false) {
}

void Interpreteur::analyse() {
m_arbre = programme(); // on lance l'analyse de la première règle
if(m_erreur){
m_arbre = nullptr; // Si on a trouvé une erreur de syntaxe on vide l'arbre
}
}

void Interpreteur::tester(const string & symboleAttendu) const {
Expand Down Expand Up @@ -63,7 +66,7 @@ Noeud* Interpreteur::seqInst() {
} catch (SyntaxeException e) {
cerr << e.what() << endl;
while (!instructions->isInstruction(m_lecteur.getSymbole()) && m_lecteur.getSymbole() != "finproc" && m_lecteur.getSymbole() != "EOF") {
m_arbre = nullptr;
m_erreur = true;
m_lecteur.avancer();
}
}
Expand Down
1 change: 1 addition & 0 deletions Interpreteur.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Interpreteur {
Lecteur m_lecteur; // Le lecteur de symboles utilisé pour analyser le fichier
TableSymboles m_table; // La table des symboles valués
Noeud* m_arbre; // L'arbre abstrait
bool m_erreur; // Etat de l'intrpreteur

// Implémentation de la grammaire
Noeud* programme(); // <programme> ::= procedure principale() <seqInst> finproc FIN_FICHIER
Expand Down
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ int main(int argc, char* argv[]) {
Interpreteur interpreteur(fichier);
interpreteur.analyse();
// Si pas d'exception levée, l'analyse syntaxique a réussi
if(interpreteur.getArbre() != nullptr){
cout << endl << "================ Syntaxe Correcte" << endl;
} else {
cout << endl << "================ Syntaxe Incorrecte" << endl;
}
if (compile) {
compiler(*out, interpreteur.getTable(), interpreteur.getArbre());
} else {
Expand Down

0 comments on commit 0691ae4

Please sign in to comment.