public void analizar(Boolean reAnalisis, LinkedList <Token> tokens)
 {
     this.tokens = tokens;
     errores.Clear();
     if (reAnalisis)
     {
         estadoActual = estadoSubInicial;
     }
     else
     {
         estadoActual = estadoInicial;
     }
     for (int j = 0; j < tokens.Count; j++)
     {
         Token token = tokens.ElementAt <Token>(j);
         valorActual = token.getTipo();
         if (!EncontrarSiguiente(token.getTipo()))
         {
             if (aceptacion)
             {
                 Console.WriteLine("TODO BIEN");
                 estadoActual = "S6";
                 j--;
             }
             else
             {
                 guardarErrores();
                 break;
             }
         }
         else if (valorActual.Equals("llave apertura"))
         {
             LinkedList <Token> temporal = buscarLlaves(j);
             if (temporal != null)
             {
                 this.analizador = new AnalizadorSintactico();
                 this.analizador.analizar(true, temporal);
                 j += temporal.Count;
             }
             else
             {
                 Console.WriteLine("VACIA");
             }
         }
     }
     estadoActual = estadoInicial;
 }
        public void analizar(RichTextBox textBox)
        {
            analizador = new AnalizadorSintactico();
            char[]  chars          = textBox.Text.ToCharArray();
            int     posicion       = 0;
            int     tamañoTemporal = 0;
            Boolean regreso        = false;

            if (textBox.Lines.Length <= 0)
            {
                MessageBox.Show("Sin texto que analizar");
                return;
            }
            estadoActual = estadoInicial;
            for (int i = 0; i < textBox.Lines.Length; i++)
            {
                char[] linea = textBox.Lines[i].ToCharArray();
                for (int j = 0; j < linea.Length; j++)
                {
                    preToken preToken = new preToken();
                    preToken.setValue(linea[j]);
                    char temporal = linea[j];
                    Console.WriteLine(temporal + "");
                    Console.WriteLine(posicion + "");

                    if (preToken.setTipo(temporal) == false && !preToken.isSymbol())
                    {
                    }
                    else
                    {
                        if (EncontrarSiguiente(preToken.getTipo()))
                        {
                            valor += temporal;
                            tamañoTemporal++;
                            if (j == linea.Length - 1 && aceptacion)
                            {
                                Console.WriteLine("Si llegue a GUARDAR TOKEN" + tamañoTemporal);
                                Token token = new Token(tipo, valor, valor.Length, posicion - valor.Length, i + 1);
                                guardarToken(token, ref tamañoTemporal);
                            }
                        }
                        else
                        {
                            if (aceptacion)
                            {
                                Token token = new Token(tipo, valor, valor.Length, posicion - valor.Length, i + 1);
                                guardarToken(token, ref tamañoTemporal);
                                j--;
                                posicion--;

                                regreso = true;
                            }
                            else if (preToken.isSymbol())
                            {
                                Token token = new Token(preToken.GetTipo(), temporal + "", 1, posicion - valor.Length, i + 1);
                                guardarToken(token, ref tamañoTemporal);
                            }
                            else
                            {
                                if (temporal != (char)32 && temporal != (char)9)
                                {
                                    valor += temporal;
                                    Console.WriteLine("Si llegue a GUARDAR ERROR");
                                    Token token = new Token(preToken.GetTipo(), temporal + "", 1, posicion - valor.Length, i + 1);
                                    errores.AddLast(token);
                                    valor          = "";
                                    estadoActual   = "S0";
                                    tamañoTemporal = 0;
                                }
                            }
                        }
                    }
                    posicion++;
                }
                posicion++;
            }
            imprimirTokens();

            Pintor pintor = new Pintor();

            pintor.pintar(textBox, tokens);
            if (errores.Count > 0)
            {
                MessageBox.Show("Errores encontrados");
            }
            analizador.analizar(false, tokens);
            tokens.Clear();
        }
 public AnalizadorLexico()
 {
     this.analizador = new AnalizadorSintactico();
 }