private void Parea(Tokens.Tipo tipo)
 {
     if (errorSintactico)
     {
         if (indice < listaTokens.Count - 1)
         {
             indice++;
             preAnalisis = listaTokens[indice];
             if (preAnalisis.tipo == Tokens.Tipo.punto_coma)
             {
                 errorSintactico = false;
             }
         }
     }
     else
     {
         if (preAnalisis.tipo == tipo)
         {
             if (indice < listaTokens.Count - 1)
         {
             
                 indice++;
                 preAnalisis = listaTokens[indice];
             }
         }
         else
         {
             Console.WriteLine("Error sintactico se esperaba[" + tipo.ToString() + "] en lugar de {" + preAnalisis.TipoToken + "," + "'" + preAnalisis.Lexema + "'" + "}");
             errorSintactico = true;
         }
     }
 }
Пример #2
0
 public void agregartoken(Tokens.Tipo tipo)
 {
     listaTokens.AddLast(new Tokens(tipo, auxlex, fila, columna));
     auxlex = "";
     estado = 0;
 }
Пример #3
0
        public List <Tokens> analizadorLexema(String entra)
        {
            entra  = entra + "#";
            estado = 0;

            Char c;

            int codigoascii = 0;

            for (int i = 0; i < entra.Length; i++)
            {
                c           = entra.ElementAt(i);
                letra       = entra[i];
                codigoascii = letra;
                switch (estado)
                {
                case 0:
                    if (letra == '\t' || letra == '\r' || letra == '\b' || letra == '\f' || letra == ' ')
                    {
                        estado = 0;
                    }
                    else if (letra == '\n')
                    {
                        fila  += 1;
                        estado = 0;
                    }
                    else if (Char.IsLetter(c))
                    {
                        auxlex += c;
                        estado  = 1;
                        columna++;
                    }
                    else if (Char.IsDigit(c))
                    {
                        auxlex += c;
                        columna++;
                        estado = 2;
                    }
                    else if (letra.Equals('+'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.mas);
                    }
                    else if (letra.Equals('-'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.menos);
                    }
                    else if (letra.Equals('*'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.asterisco);
                    }
                    else if (letra.Equals('/'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.diagonal);
                    }
                    else if (letra.Equals('('))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.parentesis_izquierdo);
                    }
                    else if (letra.Equals(')'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.parentesis_derecho);
                    }
                    else if (letra.Equals('='))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.igual);
                    }
                    else if (letra.Equals(';'))
                    {
                        auxlex += letra;
                        columna++;
                        agregarTokens(Tokens.Tipo.punto_coma);
                    }
                    else
                    {
                        if (letra.CompareTo('#') == 0 && i == entra.Length - 1 && c.CompareTo('#') == 0)
                        {
                        }
                        else
                        {
                            Console.WriteLine("Error desconocido" + " " + letra);
                            auxlex = "";
                            estado = 0;
                        }
                    }

                    break;

                case 1:
                    if (Char.IsLetter(c))
                    {
                        auxlex += c;
                        estado  = 1;
                    }
                    else if (Char.IsNumber(c))
                    {
                        auxlex += c;
                        estado  = 1;
                    }
                    else
                    {
                        Tokens.Tipo tipoaux = verificar();
                        agregarTokens(tipoaux);
                        i--;
                    }
                    break;

                case 2:
                    if (Char.IsDigit(c))
                    {
                        auxlex += c;
                        estado  = 2;
                    }
                    else
                    {
                        agregarTokens(Tokens.Tipo.numeros);
                        i -= 1;
                    }
                    break;

                default:
                    break;
                }
            }
            agregarTokens(Tokens.Tipo.SIMBOLOACEPTACION);
            return(listaTokens);
        }
Пример #4
0
 public void agregarTokens(Tokens.Tipo tipo)
 {
     listaTokens.Add(new Tokens(auxlex, tipo, fila, columna));
     auxlex = "";
     estado = 0;
 }
Пример #5
0
 private void AgregarToken3(string Lexema, int columna, int fila, int IdToken, Tokens.Tipo tipo)
 {
     TokensA.AddLast(new Tokens(Lexema, columna, fila, IdToken, tipo));
 }
Пример #6
0
 private void AgregarToken2(string Lexema, int columna, int fila, int IdToken, Tokens.Tipo tipo)
 {
     TokensA.AddLast(new Tokens(Lexema, columna, fila, IdToken, tipo));
     contadorLexico = "";
 }