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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#ifndef PARSE_H
#define PARSE_H
#include "lex.h"
struct u
{
struct storage *storage;
};
struct s
{
struct storage *storage;
};
union c
{
unsigned long long uv;
long long v;
};
struct p
{
int dummy;
};
struct t
{
int dummy;
};
struct builtin
{
const char *name;
};
struct type
{
enum {U, S, C, P, T, BUILTIN} type;
const struct tk *tk;
size_t sz;
int sign;
union
{
struct u u;
struct s s;
union c c;
struct p p;
struct t t;
struct builtin b;
} u;
};
struct param
{
const struct tk *tk;
const struct stentry *entry;
};
struct pr
{
const struct tk *tk;
struct param *params, *ret;
size_t nparams;
};
struct td
{
const struct tk *tk;
struct type *types;
size_t ntypes;
};
struct fn
{
const struct tk *tk;
enum linkage {EXTERNAL, STATIC} linkage;
struct storage *lk, *ws, *gl;
struct stmt *stmts;
struct pr *pr;
struct td *td;
size_t nstmts;
};
struct lit
{
char *name;
const struct tk *tk;
const struct fn *fn;
struct lit *next;
};
struct ast
{
struct fn *fns;
struct lit *lits, *lastlit;
size_t nfns, litcnt;
};
int parse(const struct lex *l, struct ast *ast);
void ast_free(struct ast *ast);
#endif
|