blob: 191997dadf7fc053a23712e4b245bc067cc4fb6d (
plain)
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
70
71
72
73
|
#ifndef __USCRIPT_LEX_H__
#define __USCRIPT_LEX_H__
#include "common.h"
#include "val.h"
#define XTOKENS(_) \
_(BREAK) \
_(DIV_EQL) \
_(DO) \
_(DOT_DOT) \
_(ELSE) \
_(ELSEIF) \
_(END) \
_(EQL) \
_(ERR) \
_(FALSE) \
_(FUN) \
_(GLOBAL) \
_(GTEQL) \
_(IDENT) \
_(IF) \
_(IN) \
_(LET) \
_(LOOP) \
_(LTEQL) \
_(MINUS_EQL) \
_(MOD) \
_(MOD_EQL) \
_(MULT_EQL) \
_(NEQL) \
_(NEXT) \
_(NUM) \
_(PLUS_EQL) \
_(RET) \
_(STR) \
_(TRUE) \
_(ZILCH)
// single-character tokens are represented by their ASCII value, but other types
// of tokens are represented by a token_kind enum value.
enum token_kind {
TOKEN_EOF = 256,
#define DEF_TOKEN_ENUM(name) TOKEN_##name,
XTOKENS(DEF_TOKEN_ENUM)
#undef DEF_TOKEN_ENUM
};
struct lexer {
const char *src;
const char *base;
const char *head;
int line;
int col;
};
struct token {
const char *start;
int len;
int line;
int col;
u16 kind;
struct us_val val;
};
void lex_init(struct lexer *lex, const char *src);
struct token lex_next_token(struct lexer *lex);
void token_kind_name(char *dst, size_t len, u16 kind);
void print_token(struct token tok);
#endif // __USCRIPT_LEX_H__
|