-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.h
50 lines (39 loc) · 922 Bytes
/
lexer.h
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
#ifndef LEXER_H_
#define LEXER_H_
#include <stddef.h>
#include <stdbool.h>
typedef struct M_Token M_Token;
typedef enum {
// all numbers will be handled as C doubles
M_NUMBER = 0,
// signs
M_PLUS,
M_DIVIDE,
M_TIMES,
M_MINUS,
M_MOD,
M_POW,
// symbols
M_LPAREN,
M_RPAREN,
} M_Token_Kind;
struct M_Token {
M_Token_Kind kind;
const char *value;
size_t size;
M_Token *next;
};
typedef struct {
const char *filename;
const char *content;
const size_t content_size;
size_t cursor, bot, line, col;
M_Token *head;
M_Token *tail;
} M_Lexer;
bool m_lexer_finished_with_errors();
const char *m_lexer_token_kind_display_name(M_Token_Kind kind);
M_Lexer m_lexer_create(const char *filename, const char *content, const size_t content_size);
M_Token *m_lexer_tokenize(M_Lexer *lexer);
void m_lexer_free(M_Lexer *lexer);
#endif // LEXER_H_