• Miércoles 15 de Mayo de 2024, 15:57

Autor Tema:  Analizador Lexico  (Leído 3999 veces)

kichwz_dark

  • Nuevo Miembro
  • *
  • Mensajes: 24
    • Ver Perfil
Analizador Lexico
« en: Miércoles 4 de Octubre de 2006, 08:35 »
0
holaaa necesito ayuda kon un analizador lexico k tenog k hacer yale movipor todos lado y no me sale. alguien me puede ayudar oproporcioanr uno pero tiene k ser en java ¬¬ por favor me hurgeee si si sis is
[size=109] *DaRk*[/size]

kichwz_dark

  • Nuevo Miembro
  • *
  • Mensajes: 24
    • Ver Perfil
Re: Analizador Lexico
« Respuesta #1 en: Miércoles 4 de Octubre de 2006, 08:46 »
0
esta es un parte delcosigop k tneog y es un desastre natural jeje .ay :comp:
en silok tiene k hacer esleer un archivo .java y mostrarlo en pantalla su codigo fuente, leer linea por linea y decir si es numero entero o real o alguna de las de aceptacion o error
ejemplo: aki se lee el programa
1.-    import java.io.*;
2.-    class CuentaCaracteres
3.-    {
4.-        public static void main (String args []) throws IOException
5.-        {
6.-       int contador = 0;
7.-       while (System.in.read () != '\n')
8.-           contador++;
9.-       System.out.println (); // Retorno de carro "gratuito"
10.-       System.out.println ("Tecleados " + contador + " caracteres.");
11.-        }
12.-    }

y lok hace en si el analizador lexico seria esto

import                                              *** Indentificador import ***
java.io.*                                              *** Indentificador java.io.* ***
.                                              *** Delimitador . ***
.                                              *** Delimitador . ***
;                                              *** Delimitador ; ***
*                            *** Operador Aritmetico * ***
class                                              *** Indentificador class ***
CuentaCaracteres{                                              *** Indentificador CuentaCaracteres{ ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
public                                              *** Indentificador public ***
static                                              *** Indentificador static ***
void                                              *** Indentificador void ***
main                                              *** Indentificador main ***
                                              *** Indentificador  ***
(                                              *** Delimitador ( ***
String                                              *** Indentificador String ***
args                                              *** Indentificador args ***
[]                                              *** Indentificador [] ***
)                                              *** Delimitador ) ***
                                              *** Indentificador  ***
throws                                              *** Indentificador throws ***
IOException                                              *** Indentificador IOException ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
{   int                                              *** Indentificador {   int ***
contador                                              *** Indentificador contador ***
=                                    *** Operador Relacional = ***
0                                              *** Indentificador 0 ***
   while                                              *** Indentificador    while ***
                                              *** Indentificador  ***
System.in.read                                              *** Indentificador System.in.read ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
==                                    *** Operador Relacional == ***
'\n'                                              *** Indentificador '\n' ***
                                                 *** Indentificador     ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
contador++                                              *** Indentificador contador++ ***
+                            *** Operador Aritmetico + ***
+                            *** Operador Aritmetico + ***
   System.out.println                                              *** Indentificador    System.out.println ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
//                                              *** Indentificador // ***
/                            *** Operador Aritmetico / ***
/                            *** Operador Aritmetico / ***
Retorno                                              *** Indentificador Retorno ***
de                                              *** Indentificador de ***
carro                                              *** Indentificador carro ***
                                              *** Indentificador  ***
gratuito                                              *** Indentificador gratuito ***
   System.out.println                                              *** Indentificador    System.out.println ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
Tecleados                                              *** Indentificador Tecleados ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
+                                              *** Indentificador + ***
+                            *** Operador Aritmetico + ***
contador                                              *** Indentificador contador ***
+                                              *** Indentificador + ***
+                            *** Operador Aritmetico + ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
caracteres.                                              *** Indentificador caracteres. ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***
                                              *** Indentificador  ***

 



y este esel peke programa k tengo o mini codigo pro k me falta mucho
////////////////////////////////////////////////+

import java.lang.*;
import java.lang.Object.*;
import java.util.*;
import java.io.*;
//import System.*;

public class lexico
{
    //public static void main (String [] args) throws IOException{
    String s [] = new String [100000];
    private int [] [] mat = new int [50] [60];
    //para crear el vector de las palabras reservadas.
    String reser [] = {"Array", "Else", "For", "Exit", "Repeat", "To", "True", "Char", "Begin", "Writeln", "If", "Not", "Return", "Until", "False", "String", "Case", "Readln", "Loop", "Of", "Procedure", "Var", "Div", "Byte", "Const", "Else", "Module", "Mod", "By", "While", "Integer", "Boolean", "Do", "End", "Function", "Record", "Then", "With", "Real",
        "array", "else", "for", "exit", "repeat", "to", "true", "char", "begin", "writeln", "if", "not", "return", "until", "false", "string", "case", "readln", "loop", "of", "procedure", "var", "div", "byte", "const", "else", "module", "mod", "by", "while", "integer", "boolean", "do", "end", "function", "record", "then", "with", "real",
        "ARRAY", "ELSE", "FOR", "EXIT", "REPEAT", "TO", "TRUE", "CHAR", "BEGIN", "WRITELN", "IF", "NOT", "RETURN", "UNTIL", "FALSE", "STRING", "CASE", "READLN", "LOOP", "OF", "PROCEDURE", "VAR", "DIV", "BYTE", "CONST", "ELSE", "MODULE", "MOD", "BY", "WHILE", "INTEGER", "BOOLEAN", "DO", "END", "FUNCTION", "RECORD", "THEN", "WITH", "REAL"};
//para crear un vector kon la tabla de simbolos sacada de un AFND    
String edo1 [] [] = {{"7", "1", "14", "15", "203", "203", "203", "107", "106", "125", "126", "127", "128", "129", "13", "12", "130", "9", "121", "110", "116", "10", "11", "203", "203", "135", "203", "16", "138", "137"},
        {"100", "100", "100", "2", "2", "4", "4", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100", "100"},
        {"200", "3", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200", "200"},
        {"101", "3", "101", "101", "101", "4", "4", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101", "101"},
        {"201", "6", "5", "5", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201", "201"},
        {"202", "6", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202", "202"},
        {"102", "6", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102"},
        {"102", "6", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102", "102"},
        {"7", "7", "103", "8", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103", "103"},
        {"7", "7", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204", "204"},
        {"121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121", "121"},
        {"111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "111", "114", "111", "111", "111", "111", "111", },
        {"112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "112", "113", "112", "112", "112", "112", "112", "112"},
        {"131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "131", "207", "131", "131", "131"},
        {"132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "132", "207", "132", "132", "132"},
        {"208", "133", "14", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208 ", "208", "208", "208", "208", "208"},
        {"133", "134", "208", "14", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208", "208"},
        {"209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "209", "135", "209", "209", "209"}

        };

    public void aceptacion (int t)
    {
        int constante;
        for (int a = 0 ; a <= constante ; a++)
        {
            if (edo1 [a] < 200)
            {
                switch (edo1 [t])
                {
                    case 100:
                        //System.out.println (" Constante Entera");
                        s [t] = "Constante Numerica";
                        break;
                    case 101:
                        //System.out.println (" constante Real");
                        s [t] = "Constante Real";
                        break;
                    case 102:
                        //System.out.println (" Constante de Notacion Cientifica");
                        s [t] = " Constante Notacion Cientifica";
                        break;
                    case 103:
                        //System.out.println ("Identificador");
                        s [t] = "Identificador";
                        break;
                    case 104:
                        //System.out.println ("Operacion Aritmetico +");
                        s [t] = "Operacion Aritmetica + ";
                        break;
                    case 105:
                        //System.out.println ("Operacion Aritmetico  -");
                        s [t] = "Operacion Aritmerica - ";
                        break;
                    case 106:
                        //System.out.println ("Operacion Aritmetico  *");
                        s [t] = "operacion Aritmetica *";
                        break;
                    case 107:
                        //System.out.println ("Operacion Aritmetico /");
                        s [t] = "Operacion Aritmetica / ";
                        break;
                    case 108:
                        //System.out.println ("Delimitador ,");
                        s [t] = "Delimitador , ";
                        break;
                    case 109:
                        //System.out.println ("Delimitador ;");
                        s [t] = "Delimitador ; ";
                        break;
                    case 110:
                        //System.out.println ("Operacion de Asignacion :=");
                        s [t] = "Operacion de Asignacion :=";
                        break;
                    case 111:
                        //System.out.println ("Operacion Relacional >");
                        s [t] = "Operacion Relacional > ";
                        break;
                    case 112:
                        //System.out.println ("Operacion Relacional <");
                        s [t] = "Operacion Relacional <";
                        break;
                    case 113:
                        //System.out.println ("Operacion Relacional >=");
                        s [t] = "Operacion Relacional >=";
                        break;
                    case 114:
                        //System.out.println ("Operacion Relacional <=");
                        s [t] = "Operacion Relacional <=";
                        break;
                    case 115:
                        //System.out.println ("Operacion Relacional !=");
                        s [t] = "Operacion Relacional !=";
                        break;
                    case 116:
                        //System.out.println ("Operacion Relacional =");
                        s [t] = "Operacion Relacional =";
                        break;
                    case 117:
                        //System.out.println ("Separador \t");
                        s [t] = "Separador /T ";
                        break;
                    case 118:
                        //System.out.println ("Separador \in");
                        s [t] = "Separador /in ";
                        break;
                    case 119:
                        //System.out.println ("Fin de Archivo");
                        s [t] = "Fin de Archivo ";
                        break;
                    case 120:
                        //System.out.println ("separador \n");
                        s [t] = "Separador /n ";
                        break;
                    case 121:
                        //System.out.println ("Delimitador ;");
                        s [t] = "Delimitador ; ";
                        break;
                    case 122:
                        //System.out.println ("Delimitador :");
                        s [t] = "Delimitador : ";
                        break;
                    case 123:
                        //System.out.println ("Delimitador , ");
                        s [t] = "Delimitador , ";
                        break;
                    case 124:
                        //ystem.out.println ("Delimitador (");
                        s [t] = "Delimitador (";
                        break;
                    case 125:
                        //System.out.println ("Delimitador )");
                        s [t] = "Delimitador )";
                        break;
                    case 126:
                        //System.out.println ("Delimitador [");
                        s [t] = "Delimitador [";
                        break;
                    case 127:
                        //System.out.println ("Delimitador ]");
                        s [t] = "Delimitador ]";
                        break;
                    case 128:
                        //System.out.println ("Delimitador #");
                        s [t] = "Delimitador #";
                        break;
                    case 129:
                        //System.out.println ("Delimitador &");
                        s [t] = "Delimitador &";
                        break;
                    case 130:
                        //System.out.println ("Delimitador de Comilla simple '");
                        s [t] = "Delimitador ' ";
                        break;
                    case 131:
                        //System.out.println ("Delimitador de comilla Doble  ");
                        s [t] = "Delimitador de doble comilla ";
                        break;
                    case 132:
                        //System.out.println ("Operacion Incrementa ++");
                        s [t] = "Operador Incrementa ++";
                        break;
                    case 133:
                        // System.out.println ("operacion Decrementa --");
                        s [t] = "Operador Decrementa --";
                        break;
                    case 134:
                        //System.out.println ("Operador Logico AND ||");
                        s [t] = "operador Logico And ||";
                        break;
                    case 135:
                        //System.out.println ("Operador Logico de Negacion !");
                        s [t] = "Operador logico de negacion ! ";
                        break;
                    case 136:
                        //System.out.println ("Operador Logico AND &");
                        s [t] = "Operador Logico And & ";
                        break;
                    case 137:
                        //System.out.println ("Operador Logico OR |");
                        s [t] = "Operador Logico Or |";
                    default:
                        s [t] = "Desconosico";
                        break;
                }
            }
            else (edo []....// me falta unkodigo ya k el profe no me explico todo¬¬
            {
             }
        }
    }

// errores
    public void error (int d)
    {
        int constante1;
        for (int b = 0 ; b <= constante1 ; b++)
        {
            if (edo1 > 200)
            {
                switch (B)
                {
                    case 201:
                        //System.out.println (" Erorr de lexico, se esperaba, ");
                        s [d] = "Error Lexico, se esperaba una ,";
                        break;
                    case 202:
                        //System.out.println (" Erorr de lexico, -|+ despues de E|e");
                        s [d] = "Error Lexico, -|+ despues de E|e";
                        break;
                    case 203:
                        //System.out.println (" Cadena no valida");
                        s [d] = "Cadena no valida";
                        break;
                    case 204:
                        s [d] = " Error no es operador Aritmetico";
                        break;
                    case 205:
                        s [d] = "Error no es un Delimitador";
                        break;
                    case 206:
                        s [d] = "Error no es Operador Relacional";
                        break;
                    case 207:
                        s [d] = "Falta o Sobrea una Comilla";
                        break;
                    case 208:
                        s [d] = "Error falta o Sobra + o -";
                        break;
                    default:
                        s [d] = "Desconocido";
                        break;
                }
            }
            else
            {
            }
        }
    }


    public void busca_col (char c)

    {
        //no se si va aki o arriva del { jiji (el int)
        int busca_col; // (void);
        //  c = nuevocaracter (); //funcion del sistema entrada
        switch ©
        {
            case ' ':
                //    case '/t':
                //    case '/n':
                break;           //no hace nada para los separadores
            case '+':
            case '-':
                return (op_suma_resta);
            case '*':
            case '/':
                return (op_multiplicar);
            case ',':
            case ';':
                return (op_asignacion);
            case '>':
            case '<':
                //      case '>= ':     se supone k estos los debometer a un string
                //      case '<= ':
                //      case '<> ':
                //      case '==':
                return (op_relacion);
            case ':':
            case ',':
            case '(':
            case ')':
            case '[':
            case ']':
            case '#':
                //     case '&&':
                //case ' ' ':
            case '"':
                return (delimitador);
                //     case '++':
                //     case '--':
                //         return (incremeta_decrementa);
                //      case '||':
            case '!':
            case '&':
            case '|':
                return (operador_logico);
            default:
                if (Character.isdigit©)== true)
                {
                    //se leenlos caracteres mientras sean numeros y se retornan
                    //al flujo de entrada del ultimo caracter leido, se guarda el lexema
                    //leido y se retorna con el testigo NUMERO_ENTERO
                    //return (num_entero);
                }
                else if(Character.isLetter(s.charAt©)==false)
                    {
                      return(-1);
                 
                    /*se leen caracteres mientras sean letras o numeros y se retorna al  flujo de entrada
                    el ultimo caracter es leido, se guarda el lexema leido y se comprueba si es una
                    palabr clave. se retorna IDENTIFICADOR o la palabra clave*/

                }
               
        }
    }


    //public boolean isletter (char ch)
    //Indica si el carcter Unicode especificado se clasifica por categoras como un carcter alfabtico.
    public static boolean IsLetter (char c)
    {
        c = 0;
        switch ©
        {
            case 'a':
                break;

            case 'b':
                break;

            case 'c':
                break;

            case 'd':
                break;

            case 'e':
                break;

            case 'f':
                break;

            case 'g':
                break;

            case 'h':
                break;

            case 'i':
                break;

            case 'j':
                break;

            case 'k':
                break;

            case 'l':
                break;

            case 'm':
                break;

            case 'n':
                break;

            case 'o':
                break;

            case 'p':
                break;

            case 'q':
                break;

            case 'r':
                break;

            case 's':
                break;

            case 't':
                break;

            case 'u':
                break;

            case 'v':
                break;

            case 'w':
                break;

            case 'x':
                break;

            case 'y':
                break;

            case 'z':
                System.out.println ("es una letra del Vocabulario");
            default:
                System.out.println (" error no es letra");
        }
    }

//
    public Boolean Tokens ()
    {
        char cad; // almacena caracteres de texto
        int edo = 0;
        int col = 0;

        while (!feof ())
        {
            edo = 0;
            while (edo >= 0 && edo <= 6)
            {
                cad = leer_caracter (); // falta leer_caracter
                col = busca_col (cad); //
                edo = mat [edo] [col];
            }
            if (edo >= 100 && edo <= 101)
                aceptacion (edo);
            else
                error (edo);
        }
    }
}
[size=109] *DaRk*[/size]

kichwz_dark

  • Nuevo Miembro
  • *
  • Mensajes: 24
    • Ver Perfil
Re: Analizador Lexico
« Respuesta #2 en: Miércoles 4 de Octubre de 2006, 08:55 »
0
losk me puedan ayudar porrr favorrrrr envienme  unkorreo a kmaskieresdelmundo@hotmail.com
pleaseeeeeeeeeeee

p.d.

este es uno ya echooo perolo kiero diferente jaja  :ph34r:

-------------------------------------------------------------

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.util.*;


public class ps32 extends Frame implements ActionListener, ItemListener
{
    private TextArea areaTextoEntrada;
    private TextArea areaerrores;
    private Button abrir, abrir1;
    private Button compilar;
    private BufferedReader archivoEntrada, archivoEntrada1;
    private TextField nombreCampo;
    private Button cargarBoton, cargarBoton1;
    private FileDialog obtenerNombreCuadro;
    private PrintWriter archivoSalida;

    char parentesis1 = '(';
    char parentesis2 = ')';
    char corchete1 = '[';
    char corchete2 = ']';
    char coma = ',';
    char punto = '.';
    char puntoycoma = ';';
    char dospuntos = ':';
    char gato = '#';
    char and = '&';
    char comillas = '"';
    MenuBar menuBar;
    Menu menu;
    MenuItem menuItem, exit, open, como, creadores;
    String nombreArchivo;
    String vlinea [] = new String [3000];
    String vpalabras [] = new String [100000];
    String vpalabras3 [] = new String [100000];
    String vtokens [] = new String [1000];
    int z = 0;
    int aux = 0;
    int apuntador = 0;
    int pal = 0, xxx = 0, tok = 0;
    private String preservadas [] = {"array", "begin", "case", "const", "do", "else",
        "writeln", "readln", "elseif", "end", "for",
        "if", "loop", "module", "function", "exit",
        "not", "of", "mod", "record", "repeat", "return",
        "procedure", "by", "then", "to", "until", "var",
        "while", "with", "true", "false", "div", "integer",
        "real", "char", "string", "byte", "boolean"};

    int matriz [] [] = {
        {7, 1, 104, 105, 106, 107, 111, 112, 113, 114, 108, 17, 109, 9, 203, 203, 16, 15, 11, 10, 127, 203, 203, 203, 203, 203, 203, 203, 12, 203},
        {100, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 2, 100, 100, 100, 100, 100, 100, 100, 100, 100, 4, 4, 100, 100, 100, 100, 100, 100, 100},
        {200, 3, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200},
        {101, 3, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 4, 4, 101, 101, 101, 101, 101, 101, 101},
        {201, 6, 5, 5, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201},
        {102, 6, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102},
        {7, 7, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 8, 103, 103, 103, 103, 103, 103},
        {8, 8, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204},
        {116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110},
        {123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 126, 123, 125, 123, 123, 123, 123, 123, 123, 123, 123, 123},
        {122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, 124, 122, 122, 122, 122, 122, 122, 122, 122, 122},
        {203, 203, 203, 203, 13, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203},
        {13, 13, 13, 13, 13, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13},
        {203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 129},
        {15, 15, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 121, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203},
        {16, 16, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 120, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203},
        {115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 117, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115},
        };

    ps32 ()
    {
        menuBar = new MenuBar ();
        setMenuBar (menuBar);

        menu = new Menu ("Archivo");
        menuBar.add (menu);

        open = new MenuItem ("Abrir");
        open.addActionListener (this);
        menu.add (open);

        exit = new MenuItem ("Salir");
        exit.addActionListener (this);
        menu.add (exit);

        menu = new Menu ("Ayuda");
        menuBar.add (menu);

        como = new MenuItem ("Como usar el analizador lexico");
        como.addActionListener (this);
        menu.add (como);

        creadores = new MenuItem ("Integrantes");
        creadores.addActionListener (this);
        menu.add (creadores);
    } //Cierra Constructor


    public static void main (String [] args)
    {
        ps32 window = new ps32 ();
        window.addWindowListener (new WindowAdapter ()
        {
            public void windowClosing (WindowEvent e)
            {
                System.exit (0);
            }
        }
        );
        window.setSize (720, 700);
        window.setLocation (200, 20);
        window.crearGui ();
        window.setTitle ("Analizador Lexico");
        window.setVisible (true);
    } //cierra main


    public void crearGui ()
    {
        cargarBoton = new Button ("Explorar");
        //cargarBoton.setMnemonic (KeyEvent.VK_E);
        Panel superior = new Panel ();
        abrir = new Button ("Abrir");
        //abrir.setMnemonic (KeyEvent.VK_A);
        compilar = new Button ("Compilar");
        //compilar.setMnemonic (KeyEvent.VK_C);
        nombreCampo = new TextField (40);
        superior.add (nombreCampo);
        nombreCampo.addActionListener (this);
        superior.add (abrir);
        cargarBoton = new Button ("Explorar");
        cargarBoton.addActionListener (this);
        superior.add (cargarBoton);
        superior.add (compilar);
        abrir.addActionListener (this);
        compilar.addActionListener (this);
        add ("North", superior);
        areaTextoEntrada = new TextArea ("", 10, 50);
        add ("Center", areaTextoEntrada);
        areaTextoEntrada.setEditable (false);
        areaerrores = new TextArea ("", 10, 5);
        areaerrores.setEditable (false);
        add ("South", areaerrores);
    } //cierra crearGui


    public void actionPerformed (ActionEvent evt)
    {
        if (evt.getSource () == compilar)
        {
            compilar ();
        }
        if (evt.getSource () == creadores)
        {
            integrantes ();
        }
        if (evt.getSource () == como)
        {
            ayuda ();
        }
        if (evt.getSource () == exit)
        {
            System.exit (0);
        }
        if (evt.getSource () == open)
        {
            explorar ();
        }
        if (evt.getSource () == cargarBoton)
        {
            explorar ();
        } //cierra cargarBoton
        if (evt.getSource () == abrir)
        {
            abrir ();
        } //cierra if
    } //cierra ActionEvent


    public void abrir ()
    {
        nombreArchivo = nombreCampo.getText ();
        try
        {
            archivoEntrada = new BufferedReader (
                    new FileReader (nombreArchivo));
            areaTextoEntrada.setText (""); //limpia area de entrada
            areaerrores.setText ("");
            String linea;
            int n = 1;
            while ((linea = archivoEntrada.readLine ()) != null)
            {
                areaTextoEntrada.append (n + ".-    " + linea + "\n");
                n++;
            } //cierra while
            archivoEntrada.close ();
        } //cierra try
        catch (IOException e)
        {
            System.err.println ("Error en Archivo"
                    + nombreArchivo + ": " + e.toString ());
            final Frame ferror = new Frame ("Mensaje de Error");
            Panel perror = new Panel ();
            Panel kikerror = new Panel ();
            Button aceptar = new Button ("Aceptar");
            Label error = new Label ("Error al abrir Archivo ");
            Label error2 = new Label (nombreArchivo);
            Label error3 = new Label ("No se encontro la ruta ");
            Label error4 = new Label ("El archivo no existe ");
            Label nada1 = new Label (" ");
            Label nada2 = new Label (" ");
            perror.add (error);
            perror.add (error2);
            perror.add (error3);
            perror.add (error4);
            kikerror.add (nada1);
            kikerror.add (aceptar);
            kikerror.add (nada2);
            perror.setLayout (new GridLayout (2, 2));
            ferror.add ("North", perror);
            ferror.add ("South", kikerror);
            ferror.setSize (300, 110);
            ferror.setLocation (400, 200);
            ferror.setVisible (true);


            aceptar.addActionListener (new ActionListener ()
            {

                public void actionPerformed (ActionEvent ex)
                {
                    ferror.setVisible (false);
                }
            }
            );



        } //Cierra Catch
    } //Cierra if


    public void explorar ()
    {
        obtenerNombreCuadro = new FileDialog (this, "Explorar", FileDialog.LOAD);
        obtenerNombreCuadro.show ();

        // mostrar el nombre
        nombreArchivo = "" + nombreArchivo;
        nombreArchivo = obtenerNombreCuadro.getFile ();
        nombreCampo.setText (nombreArchivo);
    } //cierra abrir


    public void ayuda ()
    {
        Frame fayuda = new Frame ("Ayuda");
        Panel payuda = new Panel ();
        Button salir = new Button ("Salir");
        Label ayuda = new Label ("---- Instrucciones de uso ----");
        Label ayuda1 = new Label ("1.- Escriba la direccion del programa a compilar");
        Label ayuda2 = new Label ("2.- Puede usar el boton explorar para abrir el programa a compilar ");
        Label ayuda4 = new Label ("3.- Cuando este la ruta del programa use el boton Abrir");
        Label ayuda3 = new Label ("4.- Oprima el boton compilar para revisar errores en el programa");
        payuda.add (ayuda);
        payuda.add (ayuda1);
        payuda.add (ayuda2);
        payuda.add (ayuda4);
        payuda.add (ayuda3);
        fayuda.add (payuda);
        fayuda.setSize (400, 150);
        fayuda.setLocation (400, 200);
        fayuda.setTitle ("Como usar el analizador lexico");
        fayuda.setVisible (true);
    } //cierra funcion ayuda


    public void compilar ()
    {
        z = 0;
        nombreArchivo = nombreCampo.getText ();
        try
        {
            archivoEntrada = new BufferedReader (
                    new FileReader (nombreArchivo));
            areaerrores.setText (""); //limpia area de errores
            String linea;
            String aux;
            int n = 1;
            while ((linea = archivoEntrada.readLine ()) != null)
            {
                aux = linea;
                vlinea [z] = aux;
                z++;
                n++;
            } //cierra while
            archivoEntrada.close ();
        } //cierra try
        catch (IOException e)
        {
            System.err.println ("Error en Archivo"
                    + nombreArchivo + ": " + e.toString ());
            final Frame ferror = new Frame ("Mensaje de Error");
            Panel perror = new Panel ();
            Panel kikerror = new Panel ();
            Button aceptar = new Button ("Aceptar");
            Label error = new Label ("Error al compilar Archivo ");
            Label error2 = new Label (nombreArchivo);
            Label error3 = new Label ("No se encontro la ruta ");
            Label error4 = new Label ("El archivo no existe ");
            Label nada1 = new Label (" ");
            Label nada2 = new Label (" ");
            perror.add (error);
            perror.add (error2);
            perror.add (error3);
            perror.add (error4);
            kikerror.add (nada1);
            kikerror.add (aceptar);
            kikerror.add (nada2);
            perror.setLayout (new GridLayout (2, 2));
            ferror.add ("North", perror);
            ferror.add ("South", kikerror);
            ferror.setSize (300, 110);
            ferror.setLocation (400, 200);
            ferror.setVisible (true);


            aceptar.addActionListener (new ActionListener ()
            {

                public void actionPerformed (ActionEvent es)
                {
                    ferror.setVisible (false);
                }
            }
            );
        } //Cierra Catch


        //Comienza lo chido

        String palabra = "";
        char c = '\0';
        String linea = "";
        int lon = 0;
        pal = 0;

        for (int k = 0 ; k < z ; k++)
        {
            apuntador++;
            linea = vlinea [k];
            lon = linea.length ();

            for (int l = 0 ; l < lon ; l++)
            {
                c = linea.charAt (l);

                if ((c == ' ') || (c == puntoycoma) || (c == parentesis1) || (c == parentesis2) || (c == coma) || (c == dospuntos) || (c == gato) || (c == and) || (c == comillas))
                {
                    c = '\0';
                    c = linea.charAt (l);
                    palabra = palabra + c;
                    vpalabras [pal] = palabra;
                    pal++;
                    xxx++;
                    palabra = "";
                    c = '\0';
                } //cierra if de validaciones

                else
                {
                    palabra = palabra + c;
                }
            } //cierra for l

        } //Cierra for k


        preservadas2 ();
    } //cierra compilar



    public void integrantes ()
    {
        Frame fintegrantes = new Frame ("Integrantes");
        Panel pintegrantes = new Panel ();
        Label l1 = new Label ("Integrantes:");
        Label l2 = new Label ("Gonzlez Martnez Luis Enrique     04041011");
        Label l3 = new Label ("Rios Nuez Jesus Gustavo             04041036");
        Label l4 = new Label ("Solis Guerrero Sara Berenice         04041045");
        pintegrantes.add (l1);
        pintegrantes.add (l2);
        pintegrantes.add (l3);
        pintegrantes.add (l4);
        fintegrantes.add (pintegrantes);
        fintegrantes.setSize (280, 120);
        fintegrantes.setLocation (400, 200);
        fintegrantes.setVisible (true);
    } //cierra funcion integrantes


    public void preservadas2 ()
    {
        int bandera = 0;
        int p = 0;
        String non = "";
        char ari [] = {'+', '-', '*', '/'};
        String deli [] = {"(", ")", "[", "]", ".", ";", ":", "..", "#", "&", "'", ",", "{"};
        String relacionales [] = {"<", ">", "=", "<=", ">="};
        String palabra = "";
        String acomp = "";
        String reser = "";
        String vlogi = "";
        String d = "";
        String vlogicos [] = {"and", "or", "not"};
        char vector [] = new char [100];
        char c = '\0';
        char b = '\0';
        aux = 0;
        String linea = "";
        int lon = 0;
        int ayuda = 0;
        for (int k = 0 ; k < xxx ; k++)
        {
            bandera = 0;
            linea = vpalabras [k];
            lon = linea.length ();
            for (int l = 0 ; l < lon - 1 ; l++)
            {
                c = linea.charAt (l);
                palabra = palabra + c;
            } //cierra for l
            vpalabras3 [aux] = palabra;

            palabra = "";
            acomp = vpalabras3 [p];
            for (int r = 0 ; r < 39 ; r++)
            {
                reser = preservadas [r];
                if (reser.equals (acomp))
                {
                    areaerrores.append (acomp + "                            *** Palabra Reservada " + acomp + " *** \n");
                    bandera = 1;
                } //Cierra if
            } //Cierra for r
            acomp = vpalabras3 [p];
            for (int i = 0 ; i < 3 ; i++)
            {
                vlogi = vlogicos ;
                if (vlogi.equals (acomp))
                {
                    areaerrores.append (acomp + "                                     *** Operador Logico " + acomp + " *** \n");
                    bandera = 1;
                } //Cierra if

            } //Cierra for     i
            linea = vpalabras [k];
            lon = 0;
            lon = linea.length ();
            for (int l = 0 ; l < lon ; l++)
            {
                c = '\0';
                c = linea.charAt (l);
                if ((c == '<') || (c == '>') || (c == '='))
                {
                    d = "";
                    d = d + c;
                    b = linea.charAt (+ 1);
                    bandera = 1;
                    if ((b == '=') || (b == '>'))
                    {
                        d = d + b;
                        b = '\0';
                        l = l + 1;
                        bandera = 1;
                    }
                    areaerrores.append (d + "                                    *** Operador Relacional " + d + " *** \n");
                } //Cierra if
            } //Cierra k



            if (bandera == 0)
            {
                non = vpalabras3 [p];
                if ((non.equals ("[")) || (non.equals ("]")))
                {
                    areaerrores.append (non + "                                              *** Delimitador " + non + " *** \n");
                }
                else
                {
                    areaerrores.append (non + "                                              *** Indentificador " + non + " ***\n");
                }
                non = "";
            }

            linea = vpalabras [k];
            lon = 0;
            lon = linea.length ();
            for (int i = 0 ; i < lon ; i++)
            {
                c = '\0';
                c = linea.charAt (i);
                if ((c == ',') || (c == '.') || (c == ';') || (c == '(') || (c == ')') || (c == ':') || (c == '#') || (c == '&') || (c == '"'))
                {
                    d = d + c;
                    for (int j = 0 ; j < 13 ; j++)
                    {
                        if (d.equals (deli [j]))
                        {
                            areaerrores.append (d + "                                              *** Delimitador " + d + " *** \n");
                            d = "";
                            bandera = 1;
                        } //cierra if
                    } // cierra j
                } //Cierra if
            } //Cierra k


            lon = 0;
            lon = linea.length ();
            for (int l = 0 ; l < lon ; l++)
            {
                c = '\0';
                c = linea.charAt (l);
                if ((c == '+') || (c == '-') || (c == '*') || (c == '/'))
                {
                    for (int j = 0 ; j < 4 ; j++)
                    {
                        if (c == ari [j])
                        {
                            areaerrores.append (c + "                            *** Operador Aritmetico " + c + " *** \n");
                            c = '\0';
                            bandera = 1;
                        } //cierra if
                    } // cierra j
                } //Cierra if
            } //Cierra l


            aux++;
            p++;
        } //Cierra for k
        grabar ();
    } //Cierra palabras reservadas2




    public void grabar ()
    {
        try
        {
            archivoSalida = new PrintWriter (
                    new FileWriter ("tokens.txt"), true);
            archivoSalida.print (areaerrores.getText ());
            archivoSalida.close ();
        }
        catch (IOException e)
        {
            System.err.println ("Error al guardar Archivo: " + e.toString ());
        }
        areaerrores.append ("\n \n \n");
        areaerrores.append ("                                                         *** Archivo de Texto creado con los tokens *** \n");
        areaerrores.append ("                                                                 *** La ruta es C:/ tokens.txt ***");
    } //Cierra funcion Grabar


    public void itemStateChanged (ItemEvent e)
    {
        MenuItem source = (MenuItem) (e.getSource ());
    }


    public void windowClosing (WindowEvent e)
    {
        System.exit (0);
    }


    public void windowIconifield (WindowEvent e)
    {
    }


    public void windowOpened (WindowEvent e)
    {
    }


    public void windowClosed (WindowEvent e)
    {
    }


    public void windowDeiconified (WindowEvent e)
    {
    }


    public void windowActivated (WindowEvent e)
    {
    }


    public void windowDeactivated (WindowEvent e)
    {
    }
} //cierra class
[size=109] *DaRk*[/size]