-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse.h
50 lines (38 loc) · 760 Bytes
/
parse.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
#include<stdio.h>
enum token_type {
EOF_TOK = -1,
LPAREN_TOK = 0,
RPAREN_TOK = 1,
INT_TOK = 2,
SYMBOL_TOK = 3
};
struct token {
enum token_type type;
union {
long long int integer;
char *symbol;
};
};
struct p_state {
// The file to read chars from
FILE *file;
// The current token buffer
struct token tok;
};
struct p_state new_p_state(FILE *file);
enum sexp_type {
LIST = 0,
SYMBOL = 1,
INTEGER = 2,
END_OF_LIST = -1
};
struct sexp {
enum sexp_type type;
union {
struct sexp *list; // NULL-terminated
char *symbol;
long long int integer;
};
};
struct sexp *parse(struct p_state *state);
void print_ast_node(struct sexp ast_node);