From 404826e78a56e15e20d3938aed80945295921745 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 22 Jun 2024 16:45:04 -0600 Subject: Add parser --- src/include/tokenizer.hpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/include/tokenizer.hpp') diff --git a/src/include/tokenizer.hpp b/src/include/tokenizer.hpp index a3f9998..7d00055 100644 --- a/src/include/tokenizer.hpp +++ b/src/include/tokenizer.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#define TOKENS_ARRAY_LEN 16 enum Type { operand, @@ -11,7 +11,8 @@ enum Type { division, left_parens, right_parens, - equals + equals, + nil }; struct Token { @@ -22,14 +23,14 @@ struct Token { class Tokenizer { private: // Private attributes - std::array tokens; + Token *tokens[17]; const std::string *to_tokenize; size_t current_char_index; short tokens_head; // Regexes - std::regex operand_regex = std::regex("^0{1}|\\d+"); - std::regex operation_regex = std::regex("\\+|-|/|\\*"); - std::regex parens_regex = std::regex("(|)"); + std::regex operand_regex = std::regex("^0{1}|^\\d+"); + std::regex operation_regex = std::regex("^\\+|^-|/|^\\*"); + std::regex parens_regex = std::regex("^\\(|^\\)"); // End of private attributes // Private methods void clearTokens(); @@ -42,6 +43,6 @@ private: public: Tokenizer(); ~Tokenizer(); - const std::array &tokenize(const std::string &operation); - const std::array &getTokens(); + Token **tokenize(const std::string &operation); + Token **getTokens(); }; -- cgit v1.2.3