import java.io.StreamTokenizer; import java.io.*; /** * Clase para generar una lista de palabras no reservadas cada una con una lista * con el numero de linea en que aparece * @author Amparo López Gaona * @version 1a. ed. */ public class ListaPalabrasNoReservadas { static String [] palabras = new String[100]; static int nPalabras = 0; public static boolean palRes(String palabra) { for (int i= 0; i < nPalabras; i++) if (palabras[i].equals(palabra)) return true; return false; } public static void leerReservadas(String s) { try { BufferedReader in = new BufferedReader (new FileReader(s)); StreamTokenizer tok = new StreamTokenizer(in); tok.ordinaryChar('.'); int tipoTok = tok.nextToken(); while (tipoTok != StreamTokenizer.TT_EOF) { if (tipoTok == StreamTokenizer.TT_WORD) palabras[nPalabras++] = tok.sval; tipoTok = tok.nextToken(); } for (int k= 0; k < nPalabras ; k++) System.out.print(palabras[k]+" "); } catch(IOException e) { System.out.println("Se genero IOException "+e); } } public static void main (String [] pps) { ListaDeIdentificadores lisId = new ListaDeIdentificadores(); int tipoTok; if (pps.length != 2) { System.out.println("Uso: ListaPalabrasReservadas archivoFuente"); System.exit(0); } leerReservadas(pps[0]); try { BufferedReader in = new BufferedReader (new FileReader(pps[1])); StreamTokenizer tok = new StreamTokenizer(in); tok.ordinaryChar('.'); tipoTok = tok.nextToken(); while (tipoTok != StreamTokenizer.TT_EOF) { if (tipoTok == StreamTokenizer.TT_WORD) if (! palRes(tok.sval)) lisId.insertar(tok.sval, new Integer(tok.lineno())); tipoTok = tok.nextToken(); } lisId.imprimir(); } catch(IOException e) { System.out.println("Se genero IOException "+e); } } }