Afficher arbre ?
Fermé
whitelight
Messages postés
2
Date d'inscription
vendredi 16 mai 2008
Statut
Membre
Dernière intervention
2 juin 2008
-
16 mai 2008 à 12:55
whitelight Messages postés 2 Date d'inscription vendredi 16 mai 2008 Statut Membre Dernière intervention 2 juin 2008 - 2 juin 2008 à 13:32
whitelight Messages postés 2 Date d'inscription vendredi 16 mai 2008 Statut Membre Dernière intervention 2 juin 2008 - 2 juin 2008 à 13:32
A voir également:
- Afficher arbre ?
- Afficher mot de passe wifi android - Guide
- Afficher appdata - Guide
- Afficher calendrier outlook dans google agenda - Guide
- Windows 11 afficher plus d'options - Guide
- Afficher mot de passe wifi - Guide
1 réponse
whitelight
Messages postés
2
Date d'inscription
vendredi 16 mai 2008
Statut
Membre
Dernière intervention
2 juin 2008
2 juin 2008 à 13:32
2 juin 2008 à 13:32
slt, ça vous aide
char* lettre[]={
"Non Utilise",
"program",
"ID",
"declar",
"corps",
"TYPE",
"listvar",
"instr (voir la grammaire!)",
"expr",
"fonct",
"CST"
};
char* type_label[]={
"Non Utilise",
"Entier",
"Reel",
"Booleen"
};
void init_arb_syn()
{
Arb_Syn=NULL;
out_a=fopen("out.arb","w");
}
void liberer_arb_syn()
{
if(Arb_Syn!=NULL)
{
//c a vous de voir comment libere tout l'espace occupé par cet arbre.
Arb_Syn=NULL;
}
fclose(out_a);
}
Arbre creer_arbre(int type)
{
Arbre temp;
temp=(Arbre) malloc(sizeof(struct arbre));
temp->type=type;
return temp;
}
void afficher_arbre_rec(Arbre rac,int prof)
{
int prof_i;
if(rac!=NULL)
{
prof_i=prof;
while(prof_i){ fprintf(out_a," "); prof_i--;}
fprintf(out_a,"%s",lettre[rac->type]);
switch(rac->type)
{
case 1: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.program.declar,prof+1);
afficher_arbre_rec(rac->data.program.corps,prof+1);
break;
case 2: fprintf(out_a,"(%d)\n",rac->data.indice);
break;
case 3: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.declar.type,prof+1);
afficher_arbre_rec(rac->data.declar.listvar,prof+1);
afficher_arbre_rec(rac->data.declar.declar,prof+1);
break;
case 4: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.corps.instr,prof+1);
//afficher_arbre_rac(rac->data.corps.corps,prof+1);
break;
case 5: fprintf(out_a,"(%s)\n",type_label[rac->data.type]);
break;
case 6: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.listvar.id,prof+1);
afficher_arbre_rec(rac->data.listvar.listvar,prof+1);
break;
case 7: fprintf(out_a,"\n");
break;
case 8: fprintf(out_a,"(%s)\n",type_label[rac->data.expr.type_exp]);
switch(rac->data.expr.type)
{
}
break;
default: fprintf(err,"Erreur lors de l'affichage de l'arbre (completer l'arbre!)\n");
}
}
}
void afficher_arbre_syntaxique()
{
fprintf(out_a,"l'Arbre Syntaxique :\n");
afficher_arbre_rec(Arb_Syn,0);
}
char* lettre[]={
"Non Utilise",
"program",
"ID",
"declar",
"corps",
"TYPE",
"listvar",
"instr (voir la grammaire!)",
"expr",
"fonct",
"CST"
};
char* type_label[]={
"Non Utilise",
"Entier",
"Reel",
"Booleen"
};
void init_arb_syn()
{
Arb_Syn=NULL;
out_a=fopen("out.arb","w");
}
void liberer_arb_syn()
{
if(Arb_Syn!=NULL)
{
//c a vous de voir comment libere tout l'espace occupé par cet arbre.
Arb_Syn=NULL;
}
fclose(out_a);
}
Arbre creer_arbre(int type)
{
Arbre temp;
temp=(Arbre) malloc(sizeof(struct arbre));
temp->type=type;
return temp;
}
void afficher_arbre_rec(Arbre rac,int prof)
{
int prof_i;
if(rac!=NULL)
{
prof_i=prof;
while(prof_i){ fprintf(out_a," "); prof_i--;}
fprintf(out_a,"%s",lettre[rac->type]);
switch(rac->type)
{
case 1: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.program.declar,prof+1);
afficher_arbre_rec(rac->data.program.corps,prof+1);
break;
case 2: fprintf(out_a,"(%d)\n",rac->data.indice);
break;
case 3: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.declar.type,prof+1);
afficher_arbre_rec(rac->data.declar.listvar,prof+1);
afficher_arbre_rec(rac->data.declar.declar,prof+1);
break;
case 4: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.corps.instr,prof+1);
//afficher_arbre_rac(rac->data.corps.corps,prof+1);
break;
case 5: fprintf(out_a,"(%s)\n",type_label[rac->data.type]);
break;
case 6: fprintf(out_a,"\n");
afficher_arbre_rec(rac->data.listvar.id,prof+1);
afficher_arbre_rec(rac->data.listvar.listvar,prof+1);
break;
case 7: fprintf(out_a,"\n");
break;
case 8: fprintf(out_a,"(%s)\n",type_label[rac->data.expr.type_exp]);
switch(rac->data.expr.type)
{
}
break;
default: fprintf(err,"Erreur lors de l'affichage de l'arbre (completer l'arbre!)\n");
}
}
}
void afficher_arbre_syntaxique()
{
fprintf(out_a,"l'Arbre Syntaxique :\n");
afficher_arbre_rec(Arb_Syn,0);
}