// // Created by lenfrex on 2023/4/13. // #ifndef LEXER_CPP_TOKEN_H #define LEXER_CPP_TOKEN_H #include #define KEYWORD_SIZE 17 const std::string keywords[KEYWORD_SIZE] = { "begin", "end", "call", "const", "do", "length", "if", "odd", "procedure", "read", "then", "var", "while", "write", "Number", "Name", "HeTaiyu", }; const std::string TokenTypeName[] = { "运算符", "标识符", "常数", "关键字", "界符", "未知" }; typedef enum TokenType { // 运算符 OPERATOR, // 标识符 IDENTIFIER, // 常数 CONSTANTS, // 保留字 KEYWORD, // 界符 DELIMITER, // 未知 UNKNOWN } TokenType; typedef struct Location { int line; int start; int length; } Location; class Token { private: Location location{}; TokenType type = UNKNOWN; std::string content; public: [[nodiscard]] const Location &getLocation() const; void setLocation(const Location &loc); [[nodiscard]] TokenType getType() const; void setType(TokenType typ); [[nodiscard]] const std::string &getContent() const; void setContent(const std::string &cont); }; #endif //LEXER_CPP_TOKEN_H