-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.h
82 lines (65 loc) · 1.03 KB
/
tokenizer.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
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "header.h"
#include "sfmem.h"
#include "sfstr.h"
enum
{
TOK_STRING = 0,
TOK_INT = 1,
TOK_FLOAT = 2,
TOK_OPERATOR = 3,
TOK_IDENTIFIER = 4,
TOK_COMMENT = 5,
TOK_SPACE = 6,
TOK_NEWLINE = 7,
TOK_EOF
};
#define NUM_OF_TOKS TOK_EOF
struct _sf_tok_s
{
int type;
union
{
struct
{
sf_charptr v;
} t_str;
struct
{
sf_int v;
} t_int;
struct
{
sf_float v;
} t_float;
struct
{
sf_charptr v;
} t_op;
struct
{
sf_charptr v;
int is_reserved;
int is_bool;
} t_ident; /* identifier */
struct
{
sf_charptr v;
} t_cmt; /* comment */
struct tokenizer
{
int v;
} t_space; /* only those spaces adjacent to a newline */
} v;
};
typedef struct _sf_tok_s tok_t;
#ifdef __cplusplus
extern "C"
{
#endif
// returned array ends with TOK_EOF node
SF_API tok_t *sf_tokenizer_gen (const char *_Data);
SF_API void sf_tokenizer_print (tok_t _Tok);
#ifdef __cplusplus
}
#endif