From 4a2d657cc5bf8ea685a0daaec803363bc2c7822c Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 16 Apr 2022 13:22:31 -0500 Subject: Añadida implementación dle diferenciados. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/differentiator.hpp | 5 +++-- include/expressions.hpp | 25 +++++++++++++++++++------ include/lexer.hpp | 3 +-- include/parser.hpp | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/differentiator.hpp b/include/differentiator.hpp index 172166f..f14f2d5 100644 --- a/include/differentiator.hpp +++ b/include/differentiator.hpp @@ -2,10 +2,11 @@ * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS * Luis Sebastián Martínez Vega - LCC */ -#include "expressions.hpp" -#include #ifndef DIFFERENTIATOR_H #define DIFFERENTIATOR_H +#include +#include "expressions.hpp" + class Differentiator { private: diff --git a/include/expressions.hpp b/include/expressions.hpp index b7a2921..3191436 100644 --- a/include/expressions.hpp +++ b/include/expressions.hpp @@ -2,10 +2,10 @@ * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS * Luis Sebastián Martínez Vega - LCC */ -#include -#include "lexer.hpp" #ifndef EXPRESSIONS_H #define EXPRESSIONS_H +#include +#include "lexer.hpp" /* Debido a que en eval() llamamos a la respectiva función trigonométrica, hay un conflicto entre @@ -23,14 +23,18 @@ enum trig_functions { i_ctg }; +class Differentiator; // Forward declaration. + class Expression { public: Expression(Expression *left, Expression *right, token_type type); virtual ~Expression() = default; std::string getRepr(); - const Expression *getLeft(); - const Expression *getRight(); + Expression *diff(const Differentiator *d); + Expression *getLeft(); + Expression *getRight(); virtual float eval(int arg) = 0; + virtual Expression *copy() = 0; // Regresa una copia de la expresión actual. protected: Expression *left; Expression *right; @@ -48,6 +52,7 @@ public: ~Literal(); int getValue(); float eval(int arg) override; + Expression *copy() override; protected: void setRepr() override; }; @@ -59,9 +64,10 @@ private: public: Function(Expression *arg, trig_functions name); ~Function(); - const Expression *getArg(); + Expression *getArg(); float eval(int arg) override; - trig_functions getFunctionName(); + trig_functions getFunctionName() const; + Expression *copy() override; protected: void delTree(); void setRepr() override; @@ -74,6 +80,7 @@ public: explicit Variable(char name); ~Variable(); float eval(int arg) override; + Expression *copy() override; protected: void setRepr() override; }; @@ -83,6 +90,7 @@ public: AddExpression(Expression *left, Expression *right); ~AddExpression(); float eval(int arg) override; + Expression *copy() override; }; class SubExpression : public Expression { @@ -90,6 +98,7 @@ public: SubExpression(Expression *left, Expression *right); ~SubExpression(); float eval(int arg) override; + Expression *copy() override; }; class NegationExpression : public Expression { @@ -97,6 +106,7 @@ public: explicit NegationExpression(Expression *right); ~NegationExpression(); float eval(int arg) override; + Expression *copy() override; protected: void setRepr() override; }; @@ -106,6 +116,7 @@ public: DivisionExpression(Expression *left, Expression *right); ~DivisionExpression(); float eval(int arg) override; + Expression *copy() override; }; class MultiplicationExpression : public Expression { @@ -113,6 +124,7 @@ public: MultiplicationExpression(Expression *left, Expression *right); ~MultiplicationExpression(); float eval(int arg) override; + Expression *copy() override; }; class PowerExpression : public Expression { @@ -120,6 +132,7 @@ public: PowerExpression(Expression *left, Expression *right); ~PowerExpression(); float eval(int arg) override; + Expression *copy() override; }; #endif /* EXPRESSIONS_H */ diff --git a/include/lexer.hpp b/include/lexer.hpp index 9c12d03..6b3960d 100644 --- a/include/lexer.hpp +++ b/include/lexer.hpp @@ -2,10 +2,9 @@ * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS * Luis Sebastián Martínez Vega - LCC */ -#include - #ifndef LEXER_H #define LEXER_H +#include enum token_type{ sum, diff --git a/include/parser.hpp b/include/parser.hpp index 3f0032b..567ef03 100644 --- a/include/parser.hpp +++ b/include/parser.hpp @@ -2,12 +2,12 @@ * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS * Luis Sebastián Martínez Vega - LCC */ +#ifndef PARSER_H +#define PARSER_H #include #include #include "expressions.hpp" #include "lexer.hpp" -#ifndef PARSER_H -#define PARSER_H class Parser{ private: -- cgit v1.2.3