diff --git a/output/affect-err.synt.xml b/output/affect-err.synt.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/affiche_table_symbole.c b/src/affiche_table_symbole.c index 55d37cc..2723a4e 100644 --- a/src/affiche_table_symbole.c +++ b/src/affiche_table_symbole.c @@ -251,10 +251,33 @@ void affiche_t_dec(n_dec *n) void affiche_t_foncDec(n_dec *n) { char *fct = "foncDec"; - //affiche_t_texte( n->nom, trace_abs ); + + int i = rechercheExecutable(n->nom); + if( i >= 0) { + printf("Fonction %s déjà déclaré\n", n->nom); + affiche_dico(); + exit(1); + } + + int id = ajouteIdentificateur(n->nom, contexte, T_FONCTION, 0, -1); + entreeFonction(); + contexte = C_ARGUMENT; affiche_t_l_dec(n->u.foncDec_.param); + + int j = 0; + for(int i = dico.sommet - 1; i >= 0; i--){ + if(dico.tab[i].classe != C_ARGUMENT) + break; + j++; + } + + dico.tab[id].complement = j; + + contexte = C_VARIABLE_LOCALE; affiche_t_l_dec(n->u.foncDec_.variables); affiche_t_instr(n->u.foncDec_.corps); + affiche_dico(); + sortieFonction(); } /*-------------------------------------------------------------------------*/ @@ -264,6 +287,7 @@ void affiche_t_varDec(n_dec *n) //affiche_t_element("varDec", n->nom, trace_abs); if(rechercheDeclarative(n->nom) >= 0) { printf("Variable %s déjà déclaré\n", n->nom); + affiche_dico(); exit(1); } @@ -278,6 +302,7 @@ void affiche_t_varDec(n_dec *n) adresseArgumentCourant += 4; } else { printf("Wtf ? %s\n", n->nom); + affiche_dico(); exit(1); } @@ -292,14 +317,16 @@ void affiche_t_tabDec(n_dec *n) if(rechercheDeclarative(n->nom) >= 0) { printf("Tableau %s déjà déclaré\n", n->nom); + affiche_dico(); exit(1); } if (contexte == C_VARIABLE_GLOBALE) { - ajouteIdentificateur(n->nom, contexte, T_ENTIER, adresseGlobalCourante, n->u.tabDec_.taille); + ajouteIdentificateur(n->nom, contexte, T_TABLEAU_ENTIER, adresseGlobalCourante, n->u.tabDec_.taille); adresseGlobalCourante += 4*n->u.tabDec_.taille; } else { printf("Wtf ? %s\n", n->nom); + affiche_dico(); exit(1); } @@ -323,9 +350,11 @@ void affiche_t_var_simple(n_var *n) int i = rechercheExecutable(n->nom); if( i < 0) { printf("Variable %s non déclaré\n", n->nom); + affiche_dico(); exit(1); } else if (dico.tab[i].type == T_TABLEAU_ENTIER) { printf("Indice tableau %s est attendu\n", n->nom); + affiche_dico(); exit(1); } } @@ -334,6 +363,18 @@ void affiche_t_var_simple(n_var *n) void affiche_t_var_indicee(n_var *n) { char *fct = "var_indicee"; + + int i = rechercheExecutable(n->nom); + if( i < 0) { + printf("Tableau %s non déclaré\n", n->nom); + affiche_dico(); + exit(1); + } else if (dico.tab[i].type == T_ENTIER) { + printf("%s n'est pas un Tableau\n", n->nom); + affiche_dico(); + exit(1); + } + affiche_t_exp( n->u.indicee_.indice ); } /*-------------------------------------------------------------------------*/ diff --git a/test/output/affect.tab b/test/output/affect.tab new file mode 100644 index 0000000..91bc69d --- /dev/null +++ b/test/output/affect.tab @@ -0,0 +1,6 @@ +------------------------------------------ +base = 2 +sommet = 2 +0 $a GLOBALE ENTIER 0 -1 +1 main GLOBALE FONCTION 0 0 +------------------------------------------ diff --git a/test/output/boucle.tab b/test/output/boucle.tab new file mode 100644 index 0000000..f37700e --- /dev/null +++ b/test/output/boucle.tab @@ -0,0 +1,7 @@ +------------------------------------------ +base = 3 +sommet = 3 +0 $i GLOBALE ENTIER 0 -1 +1 $carre GLOBALE ENTIER 4 -1 +2 main GLOBALE FONCTION 0 0 +------------------------------------------ diff --git a/test/output/expression.tab b/test/output/expression.tab new file mode 100644 index 0000000..91bc69d --- /dev/null +++ b/test/output/expression.tab @@ -0,0 +1,6 @@ +------------------------------------------ +base = 2 +sommet = 2 +0 $a GLOBALE ENTIER 0 -1 +1 main GLOBALE FONCTION 0 0 +------------------------------------------ diff --git a/test/output/max.tab b/test/output/max.tab new file mode 100644 index 0000000..3d3086c --- /dev/null +++ b/test/output/max.tab @@ -0,0 +1,15 @@ +------------------------------------------ +base = 1 +sommet = 3 +0 max GLOBALE FONCTION 0 2 +1 $a ARGUMENT ENTIER 0 -1 +2 $b ARGUMENT ENTIER 4 -1 +------------------------------------------ +------------------------------------------ +base = 2 +sommet = 4 +0 max GLOBALE FONCTION 0 2 +1 main GLOBALE FONCTION 0 0 +2 $v_1 LOCALE ENTIER 0 -1 +3 $v_2 LOCALE ENTIER 4 -1 +------------------------------------------ diff --git a/test/output/tri.tab b/test/output/tri.tab new file mode 100644 index 0000000..b248a59 --- /dev/null +++ b/test/output/tri.tab @@ -0,0 +1,49 @@ +------------------------------------------ +base = 2 +sommet = 2 +0 $tab GLOBALE TABLEAU 0 10 +1 initialiser GLOBALE FONCTION 0 0 +------------------------------------------ +------------------------------------------ +base = 3 +sommet = 5 +0 $tab GLOBALE TABLEAU 0 10 +1 initialiser GLOBALE FONCTION 0 0 +2 afficher GLOBALE FONCTION 0 1 +3 $n ARGUMENT ENTIER 0 -1 +4 $i LOCALE ENTIER 0 -1 +------------------------------------------ +------------------------------------------ +base = 4 +sommet = 7 +0 $tab GLOBALE TABLEAU 0 10 +1 initialiser GLOBALE FONCTION 0 0 +2 afficher GLOBALE FONCTION 0 1 +3 echanger GLOBALE FONCTION 0 2 +4 $i ARGUMENT ENTIER 0 -1 +5 $j ARGUMENT ENTIER 4 -1 +6 $temp LOCALE ENTIER 0 -1 +------------------------------------------ +------------------------------------------ +base = 5 +sommet = 9 +0 $tab GLOBALE TABLEAU 0 10 +1 initialiser GLOBALE FONCTION 0 0 +2 afficher GLOBALE FONCTION 0 1 +3 echanger GLOBALE FONCTION 0 2 +4 trier GLOBALE FONCTION 0 1 +5 $n ARGUMENT ENTIER 0 -1 +6 $echange LOCALE ENTIER 0 -1 +7 $j LOCALE ENTIER 4 -1 +8 $m LOCALE ENTIER 8 -1 +------------------------------------------ +------------------------------------------ +base = 6 +sommet = 6 +0 $tab GLOBALE TABLEAU 0 10 +1 initialiser GLOBALE FONCTION 0 0 +2 afficher GLOBALE FONCTION 0 1 +3 echanger GLOBALE FONCTION 0 2 +4 trier GLOBALE FONCTION 0 1 +5 main GLOBALE FONCTION 0 0 +------------------------------------------