-
Notifications
You must be signed in to change notification settings - Fork 1
/
Abstract_Tree.h
192 lines (148 loc) · 2.81 KB
/
Abstract_Tree.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
#ifndef HEAD
#define HEAD
#define bool char
#include"Enums.h"
static int line_counter = 0;
/******************************************************Program*********************************************************/
//start of the program from here
struct PROGRAM
{
struct DECLARATION *declaration;
struct FUNCTION *function;
};
/*
- to declare variables before assignment int value;
id_type : int
id : value
*/
struct DECLARATION
{
struct DECLARATION *prev;
ID_TYPE id_type;
char *ID;
};
/*
- prev: previous function
- ID: int or float or anything for future work
- parameters: send paramperter
- STMTSGROUP: { }
*/
struct FUNCTION
{
struct FUNCTION *prev;
ID_TYPE id_type;
char *ID;
struct PARAMETER *parameter;
struct STMTSGROUP *stmts_group;
};
/*
what we send in the function
- prev : if there is another parameter
- id_type: the type of identifier
- id: pointer on the identifier
*/
struct PARAMETER
{
struct PARAMETER *prev;
ID_TYPE id_type;
char *ID;
};
/*
the sent arg in the function : doSomething(3,4+4)
- prev : 3
- expr : 4+4
*/
struct ARG
{
struct ARG *prev;
struct EXPR *expr;
};
/*********************************************** Statements **************************************************/
/*
if ( condition ) if_statment else else_statemetn
- there must be condition
- else statement could be null
*/
struct IF_STMT
{
struct EXPR *condition;
struct STMT *if_stmt;
struct STMT *else_stmt;
};
/*
for loop statment : for(i = 1; i <10; i = i+1){}
- init => i=1
- condition => i < 10
- inc => i=i+1
- stmt => {}
*/
struct FOR_STMT
{
struct ASSIGN_STMT *init;
struct EXPR *condition;
struct ASSIGN_STMT *inc;
struct STMT *stmt;
};
/*
-do_while = true if it's do while operation, false otherwise
- conditon => between the while
- stmt inside the while
*/
struct WHILE_STMT
{
bool do_while;
struct EXPR *condition;
struct STMT *stmt;
};
/*
ASSIGN_STMT Operation
x = 5
- id => x
- expr => 5
*/
struct ASSIGN_STMT
{
char *ID;
struct EXPR *expr;
};
/*
group of statements grouped by { }
- declaration : its declaration
- stmt: last statement pointor on it
*/
struct STMTSGROUP
{
struct DECLARATION *declaration;
struct STMT *stmt;
};
/*
every statment in the code we compile means one of those
*/
struct STMT
{
struct STMT *prev;
STMT_TYPE stmt_type;
struct EXPR *return_expr;
struct IF_STMT *if_stmt;
struct FOR_STMT *for_stmt;
struct WHILE_STMT *while_stmt;
struct ASSIGN_STMT *assign_stmt;
struct STMTSGROUP *stmts_group;
struct DECLARATION* declaration;
};
/********************************Expressions***************************************/
/*
group all the expressions in the language
*/
struct EXPR
{
EXPR_TYPE expr_type;
struct EXPR *left_side;
struct EXPR *right_side;
struct EXPR *expr;
char *ID;
int int_val;
float floatval;
struct ARG *arg;
};
#endif