Browse Source

Compilateur teriné testé (NON EXHAUSTIF)

Paul Faure 2 years ago
parent
commit
c33c308015
4 changed files with 19 additions and 20 deletions
  1. 1
    0
      Lex_Yacc/al.lex
  2. 16
    17
      Lex_Yacc/as.y
  3. 1
    1
      Tables/Instructions/tab_instruc.c
  4. 1
    2
      Tables/Symboles/table_symboles.c

+ 1
- 0
Lex_Yacc/al.lex View File

@@ -32,6 +32,7 @@ yyerror (char const *s)
32 32
 ">"         { return tGT;       }    // Token plus grand que
33 33
 "=="        { return tEQCOND;   }    // Token égal comparaison
34 34
 
35
+"!"         { return tNOT;      }    // Token NOT 
35 36
 "&&"        { return tAND;      }    // Token ET
36 37
 "||"        { return tOR;       }    // Token OU
37 38
 

+ 16
- 17
Lex_Yacc/as.y View File

@@ -79,9 +79,9 @@ C : Fonctions                     {add_operation(STOP,0,0,0);
79 79
 
80 80
 // Le main, renvoi un int, possède le mot clé main, des arguments et un body
81 81
 // Dès que le main est reconnu (token main) on met en place le JMP
82
-Main : tINT tMAIN                 {create_jump_to_main(get_current_index()); printf("DANS LE MAIN \n");
82
+Main : tINT tMAIN                 {create_jump_to_main(get_current_index());
83 83
                                   }
84
-       tOBRACE Args tCBRACE Body {print();}; 
84
+       tOBRACE Args tCBRACE Body; 
85 85
 
86 86
 
87 87
 
@@ -217,8 +217,11 @@ Instruction : Print tPV;
217 217
 /*************************************/
218 218
 /*************************************/
219 219
 
220
-Invocation : tID tOBRACE Params tCBRACE  {struct fonction_t fonc = get_fonction($1);                              // On récupère la fonction
221
-                                          multiple_pop($3);                                                       // On pop les paramètres de la table des symboles
220
+Invocation : tID tOBRACE                 {push("0_TEMPORARY_CTX", 0, integer);                                    // On reserve la place du contexte
221
+                                          push("0_TEMPORARY_ADDR_RT", 0, pointer);                                // On reserve la place de l'adresse de retour                                
222
+                                         }
223
+						 Params tCBRACE              {struct fonction_t fonc = get_fonction($1);                              // On récupère la fonction
224
+                                          multiple_pop($4 + 2);                                                       // On pop les paramètres de la table des symboles
222 225
                                           add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0);     // On écrit le CALL
223 226
 																					// On renvoi l'adresse de la valeur retour de la fonction
224 227
                                           if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
@@ -374,7 +377,7 @@ SymboleAffectation : SymboleAffectation tOCROCH E tCCROCH  {if ($1.type.pointeur
374 377
 																																add_operation(AFC, addr, taille_types[$1.type.base],0);                   // Sinon le type de base
375 378
 																															}
376 379
 		                                                          add_operation(MUL,$3,addr,$3);                                              // On multiple le nombre de décalage par la taille du type
377
-		                                                          add_operation(ADD,$3,$1.adresse,$3);                                        // On l'ajoute a l'adresse de base
380
+		                                                          add_operation(ADD,$1.adresse,$1.adresse,$3);                                        // On l'ajoute a l'adresse de base
378 381
 																															$1.type.isTab = 0;
379 382
 		                                                          $$=$1; 
380 383
 		                                                          pop(); 
@@ -418,7 +421,6 @@ SymboleAffectation : tMUL SymboleAffectation               {if ($2.type.pointeur
418 421
 E : tNB                                  {int addr = push("0_TEMPORARY", 1, integer);              // On reserve la place de la variable temporaire
419 422
                                           add_operation(AFC, addr,$1,0);                           // On Affecte la valeur a cette adresse
420 423
                                           $$ = addr;                                               // On renvoi l'adresse
421
-																					printf("Nombre %d@%d\n", $1, addr);
422 424
                                          };
423 425
 
424 426
 // Un nombre sous forme XeY, même traitement qu'un nombre classique 
@@ -480,7 +482,7 @@ E : tSUB E                               {int addr = push("0_TEMPORARY", 1, inte
480 482
 
481 483
 
482 484
 // Opérateur == (idem multiplication)
483
-E : E tEQCOND E                          {add_operation(EQU,$1,$1,$3); 
485
+E : E tEQCOND E                          {add_operation(EQU,$1,$1,$3);
484 486
                                           $$ = $1; 
485 487
                                           pop();
486 488
                                          };
@@ -492,8 +494,6 @@ E : E tGT E                              {add_operation(SUP,$1,$1,$3);
492 494
 
493 495
 // Opérateur < (idem multiplication)
494 496
 E : E tLT E                              {add_operation(INF,$1,$1,$3); 
495
-																					printf("INF %d %d %d\n", $1, $1, $3);
496
-																					print();
497 497
                                           $$ = $1; 
498 498
                                           pop();
499 499
                                          };
@@ -502,7 +502,7 @@ E : tNOT E                               {int addr = push("0_TEMPORARY", 1, inte
502 502
                                           add_operation(AFC, addr,0,0);                            // On affecte le 0
503 503
                                           add_operation(EQU, $2, addr, $2);                        // On applique le 0==E
504 504
                                           $$ = $2;                                                 // On renvoi l'adresse
505
-                                          pop();   
505
+                                          pop();
506 506
                                          };
507 507
 
508 508
 // Opérateur E && E' <=> E*E' (idem multiplication)
@@ -539,7 +539,6 @@ E : tID                                  {struct symbole_t * symbole  = get_vari
539 539
                                             add_operation(COP, addr,symbole->adresse,0);           // Si c'est autre chose, on copie la valeur
540 540
                                           } 
541 541
                                           $$ = addr;
542
-																					printf("variable stoquée a l'adresse %d \n", addr);
543 542
                                          };
544 543
 
545 544
 // Une variable sous forme de tableau
@@ -547,10 +546,10 @@ E : tID tOCROCH E tCCROCH                {struct symbole_t * symbole  = get_vari
547 546
                                           struct type_t type = symbole->type;                                // On récupère le type
548 547
                                           type.nb_blocs = 1;                                                 
549 548
                                           int addr = push("0_TEMPORARY", 1, type);                           // On créé la variable temporaire
550
-                                          if (type.isTab == 2) {
551
-                                            add_operation(COP, addr,symbole->adresse,0);
552
-                                          } else {
549
+                                          if (type.isTab) {
553 550
                                             add_operation(AFCA, addr,symbole->adresse,0);
551
+                                          } else {
552
+                                            add_operation(COP, addr,symbole->adresse,0);
554 553
                                           } 
555 554
                                           int addr2 = push("0_TEMPORARY", 1, integer); 
556 555
                                           add_operation(AFC, addr2, taille_types[symbole->type.base],0);     
@@ -569,10 +568,10 @@ EBis : tID tOCROCH E tCCROCH             {struct symbole_t * symbole  = get_vari
569 568
                                           struct type_t type = symbole->type; 
570 569
                                           type.nb_blocs = 1; 
571 570
                                           int addr = push("0_TEMPORARY", 1, type); 
572
-                                          if(type.isTab == 2) {
573
-                                            add_operation(COP, addr,symbole->adresse,0);
574
-                                          } else {
571
+                                          if(type.isTab) {
575 572
                                             add_operation(AFCA, addr,symbole->adresse,0);
573
+                                          } else {
574
+                                            add_operation(COP, addr,symbole->adresse,0);
576 575
                                           }
577 576
                                           int addr2 = push("0_TEMPORARY", 1, integer);
578 577
                                           add_operation(AFC, addr2, taille_types[symbole->type.base],0); 

+ 1
- 1
Tables/Instructions/tab_instruc.c View File

@@ -70,7 +70,7 @@ char * get_asm_line_from_op(struct operation_t op){
70 70
 			sprintf(buffer,"SUP %d %d %d\n",op.arg1, op.arg2, op.arg3);
71 71
 			break;
72 72
 		case (EQU):
73
-			sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
73
+			sprintf(buffer,"EQU %d %d %d\n",op.arg1, op.arg2, op.arg3);
74 74
 			break;
75 75
 		case (PRI):
76 76
 			sprintf(buffer,"PRI %d\n",op.arg1);

+ 1
- 2
Tables/Symboles/table_symboles.c View File

@@ -72,7 +72,6 @@ int push(char * nom, int isInit, struct type_t type) {
72 72
 	pile->first = aux;
73 73
 	pile->taille++;
74 74
 	int addr_var = last_addr;
75
-	printf("Push de %s avec une taille de type de %d et %d blocs a l'adresse %d\n", nom, taille_types[type.base],type.nb_blocs,last_addr);
76 75
 	last_addr += (type.nb_blocs)*taille_types[type.base]; 
77 76
 	return addr_var;
78 77
 }
@@ -87,7 +86,7 @@ struct symbole_t pop() {
87 86
 		retour = aux->symbole;
88 87
 		free(aux);
89 88
 		pile->taille--;
90
-		last_addr -= taille_types[retour.type.base]; 
89
+		last_addr -= taille_types[retour.type.base] * retour.type.nb_blocs; 
91 90
 	}
92 91
 	return retour;
93 92
 }

Loading…
Cancel
Save