3
CÓDIGO #include <iostream> #include <string.h> #include <iomanip> #include <stdlib.h> #include <fstream> using namespace std; int comparacion(string [],string,int ); FILE *doc; int main(int argc, char** argv) { ifstream reglas("produccionesiniciales.txt"); ofstream salida("guardar.txt"); if(!reglas){ cerr<<"No se pudo abrir archivo"; exit(0); } if(!salida){ cerr<<"No se pudo abrir archivo"; exit(0); } char reg1[50]; string cad1,temp1,produ[10],pila,m,ent,esp(" "),jj("1"); int flecha,s,i=0,b=0; while(!reglas.eof()){ doc=fopen("guardar.txt","a+"); reglas.getline(reg1,50); cad1=reg1; temp1=cad1; flecha=cad1.find("-->"); if(flecha<=1000 && flecha>=0){ pila+=reg1+esp; temp1.erase(0,flecha+3); produ[i]=temp1; salida<<temp1; i++; b++; } else{ } } int sa,du; du: cout<<"\t\t <<< ALETVIA JACQUELINE LEON VENEGAS >>>\n"; cout<<"\t\t <<< MARICARMEN CAMPOS PASCUAL >>>\n\n"; cout<<"\t\t ---[[AUTOMATAS Y LENGUAJES FORMALES]]---\n\n"<<endl; cout<<pila<<endl<<endl; cout<<"Ingresa cadena a evaluar: "; cin>>ent; if(ent.compare(jj)==0){ goto sa; } s=comparacion(produ,ent,b); if(s==9){ cout<<"\n\t\tCADENA ACEPTADA\n"; system("pause"); system("cls"); goto du; } else{ cout<<"\n\t\tCADENA NO ACEPTADA\n"; system("pause");

7... automata de pila

Embed Size (px)

Citation preview

Page 1: 7... automata de pila

CÓDIGO #include <iostream>

#include <string.h>

#include <iomanip>

#include <stdlib.h>

#include <fstream>

using namespace std;

int comparacion(string [],string,int );

FILE *doc;

int main(int argc, char** argv) {

ifstream reglas("produccionesiniciales.txt");

ofstream salida("guardar.txt");

if(!reglas){

cerr<<"No se pudo abrir archivo";

exit(0);

}

if(!salida){

cerr<<"No se pudo abrir archivo";

exit(0);

}

char reg1[50];

string cad1,temp1,produ[10],pila,m,ent,esp(" "),jj("1");

int flecha,s,i=0,b=0;

while(!reglas.eof()){

doc=fopen("guardar.txt","a+");

reglas.getline(reg1,50);

cad1=reg1;

temp1=cad1;

flecha=cad1.find("-->");

if(flecha<=1000 && flecha>=0){

pila+=reg1+esp;

temp1.erase(0,flecha+3);

produ[i]=temp1;

salida<<temp1;

i++;

b++;

}

else{

}

}

int sa,du;

du:

cout<<"\t\t <<< ALETVIA JACQUELINE LEON VENEGAS >>>\n";

cout<<"\t\t <<< MARICARMEN CAMPOS PASCUAL >>>\n\n";

cout<<"\t\t ---[[AUTOMATAS Y LENGUAJES FORMALES]]---\n\n"<<endl;

cout<<pila<<endl<<endl;

cout<<"Ingresa cadena a evaluar: ";

cin>>ent;

if(ent.compare(jj)==0){

goto sa;

}

s=comparacion(produ,ent,b);

if(s==9){

cout<<"\n\t\tCADENA ACEPTADA\n";

system("pause");

system("cls");

goto du;

}

else{

cout<<"\n\t\tCADENA NO ACEPTADA\n";

system("pause");

Page 2: 7... automata de pila

system("cls");

goto du;

}

sa:

return 0;

}

int comparacion(string a[],string b,int c){

for(int i=0;i<c;i++){

if(a[i].compare(b)==0){

return 9;

}

}

return -1;

}

Page 3: 7... automata de pila