aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.y
diff options
context:
space:
mode:
authorAdam NAILI2018-05-04 09:14:41 +0200
committerAdam NAILI2018-05-04 09:14:41 +0200
commit2ebd7d03e6d9ff5d8badc637ca4c6ab3c6db4e81 (patch)
treeb50adeb1fc3189df196fef8c1dec40e32589a50d /src/tpc.y
parentc9c4fbbde6e4f4f3942777cd9930cf40375e0ea9 (diff)
downloadtpc-compiler-2ebd7d03e6d9ff5d8badc637ca4c6ab3c6db4e81.tar.gz
DIVSTAR working : 'It's working ! It's working' said Anakin
Diffstat (limited to 'src/tpc.y')
-rw-r--r--src/tpc.y37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/tpc.y b/src/tpc.y
index 387b3ef..41fa1d2 100644
--- a/src/tpc.y
+++ b/src/tpc.y
@@ -2,6 +2,19 @@
2/* 2/*
3 * UPEM / Compilation / Projet 3 * UPEM / Compilation / Projet
4 * Pacien TRAN-GIRARD, Adam NAILI 4 * Pacien TRAN-GIRARD, Adam NAILI
5 *
6 *
7 *
8 *
9 *
10 *
11 * TODO :
12 * - Gérer les globales avec .bss (Il faut donc décaler le début du programme après l'analyse des globales pour savoir combien de place réserver.)
13 * - Evaluation paresseuse
14 * - Gestion des tableaux
15 *
16 *
17 *
5 */ 18 */
6 19
7#include <stdio.h> 20#include <stdio.h>
@@ -160,7 +173,8 @@ Exp:
160 | EB 173 | EB
161 ; 174 ;
162EB: 175EB:
163 EB OR TB {check_expected_type($1,INT);check_expected_type($3,INT);} 176 EB {check_expected_type($1,INT); printf("pop rax\n");}
177 OR TB {check_expected_type($4,INT);}
164 | TB 178 | TB
165 ; 179 ;
166TB: 180TB:
@@ -187,7 +201,20 @@ E:
187 | T 201 | T
188 ; 202 ;
189T: 203T:
190 T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT);} 204 T DIVSTAR F {check_expected_type($1,INT);check_expected_type($3,INT);
205 if($2 == '*'){
206 printf(";E * T\npop rax\npop rcx\nimul rax,rcx\npush rax\n");
207 }
208 else{
209 printf(";E / T\npop rax\npop rcx\nxor rdx,rdx\nidiv rcx\n");
210 if ($2 == '/'){
211 printf("push rax\n");
212 }
213 else{
214 printf("push rdx\n");
215 }
216 }
217 }
191 | F 218 | F
192 ; 219 ;
193F: 220F:
@@ -196,15 +223,15 @@ F:
196 printf(";+F\n"); 223 printf(";+F\n");
197 } 224 }
198 else{ 225 else{
199 printf(";-F\npop rdx\nxor eax,eax\nsub eax,edx\npush rax\n"); 226 printf(";-F\npop rdx\nxor rax,rax\nsub rax,rdx\npush rax\n");
200 } 227 }
201 } 228 }
202 | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");} 229 | '!' F {$$ = $2;printf(";!F\npop rax\nxor rax,1\npush rax\n");}
203 | '(' Exp ')' {$$ = $2;} 230 | '(' Exp ')' {$$ = $2;}
204 | LValue {if(status == GLOBAL) {$$ = glo_lookup($<ident>1);printf("push QWORD [rbp - %d] ;%s\n",glo_get_addr($<ident>1),$<ident>1);} 231 | LValue {if(status == GLOBAL) {$$ = glo_lookup($<ident>1);printf("push QWORD [rbp - %d] ;%s\n",glo_get_addr($<ident>1),$<ident>1);}
205 else {$$ = loc_lookup($<ident>1); printf("push QWORD [rbp - %d] ;%s\n",loc_get_addr($<ident>1),$<ident>1);}} 232 else {$$ = loc_lookup($<ident>1); printf("push QWORD [rbp - %d] ;%s\n",loc_get_addr($<ident>1),$<ident>1);}}
206 | NUM {$$ = INT; printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique 233 | NUM {$$ = INT; if(status == LOCAL) printf("push %d\n",$1);} // on stocke les types pour l'analyse sémantique
207 | CARACTERE {$$ = CHAR; printf("push %d\n",$1);} 234 | CARACTERE {$$ = CHAR; if(status == LOCAL) printf("push %d\n",$1);}
208 | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement 235 | IDENT '(' Arguments ')' {$$ = INT;} //tableau d'entiers uniquement
209 ; 236 ;
210LValue: 237LValue: