-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_stream.h
More file actions
72 lines (59 loc) · 1.31 KB
/
token_stream.h
File metadata and controls
72 lines (59 loc) · 1.31 KB
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
enum token_type
{
TKN_WORD,
TKN_IONUMBER,
TKN_INPUT, // "<"
TKN_DUPIN, // "<&"
TKN_IODUAL, // "<>"
TKN_OUTPUT, // ">"
TKN_DUPOUT, // ">&"
TKN_APPEND, // ">>"
TKN_CLOBBER, // ">|"
TKN_PIPE, // "|"
TKN_OPENPAREN, // "("
TKN_CLOSEPAREN, // ")"
TKN_AND, // "&&"
TKN_OR, // "||"
TKN_SEMICOLON, // ";"
TKN_DBLSEMICLN, // ";;"
TKN_EOF, // "End Token", aka EOF
};
struct token
{
enum token_type type;
int line;
char *value;
};
struct token_node
{
struct token *value;
struct token_node *prev;
struct token_node *next;
};
struct token_stream
{
struct token_node *head;
struct token_node *tail;
struct token_node *curr;
};
typedef struct token *token_t;
typedef struct token_node *token_node_t;
typedef struct token_stream *token_stream_t;
token_stream_t
create_token_stream (int (*next_char) (void *), void *file);
void
destroy_token_stream (token_stream_t strm);
token_t
next_token (token_stream_t strm);
token_t
current_token (token_stream_t strm);
token_t
peek_token (token_stream_t strm, int c);
token_t
reset_token_stream (token_stream_t strm);
token_t
forward_token_stream (token_stream_t strm, int c);
token_t
backward_token_stream (token_stream_t strm, int c);
token_t
skip_token (token_stream_t strm, enum token_type t);