#include #include #include #include"Automaton.h" #include"reg_op.h" #define TAILLE_MEM 1000 #define TAILLE_PILE 500 #define LONGUEUR_LIGNE 100 int sommet_pile = 0; Automaton *pile[TAILLE_PILE]; Automaton *mem[TAILLE_MEM]; int trace; Automaton *sommet(void) { if(sommet_pile == 0){ printf("pile_vide\n"); return NULL; } else return pile[sommet_pile - 1]; } Automaton *depile(void) { if(sommet_pile == 0){ printf("pile_vide\n"); return NULL; } else return pile[--sommet_pile]; } void empile(Automaton *a) { pile[sommet_pile++] = a; } int main(void) { char ligne[LONGUEUR_LIGNE]; char commande[LONGUEUR_LIGNE], argument[LONGUEUR_LIGNE]; int adr; int n; while(1){ printf("> "); if(fgets(ligne, LONGUEUR_LIGNE, stdin) == NULL) { printf("au revoir !\n"); exit(1); } commande[0] = argument[0] = '\0'; n = sscanf(ligne, "%s %s\n", commande, argument); /* printf("ligne = %s n = %d commande = %s argument = %s\n", ligne, n, commande, argument); */ if(n == -1) continue; if(!strcmp(commande, "quit")){ printf("au revoir !\n"); exit(1); } if(!strcmp(commande, "pile")){ printf("%d\n", sommet_pile); } else if(!strcmp(commande, "elem")){ } else if(!strcmp(commande, "union")){ } else if(!strcmp(commande, "concat")){ } else if(!strcmp(commande, "kleene")){ } else if(!strcmp(commande, "affiche")){ if(sommet_pile !=0) print_automaton(sommet()); } else if(!strcmp(commande, "dep")){ if(n == 1) destroy_automaton(depile()); else{ adr = atoi(argument); if(adr >= TAILLE_MEM) printf("adresse %d trop grande\n", adr); else mem[adr] = depile(); } } else if(!strcmp(commande, "emp")){ if(n != 2) printf("il faut fournir une adresse pour empiler\n"); else{ adr = atoi(argument); if(adr >= TAILLE_MEM) printf("adresse %d trop grande\n", adr); else empile(mem[adr]); } } else if(!strcmp(commande, "trace")){ trace = (trace+1) % 2; printf("trace = %d\n", trace); } else if(!strcmp(commande, "aide")){ printf("pile : affiche la taille de la pile\n"); printf("elem : crée un automate reconnaissant \n"); printf("union : effectue l'union des deux automates en sommet de pile\n"); printf("concat : effectue la concaténation des deux automates en sommet de pile\n"); printf("kleene : effectue la fermeture de kleene de l'automate en sommet de pile\n"); printf("affiche : affiche l'automate en sommet de pile\n"); printf("quit : quitte\n"); } else printf("commande inconnue\n"); } }