|
@@ -59,7 +59,7 @@ Param : Type tID { printf("Prametre : %s\n", $2); };
|
59
|
59
|
SuiteParams : tCOMA Param SuiteParams ;
|
60
|
60
|
SuiteParams : ;
|
61
|
61
|
|
62
|
|
-Body : tOBRACKET {profondeur++;} Instructions tCBRACKET {print(); reset_pronf(); profondeur--;} ;
|
|
62
|
+Body : tOBRACKET {inc_prof();} Instructions tCBRACKET {print(); reset_prof();} ;
|
63
|
63
|
|
64
|
64
|
|
65
|
65
|
Instructions : Instruction Instructions ;
|
|
@@ -76,28 +76,28 @@ add_operation(JMF,$3,0,0); $1 = get_current_index() - 1;}
|
76
|
76
|
Body {int current = get_current_index();
|
77
|
77
|
patch($1,current + 1);
|
78
|
78
|
add_operation(JMP,0,0,0);
|
79
|
|
- instructions_ligne_to_patch[profondeur][nbs_instructions_to_patch[profondeur]] = current;
|
80
|
|
- nbs_instructions_to_patch[profondeur]++;
|
81
|
|
- decrement_temp_var();}
|
|
79
|
+ instructions_ligne_to_patch[get_prof()][nbs_instructions_to_patch[get_prof()]] = current;
|
|
80
|
+ nbs_instructions_to_patch[get_prof()]++;
|
|
81
|
+ pop();}
|
82
|
82
|
Else {printf("If reconnu\n");};
|
83
|
83
|
|
84
|
84
|
|
85
|
85
|
Else : tELSE If { printf("Else if reconnu\n"); };
|
86
|
86
|
Else : tELSE Body { printf("Else reconnu\n"); int current = get_current_index();
|
87
|
|
-for (int i = 0; i< nbs_instructions_to_patch[profondeur]; i++){
|
88
|
|
- patch(instructions_ligne_to_patch[profondeur][i],current);
|
|
87
|
+for (int i = 0; i< nbs_instructions_to_patch[get_prof()]; i++){
|
|
88
|
+ patch(instructions_ligne_to_patch[get_prof()][i],current);
|
89
|
89
|
}
|
90
|
|
-nbs_instructions_to_patch[profondeur] = 0;
|
|
90
|
+nbs_instructions_to_patch[get_prof()] = 0;
|
91
|
91
|
};
|
92
|
92
|
Else : {int current = get_current_index();
|
93
|
|
-for (int i = 0; i< nbs_instructions_to_patch[profondeur]; i++){
|
94
|
|
- patch(instructions_ligne_to_patch[profondeur][i],current);
|
|
93
|
+for (int i = 0; i< nbs_instructions_to_patch[get_prof()]; i++){
|
|
94
|
+ patch(instructions_ligne_to_patch[get_prof()][i],current);
|
95
|
95
|
}
|
96
|
|
-nbs_instructions_to_patch[profondeur] = 0;};
|
|
96
|
+nbs_instructions_to_patch[get_prof()] = 0;};
|
97
|
97
|
While : tWHILE tOBRACE E tCBRACE {
|
98
|
98
|
add_operation(JMF,$3,0,0);
|
99
|
99
|
$1 = get_current_index() - 1;
|
100
|
|
-decrement_temp_var();}
|
|
100
|
+pop();}
|
101
|
101
|
|
102
|
102
|
Body { printf("While reconnu\n");
|
103
|
103
|
int current = get_current_index();
|
|
@@ -105,40 +105,41 @@ patch($1,current + 1);
|
105
|
105
|
add_operation(JMP,$1,0,0);};
|
106
|
106
|
|
107
|
107
|
|
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();};
|
|
108
|
+Aff : DebutAff tEQ E tPV {add_operation(COP, $1, $3,0); pop();} ;
|
|
109
|
+Aff : DebutAffPointeur tEQ E tPV {add_operation(WR,$1,$3,0); pop(); pop();};
|
110
|
110
|
|
111
|
111
|
DebutAff : tID {struct symbole_t * symbole = get_variable($1); symbole->initialized = 1; $$=symbole->adresse; printf("%s prend une valeur\n", $1);};
|
112
|
112
|
|
113
|
113
|
DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
|
114
|
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();};
|
|
115
|
+SuiteAffPointeur : tMUL tID {struct symbole_t * symbole = get_variable($2); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
|
116
|
+SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(AFC, addr,symbole->adresse,0); int addr2 = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr2, taille_types[symbole->type.base],0); add_operation(MUL,$3,addr2,$3); add_operation(ADD,$3,addr,$3); $$=$3; pop(); pop();};
|
117
|
117
|
|
118
|
118
|
|
119
|
|
-E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
120
|
|
-E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
121
|
|
-E : E tMUL E { printf("Mul\n"); add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
122
|
|
-E : E tDIV E { printf("Div\n"); add_operation(DIV, $1,$1,$3); $$ = $1; decrement_temp_var();};
|
123
|
|
-E : E tSUB E { printf("Sub\n"); add_operation(SOU,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
124
|
|
-E : E tADD E { printf("Add\n"); add_operation(ADD,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
125
|
|
-E : Invocation { printf("Invoc\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
|
119
|
+E : tNB { int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
|
|
120
|
+E : tNBEXP { printf("Nombre exp\n"); int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
|
|
121
|
+E : E tMUL E { printf("Mul\n"); add_operation(MUL,$1,$1,$3); $$ = $1; pop();};
|
|
122
|
+E : E tDIV E { printf("Div\n"); add_operation(DIV, $1,$1,$3); $$ = $1; pop();};
|
|
123
|
+E : E tSUB E { printf("Sub\n"); add_operation(SOU,$1,$1,$3); $$ = $1; pop();};
|
|
124
|
+E : E tADD E { printf("Add\n"); add_operation(ADD,$1,$1,$3); $$ = $1; pop();};
|
|
125
|
+E : Invocation { printf("Invoc\n"); int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
|
126
|
126
|
E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
|
127
|
|
-E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,0,0); add_operation(SOU, $2,$2,addr); $$ = $2; decrement_temp_var();};
|
128
|
|
-E : E tEQCOND E { printf("==\n"); add_operation(EQU,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
129
|
|
-E : E tGT E { printf(">\n"); add_operation(SUP,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
130
|
|
-E : E tLT E { printf("<\n"); add_operation(INF,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
|
127
|
+E : tSUB E { printf("Moins\n"); int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,0,0); add_operation(SOU, $2,$2,addr); $$ = $2; pop();};
|
|
128
|
+E : E tEQCOND E { printf("==\n"); add_operation(EQU,$1,$1,$3); $$ = $1; pop();};
|
|
129
|
+E : E tGT E { printf(">\n"); add_operation(SUP,$1,$1,$3); $$ = $1; pop();};
|
|
130
|
+E : E tLT E { printf("<\n"); add_operation(INF,$1,$1,$3); $$ = $1; pop();};
|
131
|
131
|
E : tNOT E { printf("!\n"); };
|
132
|
|
-E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; decrement_temp_var();};
|
133
|
|
-E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; decrement_temp_var();} ;
|
|
132
|
+E : E tAND E {add_operation(MUL,$1,$1,$3); $$ = $1; pop();};
|
|
133
|
+E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; pop();} ;
|
134
|
134
|
E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
|
135
|
135
|
E : tADDR EBis {add_operation(COPA,$2, $2,0); $$=$2;};
|
136
|
136
|
E : tADDR ETer {add_operation(COPA,$2, $2,0); $$=$2;};
|
137
|
137
|
E : tID 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;};
|
138
|
138
|
E : 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();};
|
139
|
139
|
|
140
|
|
-EBis : 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();};
|
141
|
|
-ETer : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = allocate_mem_temp_var(symbole->type.base); add_operation(AFC, addr,symbole->adresse,0); $$=addr;};
|
|
140
|
+
|
|
141
|
+EBeforeAddr : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(AFC, addr,symbole->adresse,0); int addr2 = push("0_TEMPORARY", 1, integer); 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; pop(); pop();};
|
|
142
|
+EBeforeAddr : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); add_operation(COP, addr,symbole->adresse,0); $$=addr;};
|
142
|
143
|
|
143
|
144
|
|
144
|
145
|
//Créer un champ isConst dans la table des symboles
|
|
@@ -151,12 +152,12 @@ Decl : Type SuiteDecl FinDecl ;
|
151
|
152
|
Decl : tCONST Type SuiteDeclConst FinDeclConst;
|
152
|
153
|
|
153
|
154
|
SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
|
154
|
|
-SuiteDecl : tID tEQ E {decrement_temp_var(); int addr = push($1,1, type_courant);};
|
155
|
|
-SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.pointeur_level++; decl_tab($1,type_courant,$3); type_courant.nb_blocs = 1;} ;
|
|
155
|
+SuiteDecl : tID tEQ E {pop(); int addr = push($1,1, type_courant);};
|
|
156
|
+SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.pointeur_level++; type_courant.nb_blocs = $3; push($1, 0, type_courant);} ;
|
156
|
157
|
FinDecl : tPV { printf("Fin Decl\n");};
|
157
|
158
|
FinDecl : tCOMA SuiteDecl FinDecl ;
|
158
|
159
|
|
159
|
|
-SuiteDeclConst : tID tEQ E {decrement_temp_var(); int addr = push($1,1, type_courant);};
|
|
160
|
+SuiteDeclConst : tID tEQ E {pop(); int addr = push($1,1, type_courant);};
|
160
|
161
|
FinDeclConst : tPV;
|
161
|
162
|
FinDeclConst : tCOMA SuiteDeclConst FinDeclConst;
|
162
|
163
|
|