Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <exception>
- #include "expression.h"
- std::vector<char>* saisie()
- {
- std::string* laChaine;
- std::vector<char>* leTab;
- laChaine = new std::string();
- std::cout << "$ ";
- std::cin >> *laChaine;
- leTab = new std::vector<char>();
- for (std::string::iterator it = laChaine->begin(); it != laChaine->end(); it++)
- {
- leTab->push_back(*it);
- }
- return leTab;
- }
- void afficheVecteur(std::vector<char>* unTab)
- {
- for (std::vector<char>::iterator it = unTab->begin(); it != unTab->end(); it++)
- {
- std::cout << *it;
- }
- std::cout << std::endl;
- }
- int main()
- {
- std::vector<char>* leVect;
- Expression* expr = new Expression();
- while (1)
- {
- try
- {
- leVect = saisie();
- std::cout << "-> " << expr->evaluer(leVect) << std::endl;
- }
- catch (int& exception)
- {
- std::cout << "Erreur: ";
- switch (exception)
- {
- case 0:
- std::cout << "division par zéro";
- break;
- case 1:
- std::cout << "opérateur inconnu";
- break;
- case 2:
- std::cout << "opération avec pile vide";
- break;
- case 3:
- std::cout << "pile non vide à la fin de l'évaluation";
- }
- std::cout << std::endl;
- }
- delete leVect;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement