Compilateur teriné testé (NON EXHAUSTIF)
This commit is contained in:
parent
7718e9c861
commit
c33c308015
4 changed files with 19 additions and 20 deletions
|
@ -32,6 +32,7 @@ yyerror (char const *s)
|
||||||
">" { return tGT; } // Token plus grand que
|
">" { return tGT; } // Token plus grand que
|
||||||
"==" { return tEQCOND; } // Token égal comparaison
|
"==" { return tEQCOND; } // Token égal comparaison
|
||||||
|
|
||||||
|
"!" { return tNOT; } // Token NOT
|
||||||
"&&" { return tAND; } // Token ET
|
"&&" { return tAND; } // Token ET
|
||||||
"||" { return tOR; } // Token OU
|
"||" { return tOR; } // Token OU
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,9 @@ C : Fonctions {add_operation(STOP,0,0,0);
|
||||||
|
|
||||||
// Le main, renvoi un int, possède le mot clé main, des arguments et un body
|
// Le main, renvoi un int, possède le mot clé main, des arguments et un body
|
||||||
// Dès que le main est reconnu (token main) on met en place le JMP
|
// Dès que le main est reconnu (token main) on met en place le JMP
|
||||||
Main : tINT tMAIN {create_jump_to_main(get_current_index()); printf("DANS LE MAIN \n");
|
Main : tINT tMAIN {create_jump_to_main(get_current_index());
|
||||||
}
|
}
|
||||||
tOBRACE Args tCBRACE Body {print();};
|
tOBRACE Args tCBRACE Body;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,8 +217,11 @@ Instruction : Print tPV;
|
||||||
/*************************************/
|
/*************************************/
|
||||||
/*************************************/
|
/*************************************/
|
||||||
|
|
||||||
Invocation : tID tOBRACE Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
Invocation : tID tOBRACE {push("0_TEMPORARY_CTX", 0, integer); // On reserve la place du contexte
|
||||||
multiple_pop($3); // On pop les paramètres de la table des symboles
|
push("0_TEMPORARY_ADDR_RT", 0, pointer); // On reserve la place de l'adresse de retour
|
||||||
|
}
|
||||||
|
Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
||||||
|
multiple_pop($4 + 2); // On pop les paramètres de la table des symboles
|
||||||
add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); // On écrit le CALL
|
add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); // On écrit le CALL
|
||||||
// On renvoi l'adresse de la valeur retour de la fonction
|
// On renvoi l'adresse de la valeur retour de la fonction
|
||||||
if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
|
if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
|
||||||
|
@ -374,7 +377,7 @@ SymboleAffectation : SymboleAffectation tOCROCH E tCCROCH {if ($1.type.pointeur
|
||||||
add_operation(AFC, addr, taille_types[$1.type.base],0); // Sinon le type de base
|
add_operation(AFC, addr, taille_types[$1.type.base],0); // Sinon le type de base
|
||||||
}
|
}
|
||||||
add_operation(MUL,$3,addr,$3); // On multiple le nombre de décalage par la taille du type
|
add_operation(MUL,$3,addr,$3); // On multiple le nombre de décalage par la taille du type
|
||||||
add_operation(ADD,$3,$1.adresse,$3); // On l'ajoute a l'adresse de base
|
add_operation(ADD,$1.adresse,$1.adresse,$3); // On l'ajoute a l'adresse de base
|
||||||
$1.type.isTab = 0;
|
$1.type.isTab = 0;
|
||||||
$$=$1;
|
$$=$1;
|
||||||
pop();
|
pop();
|
||||||
|
@ -418,7 +421,6 @@ SymboleAffectation : tMUL SymboleAffectation {if ($2.type.pointeur
|
||||||
E : tNB {int addr = push("0_TEMPORARY", 1, integer); // On reserve la place de la variable temporaire
|
E : tNB {int addr = push("0_TEMPORARY", 1, integer); // On reserve la place de la variable temporaire
|
||||||
add_operation(AFC, addr,$1,0); // On Affecte la valeur a cette adresse
|
add_operation(AFC, addr,$1,0); // On Affecte la valeur a cette adresse
|
||||||
$$ = addr; // On renvoi l'adresse
|
$$ = addr; // On renvoi l'adresse
|
||||||
printf("Nombre %d@%d\n", $1, addr);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Un nombre sous forme XeY, même traitement qu'un nombre classique
|
// 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
|
||||||
|
|
||||||
|
|
||||||
// Opérateur == (idem multiplication)
|
// Opérateur == (idem multiplication)
|
||||||
E : E tEQCOND E {add_operation(EQU,$1,$1,$3);
|
E : E tEQCOND E {add_operation(EQU,$1,$1,$3);
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
pop();
|
pop();
|
||||||
};
|
};
|
||||||
|
@ -492,8 +494,6 @@ E : E tGT E {add_operation(SUP,$1,$1,$3);
|
||||||
|
|
||||||
// Opérateur < (idem multiplication)
|
// Opérateur < (idem multiplication)
|
||||||
E : E tLT E {add_operation(INF,$1,$1,$3);
|
E : E tLT E {add_operation(INF,$1,$1,$3);
|
||||||
printf("INF %d %d %d\n", $1, $1, $3);
|
|
||||||
print();
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
pop();
|
pop();
|
||||||
};
|
};
|
||||||
|
@ -502,7 +502,7 @@ E : tNOT E {int addr = push("0_TEMPORARY", 1, inte
|
||||||
add_operation(AFC, addr,0,0); // On affecte le 0
|
add_operation(AFC, addr,0,0); // On affecte le 0
|
||||||
add_operation(EQU, $2, addr, $2); // On applique le 0==E
|
add_operation(EQU, $2, addr, $2); // On applique le 0==E
|
||||||
$$ = $2; // On renvoi l'adresse
|
$$ = $2; // On renvoi l'adresse
|
||||||
pop();
|
pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Opérateur E && E' <=> E*E' (idem multiplication)
|
// Opérateur E && E' <=> E*E' (idem multiplication)
|
||||||
|
@ -539,7 +539,6 @@ E : tID {struct symbole_t * symbole = get_vari
|
||||||
add_operation(COP, addr,symbole->adresse,0); // Si c'est autre chose, on copie la valeur
|
add_operation(COP, addr,symbole->adresse,0); // Si c'est autre chose, on copie la valeur
|
||||||
}
|
}
|
||||||
$$ = addr;
|
$$ = addr;
|
||||||
printf("variable stoquée a l'adresse %d \n", addr);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Une variable sous forme de tableau
|
// Une variable sous forme de tableau
|
||||||
|
@ -547,10 +546,10 @@ E : tID tOCROCH E tCCROCH {struct symbole_t * symbole = get_vari
|
||||||
struct type_t type = symbole->type; // On récupère le type
|
struct type_t type = symbole->type; // On récupère le type
|
||||||
type.nb_blocs = 1;
|
type.nb_blocs = 1;
|
||||||
int addr = push("0_TEMPORARY", 1, type); // On créé la variable temporaire
|
int addr = push("0_TEMPORARY", 1, type); // On créé la variable temporaire
|
||||||
if (type.isTab == 2) {
|
if (type.isTab) {
|
||||||
add_operation(COP, addr,symbole->adresse,0);
|
|
||||||
} else {
|
|
||||||
add_operation(AFCA, addr,symbole->adresse,0);
|
add_operation(AFCA, addr,symbole->adresse,0);
|
||||||
|
} else {
|
||||||
|
add_operation(COP, addr,symbole->adresse,0);
|
||||||
}
|
}
|
||||||
int addr2 = push("0_TEMPORARY", 1, integer);
|
int addr2 = push("0_TEMPORARY", 1, integer);
|
||||||
add_operation(AFC, addr2, taille_types[symbole->type.base],0);
|
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
|
||||||
struct type_t type = symbole->type;
|
struct type_t type = symbole->type;
|
||||||
type.nb_blocs = 1;
|
type.nb_blocs = 1;
|
||||||
int addr = push("0_TEMPORARY", 1, type);
|
int addr = push("0_TEMPORARY", 1, type);
|
||||||
if(type.isTab == 2) {
|
if(type.isTab) {
|
||||||
add_operation(COP, addr,symbole->adresse,0);
|
|
||||||
} else {
|
|
||||||
add_operation(AFCA, addr,symbole->adresse,0);
|
add_operation(AFCA, addr,symbole->adresse,0);
|
||||||
|
} else {
|
||||||
|
add_operation(COP, addr,symbole->adresse,0);
|
||||||
}
|
}
|
||||||
int addr2 = push("0_TEMPORARY", 1, integer);
|
int addr2 = push("0_TEMPORARY", 1, integer);
|
||||||
add_operation(AFC, addr2, taille_types[symbole->type.base],0);
|
add_operation(AFC, addr2, taille_types[symbole->type.base],0);
|
||||||
|
|
|
@ -70,7 +70,7 @@ char * get_asm_line_from_op(struct operation_t op){
|
||||||
sprintf(buffer,"SUP %d %d %d\n",op.arg1, op.arg2, op.arg3);
|
sprintf(buffer,"SUP %d %d %d\n",op.arg1, op.arg2, op.arg3);
|
||||||
break;
|
break;
|
||||||
case (EQU):
|
case (EQU):
|
||||||
sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
|
sprintf(buffer,"EQU %d %d %d\n",op.arg1, op.arg2, op.arg3);
|
||||||
break;
|
break;
|
||||||
case (PRI):
|
case (PRI):
|
||||||
sprintf(buffer,"PRI %d\n",op.arg1);
|
sprintf(buffer,"PRI %d\n",op.arg1);
|
||||||
|
|
|
@ -72,7 +72,6 @@ int push(char * nom, int isInit, struct type_t type) {
|
||||||
pile->first = aux;
|
pile->first = aux;
|
||||||
pile->taille++;
|
pile->taille++;
|
||||||
int addr_var = last_addr;
|
int addr_var = last_addr;
|
||||||
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);
|
|
||||||
last_addr += (type.nb_blocs)*taille_types[type.base];
|
last_addr += (type.nb_blocs)*taille_types[type.base];
|
||||||
return addr_var;
|
return addr_var;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +86,7 @@ struct symbole_t pop() {
|
||||||
retour = aux->symbole;
|
retour = aux->symbole;
|
||||||
free(aux);
|
free(aux);
|
||||||
pile->taille--;
|
pile->taille--;
|
||||||
last_addr -= taille_types[retour.type.base];
|
last_addr -= taille_types[retour.type.base] * retour.type.nb_blocs;
|
||||||
}
|
}
|
||||||
return retour;
|
return retour;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue