SHOW:
|
|
- or go back to the newest paste.
| 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; |
| 14 | + | std::getline(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 | break; | |
| 67 | } | |
| 68 | ||
| 69 | std::cout << std::endl; | |
| 70 | } | |
| 71 | ||
| 72 | delete leVect; | |
| 73 | } | |
| 74 | ||
| 75 | return 0; | |
| 76 | - | |
| 76 | + | |
| 77 | - | |
| 77 | + | |
| 78 | // EOF |