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.
46 lines
857 B
46 lines
857 B
2 years ago
|
//
|
||
|
// 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
|