Repository navigation
Expand file tree
/
Copy pathparser.h
More file actions
136 lines (118 loc) · 2.76 KB
/
Copy pathparser.h
File metadata and controls
136 lines (118 loc) · 2.76 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef PARSER_H
#define PARSER_H
#include "tokenizer.h"
#include <stdbool.h>
typedef enum {
nd_add,
nd_sub,
nd_mul,
nd_div,
nd_eq,
nd_ne,
nd_lt,
nd_le,
nd_assign,
nd_addr,
nd_deref,
nd_ret,
nd_if,
nd_while,
nd_for,
nd_sizeof,
nd_block,
nd_func_call,
nd_expr_stmt,
nd_var,
nd_num,
nd_null
} node_kind_t;
typedef enum { ty_char, ty_int, ty_ptr, ty_array } type_kind_t;
typedef struct typ {
type_kind_t kind;
struct typ *base;
int array_size;
} typ_t;
typedef struct {
char *name;
typ_t *ty;
bool is_local;
char *contents;
int content_length;
int offset;
} va_t;
typedef struct var_list {
struct var_list *next;
va_t *v;
} var_list_t;
typedef struct node {
node_kind_t kind;
struct node *next;
struct typ *ty;
token_t *tok;
struct node *lhs;
struct node *rhs;
struct node *cond;
struct node *then;
struct node *els;
struct node *init;
struct node *inc;
struct node *body;
char *func_name;
struct node *args;
va_t *v;
int val;
} node_t;
typedef struct fun {
struct fun *next;
char *name;
struct var_list *params;
struct node *node;
struct var_list *locals;
int stack_size;
} fun_t;
typedef struct {
struct var_list *globals;
fun_t *fns;
} program_t;
// struct var_list *locals;
// struct var_list *globals;
extern int label_count;
void init_node(node_t *init_node, node_kind_t kind, node_t *next, typ_t *ty,
token_t *tok, node_t *lhs, node_t *rhs, node_t *cond,
node_t *then, node_t *els, node_t *init, node_t *inc,
node_t *body, char *func_name, node_t *args, va_t *v, int val);
void init_va(va_t *v, char *name, typ_t *ty, bool is_local, char *contents,
int content_len, int offset);
void init_type(typ_t *ty, type_kind_t kind, typ_t *base, int array_size);
void init_var_list(var_list_t *vl, var_list_t *next, va_t *v);
void init_function(fun_t *fn, fun_t *next, char *name, var_list_t *params,
node_t *node, var_list_t *locals, int stack_size);
va_t *find_var(token_t *tok);
node_t *new_unary(node_kind_t k, node_t *n, token_t *tok);
node_t *new_binary(node_kind_t k, node_t *lhs, node_t *rhs, token_t *tok);
node_t *new_number(int v, token_t *tok);
node_t *new_var(va_t *v, token_t *tok);
char *new_label();
va_t *push_var(char *name, typ_t *ty, bool is_local);
node_t *primary();
node_t *func_args();
node_t *post_fix();
node_t *unary();
node_t *mul();
node_t *add();
node_t *relational();
node_t *equality();
node_t *assign();
node_t *expr();
node_t *stmt();
bool is_type_name();
node_t *read_expr_stmt();
node_t *declaration();
void global_var();
fun_t *function();
typ_t *base_type();
typ_t *read_type_suffix(typ_t *b);
var_list_t *read_func_params();
bool is_function();
program_t *prog();
#endif /* PARSER_H */