2023-10-27 14:46:32 +02:00
|
|
|
#ifndef TOKENIZE_H
|
|
|
|
#define TOKENIZE_H
|
|
|
|
|
2023-10-27 14:37:03 +02:00
|
|
|
#include <vector>
|
2023-11-10 13:42:53 +01:00
|
|
|
#include <variant>
|
2023-10-27 17:53:58 +02:00
|
|
|
#include <string>
|
2023-10-27 14:37:03 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2023-11-14 17:00:34 +01:00
|
|
|
enum class TokenType { Type, Identifier, Int, Plus, Minus, DoublePlus, DoubleMinus, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese };
|
2023-10-27 14:37:03 +02:00
|
|
|
enum class Type { Int };
|
|
|
|
|
2023-11-10 17:35:33 +01:00
|
|
|
using TokenData = variant<int, string, Type>;
|
2023-10-27 14:37:03 +02:00
|
|
|
|
|
|
|
struct Token {
|
|
|
|
TokenType type;
|
2023-11-10 17:50:00 +01:00
|
|
|
TokenData data { };
|
2023-10-27 14:46:32 +02:00
|
|
|
};
|
|
|
|
|
2023-11-10 17:35:33 +01:00
|
|
|
/*
|
|
|
|
Parses a string into a vector of tokens
|
|
|
|
*/
|
|
|
|
vector<Token> tokenize(string str);
|
|
|
|
|
2023-11-10 19:04:24 +01:00
|
|
|
/*
|
|
|
|
Format and print a Token
|
|
|
|
*/
|
|
|
|
void _debug_print_token(Token token);
|
|
|
|
|
2023-11-10 17:35:33 +01:00
|
|
|
/*
|
|
|
|
Formats a list of tokens and prints it
|
|
|
|
*/
|
|
|
|
void _debug_print_tokens(vector<Token> tokens);
|
|
|
|
|
2023-10-27 14:46:32 +02:00
|
|
|
#endif
|