summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/main.cpp b/main.cpp
index c1ecd22..9328b1e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,3 +1,7 @@
+/* PIA - Lenguajes Modernos de Programación
+ * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS
+ * Luis Sebastián Martínez Vega - LCC */
+
#include <iterator>
#include <ostream>
#include <string>
@@ -13,26 +17,33 @@ using std::string, std::cin, std::cout, std::getline, std::vector,
std::begin, std::end, std::endl;
int main(){
+ int counter = 1;
string input;
Parser parser;
- Expression *tree;
- Expression *simplified = NULL;
- getline(cin, input);
+ Expression *tree, *simplified, *diff;
- try {
- tree = parser.parse(input);
- cout << tree->getRepr() << '\n';
- } catch(const ParserException &e) {
- cout << e.showMsg() << endl;
- tree = NULL;
- }
+ cout << ">> ";
+ while(getline(cin, input)) {
+ try {
+ tree = parser.parse(input);
+ } catch(const ParserException &e) {
+ cout << e.showMsg();
+ cout << ">> ";
+ continue;
+ }
+
+ diff = deriv(tree);
+ simplified = simplify(diff);
+ cout << "OUT " << counter << ": " << simplified->getRepr() << "\n";
+ cout << ">> ";
- if(tree != NULL) {
- simplified = simplify(tree);
- cout << simplified->getRepr() << endl;
delete tree;
delete simplified;
+ delete diff;
+ ++counter;
}
+
+ cout << "Adiós!\n" << endl;
return 0;
}