-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharbre.h
More file actions
260 lines (176 loc) · 5.29 KB
/
arbre.h
File metadata and controls
260 lines (176 loc) · 5.29 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
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
#ifndef ARBRE_H
#define ARBRE_H
#include "table_symbole.h"
#include "quad.h"
// Enum des types de Noeuds dans l'AST
typedef enum arbre_type{
//--- Sprint 1
ast_constant,
ast_str,
ast_printf,
ast_printi,
ast_return,
ast_main,
//--- Sprint 2
ast_var,
ast_plus,
ast_moins,
ast_fois,
ast_div,
ast_affectation,
ast_declaration,
ast_autoIncrementPlus,
ast_autoIncrementMoins,
//--- Sprint 3
ast_and,
ast_or,
ast_not,
ast_equal,
ast_nequal,
ast_greater,
ast_greaterOrEqual,
ast_less,
ast_lessOrEqual,
ast_if,
ast_bloc,
//--- Sprint 4
ast_while,
ast_for,
//--- Sprint 5
ast_tableau,
ast_listTableau,
//--- Sprint 6
ast_stencil,
ast_applyStencil,
ast_fonction,
ast_args,
ast_instruction,
ast_returnFct,
}arbre_type;
// Structure du stencil
typedef struct str_stencil{
int profondeurs;
int member;
char* name;
} std_stencil, *Stencil;
// Union definissant les valeurs possibles d'une feuille
typedef union tree_value{
char* str;
int constante;
char op;
struct{
quad trueList;
quad falseList;
} boolList;
std_stencil stencil;
}tree_value;
// Structure de l'AST
typedef struct str_arbre{
arbre_type type;
struct str_arbre* fils;
struct str_arbre* freres;
tree_value val;
} std_arbre,*Arbre;
// Structure de la liste de Define
typedef struct str_define{
char* id;
int cst;
struct str_define* next;
} std_define, *ListeDefine;
//------- SPRINT 1 -------
//creation d'un arbre vide
Arbre newArbre();
//creation d'une feuille const
Arbre new_const(int val);
//creation d'une feuille string
Arbre new_string(char* str);
//ajout de a2 dans les frere de a1
Arbre concat(Arbre a1,Arbre a2);
//Ajout d'un noeud print
Arbre ast_new_print(arbre_type type,Arbre feuille);
//Ajout d'un noeud return
Arbre ast_new_return(Arbre feuille);
//Ajout un noeud main
Arbre ast_new_main(Arbre statement);
//------- SPRINT 2 -------
//creation d'une feuille variable avec un ID donné
Arbre new_var(char* var);
//Ajout d'un noeud de declaration
Arbre ast_new_declaration(Arbre feuille);
//Ajout d'un noeud affectation
Arbre ast_new_affectation(Arbre id, Arbre Expr);
//Ajout d'un noeud somme
Arbre ast_new_plus(Arbre operande1, Arbre operande2);
//Ajout d'un noeud soustraction
Arbre ast_new_moins(Arbre operande1, Arbre operande2);
//Ajout d'un noeud division
Arbre ast_new_div(Arbre operande1, Arbre operande2);
//Ajout d'un noeud produit
Arbre ast_new_fois(Arbre operande1, Arbre operande2);
//Ajout d'un noeud AutoIncrementation +
Arbre ast_new_autoIncrement_plus(Arbre var);
//Ajout d'un noeud AutoIncrementation -
Arbre ast_new_autoIncrement_moins(Arbre var);
//Libere la mémoire de l'AST
void ast_free(Arbre);
//------- SPRINT 3 -------
//Ajout d'un noeud &&
Arbre ast_new_and(Arbre operande1, Arbre operande2);
//Ajout d'un noeud ||
Arbre ast_new_or(Arbre operande1, Arbre operande2);
//Ajout d'un noeud !
Arbre ast_new_not(Arbre operande);
//Ajout d'un noeud ==
Arbre ast_new_equal(Arbre operande1, Arbre operande2);
//Ajout d'un noeud !=
Arbre ast_new_nequal(Arbre operande1, Arbre operande2);
//Ajout d'un noeud >
Arbre ast_new_greater(Arbre operande1, Arbre operande2);
//Ajout d'un noeud >=
Arbre ast_new_greaterOrEqual(Arbre operande1, Arbre operande2);
//Ajout d'un noeud <
Arbre ast_new_less(Arbre operande1, Arbre operande2);
//Ajout d'un noeud <=
Arbre ast_new_lessOrEqual(Arbre operande1, Arbre operande2);
//Ajout d'un noeud de condition IF
Arbre ast_new_if(Arbre ifCondition, Arbre ifInstructions, Arbre elseInstructions);
//------- SPRINT 4 -------
//Ajout d'un noeud de boucle for
Arbre ast_new_for(Arbre inits,Arbre conditions,Arbre increments,Arbre instructions);
//Ajout d'un noeud de boucle while
Arbre ast_new_while(Arbre conditions, Arbre instructions);
//------- SPRINT 5 -------
Arbre ast_new_tableauDeclare(char* id, Arbre dimension, Arbre affect);
Arbre ast_new_tableauAffec(char* id, Arbre dimension, Arbre affect);
Arbre new_tableau(char* id, Arbre dimension);
Arbre ast_new_blocTableau(Arbre a);
int verifTableau(Arbre Dim , Arbre tableau);
//------- SPRINT 6 -------
Arbre new_stencil(char* id);
Arbre ast_new_stencilDeclare(char* id,Arbre member,int n,int prof);
Arbre ast_new_blocStencil(Arbre a);
Arbre ast_new_applyStencilD(Arbre stencil, Arbre tableau);
Arbre ast_new_applyStencilG(Arbre tableau,Arbre stencil);
int verifStencil(Arbre astStencil, int member, int dim);
//------- SPRINT 7 -------
Arbre ast_new_appelFonction(char* id, Arbre arg);
Arbre ast_new_fonction(char* id, Arbre args, Arbre fct);
int replaceIdMain(Arbre ast);
int replaceIdVarFct(char *id, Arbre ast);
int repaceIdInAST(Arbre ast);
//------- All sprints -------
//Affiche dans le terminal l'AST général avec ses frères et fils
void ast_print(Arbre a);
//Affiche dans le terminal l'AST donné a une profondeur donné
void ast_print_aux(Arbre a,int profondeur);
//return 0 si l'analyse et bonne sinon ficher non semantiquement correct
int ast_semantique(Arbre a ,Symbole sym_table[TAILLE_TABLE]);
//------- DEFINE -------
ListeDefine newListeDefine();
void free_define(ListeDefine l);
ListeDefine new_define(char* id, int constante);
ListeDefine concat_define(ListeDefine d,ListeDefine r);
void replaceDefineInAST(Arbre ast,ListeDefine d);
ListeDefine findInDefine(ListeDefine d, char* id);
void print_define(ListeDefine d);
#endif