Advertisement
GeeckoDev

main.cpp

Dec 14th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <exception>
  4.  
  5. #include "expression.h"
  6.  
  7. std::vector<char>* saisie()
  8. {
  9.     std::string* laChaine;
  10.     std::vector<char>* leTab;
  11.  
  12.     laChaine = new std::string();
  13.     std::cout << "$ ";
  14.     std::cin >> *laChaine;
  15.  
  16.     leTab = new std::vector<char>();
  17.     for (std::string::iterator it = laChaine->begin(); it != laChaine->end(); it++)
  18.     {
  19.         leTab->push_back(*it);
  20.     }
  21.  
  22.     return leTab;
  23. }
  24.  
  25.  
  26. void afficheVecteur(std::vector<char>* unTab)
  27. {
  28.     for (std::vector<char>::iterator it = unTab->begin(); it != unTab->end(); it++)
  29.     {
  30.         std::cout << *it;
  31.     }
  32.  
  33.     std::cout << std::endl;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     std::vector<char>* leVect;
  40.     Expression* expr = new Expression();
  41.  
  42.     while (1)
  43.     {
  44.         try
  45.         {
  46.             leVect = saisie();
  47.             std::cout << "-> " << expr->evaluer(leVect) << std::endl;
  48.         }
  49.         catch (int& exception)
  50.         {
  51.             std::cout << "Erreur: ";
  52.  
  53.             switch (exception)
  54.             {
  55.             case 0:
  56.                 std::cout << "division par zéro";
  57.                 break;
  58.             case 1:
  59.                 std::cout << "opérateur inconnu";
  60.                 break;
  61.             case 2:
  62.                 std::cout << "opération avec pile vide";
  63.                 break;
  64.             case 3:
  65.                 std::cout << "pile non vide à la fin de l'évaluation";
  66.             }
  67.  
  68.             std::cout << std::endl;
  69.         }
  70.  
  71.         delete leVect;
  72.     }
  73.  
  74.     return 0;
  75. }
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement