某个编译原理的实验代码存档
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
compile-work/lexer/Token.h

75 lines
1.2 KiB

//
// Created by lenfrex on 2023/4/13.
//
#ifndef LEXER_CPP_TOKEN_H
#define LEXER_CPP_TOKEN_H
#include <string>
#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