#include "Graphics.h" #include "Stdlib.h" #include "Stdio.h" #include "Ctype.h" #include "Conio.h" #include "Io.h" #include "String.h" #include #include "C:\SISTEMA\LIBRERIA.H" #define TOTAL 10 #define TOT 4 #define MAX 20 void APila(void); char ter[50]; char term[5][20]; char nter[50]; char com[10][20]; char NT[20]; char TNT[5][20]; char ini[1]; int b=0,c=0,a=0,h=0,m=0,s=0,t=0,z=0, T=0; char x[100]; int gm,gd=DETECT; struct stack { char datos[MAX]; int tope; } pila; int VerifiUni(char NTer[], char Ter[], char Uni[]); int Evaluacion(char Gra[TOTAL][TOT], char Len[TOTAL],char NTer[]); void Grafica1(void); void Grafica2(void); void Grafica3(void); void ini_pila(struct stack &pilita); int pila_vacia(struct stack pilita); int pila_llena(struct stack pilita); void push (struct stack &pilita, char newelem); void pop(struct stack &pilita, char &delelem); char NTer[TOTAL], Ter[TOT]; char Len[TOTAL],valor; int Vector[TOT]; int Util, klm=0; int ban=0, kan=0, pt=0, flag=0; int i=0, j=0, k=0,l=0,n=0; char in; char out; char ANT[TOT]; void GRAREG(); void main(void) { int Cadena[10], i, X=245, Y=90, Inicio; GRAFICOS Graficos; MENU Menu[10]; CABECERA Cabecera; METODO_SR SR; METODO_SL SL; settextjustify(LEFT_TEXT,TOP_TEXT); setcolor(LIGHTGREEN); METODO_RX RX; METODO_RNOX RNOX; METODO_LX LX; METODO_LNOX LNOX; settextjustify(LEFT_TEXT,TOP_TEXT); setcolor(LIGHTGREEN); char *MenRL[9]={"Gram. Regular","Aut. De Pila","Rx ","Rªx ","Lx ","Lªx "," Sr "," Sl"," Salir" }; // cleardevice(); Pantalla(1,1,639,479,7,CBarra,"Sistema de Lenguajes y Automatas "); int CBor=0, Mp=0, Ban=0, Retorno=0,var=0; int op1; Cuadro(10,44,630,450,CBor,1); Cuadro(10,455,630,475,7,1); X=245; Y=90; for(;Mp!=27 && Ban==0;) { Pantalla(1,1,639,479,7,CBarra,"Sistema de Lenguajes y Automatas "); Cuadro(10,44,630,450,CBor,1); Cuadro(10,455,630,475,7,1); //CBor=0; // Mp=0; Mp=MenuH(20,28,9,Retorno,0,MenRL,var); Retorno=Mp; //MenuH(20,45,9,CBarra,CBor,MenRL); if (Mp==0) { GRAREG(); Limpiado(20,50,600,440,0); } if (Mp==1) { restorecrtmode(); APila(); } if (Mp==2) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); RX.Datos(245,155,Cadena,Inicio); RX.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==3) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); RNOX.Datos(245,155,Cadena,Inicio); RNOX.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==4) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); LX.Datos(245,155,Cadena,Inicio); LX.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==5) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); LNOX.Datos(245,155,Cadena,Inicio); LNOX.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==6) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); SR.Datos(245,155,Cadena,Inicio); SR.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==7) { for(i=0;i<10;i++,X+=SEPARACION) { Menu[i].Posicion(X,Y); Menu[i].Mostrar(); } for(i=0;i<10;i++) { Cadena[i]=Menu[i].Evaluar(); } Cabecera.Datos(245,135,Cadena); Cabecera.Mostrar(); Inicio=Cabecera.Evaluar(); SL.Datos(245,155,Cadena,Inicio); SL.Evaluar(); getch(); Limpiado(90, 50, 600, 450, 0); } if (Mp==8) { Ban=1; Cuadro(10,44,630,450,CBor,1); } Limpiado(20,50,600,440,0); } getch(); } void GRAREG() { int ban; int m,ter; char Bidi[TOTAL][TOT], Uni[TOTAL],c; int NoTerm[4]={NUMERO_S,NUMERO_A,NUMERO_B,NUMERO_C}; // int Term[4]={NUMERO_a,NUMERO_b,NUMERO_c}; int NoTerminales[TOTAL]={0}, Terminales[TOTAL]={0}; int i, j, X, Y, Entrada[TOTAL][3], Cadena[TOTAL]; // GRAFICOS Graficos; MENU_NOTERMINALES0 MenuNT0[TOTAL]; MENU_TERMINALES1 MenuT1[TOTAL], MenuCadena[TOTAL]; MENU_NOTERMINALES1 MenuNT1[TOTAL]; settextjustify(LEFT_TEXT,TOP_TEXT); setcolor(LIGHTGREEN); outtextxy(100,90,"Gramatica:"); for(i=0,X=100,Y=120;i1; k--) { if ((Gra[Vector[i]][k])!='\x0') { push(pila,Gra[Vector[i]][k]); ban=0; flag=0; } } l=n; n--; } i++; kan=i; } else { flag=2; ban=2; } } } } n++; } if(flag==2) { pila.tope=-1; pt=1; //printf("Cadena no encontrada\n"); } } while(pila.tope!=-1); //if pila.tope==-1 return (pt); } /////////////////PILA///////////////////// void ini_pila(struct stack &pilita) { pilita.tope = -1; } int pila_vacia(struct stack pilita) { if(pilita.tope == -1) return(1); else return(0); } int pila_llena(struct stack pilita) { if(pilita.tope == (MAX - 1)) return(1); else return(0); } void push (struct stack &pilita, char newelem) { if(!pila_llena(pilita)) { pilita.tope++; pilita.datos[pilita.tope]=newelem; } } void pop(struct stack &pilita, char &delelem) { if(!pila_vacia(pilita)) {delelem = pilita.datos[pilita.tope]; pilita.tope--; } } /////////////////GRAFICAS///////////////////// void Grafica1() { /*setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(300,200,"S");*/ setcolor(LIGHTBLUE); setfillstyle(SOLID_FILL,LIGHTBLUE); fillellipse(300,200,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(300,200,"S"); line(250,200,300,200); //inicio circle(300+20,200-20,30); line(300,200,500,200); //s-a //circulo A setcolor(LIGHTGREEN); setfillstyle(SOLID_FILL,LIGHTGREEN); fillellipse(500,200,30,30); // setcolor(0); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(500,200,"A"); setcolor(LIGHTGREEN); circle(500+20,200-20,30); line(505,205,305,205); //a-s } void Grafica2(void) { //circulo S setcolor(LIGHTBLUE); setfillstyle(SOLID_FILL,LIGHTBLUE); fillellipse(300,200,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(300,200,"S"); line(250,200,300,200); //inicio circle(300+20,200-20,30); //s-s line(300,200,500,200); //s-a line(300,200,300,400); //s-b //circulo A setcolor(LIGHTGREEN); setfillstyle(SOLID_FILL,LIGHTGREEN); fillellipse(500,200,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(500,200,"A"); //setcolor(0); setcolor(LIGHTGREEN); circle(500+20,200-20,30); //a-a line(505,205,305,205); //a-s line(505,205,305,405); //a-b //circulo B setcolor(LIGHTCYAN); setfillstyle(SOLID_FILL,LIGHTCYAN); fillellipse(300,400,30,30); setfillstyle(SOLID_FILL,LIGHTCYAN); fillellipse(300,400,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(305,410,"B"); setcolor(LIGHTCYAN); circle(300+20,400-20,30); //b-b line(310,410,310,210); //b-s line(310,410,510,210); //b-a } void Grafica3(void) { //circulo S setcolor(LIGHTBLUE); setfillstyle(SOLID_FILL,LIGHTBLUE); fillellipse(300,200,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(300,200,"S"); setcolor(LIGHTBLUE); line(250,200,300,200); //inicio circle(300+20,200-20,30); line(300,200,500,200); //s-a line(300,200,300,400); //s-b line(300,200,500,400); //s-c //circulo A setcolor(LIGHTGREEN); setfillstyle(SOLID_FILL,LIGHTGREEN); fillellipse(500,200,30,30); // setcolor(0); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(500,200,"A"); setcolor(LIGHTGREEN); circle(500+20,200-20,30); line(505,205,305,205); //a-s line(505,205,305,405); //a-b line(505,205,505,405); //a-c //circulo B setcolor(LIGHTCYAN); setfillstyle(SOLID_FILL,LIGHTCYAN); fillellipse(300,400,30,30); setfillstyle(SOLID_FILL,LIGHTCYAN); fillellipse(300,400,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(305,410,"B"); setcolor(LIGHTCYAN); circle(300+20,400-20,30); //b-b line(310,410,310,210); //b-s line(310,410,510,210); //b-a line(310,410,510,410); //b-c //circulo c setcolor(LIGHTRED); setfillstyle(SOLID_FILL,LIGHTRED); fillellipse(500,400,30,30); setcolor(4); settextstyle(1, HORIZ_DIR, 2); outtextxy(520,415,"C"); setcolor(LIGHTCYAN); setcolor(LIGHTRED); circle(500+20,400-20,30); //c-c line(505,415,305,215); //c-s line(515,415,515,215); //c-a line(515,415,315,415); //c-b } /////////////////// void APila() { clrscr(); char resp; char alf[20]; char simpi[20]; char simpim[20]; char alfm[20]; char esta[20]; char estan[20]; char cad[20]; char com[100]; char compo[5][20]; char cima[20]; char acep; char Estida; char ini; int z=0,s=0,l=0,m=0,a=0,b=0,x=0,j=0,k=0,c=0,i=0,E=0; int band=0; int BAND=0; textcolor(6); textbackground(8); cout<<"Introduzca el alfabeto: "; cin>>alf; while (alf[z]!=EOF && alf[z]!=0 ) //separamos los simbolos del alfabeto { while (alf[z]!=44 && alf[z]!=0 && alf[z]!=EOF) { alfm[s]=alf[z]; //cout<>simpi; while (simpi[l]!=EOF && simpi[l]!=0) { while (simpi[l]!=44 && simpi[l]!=0 && simpi[l]!=EOF) { simpim[m]=simpi[l]; // cout<>esta; a=0; while (esta[a]!=EOF && esta[a]!=0) //separamos los estados { while (esta[a]!=44 && esta[a]!=0 && esta[a]!=EOF) { estan[b]=esta[a]; // cout<>ini; b=0; while (ini!=estan[b] && estan[b]!=EOF) { b++; } if (estan[b]==EOF) { cout<<"El estado inicial no pertenece al conjunto de estados"; band=1; getch(); exit(0); } if (band!=1) { cout<<"Introduzca el estado de aceptaci¢n: "; cin>>acep; b=0; while (acep!=estan[b] && estan[b]!=EOF) { b++; } if (estan[b]==EOF) { cout<<"El estado de aceptaci¢n no pertenece al conjunto de estados"; getch(); exit(0); } } cout<<"Introduzca las composiciones:"; cin>>com; while (com[c]!=EOF && com[c]!=0) { while (com[c]!=40 && com[c]!=41 && com[c]!=44 && com[c]!=59) { compo[k][i]=com[c]; // cout<>cad; k=0; band=0; while(compo[k][0]!=EOF && compo[k][0]!=0 && band!=1) { while (ini!=compo[k][0]) { k++; } band=1; } while(compo[k][0]!=EOF && compo[k][0]!=0) { if (compo[k][1]=='œ') { if (compo[k][2]=='œ') { if (compo[k][4]=='œ') { if (x!=0) {x--;} cima[x]=EOF; Estida=compo[k][3]; } else { cima[x]=compo[k][4]; Estida=compo[k][3]; x++; } } else //del if para compo k2 { if (compo[k][2]==cima[x-1]) { if (compo[k][4]=='œ') { if (x!=0) {x--;} cima[x]=EOF; Estida=compo[k][3]; j++; } else { cima[x]=compo[k][4]; Estida=compo[k][3]; x++; } } else { // cout<<"LA CADENA NO ES ACEPTADA"; getch(); Estida!=acep; break; //exit(0); } } } else //el els del 1er if { if (compo[k][1]==cad[j]) { if (compo[k][2]=='œ') { if (compo[k][4]=='œ') { x--; cima[x]=EOF; Estida=compo[k][3]; j++; } else { j++; cima[x]=compo[k][4]; Estida=compo[k][3]; x++; } } else { if (compo[k][2]==cima[x-1]) { if (compo[k][4]=='œ') { if (x!=0) {x--;} cima[x]=EOF; Estida=compo[k][3]; j++; } else { j++; cima[x]=compo[k][4]; Estida=compo[k][3]; x++; } } else { // cout<<"LA CADENA NO ES ACEPTADA"<>resp; getch(); }while (resp=='s' || resp=='S'); setgraphmode(getgraphmode()); //setgraphmode(); }