Les tableaux c'est ENFIN bon normalement
This commit is contained in:
parent
f196725be3
commit
2001f717a6
7 changed files with 21 additions and 16 deletions
|
@ -1,6 +1,5 @@
|
|||
int main(){
|
||||
int b[3];
|
||||
int a;
|
||||
a = b[1];
|
||||
int * c = &b[2];
|
||||
int * f = &b[1];
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ DebutAff : tID {struct symbole_t * symbole = get_variable($1); symbole->initial
|
|||
DebutAffPointeur : tMUL SuiteAffPointeur {add_operation(READ, $2, $2, 0); $$=$2;};
|
||||
DebutAffPointeur : SuiteAffPointeur {$$=$1;};
|
||||
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;};
|
||||
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();};
|
||||
SuiteAffPointeur : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); int addr = push("0_TEMPORARY", 1, symbole->type); if (symbole->type.pointeur_level > 0){add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, 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();};
|
||||
|
||||
|
||||
E : tNB { int addr = push("0_TEMPORARY", 1, integer); add_operation(AFC, addr,$1,0); $$ = addr;};
|
||||
|
@ -134,16 +134,16 @@ E : E tOR E {add_operation(ADD,$1,$1,$3); $$ = $1; pop();} ;
|
|||
E : tMUL E { add_operation(READ, $2, $2, 0); $$=$2;};
|
||||
E : tADDR EBis {add_operation(COPA,$2, $2,0); $$=$2;};
|
||||
E : tADDR ETer {add_operation(COPA,$2, $2,0); $$=$2;};
|
||||
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;};
|
||||
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();};
|
||||
E : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if (symbole->type.isTab){add_operation(AFCA, addr,symbole->adresse,0); } else{add_operation(COP, addr,symbole->adresse,0);} $$=addr;};
|
||||
E : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if(type.pointeur_level > 0) {add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, 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();};
|
||||
|
||||
EBis : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); if(type.pointeur_level > 0) {add_operation(COP, addr,symbole->adresse,0);} else{add_operation(AFCA, 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();};
|
||||
ETer : tID { printf("Id\n"); struct symbole_t * symbole = get_variable($1); struct type_t type = symbole->type; type.nb_blocs = 1; int addr = push("0_TEMPORARY", 1, type); add_operation(AFCA, addr,symbole->adresse,0); $$=addr;};
|
||||
|
||||
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();};
|
||||
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;};
|
||||
|
||||
|
||||
//Créer un champ isConst dans la table des symboles
|
||||
Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; type_courant.nb_blocs = 1; printf("Type int\n");} ;
|
||||
Type : tINT {type_courant.base = INT; type_courant.pointeur_level = 0; type_courant.isTab = 0; type_courant.nb_blocs = 1; printf("Type int\n");} ;
|
||||
Type : Type tMUL {type_courant.pointeur_level++; printf("Type int *\n");};
|
||||
//SuiteType : tMUL SuiteType {type_courant.pointeur_level++; printf(" * en plus\n");} ;
|
||||
//SuiteType : ;
|
||||
|
@ -153,7 +153,7 @@ Decl : tCONST Type SuiteDeclConst FinDeclConst;
|
|||
|
||||
SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
|
||||
SuiteDecl : tID tEQ E {pop(); int addr = push($1,1, type_courant);};
|
||||
SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.pointeur_level++; type_courant.nb_blocs = $3; push($1, 0, type_courant);} ;
|
||||
SuiteDecl : tID tOCROCH tNB tCCROCH {type_courant.isTab = 1; type_courant.nb_blocs = $3; push($1, 0, type_courant);} ;
|
||||
FinDecl : tPV { printf("Fin Decl\n");};
|
||||
FinDecl : tCOMA SuiteDecl FinDecl ;
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -17,7 +17,7 @@ clean_Lex_Yacc:
|
|||
@rm -f Lex_Yacc/as.output Lex_Yacc/as.tab.* Lex_Yacc/lex.yy.*
|
||||
|
||||
build : clean build_Symboles build_Instructions build_Lex_Yacc
|
||||
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o -ly -o rondoudou_gcc
|
||||
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o -ll -o rondoudou_gcc
|
||||
|
||||
build_Symboles: clean_Symboles
|
||||
gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o
|
||||
|
|
|
@ -36,6 +36,9 @@ char * get_asm_line_from_op(struct operation_t op){
|
|||
case (AFC):
|
||||
sprintf(buffer,"AFC %d %d\n",op.arg1, op.arg2);
|
||||
break;
|
||||
case (AFCA):
|
||||
sprintf(buffer,"AFCA %d %d\n",op.arg1, op.arg2);
|
||||
break;
|
||||
case (COPA):
|
||||
sprintf(buffer,"COPA %d %d\n",op.arg1, op.arg2);
|
||||
break;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
|
||||
enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,COPA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR};
|
||||
enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,COPA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR};
|
||||
|
||||
struct operation_t {
|
||||
enum opcode_t opcode;
|
||||
|
|
|
@ -67,9 +67,9 @@ char * type_to_string(struct type_t type) {
|
|||
void print_symbole(struct symbole_t symbole) {
|
||||
char * type = type_to_string(symbole.type);
|
||||
if (symbole.initialized) {
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d}\n", symbole.nom, symbole.adresse, type, symbole.profondeur);
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d, isTab : %d}\n", symbole.nom, symbole.adresse, type, symbole.profondeur,symbole.type.isTab);
|
||||
} else {
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d}\n", symbole.nom, symbole.adresse, type,symbole.profondeur);
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d, isTab : %d}\n", symbole.nom, symbole.adresse, type,symbole.profondeur,symbole.type.isTab);
|
||||
}
|
||||
free(type);
|
||||
}
|
||||
|
@ -130,9 +130,9 @@ void print() {
|
|||
int i;
|
||||
for (i=0; i < pile->taille; i++) {
|
||||
if (aux->symbole.initialized) {
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur);
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:OUI, profondeur : %d, isTab : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur, aux->symbole.type.isTab);
|
||||
} else {
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur);
|
||||
printf("\t\t{nom:%s, adresse:%ld, type:%s, initialized:NON, profondeur : %d, isTab : %d}\n", aux->symbole.nom, aux->symbole.adresse, type_to_string(aux->symbole.type), aux->symbole.profondeur, aux->symbole.type.isTab);
|
||||
}
|
||||
aux = aux->suivant;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,11 @@ struct type_t {
|
|||
enum base_type_t base;
|
||||
//Si la variable est un pointeur, on enregitre son niveau (nombre de *)
|
||||
int pointeur_level;
|
||||
//Si il s'agit d'un tableau, on enregistre sa taille (nombre de cases)
|
||||
//Si il s'agit d'un tableau, on enregistre sa taille (nombre de cases) (même si c'est une variable on met quand même un nb_blocs à)
|
||||
int nb_blocs;
|
||||
//Si c'est un tableau, cette valeur est à 1
|
||||
int isTab;
|
||||
|
||||
};
|
||||
//Constante pour les entiers
|
||||
extern const struct type_t integer;
|
||||
|
|
Loading…
Reference in a new issue