Skip to content

Commit

Permalink
3 vue secondaires and WHILE operator left
Browse files Browse the repository at this point in the history
  • Loading branch information
nhuhoang0701 committed Nov 26, 2020
1 parent 4ee68f2 commit 2b5b077
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 55 deletions.
2 changes: 1 addition & 1 deletion include/controleur.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Controleur
Pile &getPile() { return *litteraleAffiche_; }
identifieurMap_t *getIdentifieurMap() { return &identifieurMap_; }

void commande(const QString &c);
void traiterCommandBar(const QString &c);
TypeLitterale estLitterale(const QString &s);
bool estIdentifieur(const QString &s);
bool estOperateurNumerique(const QString &s);
Expand Down
10 changes: 9 additions & 1 deletion src/controleur.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QStringList>
#include <iostream>
#include <stack>
#include <QRegExp>

#include "controleur.h"
#include "litterale_entiere.h"
Expand Down Expand Up @@ -189,6 +190,13 @@ Litterale *Controleur::creerLitterale(QString str, TypeLitterale type)
}
if (type == TypeLitterale::EXPRESSION)
{
QRegExp regex("^[A-Z]([A-Z]|[0-9])*");
if (!regex.exactMatch(str.mid(1, str.length() - 2)))
{
throw CalculateurException(("Littérale expression n'est pas correcte syntaxiquement: " +
str.toStdString())
.c_str());
}
return new LitteraleExpression{str};
}
if (type == TypeLitterale::PROGRAMME)
Expand All @@ -198,7 +206,7 @@ Litterale *Controleur::creerLitterale(QString str, TypeLitterale type)
return nullptr;
}

void Controleur::commande(const QString &s)
void Controleur::traiterCommandBar(const QString &s)
{
Pile *pileCopy{litteraleAffiche_->cloneOnHeapGeneral()};
try
Expand Down
2 changes: 1 addition & 1 deletion src/litterale_programme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

LitteraleNombre *LitteraleProgramme::evaluer()
{
controleur_->commande(programme_.mid(1, programme_.length() - 2));
controleur_->traiterCommandBar(programme_.mid(1, programme_.length() - 2));
std::cout << "nullptr in programme" << '\n';
return nullptr;
}
49 changes: 0 additions & 49 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,9 @@
#include <iostream>
#include <QApplication>
#include <QString>
#include <QtAlgorithms>
#include <algorithm>
#include <string>

#include "exceptions.h"
#include "controleur.h"
#include "litterale_entiere.h"
#include "litterale_rationnelle.h"
#include "litterale_reelle.h"
#include "litterale_complexe.h"
#include "operateur_numerique.h"
#include "operateur_binaire.h"
#include "qcalculateur.h"
#include "pile.h"

std::string &trim(std::string &str)
{
return str;
}

int main(int argc, char *argv[])
{
LitteraleNombre *r1 = new LitteraleRationnelle{-20, -30};
LitteraleNombre *r2 = new LitteraleReelle{123.34};
LitteraleNombre *r3 = new LitteraleEntier{34};
LitteraleNombre *r4 = new LitteraleRationnelle{12, 34};
LitteraleEntier *r5 = new LitteraleEntier{4};
LitteraleNombre *c1 = new LitteraleComplexe{r1->cloneOnHeapNombre(), r2->cloneOnHeapNombre()};
LitteraleNombre *c2 = new LitteraleComplexe{r3->cloneOnHeapNombre(), r4->cloneOnHeapNombre()};
Pile p = Pile{};
p.push(*r1);
p.push(*r2);
p.push(*r3);
p.push(*c2);
PileIterator pitr = PileIterator{&p};
for (auto itr = pitr.begin(); itr != pitr.end(); itr++)
{
// std::cout << (*itr)->affichage().toStdString() << '\n';
}

// std::cout << op->traitement(std::vector<Litterale *>{r1, r4})->affichage().toStdString() << '\n';
try
{
// std::cout << op->traitement(std::vector<Litterale *>{r1, c2})->affichage().toStdString();
// Controleur &controleur = Controleur::getInstance();
// std::cout << controleur.commande("1 2.5 12 /").toStdString() << '\n';
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}

QApplication app = QApplication{argc, argv};
QCalculateur cal = QCalculateur();
cal.show();
Expand Down
1 change: 0 additions & 1 deletion src/operateur_numerique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ OperateurNumerique *OperateurNumerique::getOperateurNumerique(const QString &sym

if (operateurMap_.find(symbol) == operateurMap_.end())
{
std::cout << "return null pointer in operateur" << '\n';
return nullptr;
}
return operateurMap_.at(symbol).get();
Expand Down
2 changes: 1 addition & 1 deletion src/qcalculateur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ QCalculateur::QCalculateur()

bool QCalculateur::calculerAutoOperateur(QString op)
{
controleur_.commande(commandeBar_->text() + " " + op);
controleur_.traiterCommandBar(commandeBar_->text() + " " + op);
renderVuePile();
message_->clear();
commandeBar_->clear();
Expand Down
2 changes: 1 addition & 1 deletion src/qclavier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void QClavier::autoOperatorClicked()
bool QClavier::calculerAutoOperateur(QString op)
{
QLineEdit &commandeBar = calculateur_.getCommandBar();
calculateur_.getControleur().commande(commandeBar.text() + " " + op);
calculateur_.getControleur().traiterCommandBar(commandeBar.text() + " " + op);
calculateur_.renderVuePile();
calculateur_.setMessage("");
commandeBar.clear();
Expand Down

0 comments on commit 2b5b077

Please sign in to comment.