46 lines
1004 B
C
46 lines
1004 B
C
|
#pragma once
|
||
|
#include "Token.h"
|
||
|
#include <memory>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <array>
|
||
|
|
||
|
typedef std::vector<Token> TokenStream;
|
||
|
#define KEYWORD_COUNT 3
|
||
|
|
||
|
class Lexer
|
||
|
{
|
||
|
private:
|
||
|
Location loc;
|
||
|
Location prev_loc;
|
||
|
|
||
|
int advance();
|
||
|
int rewind();
|
||
|
char current_char;
|
||
|
int index;
|
||
|
|
||
|
Lexer(const std::string& fname);
|
||
|
|
||
|
std::string current_line_text;
|
||
|
std::string previous_line_text;
|
||
|
|
||
|
std::string current_lexed_text;
|
||
|
|
||
|
std::string recalculate_current_line(const std::string& text);
|
||
|
|
||
|
Token create_string();
|
||
|
Token create_number();
|
||
|
Token create_identifier();
|
||
|
|
||
|
bool is_in_string(const std::string& string, const char& character);
|
||
|
public:
|
||
|
static const std::array<std::string,KEYWORD_COUNT> keywords;
|
||
|
~Lexer();
|
||
|
|
||
|
TokenStream lex(const std::string& text);
|
||
|
|
||
|
static std::shared_ptr<Lexer> make_lexer(const std::string& fname);
|
||
|
|
||
|
static void assign_parent_location(std::shared_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc);
|
||
|
};
|