#pragma once /* * Created by Brett on 17/11/23. * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ #ifndef BRAINFUCK_MISC_BF_TOKENIZER_H #define BRAINFUCK_MISC_BF_TOKENIZER_H #include #include #include enum class bf_token { INC_DP, DEC_DP, INC_DV, DEC_DV, PRINT, READ, OPEN, CLOSE }; struct token_t { bf_token token; std::optional name = {}; explicit token_t(bf_token token): token(token) {} }; typedef std::optional> optional_token; class tokenizer { private: std::vector tokens; size_t conditionalCount = 0; size_t currentIndex = 0; void tokenize(const std::string& program); void bf_name(); public: explicit tokenizer(const std::string& program) { tokenize(program); bf_name(); } inline bool hasNext(){ return currentIndex < tokens.size(); } inline void advance(){ currentIndex++; } inline optional_token next() { if (currentIndex >= tokens.size()) return {}; return tokens[currentIndex++]; } inline optional_token peek(){ if (currentIndex >= tokens.size()) return {}; return tokens[currentIndex]; } void print(size_t index = 0); }; #endif //BRAINFUCK_MISC_BF_TOKENIZER_H