*;
import java.util.*;
//"A->aB|c|Mo|U"; 5
//"B->Bv|c"; 3
//"C->aGB|y|Mo"; 4
public class Main {
public static void main(String args[]) throws IOException {
String[]NT1 = new String[99];
String[][] NT = new String[99][99];
String[] NT2 = new String[99];
String[] NT3 = new String[99];
String[] NT3EP = new String[99];
String[] NT4 = new String[99];
String aux;
char auxchar;
int xprod=0,a=0,i=0,j=0,k=0,l=0,m=0,per=0,auxlargo=0,mom=0;
int i1=0,i2=0,i3=0,i4=0,i5=0,elige=0,LONNT=0,LONNT1=0,LONNT2=0,LONNT3=0,LONN
T4=0;
/****************************************************************************/
/************
PREGUNTA EL NUMERO DE PRODUCCIONES QUE SE
*********/
/************ TIENEN PARA CREAR LOS ARREGLOS DE ESAS DIMENSIONES *********/
/****************************************************************************/
xprod = Teclado.entero("Cuantas producciones tiene tu gramatica ?: ");
System.out.println();
System.out.println();
String[] lista = new String[xprod];
String[][] prod = new String[xprod][99];
String[][] alg1 = new String[xprod][99];
String[][] alg2 = new String[xprod][99];
String[][] alg3 = new String[xprod][99];
String[][] alg4 = new String[xprod][99];
int []numprod=new int[xprod];
int []numprodalg1=new int[xprod];
int []numprodalg2=new int[xprod];
int []numprodalg3=new int[xprod];
int []numprodalg4=new int[xprod];
StringTokenizer st[];
StringTokenizer otra;
/****************************************************************************/
/************ LEER LAS N LISTAS DE PRODUCCIONES Y LAS GUARDA ************/
/****************************************************************************/
for (a=0;a<xprod;a++){
aux = Teclado.cadena("Escriba la produccion "+a+" :");
lista[a]=aux;}
System.out.println();
System.out.println();
//
//
/*******************************************************************************
**************
********************************************************************************
*************
*** AQUI SE SEPARA EN PRODUCCIONES CADA LISAT QUE SE TIENE, SI ESTAN A->ABH|GY
T
***
*** LAS SEPARA EN TRES PRODUCCIONES, Y LAS GUARDA EN UN ARRLEGO BIDIMENCIONAL
***
*** DE xprod POR 99 SITRING, SE VAN A ALMACENAR
***
*** SI TENGO LAS PRODUCCIONES A->aB|c|Mo|U B->Bv|c C->aGB|y|Mo
***
*** QUEDARA DE LA SIGUIENTE FORMA MI ARREGLO LLAMADO PROD[][]
***
*** [0][0]= A
[0][1]=aB [0][2]=c
[0][3]=Mo [0][4]=U
***
*** [1][0]= B
[1][1]=Bv [1][2]=c
***
*** [2][0]= C
[2][1]=aGB [2][2]=y
[2][3]=Mo
***
*** EN LA COLUMNA UNO ESTA EL NUIMERO DE LA PRODUCCION Y EN LA SEGUNDA SUS PRO
DUCCIONES ***
********************************************************************************
**************
********************************************************************************
**************/
for (a=0;a<xprod;a++){
aux=lista[a];
otra= new StringTokenizer(aux, "->| ");
//st[a]=otra;
while(otra.hasMoreTokens()) {
prod[a][i1]= otra.nextToken();
System.out.println(prod[a][i1] + " "+a+i1);
i1++;}
numprod[a]=i1;
i1=0;}
System.out.println();
System.out.println();
for(i3=0;i3<xprod;i3++){
System.out.println("la lista "+i3+" tiene "+numprod[i3]);}
System.out.println();
System.out.println();
/****************************************************************************/
/**********************
ALGORITMO 1
******************/
/****************************************************************************/
){
alg1[13][ numprodalg1[i3]]=aux;
auxchar=prod[i3][0].charAt(i1);
per=pertenece(auxchar,NT1,LONNT1);
if(per!=0){
LONNT1++;
NT1[LONNT1]=prod[i3][0];
}
}
if(per!=0){break;}
}
else{i1++;}
}
i1=0;
} } }
System.out.println();
System.out.println();
// PARA COMPROBAR SI SE GUARDO EL NUERO DE PRODUCCIONES CON PPURAS MINUSCULAS
for(i3=0;i3<xprod;i3++){
System.out.println("el algoritmo 1 en la produccion "+i3+" tiene "+nu
mprodalg1[i3]+" elementos");}
/****************************************************************************/
/**********************
ALGORITMO 2
******************/
/****************************************************************************/
NT2[0]=alg1[0][0];
i2=i1=0;
for(i3=0;i3<xprod;i3++){
i5=0;
for(i4=1;i4<numprodalg1[i3];i4++){
aux=alg1[i3][i4];
while(i1<aux.length()){
auxchar=aux.charAt(i1);
if(i3==0){
mom=tipoMayMin(auxchar);
if(mom==0){
i1++;}
else{
NT2[i2]=NT2[i2]+auxchar;
i2++;
i1++;
LONNT2=i2;}
if(i1==(aux.length())){
alg2[i3][i5]=alg1[i3][i4];
i2++;
i5++;
numprodalg2[i3]=i5;
break;}
}
else{
mom=tipoMayMin(auxchar);
if(mom==0){//quiere decir que es min
i1++;}
else{
mom=pertenece((alg1[i3][0].charAt(0)),NT2,LONNT2);
if(mom==0){
mom=tipoMayMin(auxchar);
if(mom==0){
i1++;}
else{
NT2[i2]=NT2[i2]+auxchar;
i2++;
i1++;
LONNT2=i2;}
if(i1==(aux.length())){
alg2[i3][i5]=alg1[i3][i4];
i2++;
i5++;
numprodalg2[i3]=i5;
break;}
}
else{
i4=i4+1000;
break;}
}
}
}
elige = stringMayMin(prod[i3][i4]);
alg2[i3][i2]=alg1[i3][i4];
numprodalg1[i3]=i2;
NT1 [i1]=prod[i3][0];
}
}
/****************************************************************************/
/**********************
ALGORITMO 3
******************/
/****************************************************************************/
/****************************************************************************/
/**********************
ALGORITMO 4
******************/
/****************************************************************************/
System.out.println();
System.out.println();
//
//