diff options
author | HombreLaser <sebastian-440@live.com> | 2022-04-10 10:21:12 -0500 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-04-10 10:21:12 -0500 |
commit | 531f8f2f1adc1c6777920f0a8c68caaee30b0fc4 (patch) | |
tree | c3d8ac22f3ecc118cd2b5056e7ac556371efaca7 /include | |
parent | ae25e110ca9d65c4e2cfffef21abc16f26ac3739 (diff) |
Corregidos errores de las expresiones.
Diffstat (limited to 'include')
-rw-r--r-- | include/exceptions.hpp | 2 | ||||
-rw-r--r-- | include/expressions.hpp | 1 | ||||
-rw-r--r-- | include/lexer.hpp | 3 | ||||
-rw-r--r-- | include/parser.hpp | 8 |
4 files changed, 10 insertions, 4 deletions
diff --git a/include/exceptions.hpp b/include/exceptions.hpp index 4b5fcfa..050779d 100644 --- a/include/exceptions.hpp +++ b/include/exceptions.hpp @@ -12,7 +12,7 @@ private: std::string error_msg; public: explicit Exception(const std::string &error_msg): error_msg(error_msg){} - std::string showMsg(); + std::string showMsg() const; }; class LexerException: public Exception{ diff --git a/include/expressions.hpp b/include/expressions.hpp index 974612d..b7a2921 100644 --- a/include/expressions.hpp +++ b/include/expressions.hpp @@ -59,6 +59,7 @@ private: public: Function(Expression *arg, trig_functions name); ~Function(); + const Expression *getArg(); float eval(int arg) override; trig_functions getFunctionName(); protected: diff --git a/include/lexer.hpp b/include/lexer.hpp index 39d8411..9c12d03 100644 --- a/include/lexer.hpp +++ b/include/lexer.hpp @@ -29,12 +29,11 @@ struct Token{ class Lexer{ private: - char var_name; std::string text; size_t current_char; Token current_token; - bool matchFunction(const std::string &function_name); std::string createNumber(); + bool matchFunction(const std::string &function_name); public: Lexer(std::string text = {}); void setText(std::string text); diff --git a/include/parser.hpp b/include/parser.hpp index 02471d8..3f0032b 100644 --- a/include/parser.hpp +++ b/include/parser.hpp @@ -4,6 +4,7 @@ #include <string> #include <vector> +#include "expressions.hpp" #include "lexer.hpp" #ifndef PARSER_H #define PARSER_H @@ -12,6 +13,11 @@ class Parser{ private: std::string text; Lexer tokenizer; + std::vector<Expression *> tree_stack; + Token var{nil, "{}"}; + void panic(); + Expression *popStack(); + Expression *newTree(token_type type); void setText(std::string text); void parseExpr(); void parsePrimeExpr(); @@ -22,7 +28,7 @@ private: void parseFactor(); bool checkToken(); // Checa el token actual del lexer. public: - void parse(std::string expr); + Expression *parse(std::string expr); }; #endif /* PARSER_H */ |