-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
32 lines (25 loc) · 884 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
#ifndef FIREVM_LEXER_H
#define FIREVM_LEXER_H
#include <stdlib.h>
#include "tokens.h"
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
// lexer adapted from the Gravity lexer, will rewrite when I have time
struct lexer {
const char* buffer;
uint32_t offset; // current buffer offset (in bytes)
uint32_t position; // current buffer position (in characters)
uint32_t length; // buffer length (in bytes)
uint32_t line; // line counter
uint32_t column;
struct token token; // current token
};
enum token_type lexer_peek(struct lexer* lexer, int ahead);
struct token lexer_next(struct lexer* lexer);
struct lexer* lexer_create(const char* filename);
void lexer_free(struct lexer* lexer);
int token_int(struct lexer* lexer, struct token token);
char* token_string(struct lexer* lexer, struct token token);
#endif