|
@@ -20,6 +20,7 @@ int nbs_instructions_to_patch[10];
|
20
|
20
|
%token tMAIN
|
21
|
21
|
%token tOBRACKET tCBRACKET
|
22
|
22
|
%token tOBRACE tCBRACE
|
|
23
|
+%token tOCROCH tCCROCH
|
23
|
24
|
%token tINT
|
24
|
25
|
%token tCONST
|
25
|
26
|
%token tPV tCOMA
|
|
@@ -33,14 +34,14 @@ int nbs_instructions_to_patch[10];
|
33
|
34
|
%token tAND tOR
|
34
|
35
|
%token tADDR
|
35
|
36
|
|
36
|
|
-%left tAND tOR
|
37
|
|
-%left tNOT
|
38
|
37
|
%left tLT tGT
|
39
|
38
|
%left tEQCOND
|
|
39
|
+%left tAND tOR
|
|
40
|
+%left tNOT
|
40
|
41
|
%left tADD tSUB
|
41
|
42
|
%left tMUL tDIV
|
42
|
43
|
|
43
|
|
-%type<nombre> E Invocation DebutAff
|
|
44
|
+%type<nombre> E Invocation DebutAff SuiteAffPointeur DebutAffPointeur EBeforeAddr
|
44
|
45
|
|
45
|
46
|
|
46
|
47
|
|
|
@@ -63,11 +64,11 @@ Body : tOBRACKET {profondeur++;} Instructions tCBRACKET {print(); reset_pronf();
|
63
|
64
|
|
64
|
65
|
Instructions : Instruction Instructions ;
|
65
|
66
|
Instructions : ;
|
66
|
|
-Instruction : Aff {reset_temp_vars();};
|
67
|
|
-Instruction : Decl {reset_temp_vars();};
|
68
|
|
-Instruction : Invocation tPV{reset_temp_vars();};
|
69
|
|
-Instruction : If {reset_temp_vars();};
|
70
|
|
-Instruction : While {reset_temp_vars();};
|
|
67
|
+Instruction : Aff {};
|
|
68
|
+Instruction : Decl {};
|
|
69
|
+Instruction : Invocation tPV{};
|
|
70
|
+Instruction : If {};
|
|
71
|
+Instruction : While {};
|
71
|
72
|
|
72
|
73
|
//On considère que la première ligne du code en ASM est la ligne 0
|
73
|
74
|
If : tIF tOBRACE E tCBRACE {
|
|
@@ -76,8 +77,9 @@ Body {int current = get_current_index();
|
76
|
77
|
patch($1,current + 1);
|
77
|
78
|
add_operation(JMP,0,0,0);
|
78
|
79
|
instructions_ligne_to_patch[profondeur][nbs_instructions_to_patch[profondeur]] = current;
|
79
|
|
- nbs_instructions_to_patch[profondeur]++;}
|
80
|
|
-Else { printf("If reconnu\n");};
|
|
80
|
+ nbs_instructions_to_patch[profondeur]++;
|
|
81
|
+ decrement_temp_var();}
|
|
82
|
+Else {printf("If reconnu\n");};
|
81
|
83
|
|
82
|
84
|
|
83
|
85
|
Else : tELSE If { printf("Else if reconnu\n"); };
|
|
@@ -94,7 +96,8 @@ for (int i = 0; i< nbs_instructions_to_patch[profondeur]; i++){
|
94
|
96
|
nbs_instructions_to_patch[profondeur] = 0;};
|
95
|
97
|
While : tWHILE tOBRACE E tCBRACE {
|
96
|
98
|
add_operation(JMF,$3,0,0);
|
97
|
|
-$1 = get_current_index() - 1;}
|
|
99
|
+$1 = get_current_index() - 1;
|
|
100
|
+decrement_temp_var();}
|
98
|
101
|
|
99
|
102
|
Body { printf("While reconnu\n");
|
100
|
103
|
int current = get_current_index();
|
|
@@ -102,16 +105,19 @@ patch($1,current + 1);
|
102
|
105
|
add_operation(JMP,$1,0,0);};
|
103
|
106
|
|
104
|
107
|
|
105
|
|
-Aff : DebutAff tEQ E tPV {add_operation(COP, $1, $3,0);} ; //besoin de get_address
|
|
108
|
+Aff : DebutAff tEQ E tPV {add_operation(COP, $1, $3,0); decrement_temp_var();} ;
|
|
109
|
+Aff : DebutAffPointeur tEQ E tPV {add_operation(WR,$1,$3,0); decrement_temp_var(); decrement_temp_var();};
|
106
|
110
|
|
107
|
111
|
DebutAff : tID {struct symbole_t * symbole = get_variable($1); symbole->initialized = 1; $$=symbole->adresse; printf("%s prend une valeur\n", $1);};
|
108
|
|
-DebutAff : tMUL E { add_operation(GET, $2, $2, 0); $$=$2;};
|
109
|
|
-DebutAff : tADDR tID { int addr = allocate_mem_temp_var(INT); struct symbole_t * symbole = get_variable($2); add_operation(AFC,addr, symbole->adresse,0); $$=addr;};
|
110
|
112
|
|
111
|
|
-E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
|
113
|
+DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
|
|
114
|
+DebutAffPointeur : SuiteAffPointeur {$$=$1;};
|
|
115
|
+SuiteAffPointeur : tMUL tID {struct symbole_t * symbole = get_variable($2); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
|
116
|
+SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(AFC, addr,symbole->adresse,0); int addr2 = allocate_mem_temp_var(INT); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); $$=$3; decrement_temp_var(); decrement_temp_var();};
|
|
117
|
+
|
112
|
118
|
|
|
119
|
+E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
113
|
120
|
E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
114
|
|
-E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
115
|
121
|
E : E tMUL E { printf("Mul\n"); add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
116
|
122
|
E : E tDIV E { printf("Div\n"); add_operation(DIV, $1,$1,$3); $$ = $1; decrement_temp_var();};
|
117
|
123
|
E : E tSUB E { printf("Sub\n"); add_operation(SOU,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
@@ -125,13 +131,17 @@ E : E tLT E { printf("<\n"); add_operation(INF,$1,$1,$3); $$ = $1; decrement_tem
|
125
|
131
|
E : tNOT E { printf("!\n"); };
|
126
|
132
|
E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
127
|
133
|
E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; decrement_temp_var();} ;
|
128
|
|
-E : tMUL E { add_operation(GET, $2, $2, 0); $$=$2;};
|
129
|
|
-E : tADDR tID { int addr = allocate_mem_temp_var(INT); struct symbole_t * symbole = get_variable($2); add_operation(AFC,addr, symbole->adresse,0); $$=addr;};
|
|
134
|
+E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
|
|
135
|
+E : tADDR EBeforeAddr {add_operation(AFCA,$2, $2,0); $$=$2;};
|
|
136
|
+E : EBeforeAddr {$$=$1;};
|
|
137
|
+
|
130
|
138
|
|
|
139
|
+EBeforeAddr : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(AFC, addr,symbole->adresse,0); int addr2 = allocate_mem_temp_var(INT); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); add_operation(READ,$3,$3,0); $$=$3; decrement_temp_var(); decrement_temp_var();};
|
|
140
|
+EBeforeAddr : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
131
|
141
|
|
132
|
142
|
|
133
|
143
|
//Créer un champ isConst dans la table des symboles
|
134
|
|
-Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; printf("Type int\n");} ;
|
|
144
|
+Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; type_courant.nb_blocs = 1; printf("Type int\n");} ;
|
135
|
145
|
Type : Type tMUL {type_courant.pointeur_level++; printf("Type int *\n");};
|
136
|
146
|
//SuiteType : tMUL SuiteType {type_courant.pointeur_level++; printf(" * en plus\n");} ;
|
137
|
147
|
//SuiteType : ;
|
|
@@ -140,11 +150,12 @@ Decl : Type SuiteDecl FinDecl ;
|
140
|
150
|
Decl : tCONST Type SuiteDeclConst FinDeclConst;
|
141
|
151
|
|
142
|
152
|
SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
|
143
|
|
-SuiteDecl : tID tEQ E {int addr = push($1,1, type_courant); add_operation(COP, addr,$3,0);};
|
|
153
|
+SuiteDecl : tID tEQ E {decrement_temp_var(); int addr = push($1,1, type_courant);};
|
|
154
|
+SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.pointeur_level++; decl_tab($1,type_courant,$3); type_courant.nb_blocs = 1;} ;
|
144
|
155
|
FinDecl : tPV { printf("Fin Decl\n");};
|
145
|
156
|
FinDecl : tCOMA SuiteDecl FinDecl ;
|
146
|
157
|
|
147
|
|
-SuiteDeclConst : tID tEQ E {int addr = push($1,1, type_courant); add_operation(COP, addr,$3,0);};
|
|
158
|
+SuiteDeclConst : tID tEQ E {decrement_temp_var(); int addr = push($1,1, type_courant);};
|
148
|
159
|
FinDeclConst : tPV;
|
149
|
160
|
FinDeclConst : tCOMA SuiteDeclConst FinDeclConst;
|
150
|
161
|
|