-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenize.h
69 lines (49 loc) · 1.17 KB
/
tokenize.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef TOKENIZE_H_
#define TOKENIZE_H_
#define BUFFER_SIZE 256
#define INITIAL_TOKEN_CAPACITY 8
#include <stddef.h>
typedef enum {
STRING,
NUMBER,
LESS,
GREATER,
GREATERGREATER,
SEMICOLON,
OPEN_PARENS,
CLOSE_PARENS,
PIPE,
BACKSLASH,
WORD
// Add more as needed.
} Lexeme;
typedef struct {
Lexeme lexeme;
char *literal;
double value;
int position;
} Token;
typedef struct {
Token *tokens;
size_t numTokens;
size_t capacity;
char *source;
size_t current;
size_t source_length;
size_t start;
} TokenizerState;
int isAtEnd(TokenizerState *state);
void addToken(TokenizerState *state, Lexeme type, char *literal, double value);
char advance(TokenizerState *state);
char peek(TokenizerState *state);
char peekNext(TokenizerState *state);
void string(TokenizerState *state);
void number(TokenizerState *state);
void word(TokenizerState *state);
void scanToken(TokenizerState *state);
const char *lexemeToString(Lexeme type);
void scanner(TokenizerState *state);
TokenizerState initializeTokenizerState(size_t bufferSize);
void freeTokens(TokenizerState *state);
void destroyTokenizerState(TokenizerState *state);
#endif // TOKENIZE_H_