某个编译原理的实验代码存档
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/Lexer.h

45 lines
857 B

//
// Created by lenfrex on 2023/4/13.
//
#ifndef LEXER_CPP_LEXER_H
#define LEXER_CPP_LEXER_H
#include <string>
#include <vector>
#include "Token.h"
class Lexer {
public:
explicit Lexer(char *code);
void lexAll();
[[nodiscard]] const std::vector<Token> &getResults() const;
private:
char *buffer;
std::vector<Token> results = std::vector<Token>();
bool stop = false;
int currLine = 0;
int currPos = 0;
void lexNumber(Token &token);
void lexIdentifier(Token &token);
static std::string copyAsString(const char *sourceStart, int length);
void setToken(Token &token, TokenType type, const char *source, int length);
void setToken(Token &token, TokenType type, const std::string &content, int length);
void move(int offset);
void lexToken(Token &token);
};
#endif //LEXER_CPP_LEXER_H