Ajout table_symbole pour les fonctions

This commit is contained in:
2016-03-09 10:52:31 +01:00
parent 634440714c
commit ef3f2bb998
7 changed files with 126 additions and 2 deletions

View File

View File

@@ -251,10 +251,33 @@ void affiche_t_dec(n_dec *n)
void affiche_t_foncDec(n_dec *n) void affiche_t_foncDec(n_dec *n)
{ {
char *fct = "foncDec"; 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); 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_l_dec(n->u.foncDec_.variables);
affiche_t_instr(n->u.foncDec_.corps); 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); //affiche_t_element("varDec", n->nom, trace_abs);
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);
affiche_dico();
exit(1); exit(1);
} }
@@ -278,6 +302,7 @@ void affiche_t_varDec(n_dec *n)
adresseArgumentCourant += 4; adresseArgumentCourant += 4;
} else { } else {
printf("Wtf ? %s\n", n->nom); printf("Wtf ? %s\n", n->nom);
affiche_dico();
exit(1); exit(1);
} }
@@ -292,14 +317,16 @@ void affiche_t_tabDec(n_dec *n)
if(rechercheDeclarative(n->nom) >= 0) { if(rechercheDeclarative(n->nom) >= 0) {
printf("Tableau %s déjà déclaré\n", n->nom); printf("Tableau %s déjà déclaré\n", n->nom);
affiche_dico();
exit(1); exit(1);
} }
if (contexte == C_VARIABLE_GLOBALE) { 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; adresseGlobalCourante += 4*n->u.tabDec_.taille;
} else { } else {
printf("Wtf ? %s\n", n->nom); printf("Wtf ? %s\n", n->nom);
affiche_dico();
exit(1); exit(1);
} }
@@ -323,9 +350,11 @@ void affiche_t_var_simple(n_var *n)
int i = rechercheExecutable(n->nom); int i = rechercheExecutable(n->nom);
if( i < 0) { if( i < 0) {
printf("Variable %s non déclaré\n", n->nom); printf("Variable %s non déclaré\n", n->nom);
affiche_dico();
exit(1); exit(1);
} else if (dico.tab[i].type == T_TABLEAU_ENTIER) { } else if (dico.tab[i].type == T_TABLEAU_ENTIER) {
printf("Indice tableau %s est attendu\n", n->nom); printf("Indice tableau %s est attendu\n", n->nom);
affiche_dico();
exit(1); exit(1);
} }
} }
@@ -334,6 +363,18 @@ void affiche_t_var_simple(n_var *n)
void affiche_t_var_indicee(n_var *n) void affiche_t_var_indicee(n_var *n)
{ {
char *fct = "var_indicee"; 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 ); affiche_t_exp( n->u.indicee_.indice );
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/

6
test/output/affect.tab Normal file
View File

@@ -0,0 +1,6 @@
------------------------------------------
base = 2
sommet = 2
0 $a GLOBALE ENTIER 0 -1
1 main GLOBALE FONCTION 0 0
------------------------------------------

7
test/output/boucle.tab Normal file
View File

@@ -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
------------------------------------------

View File

@@ -0,0 +1,6 @@
------------------------------------------
base = 2
sommet = 2
0 $a GLOBALE ENTIER 0 -1
1 main GLOBALE FONCTION 0 0
------------------------------------------

15
test/output/max.tab Normal file
View File

@@ -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
------------------------------------------

49
test/output/tri.tab Normal file
View File

@@ -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
------------------------------------------