Panini 4 cancers
This commit is contained in:
@@ -1,36 +0,0 @@
|
|||||||
#ifndef __affiche_ARBRE_ABSTRAIT__
|
|
||||||
#define __affiche_ARBRE_ABSTRAIT__
|
|
||||||
|
|
||||||
#include "syntabs.h"
|
|
||||||
#include "dico.h"
|
|
||||||
|
|
||||||
void affiche_t_table(n_prog *n);
|
|
||||||
void affiche_t_l_instr(n_l_instr *n);
|
|
||||||
void affiche_t_instr(n_instr *n);
|
|
||||||
void affiche_t_instr_si(n_instr *n);
|
|
||||||
void affiche_t_instr_tantque(n_instr *n);
|
|
||||||
void affiche_t_instr_faire(n_instr *n);
|
|
||||||
void affiche_t_instr_pour(n_instr *n);
|
|
||||||
void affiche_t_instr_affect(n_instr *n);
|
|
||||||
void affiche_t_instr_appel(n_instr *n);
|
|
||||||
void affiche_t_instr_retour(n_instr *n);
|
|
||||||
void affiche_t_instr_ecrire(n_instr *n);
|
|
||||||
int affiche_t_l_exp(n_l_exp *n);
|
|
||||||
void affiche_t_exp(n_exp *n);
|
|
||||||
void affiche_t_varExp(n_exp *n);
|
|
||||||
void affiche_t_opExp(n_exp *n);
|
|
||||||
void affiche_t_intExp(n_exp *n);
|
|
||||||
void affiche_t_lireExp(n_exp *n);
|
|
||||||
void affiche_t_appelExp(n_exp *n);
|
|
||||||
void affiche_t_l_dec(n_l_dec *n);
|
|
||||||
void affiche_t_dec(n_dec *n);
|
|
||||||
void affiche_t_foncDec(n_dec *n);
|
|
||||||
void affiche_t_varDec(n_dec *n);
|
|
||||||
void affiche_t_tabDec(n_dec *n);
|
|
||||||
void affiche_t_var(n_var *n);
|
|
||||||
void affiche_t_var_simple(n_var *n);
|
|
||||||
void affiche_t_var_indicee(n_var *n);
|
|
||||||
void affiche_t_appel(n_appel *n);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
38
header/parcours.h
Normal file
38
header/parcours.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef __PARCOURS__
|
||||||
|
#define __PARCOURS__
|
||||||
|
|
||||||
|
#include "syntabs.h"
|
||||||
|
#include "dico.h"
|
||||||
|
|
||||||
|
void printMips( const char * msg );
|
||||||
|
|
||||||
|
void parcours_table(n_prog *n);
|
||||||
|
void parcours_l_instr(n_l_instr *n);
|
||||||
|
void parcours_instr(n_instr *n);
|
||||||
|
void parcours_instr_si(n_instr *n);
|
||||||
|
void parcours_instr_tantque(n_instr *n);
|
||||||
|
void parcours_instr_faire(n_instr *n);
|
||||||
|
void parcours_instr_pour(n_instr *n);
|
||||||
|
void parcours_instr_affect(n_instr *n);
|
||||||
|
void parcours_instr_appel(n_instr *n);
|
||||||
|
void parcours_instr_retour(n_instr *n);
|
||||||
|
void parcours_instr_ecrire(n_instr *n);
|
||||||
|
void parcours_l_exp(n_l_exp *n);
|
||||||
|
int parcours_exp(n_exp *n);
|
||||||
|
int parcours_varExp(n_exp *n);
|
||||||
|
int parcours_opExp(n_exp *n);
|
||||||
|
int parcours_intExp(n_exp *n);
|
||||||
|
int parcours_lireExp(n_exp *n);
|
||||||
|
int parcours_appelExp(n_exp *n);
|
||||||
|
void parcours_l_dec(n_l_dec *n);
|
||||||
|
void parcours_dec(n_dec *n);
|
||||||
|
void parcours_foncDec(n_dec *n);
|
||||||
|
void parcours_varDec(n_dec *n);
|
||||||
|
void parcours_tabDec(n_dec *n);
|
||||||
|
void parcours_var(n_var *n);
|
||||||
|
void parcours_var_simple(n_var *n);
|
||||||
|
void parcours_var_indicee(n_var *n);
|
||||||
|
void parcours_appel(n_appel *n);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -3,16 +3,19 @@
|
|||||||
#include "analyseur_lexical.h"
|
#include "analyseur_lexical.h"
|
||||||
#include "analyseur_syntaxyque.h"
|
#include "analyseur_syntaxyque.h"
|
||||||
#include "affiche_arbre_abstrait.h"
|
#include "affiche_arbre_abstrait.h"
|
||||||
#include "affiche_table_symbole.h"
|
#include "parcours.h"
|
||||||
#include "symboles.h"
|
#include "symboles.h"
|
||||||
|
|
||||||
#define A_LEXI 1
|
#define A_LEXI 1
|
||||||
#define A_SYNT 2
|
#define A_SYNT 2
|
||||||
#define A_ABST 3
|
#define A_ABST 3
|
||||||
#define A_SYMB 4
|
#define A_SYMB 4
|
||||||
|
#define A_MIPS 5
|
||||||
|
|
||||||
extern int uniteCourante;
|
extern int uniteCourante;
|
||||||
extern int afficheSyntaxyque;
|
extern int afficheSyntaxyque;
|
||||||
|
extern int afficheDico;
|
||||||
|
extern int afficheMips;
|
||||||
|
|
||||||
char yytext[100];
|
char yytext[100];
|
||||||
FILE *yyin;
|
FILE *yyin;
|
||||||
@@ -25,6 +28,7 @@ void usage()
|
|||||||
printf("./compilateur-l -s fileName\n");
|
printf("./compilateur-l -s fileName\n");
|
||||||
printf("./compilateur-l -a fileName\n");
|
printf("./compilateur-l -a fileName\n");
|
||||||
printf("./compilateur-l -t fileName\n");
|
printf("./compilateur-l -t fileName\n");
|
||||||
|
printf("./compilateur-l -m fileName\n");
|
||||||
printf("./compilateur-l fileName\n");
|
printf("./compilateur-l fileName\n");
|
||||||
exit (8);
|
exit (8);
|
||||||
}
|
}
|
||||||
@@ -32,7 +36,7 @@ void usage()
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
int sortie = A_SYMB;
|
int sortie = A_MIPS;
|
||||||
while ((argc > 1) && (argv[1][0] == '-'))
|
while ((argc > 1) && (argv[1][0] == '-'))
|
||||||
{
|
{
|
||||||
switch (argv[1][1])
|
switch (argv[1][1])
|
||||||
@@ -53,6 +57,10 @@ int main(int argc, char **argv) {
|
|||||||
sortie = A_SYMB;
|
sortie = A_SYMB;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
sortie = A_MIPS;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("Wrong Argument: %s\n", argv[1]);
|
printf("Wrong Argument: %s\n", argv[1]);
|
||||||
usage();
|
usage();
|
||||||
@@ -93,9 +101,19 @@ int main(int argc, char **argv) {
|
|||||||
case A_SYMB:
|
case A_SYMB:
|
||||||
initialise_premiers();
|
initialise_premiers();
|
||||||
initialise_suivants();
|
initialise_suivants();
|
||||||
|
afficheDico = 1;
|
||||||
uniteCourante = yylex();
|
uniteCourante = yylex();
|
||||||
p = programme();
|
p = programme();
|
||||||
affiche_t_table(p);
|
parcours_table(p);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case A_MIPS:
|
||||||
|
initialise_premiers();
|
||||||
|
initialise_suivants();
|
||||||
|
afficheMips = 1;
|
||||||
|
uniteCourante = yylex();
|
||||||
|
p = programme();
|
||||||
|
parcours_table(p);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "dico.h"
|
#include "dico.h"
|
||||||
|
|
||||||
|
int afficheDico = 0;
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void entreeFonction(void){
|
void entreeFonction(void){
|
||||||
@@ -65,6 +67,7 @@ int rechercheDeclarative(char *identif)
|
|||||||
|
|
||||||
void affiche_dico(void)
|
void affiche_dico(void)
|
||||||
{
|
{
|
||||||
|
if(afficheDico) {
|
||||||
int i;
|
int i;
|
||||||
printf("------------------------------------------\n");
|
printf("------------------------------------------\n");
|
||||||
printf("base = %d\n", dico.base);
|
printf("base = %d\n", dico.base);
|
||||||
@@ -85,8 +88,8 @@ void affiche_dico(void)
|
|||||||
printf("ENTIER ");
|
printf("ENTIER ");
|
||||||
else if(dico.tab[i].type == T_TABLEAU_ENTIER)
|
else if(dico.tab[i].type == T_TABLEAU_ENTIER)
|
||||||
printf("TABLEAU ");
|
printf("TABLEAU ");
|
||||||
/* else if(dico.tab[i].type == _ARGUMENT) */
|
/* else if(dico.tab[i].type == _ARGUMENT) */
|
||||||
/* printf("ARGUMENT "); */
|
/* printf("ARGUMENT "); */
|
||||||
else if(dico.tab[i].type == T_FONCTION)
|
else if(dico.tab[i].type == T_FONCTION)
|
||||||
printf("FONCTION ");
|
printf("FONCTION ");
|
||||||
|
|
||||||
@@ -94,4 +97,5 @@ void affiche_dico(void)
|
|||||||
printf("%d\n", dico.tab[i].complement);
|
printf("%d\n", dico.tab[i].complement);
|
||||||
}
|
}
|
||||||
printf("------------------------------------------\n");
|
printf("------------------------------------------\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,34 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "affiche_table_symbole.h"
|
#include "parcours.h"
|
||||||
#include "syntabs.h"
|
#include "syntabs.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "parcours.h"
|
||||||
|
|
||||||
int contexte = C_VARIABLE_GLOBALE;
|
int contexte = C_VARIABLE_GLOBALE;
|
||||||
int adresseGlobalCourante = 0;
|
int adresseGlobalCourante = 0;
|
||||||
int adresseLocaleCourante = 0;
|
int adresseLocaleCourante = 0;
|
||||||
int adresseArgumentCourant = 0;
|
int adresseArgumentCourant = 0;
|
||||||
|
int afficheMips = 0;
|
||||||
|
int creg = 0;
|
||||||
extern dico_ dico;
|
extern dico_ dico;
|
||||||
|
|
||||||
|
void printMips( const char * msg ) {
|
||||||
|
if(afficheMips)
|
||||||
|
printf("%s\n", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int newReg() {
|
||||||
|
return creg++%10;
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_table(n_prog *n)
|
void parcours_table(n_prog *n)
|
||||||
{
|
{
|
||||||
affiche_t_l_dec(n->variables);
|
printMips(".data");
|
||||||
affiche_t_l_dec(n->fonctions);
|
parcours_l_dec(n->variables);
|
||||||
|
printMips(".text");
|
||||||
|
parcours_l_dec(n->fonctions);
|
||||||
|
|
||||||
int id = rechercheExecutable("main");
|
int id = rechercheExecutable("main");
|
||||||
if(id < 0 || dico.tab[id].complement != 0) {
|
if(id < 0 || dico.tab[id].complement != 0) {
|
||||||
@@ -26,85 +40,85 @@ void affiche_t_table(n_prog *n)
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_l_instr(n_l_instr *n)
|
void parcours_l_instr(n_l_instr *n)
|
||||||
{
|
{
|
||||||
if(n) {
|
if(n) {
|
||||||
affiche_t_instr(n->tete);
|
parcours_instr(n->tete);
|
||||||
affiche_t_l_instr(n->queue);
|
parcours_l_instr(n->queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr(n_instr *n)
|
int parcours_instr(n_instr *n)
|
||||||
{
|
{
|
||||||
if(n) {
|
if(n) {
|
||||||
if(n->type == blocInst) affiche_t_l_instr(n->u.liste);
|
if(n->type == blocInst) parcours_l_instr(n->u.liste);
|
||||||
else if(n->type == affecteInst) affiche_t_instr_affect(n);
|
else if(n->type == affecteInst) parcours_instr_affect(n);
|
||||||
else if(n->type == siInst) affiche_t_instr_si(n);
|
else if(n->type == siInst) parcours_instr_si(n);
|
||||||
else if(n->type == tantqueInst) affiche_t_instr_tantque(n);
|
else if(n->type == tantqueInst) parcours_instr_tantque(n);
|
||||||
else if(n->type == faireInst) affiche_t_instr_faire(n);
|
else if(n->type == faireInst) parcours_instr_faire(n);
|
||||||
else if(n->type == pourInst) affiche_t_instr_pour(n);
|
else if(n->type == pourInst) parcours_instr_pour(n);
|
||||||
else if(n->type == appelInst) affiche_t_instr_appel(n);
|
else if(n->type == appelInst) parcours_instr_appel(n);
|
||||||
else if(n->type == retourInst) affiche_t_instr_retour(n);
|
else if(n->type == retourInst) parcours_instr_retour(n);
|
||||||
else if(n->type == ecrireInst) affiche_t_instr_ecrire(n);
|
else if(n->type == ecrireInst) parcours_instr_ecrire(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_si(n_instr *n)
|
void parcours_instr_si(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_exp(n->u.si_.test);
|
parcours_exp(n->u.si_.test);
|
||||||
affiche_t_instr(n->u.si_.alors);
|
parcours_instr(n->u.si_.alors);
|
||||||
if(n->u.si_.sinon){
|
if(n->u.si_.sinon){
|
||||||
affiche_t_instr(n->u.si_.sinon);
|
parcours_instr(n->u.si_.sinon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_tantque(n_instr *n)
|
void parcours_instr_tantque(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_exp(n->u.tantque_.test);
|
parcours_exp(n->u.tantque_.test);
|
||||||
affiche_t_instr(n->u.tantque_.faire);
|
parcours_instr(n->u.tantque_.faire);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_faire(n_instr *n)
|
void parcours_instr_faire(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_instr(n->u.faire_.faire);
|
parcours_instr(n->u.faire_.faire);
|
||||||
affiche_t_exp(n->u.faire_.test);
|
parcours_exp(n->u.faire_.test);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_pour(n_instr *n)
|
void parcours_instr_pour(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_instr(n->u.pour_.init);
|
parcours_instr(n->u.pour_.init);
|
||||||
affiche_t_exp(n->u.pour_.test);
|
parcours_exp(n->u.pour_.test);
|
||||||
affiche_t_instr(n->u.pour_.faire);
|
parcours_instr(n->u.pour_.faire);
|
||||||
affiche_t_instr(n->u.pour_.incr);
|
parcours_instr(n->u.pour_.incr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_affect(n_instr *n)
|
void parcours_instr_affect(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_var(n->u.affecte_.var);
|
parcours_var(n->u.affecte_.var);
|
||||||
affiche_t_exp(n->u.affecte_.exp);
|
parcours_exp(n->u.affecte_.exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_appel(n_instr *n)
|
void parcours_instr_appel(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_appel(n->u.appel);
|
parcours_appel(n->u.appel);
|
||||||
}
|
}
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_appel(n_appel *n)
|
void parcours_appel(n_appel *n)
|
||||||
{
|
{
|
||||||
int id = rechercheExecutable(n->fonction);
|
int id = rechercheExecutable(n->fonction);
|
||||||
if(id < 0) {
|
if(id < 0) {
|
||||||
@@ -113,7 +127,7 @@ void affiche_t_appel(n_appel *n)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nbArg = affiche_t_l_exp(n->args);
|
int nbArg = parcours_l_exp(n->args);
|
||||||
if(dico.tab[id].complement != nbArg) {
|
if(dico.tab[id].complement != nbArg) {
|
||||||
printf("Nombre Argument différent pour l'appel à %s\n", n->fonction);
|
printf("Nombre Argument différent pour l'appel à %s\n", n->fonction);
|
||||||
affiche_dico();
|
affiche_dico();
|
||||||
@@ -123,105 +137,117 @@ void affiche_t_appel(n_appel *n)
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_retour(n_instr *n)
|
void parcours_instr_retour(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_exp(n->u.retour_.expression);
|
parcours_exp(n->u.retour_.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_instr_ecrire(n_instr *n)
|
void parcours_instr_ecrire(n_instr *n)
|
||||||
{
|
{
|
||||||
affiche_t_exp(n->u.ecrire_.expression);
|
int tRegistre = parcours_exp(n->u.ecrire_.expression);
|
||||||
|
char tmp[250];
|
||||||
|
sprintf(tmp, "move $a0 $t%d", tRegistre);
|
||||||
|
printMips(tmp);
|
||||||
|
printMips("li $v0 1");
|
||||||
|
printMips("systcall");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int affiche_t_l_exp(n_l_exp *n)
|
int parcours_l_exp(n_l_exp *n)
|
||||||
{
|
{
|
||||||
if(n){
|
if(n){
|
||||||
affiche_t_exp(n->tete);
|
parcours_exp(n->tete);
|
||||||
return 1 + affiche_t_l_exp(n->queue);
|
return 1 + parcours_l_exp(n->queue);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_exp(n_exp *n)
|
int parcours_exp(n_exp *n)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(n->type == varExp) affiche_t_varExp(n);
|
if(n->type == varExp) return parcours_varExp(n);
|
||||||
else if(n->type == opExp) affiche_t_opExp(n);
|
else if(n->type == opExp) return parcours_opExp(n);
|
||||||
else if(n->type == intExp) affiche_t_intExp(n);
|
else if(n->type == intExp) return parcours_intExp(n);
|
||||||
else if(n->type == appelExp) affiche_t_appelExp(n);
|
else if(n->type == appelExp) return parcours_appelExp(n);
|
||||||
else if(n->type == lireExp) affiche_t_lireExp(n);
|
else if(n->type == lireExp) return parcours_lireExp(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_varExp(n_exp *n)
|
int parcours_varExp(n_exp *n)
|
||||||
{
|
{
|
||||||
affiche_t_var(n->u.var);
|
parcours_var(n->u.var);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
void affiche_t_opExp(n_exp *n)
|
int parcours_opExp(n_exp *n)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_intExp(n_exp *n)
|
int parcours_intExp(n_exp *n)
|
||||||
{
|
{
|
||||||
char texte[ 50 ]; // Max. 50 chiffres
|
char texte[ 50 ]; // Max. 50 chiffres
|
||||||
sprintf(texte, "%d", n->u.entier);
|
sprintf(texte, "%d", n->u.entier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
void affiche_t_lireExp(n_exp *n)
|
int parcours_lireExp(n_exp *n)
|
||||||
{
|
{
|
||||||
|
printMips("li $v0 5");
|
||||||
|
printMips("systcall");
|
||||||
|
int iRegistre = newReg();
|
||||||
|
char tmp[250];
|
||||||
|
sprintf(tmp, "move $t%d $a0", iRegistre);
|
||||||
|
printMips(tmp);
|
||||||
|
return iRegistre;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_appelExp(n_exp *n)
|
int parcours_appelExp(n_exp *n)
|
||||||
{
|
{
|
||||||
affiche_t_appel(n->u.appel);
|
parcours_appel(n->u.appel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_l_dec(n_l_dec *n)
|
void parcours_l_dec(n_l_dec *n)
|
||||||
{
|
{
|
||||||
if( n ){
|
if( n ){
|
||||||
affiche_t_dec(n->tete);
|
parcours_dec(n->tete);
|
||||||
affiche_t_l_dec(n->queue);
|
parcours_l_dec(n->queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_dec(n_dec *n)
|
void parcours_dec(n_dec *n)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(n){
|
if(n){
|
||||||
if(n->type == foncDec) {
|
if(n->type == foncDec) {
|
||||||
affiche_t_foncDec(n);
|
parcours_foncDec(n);
|
||||||
}
|
}
|
||||||
else if(n->type == varDec) {
|
else if(n->type == varDec) {
|
||||||
affiche_t_varDec(n);
|
parcours_varDec(n);
|
||||||
}
|
}
|
||||||
else if(n->type == tabDec) {
|
else if(n->type == tabDec) {
|
||||||
affiche_t_tabDec(n);
|
parcours_tabDec(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_foncDec(n_dec *n)
|
void parcours_foncDec(n_dec *n)
|
||||||
{
|
{
|
||||||
int i = rechercheExecutable(n->nom);
|
int i = rechercheExecutable(n->nom);
|
||||||
if( i >= 0) {
|
if( i >= 0) {
|
||||||
@@ -233,7 +259,7 @@ void affiche_t_foncDec(n_dec *n)
|
|||||||
int id = ajouteIdentificateur(n->nom, contexte, T_FONCTION, 0, -1);
|
int id = ajouteIdentificateur(n->nom, contexte, T_FONCTION, 0, -1);
|
||||||
entreeFonction();
|
entreeFonction();
|
||||||
contexte = C_ARGUMENT;
|
contexte = C_ARGUMENT;
|
||||||
affiche_t_l_dec(n->u.foncDec_.param);
|
parcours_l_dec(n->u.foncDec_.param);
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(int i = dico.sommet - 1; i >= 0; i--){
|
for(int i = dico.sommet - 1; i >= 0; i--){
|
||||||
@@ -245,15 +271,15 @@ void affiche_t_foncDec(n_dec *n)
|
|||||||
dico.tab[id].complement = j;
|
dico.tab[id].complement = j;
|
||||||
|
|
||||||
contexte = C_VARIABLE_LOCALE;
|
contexte = C_VARIABLE_LOCALE;
|
||||||
affiche_t_l_dec(n->u.foncDec_.variables);
|
parcours_l_dec(n->u.foncDec_.variables);
|
||||||
affiche_t_instr(n->u.foncDec_.corps);
|
parcours_instr(n->u.foncDec_.corps);
|
||||||
affiche_dico();
|
affiche_dico();
|
||||||
sortieFonction();
|
sortieFonction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_varDec(n_dec *n)
|
void parcours_varDec(n_dec *n)
|
||||||
{
|
{
|
||||||
if(rechercheDeclarative(n->nom) >= 0) {
|
if(rechercheDeclarative(n->nom) >= 0) {
|
||||||
printf("Variable %s déjà déclaré\n", n->nom);
|
printf("Variable %s déjà déclaré\n", n->nom);
|
||||||
@@ -263,6 +289,9 @@ void affiche_t_varDec(n_dec *n)
|
|||||||
|
|
||||||
if (contexte == C_VARIABLE_GLOBALE) {
|
if (contexte == C_VARIABLE_GLOBALE) {
|
||||||
ajouteIdentificateur(n->nom, contexte, T_ENTIER, adresseGlobalCourante, -1);
|
ajouteIdentificateur(n->nom, contexte, T_ENTIER, adresseGlobalCourante, -1);
|
||||||
|
char tmp[250];
|
||||||
|
sprintf(tmp, "$%s: .word", n->nom);
|
||||||
|
printMips(tmp);
|
||||||
adresseGlobalCourante += 4;
|
adresseGlobalCourante += 4;
|
||||||
} else if (contexte == C_VARIABLE_LOCALE) {
|
} else if (contexte == C_VARIABLE_LOCALE) {
|
||||||
ajouteIdentificateur(n->nom, contexte, T_ENTIER, adresseLocaleCourante, -1);
|
ajouteIdentificateur(n->nom, contexte, T_ENTIER, adresseLocaleCourante, -1);
|
||||||
@@ -280,7 +309,7 @@ void affiche_t_varDec(n_dec *n)
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_tabDec(n_dec *n)
|
void parcours_tabDec(n_dec *n)
|
||||||
{
|
{
|
||||||
char texte[100]; // Max. 100 chars nom tab + taille
|
char texte[100]; // Max. 100 chars nom tab + taille
|
||||||
sprintf(texte, "%s[%d]", n->nom, n->u.tabDec_.taille);
|
sprintf(texte, "%s[%d]", n->nom, n->u.tabDec_.taille);
|
||||||
@@ -293,6 +322,9 @@ void affiche_t_tabDec(n_dec *n)
|
|||||||
|
|
||||||
if (contexte == C_VARIABLE_GLOBALE) {
|
if (contexte == C_VARIABLE_GLOBALE) {
|
||||||
ajouteIdentificateur(n->nom, contexte, T_TABLEAU_ENTIER, adresseGlobalCourante, n->u.tabDec_.taille);
|
ajouteIdentificateur(n->nom, contexte, T_TABLEAU_ENTIER, adresseGlobalCourante, n->u.tabDec_.taille);
|
||||||
|
char tmp[250];
|
||||||
|
sprintf(tmp, "$%s: .space %d", n->nom, 4*n->u.tabDec_.taille);
|
||||||
|
printMips(tmp);
|
||||||
adresseGlobalCourante += 4*n->u.tabDec_.taille;
|
adresseGlobalCourante += 4*n->u.tabDec_.taille;
|
||||||
} else {
|
} else {
|
||||||
printf("Wtf ? %s\n", n->nom);
|
printf("Wtf ? %s\n", n->nom);
|
||||||
@@ -304,18 +336,18 @@ void affiche_t_tabDec(n_dec *n)
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void affiche_t_var(n_var *n)
|
void parcours_var(n_var *n)
|
||||||
{
|
{
|
||||||
if(n->type == simple) {
|
if(n->type == simple) {
|
||||||
affiche_t_var_simple(n);
|
parcours_var_simple(n);
|
||||||
}
|
}
|
||||||
else if(n->type == indicee) {
|
else if(n->type == indicee) {
|
||||||
affiche_t_var_indicee(n);
|
parcours_var_indicee(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
void affiche_t_var_simple(n_var *n)
|
void parcours_var_simple(n_var *n)
|
||||||
{
|
{
|
||||||
int i = rechercheExecutable(n->nom);
|
int i = rechercheExecutable(n->nom);
|
||||||
if( i < 0) {
|
if( i < 0) {
|
||||||
@@ -330,7 +362,7 @@ void affiche_t_var_simple(n_var *n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
void affiche_t_var_indicee(n_var *n)
|
void parcours_var_indicee(n_var *n)
|
||||||
{
|
{
|
||||||
int i = rechercheExecutable(n->nom);
|
int i = rechercheExecutable(n->nom);
|
||||||
if( i < 0) {
|
if( i < 0) {
|
||||||
@@ -343,6 +375,6 @@ void affiche_t_var_indicee(n_var *n)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
affiche_t_exp( n->u.indicee_.indice );
|
parcours_exp( n->u.indicee_.indice );
|
||||||
}
|
}
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
0
test/output/affect.mips
Normal file
0
test/output/affect.mips
Normal file
0
test/output/boucle.mips
Normal file
0
test/output/boucle.mips
Normal file
0
test/output/expression.mips
Normal file
0
test/output/expression.mips
Normal file
0
test/output/max.mips
Normal file
0
test/output/max.mips
Normal file
0
test/output/tri.mips
Normal file
0
test/output/tri.mips
Normal file
@@ -14,7 +14,7 @@ MYCOMPILOLEX="${MYCOMPILO} -l"
|
|||||||
MYCOMPILOSYNT="${MYCOMPILO} -s"
|
MYCOMPILOSYNT="${MYCOMPILO} -s"
|
||||||
MYCOMPILOASYNT="${MYCOMPILO} -a"
|
MYCOMPILOASYNT="${MYCOMPILO} -a"
|
||||||
MYCOMPILOTAB="${MYCOMPILO} -t"
|
MYCOMPILOTAB="${MYCOMPILO} -t"
|
||||||
#MYCOMPILOMIPS="${MYCOMPILO} -m"
|
MYCOMPILOMIPS="${MYCOMPILO} -m"
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ function test_fichier_ok() {
|
|||||||
diff_prog ${XMLDIFF} $input asynt
|
diff_prog ${XMLDIFF} $input asynt
|
||||||
${MYCOMPILOTAB} input/$input.l > output/$input.tab
|
${MYCOMPILOTAB} input/$input.l > output/$input.tab
|
||||||
diff_prog "${REGDIFF}" $input tab
|
diff_prog "${REGDIFF}" $input tab
|
||||||
#${MYCOMPILOMIPS} input/$input.l > output/$input.mips
|
${MYCOMPILOMIPS} input/$input.l > output/$input.mips
|
||||||
#diff_prog "${REGDIFF}" $input mips
|
#diff_prog "${REGDIFF}" $input mips
|
||||||
else
|
else
|
||||||
echo -e "\033[31minput/$input.l non trouvé\033[0m"
|
echo -e "\033[31minput/$input.l non trouvé\033[0m"
|
||||||
|
|||||||
Reference in New Issue
Block a user