-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLexer.hpp
More file actions
63 lines (55 loc) · 1.41 KB
/
Copy pathLexer.hpp
File metadata and controls
63 lines (55 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include <fstream>
#include <streambuf>
#include "Type.hpp"
std::string load_source(std::string filename);
struct Token
{
Type type = TYPE_EMPTY;
int line;
int column;
union
{
char char_value;
int32_t int_value;
float float_value;
long hex_value;
std::string* string_value;
std::string* id_name;
};
bool op = false;
bool unary_op = false;
bool literal_type = false;
};
struct LexerEnvironment
{
std::string file_name;
std::string source;
int source_length;
int index = 0;
char current_char;
int line = 1;
int column = 1;
std::vector<Token*> tokens;
};
class Lexer
{
public:
std::vector<LexerEnvironment*> lexer_env;
LexerEnvironment* new_lexer_env(std::string filename);
void advance(LexerEnvironment* lexer_env, int n);
char peek(LexerEnvironment* lexer_env, int n);
void build_word(LexerEnvironment* lexer_env);
void build_number(LexerEnvironment* lexer_env);
void build_string(LexerEnvironment* lexer_env);
void build_char(LexerEnvironment* lexer_env);
void add_token(LexerEnvironment* lexer_env, Type type, int size, int op, int unary_op);
void handle_line_comment(LexerEnvironment* lexer_env);
void handle_block_comment(LexerEnvironment* lexer_env);
void tokenize(LexerEnvironment* lexer_env);
void print_tokens(LexerEnvironment* lexer_env);
void error_and_exit(LexerEnvironment* lexer_env, std::string message);
};