-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAST.h
325 lines (263 loc) · 5.9 KB
/
AST.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* AST.h
*
* Created on: Dec 2, 2017
* Author: Josip
*/
#ifndef INTERPRETER_AST_H_
#define INTERPRETER_AST_H_
/********* Statement types *********/
typedef enum
{
NO_OP,
TYPE,
NUM,
VAR,
UNARY_OP,
BINARY_OP,
ASSIGNMENT,
VAR_DECL,
COMPOUND_MAIN,
COMPOUND,
COMPOUND_RETURN,
PARAMETER,
COMPOUND_CALL,
ARGUMENT,
RETURN_STATEMENT,
IF_STATEMENT,
IF_CONDITION,
ELSE_CONDITION,
FOR_STATEMENT,
WHILE_STATEMENT,
BREAK_STATEMENT,
TEST_WAIT_TIMEOUT,
PROGRAM
}e_ast_node_type;
/********* AST Nodes *********/
/* Default AST node info */
typedef struct
{
e_ast_node_type type;
uint16_t line;
} s_ast_node_info;
/* No Operation */
typedef struct
{
s_ast_node_info info;
} s_ast_noop;
/* Type */
typedef struct
{
s_ast_node_info info;
s_lexer_token token;
} s_ast_type;
/* Numerical */
typedef struct
{
s_ast_node_info info;
s_lexer_token token;
} s_ast_num;
/* Variable */
typedef struct
{
s_ast_node_info info;
s_lexer_token token;
} s_ast_variable;
/* Unary Operation */
typedef struct
{
s_ast_node_info info;
s_lexer_token token;
void* operand;
} s_ast_unary;
/* Binary Operation */
typedef struct
{
s_ast_node_info info;
s_lexer_token token;
void* leftOperand;
void* rightOperand;
} s_ast_binary;
/* Assignment */
typedef struct
{
s_ast_node_info info;
s_ast_variable* variable;
void* expression;
} s_ast_assignment;
/* Variable Declaration */
typedef struct
{
s_ast_node_info info;
s_ast_type* type;
/* Variable linked list */
struct var_link
{
s_ast_variable* variable;
struct var_link* next_var_link;
struct var_link* prev_var_link;
} var_link;
} s_ast_var_declaration;
/* Statement linked list link */
typedef struct s_ast_statement_link
{
void* statement;
struct s_ast_statement_link* next_statement_link;
struct s_ast_statement_link* perv_statement_link;
} s_ast_statement_link;
/* Test Wait For Timeout */
typedef struct
{
s_ast_node_info info;
void* value;
} s_ast_testWaitForTimeout;
/* Break Statement */
typedef struct
{
s_ast_node_info info;
} s_ast_breakStatement;
/* While Statement */
typedef struct
{
s_ast_node_info info;
void* condition;
/* For Statement linked list */
s_ast_statement_link statement_link;
} s_ast_whileStatement;
/* For Statement */
typedef struct
{
s_ast_node_info info;
void* initStatement;
void* condition;
/* For Statement linked list */
s_ast_statement_link statement_link;
void* postStatement;
} s_ast_forStatement;
/* If Condition */
typedef struct
{
s_ast_node_info info;
void* condition;
/* If Statement linked list */
s_ast_statement_link statement_link;
} s_ast_ifCondition;
/* Else Condition */
typedef struct
{
s_ast_node_info info;
/* Else Statement linked list */
s_ast_statement_link statement_link;
} s_ast_elseCodnition;
/* If Statement */
typedef struct
{
s_ast_node_info info;
/* if Condition linked list */
struct if_condition_link
{
s_ast_ifCondition* ifCondition;
struct if_condition_link* next_ifCondition_link;
struct if_condition_link* perv_ifCondition_link;
} if_condition_link;
s_ast_elseCodnition* elseCondition;
} s_ast_ifStatement;
/* Compound Return Statement */
typedef struct
{
s_ast_node_info info;
void* value;
} s_ast_compoundReturnStatement;
/* Compound Call Argument */
typedef struct
{
s_ast_node_info info;
void* argument;
} s_ast_compoundCallArg;
/* Compound Statement Call */
typedef struct
{
s_ast_node_info info;
s_lexer_token cmpStatementName;
/* Compound Statement Call Argument linked list */
struct argument_link
{
s_ast_compoundCallArg* argument;
struct argument_link* next_argument_link;
struct argument_link* perv_argument_link;
} argument_link;
} s_ast_compoundStatementCall;
/* Compound Return */
typedef struct
{
s_ast_node_info info;
s_ast_type* type;
} s_ast_compound_return;
/* Parameter */
typedef struct
{
s_ast_node_info info;
s_ast_type* type;
s_ast_variable* variable;
} s_ast_parameter;
/* Compound */
typedef struct
{
s_ast_node_info info;
/* Return Type */
s_ast_compound_return* return_type;
/* Name */
s_lexer_token name;
/* Parameter linked list */
struct parameter_link
{
s_ast_parameter* parameter;
struct parameter_link* next_parameter_link;
struct parameter_link* perv_parameter_link;
} parameter_link;
/* Compound Variable Declarations linked list */
struct cmp_var_decl_link
{
s_ast_var_declaration* var_declaration;
struct cmp_var_decl_link* next_var_decl_link;
struct cmp_var_decl_link* perv_var_decl_link;
} cmp_var_decl_link;
/* Statement linked list */
s_ast_statement_link statement_link;
} s_ast_compound;
/* Compound Main */
typedef struct
{
s_ast_node_info info;
/* Main Variable Declarations linked list */
struct main_var_decl_link
{
s_ast_var_declaration* var_declaration;
struct main_var_decl_link* next_var_decl_link;
struct main_var_decl_link* perv_var_decl_link;
} main_var_decl_link;
/* Statement linked list */
s_ast_statement_link statement_link;
} s_ast_compound_main;
/* Program */
typedef struct
{
s_ast_node_info info;
/* Global Variable Declarations linked list */
struct global_var_decl_link
{
s_ast_var_declaration* var_declaration;
struct global_var_decl_link* next_var_decl_link;
struct global_var_decl_link* perv_var_decl_link;
} global_var_decl_link;
/* Compound Statement linked list */
struct compound_link
{
s_ast_compound* compound_statement;
struct compound_link* next_compound_link;
struct compound_link* perv_compound_link;
} compound_link;
s_ast_compound_main* compound_main;
} s_ast_program;
/*****************************/
#endif /* INTERPRETER_AST_H_ */