示例#1
0
        private ArrayList elementos; //Valor

        #endregion Fields

        #region Constructors

        public ValorArreglo(Arreglo tipo)
        {
            ArrayList dimensiones = tipo.Rangos; //Dimensiones Expresiones
            Valor tmpsize = ((Expresiones) (dimensiones[0])).interpretar();
            int size = ((ValorEntero)tmpsize).Valor;
            for (int i = 1; i < dimensiones.Count; i++)
            {
                Valor tmp = ((Expresiones) (dimensiones[i])).interpretar();
                size *= ((ValorEntero)tmp).Valor;//POIO LO TIENE CON MAS
            }
            Elementos = new ArrayList();
            for (int i = 0; i < size;i++)
            {
                if (tipo.Contenido is Entero)
                    Elementos.Add(new ValorEntero(0));
                if (tipo.Contenido is Cadena)
                    Elementos.Add(new ValorCadena(""));
                if (tipo.Contenido is Flotante)
                    Elementos.Add(new ValorFlotante((float)(0.0)));
                if (tipo.Contenido is Caracter)
                    Elementos.Add(new ValorCaracter(""));
                if (tipo.Contenido is Booleano)
                    Elementos.Add(new ValorBooleano(true));

            }
            this.Tipo = tipo;
        }
示例#2
0
        public IActionResult Index(Arreglo arr, string calcular)
        {
            if (calcular == "cal")
            {
                for (int i = 0; i < 10; i++)
                {
                    arr.Numeros[i] = int.Parse(Request.Form["num"][i]);
                }

                arr.Mayor = arr.Numeros.Max().ToString();
                arr.Menor = arr.Numeros.Min().ToString();
            }

            return(View(arr));
        }
示例#3
0
 public Objeto Copia(Objeto entrada)
 {
     if (entrada.getTipo() == Objeto.TipoObjeto.OBJECTS)
     {
         Type_obj salida = new Type_obj();
         salida = (Type_obj)entrada.Clonar_Objeto();
         return(salida);
     }
     else if (entrada.getTipo() == Objeto.TipoObjeto.ARRAY)
     {
         Arreglo salida = new Arreglo();
         salida = (Arreglo)entrada.Clonar_Objeto();
         return(salida);
     }
     return(null);
 }
示例#4
0
        private static bool validarArreglo(Arreglo arr, object[] arreglo)
        {
            if (arreglo[0] == null)
            {
                throw new Exception("El arreglo que intenta usar no tiene valores asignados");
            }

            switch (arr.tipo)
            {
            case "Int":
                if (!(arreglo[0] is int))
                {
                    return(false);
                }
                break;

            case "String":
                if (!(arreglo[0] is string))
                {
                    return(false);
                }
                break;

            case "Double":
                if (!(arreglo[0] is double))
                {
                    return(false);
                }
                break;

            case "Bool":
                if (!(arreglo[0] is bool))
                {
                    return(false);
                }
                break;

            case "Char":
                if (!(arreglo[0] is char))
                {
                    return(false);
                }
                break;
            }
            return(true);
        }
示例#5
0
 private void declaracionApartirDeArbol(Ambito ambito)
 {
     if (!ambito.existeVariable(this.idArr.ToLower()))
     {
         GeneradorArreglo gen = new GeneradorArreglo(this.arbolArreglo);
         if (!gen.huboError)
         {
             int numaux = gen.numDimensiones;
             if (NumDim == gen.numDimensiones)
             {
                 ///FALTA COMPROBAR SI TODOS LOS ELEMENTOS DEL ARREGLO SON DEL MISMO TIPO
                 ///
                 List <Object> valores = linealizadaValores(gen.linealizacion, ambito);
                 if (valores != null)
                 {
                     Arreglo arr = new Arreglo(this.arbolArreglo, valores, gen.dimensiones, this.NumDim, this.idArr.ToLower(), true, this.visibilidad, this.tipo);
                     ambito.agregarVariableAlAmbito(this.idArr.ToLower(), arr);
                 }
                 else
                 {
                     TError error = new TError("Semantico", "El Arreglo: \"" + this.idArr + "\" no concuerda con el tipo esperado: " + this.tipo + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else
             {
                 TError error = new TError("Semantico", "Las dimensiones declaradas para: \"" + this.idArr + "\" No concuerdan, Se esperaban: " + this.NumDim + " y se encontro: " + gen.numDimensiones + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                 Estatico.errores.Add(error);
                 Estatico.ColocaError(error);
             }
         }
         else
         {
             TError error = new TError("Semantico", "Declaracion erreonea de Arreglo: \"" + this.idArr + "\" en este Ambito | Error: " + gen.mensajesError + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
             Estatico.errores.Add(error);
             Estatico.ColocaError(error);
         }
     }
     else
     {
         TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idArr + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
 }
        public object ejecutar(Contexto ctx, Stuff stuff)
        {
            object resEx = Operacion.Validar(exp.ejecutar(ctx, stuff), ctx, stuff, exp.getLinea(), exp.getColumna());

            if (resEx == null)
            {
                return(null);
            }
            if (resEx is Arreglo)
            {
                object resIndice = Operacion.Validar(indice.ejecutar(ctx, stuff), ctx, stuff, indice.getLinea(), indice.getColumna());
                if (resIndice == null)
                {
                    return(null);
                }
                if (resIndice is BigInteger index)
                {
                    Arreglo arr = (Arreglo)resEx;
                    if (index < 0)
                    {
                        stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado pequeño. Encontrado: " + index + ", Minimo: 0.", indice.getLinea(), indice.getColumna(), ctx);
                        return(null);
                    }
                    if (index >= arr.val.Count)
                    {
                        stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado grande. Encontrado: " + index + ", Maximo: " + (arr.val.Count - 1) + ".", indice.getLinea(), indice.getColumna(), ctx);
                        return(null);
                    }
                    return(arr.val.ElementAt((int)index));
                }
                stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del indice es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resIndice) + ", Esperado: 'ENTERO'.", indice.getLinea(), indice.getColumna(), ctx);
                return(null);
            }
            stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resEx) + ", Esperado: 'ARREGLO'.", exp.getLinea(), exp.getColumna(), ctx);
            return(null);
        }
示例#7
0
 public static bool validarParametros(object arg1, object arg2)
 {
     if (arg1 is Simbolo)
     {
         if (arg2 is Simbolo)
         {
             Simbolo uno = (Simbolo)arg1;
             Simbolo dos = (Simbolo)arg2;
             if (uno.tipo.Equals(dos.tipo))
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     else if (arg1 is Arreglo)
     {
         if (arg2 is Arreglo)
         {
             Arreglo one = (Arreglo)arg1;
             Arreglo two = (Arreglo)arg2;
             if (one.tipo.Equals(two.tipo))
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
示例#8
0
        public object getValor(Ambito ambito)
        {
            if (this.identificador.ToLower().Equals("nada"))
            {
                return(-1);
            }
            if (this.identificador.ToLower().Equals("este"))
            {
                return(new Este());
            }
            Simbolo aux = ambito.getSimbolo(this.identificador.ToLower());

            if (aux != null)
            {
                if (aux is Variable)
                {
                    Variable v = (Variable)aux;
                    this.ValorAux = v.valor;
                    return(v.valor);
                }
                else if (aux is Arreglo)
                {
                    //RETORNO SI ES OTRO TIPO
                    Arreglo arr = (Arreglo)aux;
                    this.ValorAux = arr;
                    return(arr);
                }
            }
            else
            {
                TError erro = new TError("Semantico", "Se hacer referencia a: " + this.identificador + ", La cual no Existe en este Contexto: Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                Estatico.errores.Add(erro);
                Estatico.ColocaError(erro);
            }
            return(new Nulo());
        }
示例#9
0
        public object ejecutar(Contexto ctx, Stuff stuff)
        {
            if (exp1 is Operacion)
            {
                Operacion op1 = (Operacion)exp1;
                if (op1.tipo == Operacion.Tipo.IDENTIFICADOR)
                {
                    Simbolo s = ctx.findSymbol(op1.value.ToString());
                    if (s == null)
                    {
                        stuff.error("Semántico", "'ASIGNACION', la variable '" + op1.value.ToString() + "' no existe.", exp1.getLinea(), exp1.getColumna(), ctx);
                        return(null);
                    }
                    object resOp = Operacion.Validar(exp2.ejecutar(ctx, stuff), ctx, stuff, exp2.getLinea(), exp2.getColumna());
                    if (resOp == null)
                    {
                        resOp = Simbolo.NULL;
                    }
                    s.value = resOp;
                    return(null);
                }
                else
                {
                    stuff.error("Semántico", "'ASIGNACION', El lado izquierdo de una asignación debe ser una variable, propiedad o indizador.", exp1.getLinea(), exp1.getColumna(), ctx);
                    return(null);
                }
            }
            else if (exp1 is AccesoArreglo)
            {
                AccesoArreglo aa    = (AccesoArreglo)exp1;
                object        resEx = Operacion.Validar(aa.exp.ejecutar(ctx, stuff), ctx, stuff, aa.exp.getLinea(), aa.exp.getColumna());
                if (resEx == null)
                {
                    return(null);
                }
                if (resEx is Arreglo)
                {
                    object resIndice = Operacion.Validar(aa.indice.ejecutar(ctx, stuff), ctx, stuff, aa.indice.getLinea(), aa.indice.getColumna());
                    if (resIndice == null)
                    {
                        return(null);
                    }
                    if (resIndice is BigInteger index)
                    {
                        Arreglo arr = (Arreglo)resEx;
                        if (index < 0)
                        {
                            stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado pequeño. Encontrado: " + index + ", Minimo: 0.", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                            return(null);
                        }
                        if (index >= arr.val.Count)
                        {
                            stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado grande. Encontrado: " + index + ", Maximo: " + (arr.val.Count - 1) + ".", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                            return(null);
                        }
                        object resOp = Operacion.Validar(exp2.ejecutar(ctx, stuff), ctx, stuff, exp2.getLinea(), exp2.getColumna());
                        if (resOp == null)
                        {
                            resOp = Simbolo.NULL;
                        }
                        arr.val.RemoveAt((int)index);
                        arr.val.Insert((int)index, resOp);
                        return(null);
                    }
                    stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del indice es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resIndice) + ", Esperado: 'ENTERO'.", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                    return(null);
                }
                stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resEx) + ", Esperado: 'ARREGLO'.", aa.exp.getLinea(), aa.exp.getColumna(), ctx);
                return(null);
            }
            else if (exp1 is AccesoPropiedad)
            {
                AccesoPropiedad ap = (AccesoPropiedad)exp1;

                object resExp1 = Operacion.Validar(ap.exp1.ejecutar(ctx, stuff), ctx, stuff, ap.exp1.getLinea(), ap.exp1.getColumna());
                if (resExp1 == null)
                {
                    return(null);
                }
                if (resExp1 is Objeto)
                {
                    if (ap.exp2 is LlamadaMetodo)
                    {
                        stuff.error("Semántico", "'ASIGNACION', El lado izquierdo de una asignación debe ser una variable, propiedad o indizador.", exp1.getLinea(), exp1.getColumna(), ctx);
                        return(null);
                    }
                    else if (ap.exp2 is Operacion)
                    {
                        Operacion op = (Operacion)ap.exp2;
                        Objeto    ob = (Objeto)resExp1;
                        Simbolo   s  = ob.atributos.findAttribute(op.value.ToString());
                        if (s == null)
                        {
                            stuff.error("Semántico", "'ACCESO PROPIEDAD', la variable '" + op.value.ToString() + "' no existe como propiedad de la clase '" + ob.nombre_clase + "'.", op.getLinea(), op.getColumna(), ctx);
                            return(null);
                        }
                        object resOp = Operacion.Validar(exp2.ejecutar(ctx, stuff), ctx, stuff, exp2.getLinea(), exp2.getColumna());
                        if (resOp == null)
                        {
                            resOp = Simbolo.NULL;
                        }
                        s.value = resOp;
                        return(null);
                    }
                }
                else
                {
                    stuff.error("Semántico", "'ACCESO PROPIEDAD', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resExp1) + ", Esperado: 'OBJETO'.", ap.exp1.getLinea(), ap.exp1.getColumna(), ctx);
                }
                return(null);
            }
            else if (exp1 is LlamadaMetodo)
            {
                stuff.error("Semántico", "'ASIGNACION', El lado izquierdo de una asignación debe ser una variable, propiedad o indizador.", exp1.getLinea(), exp1.getColumna(), ctx);
                return(null);
            }
            return(null);
        }
示例#10
0
 public object Ejecutar(Ambito ambito)
 {
     try
     {
         Simbolo s = (Simbolo)ambito.getSimbolo(this.idArr.ToLower());
         if (s != null)
         {
             if (s is Arreglo)
             {
                 Arreglo arr = (Arreglo)s;
                 /// DIMENSIONES DEL ARREGLO
                 List <int> dimensiones = getDimensiones(ambito);
                 if (dimensiones != null)
                 {
                     Object valorAsignado = val.getValor(ambito);
                     String tipoVal       = val.getTipo(ambito);
                     if (tipoVal.ToLower().Equals(arr.Tipo.ToLower()))
                     {
                         //ASIGNO EL VALOR
                         if (arr.esCoordenadaValida(dimensiones))
                         {
                             int realIndex = arr.calcularPosicion(dimensiones);
                             arr.setValueAtPosition(realIndex, valorAsignado);
                         }
                         else
                         {
                             TError error = new TError("Semantico", "Asignacion a Arreglo: \"" + this.idArr + "\" no se puede realizar ya que la posicion no es valida! | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                             Estatico.errores.Add(error);
                             Estatico.ColocaError(error);
                         }
                     }
                     else
                     {
                         TError error = new TError("Semantico", "El valor asignar al arreglo: \"" + this.idArr + "\" no coincide con el tipo esperado. Se esperaba: \"" + arr.Tipo + "\" y se encontro:\"" + tipoVal + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                         Estatico.errores.Add(error);
                         Estatico.ColocaError(error);
                     }
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Las dimensiones no contienen valores valodos, solo enteros son admitidos: \"" + this.idArr + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else
             {
                 TError error = new TError("Semantico", "El simbolo: \"" + this.idArr + "\" No es un arreglo para poder realizara la asignacion | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                 Estatico.errores.Add(error);
                 Estatico.ColocaError(error);
             }
         }
         else
         {
             TError error = new TError("Semantico", "El arreglo: \"" + idArr + "\" no existe en este ambito! | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
             Estatico.errores.Add(error);
             Estatico.ColocaError(error);
         }
     }
     catch (Exception e)
     {
         TError error = new TError("Ejecucion", "Error de Ejecucion al intentar asignar posicion de un Arreglo | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
     return(null);
 }
        public object getValor(Ambito ambito)
        {
            try
            {
                if (tipo == 1)
                {
                    double v         = 0;
                    int    iteracion = 0;
                    foreach (Expresion e in this.expresiones)
                    {
                        Object val      = e.getValor(ambito);
                        double auxiliar = 0;
                        if (val is int)
                        {
                            int aux = (int)val;
                            auxiliar = Convert.ToDouble(aux);
                            if (iteracion == 0)
                            {
                                v = auxiliar;
                            }
                        }
                        else if (val is double)
                        {
                            double aux = (double)val;
                            auxiliar = aux;
                            if (iteracion == 0)
                            {
                                v = auxiliar;
                            }
                        }
                        else if (val is String)
                        {
                            String aux = (String)val;
                            double x   = 0;
                            foreach (char c in aux)
                            {
                                x = x + Convert.ToInt32(c);
                            }
                            auxiliar = x;
                            if (iteracion == 0)
                            {
                                v = auxiliar;
                            }
                        }
                        else if (val is Objeto || val is Nulo)
                        {
                            this.valor = 0;
                            return(0);
                        }

                        if (auxiliar < v)
                        {
                            v = auxiliar;
                        }
                        iteracion++;
                    }
                    this.valor = v;
                    return(v);
                }
                else
                {
                    Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                    if (s != null)
                    {
                        if (s is Arreglo)
                        {
                            Arreglo       aux         = (Arreglo)s;
                            List <object> linealizado = aux.linealizacion;
                            double        auxiliar    = 0;
                            int           iteracion   = 0;
                            foreach (object ob in linealizado)
                            {
                                double v = 0;
                                if (ob is int)
                                {
                                    int x = (int)ob;
                                    v = Convert.ToDouble(x);
                                    if (iteracion == 0)
                                    {
                                        auxiliar = v;
                                    }
                                }
                                else if (ob is double)
                                {
                                    double x = (double)ob;
                                    v = x;
                                    if (iteracion == 0)
                                    {
                                        auxiliar = v;
                                    }
                                }
                                else if (ob is String)
                                {
                                    String x = (String)ob;
                                    double y = 0;
                                    foreach (char c in x)
                                    {
                                        y = y + Convert.ToInt32(c);
                                    }
                                    v = y;
                                    if (iteracion == 0)
                                    {
                                        auxiliar = v;
                                    }
                                }
                                else if (ob is Objeto || ob is Nulo)
                                {
                                    this.valor = 0;
                                    return(0.0);
                                }

                                if (v < auxiliar)
                                {
                                    auxiliar = v;
                                }
                                iteracion++;
                            }
                            this.valor = auxiliar;
                            return(auxiliar);
                        }
                        else
                        {
                            TError error = new TError("Semantico", "El simbolo: \"" + identificador + "\" no es un arreglo para poder aplicar la funcion Min() | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else
                    {
                        TError error = new TError("Semantico", "En funcion Min() se hace referencia a Arreglo: \"" + s.idSimbolo + "\" el cual no existe | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                        Estatico.errores.Add(error);
                        Estatico.ColocaError(error);
                    }
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar la funcion Min() | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(0.0);
        }
示例#12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.arr   = new Arreglo();
     this.datos = this.arr.getLista();
     texto.Text = "controlandoDesdeCodeBehind";
 }
示例#13
0
        public object ejecutar(Contexto ctx, Stuff stuff)
        {
            if (op is Operacion)
            {
                Operacion op1 = (Operacion)op;
                if (op1.tipo == Operacion.Tipo.IDENTIFICADOR)
                {
                    Simbolo s = ctx.findSymbol(op1.value.ToString());
                    if (s == null)
                    {
                        stuff.error("Semántico", "'AUMENTO', la variable '" + op1.value.ToString() + "' no existe.", op1.getLinea(), op1.getColumna(), ctx);
                        return(null);
                    }
                    if (s.value is BigInteger)
                    {
                        BigInteger r1 = (BigInteger)s.value;
                        s.value = Operacion.Validar(r1 + 1, ctx, stuff, op1.getLinea(), op1.getColumna());
                        return(r1);
                    }
                    if (s.value is double)
                    {
                        double r1 = (double)s.value;
                        s.value = Operacion.Validar(r1 + 1.0, ctx, stuff, op1.getLinea(), op1.getColumna());
                        return(r1);
                    }
                    if (s.value is char)
                    {
                        BigInteger r1 = (char)s.value;
                        s.value = Operacion.Validar(r1 + 1, ctx, stuff, op1.getLinea(), op1.getColumna());
                        return(r1);
                    }
                    stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(s.value) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                    return(null);
                }
                else
                {
                    object resOp = Operacion.Validar(op.ejecutar(ctx, stuff), ctx, stuff, fila, columna);
                    if (resOp == null)
                    {
                        return(null);
                    }
                    if (resOp is BigInteger)
                    {
                        BigInteger r1 = (BigInteger)resOp + 1;
                        return(r1);
                    }
                    if (resOp is double)
                    {
                        double r1 = (double)resOp + 1.0;
                        return(r1);
                    }
                    if (resOp is char)
                    {
                        BigInteger r1 = ((char)resOp + 1);
                        return(r1);
                    }
                    stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resOp) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                    return(null);
                }
            }
            else if (op is AccesoArreglo)
            {
                AccesoArreglo aa    = (AccesoArreglo)op;
                object        resEx = Operacion.Validar(aa.exp.ejecutar(ctx, stuff), ctx, stuff, aa.exp.getLinea(), aa.exp.getColumna());
                if (resEx == null)
                {
                    return(null);
                }
                if (resEx is Arreglo)
                {
                    object resIndice = Operacion.Validar(aa.indice.ejecutar(ctx, stuff), ctx, stuff, aa.indice.getLinea(), aa.indice.getColumna());
                    if (resIndice == null)
                    {
                        return(null);
                    }
                    if (resIndice is BigInteger index)
                    {
                        Arreglo arr = (Arreglo)resEx;
                        if (index < 0)
                        {
                            stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado pequeño. Encontrado: " + index + ", Minimo: 0.", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                            return(null);
                        }
                        if (index >= arr.val.Count)
                        {
                            stuff.error("Semántico", "'ACCESO ARREGLO', el valor del indice es demasiado grande. Encontrado: " + index + ", Maximo: " + (arr.val.Count - 1) + ".", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                            return(null);
                        }
                        if (arr.val.ElementAt((int)index) is BigInteger)
                        {
                            BigInteger r1 = (BigInteger)arr.val.ElementAt((int)index);
                            arr.val.RemoveAt((int)index);
                            arr.val.Insert((int)index, Operacion.Validar(r1 + 1, ctx, stuff, aa.indice.getLinea(), aa.indice.getColumna()));
                            return(r1);
                        }
                        if (arr.val.ElementAt((int)index) is double)
                        {
                            double r1 = (double)arr.val.ElementAt((int)index);
                            arr.val.RemoveAt((int)index);
                            arr.val.Insert((int)index, Operacion.Validar(r1 + 1.0, ctx, stuff, aa.indice.getLinea(), aa.indice.getColumna()));
                            return(r1);
                        }
                        if (arr.val.ElementAt((int)index) is char)
                        {
                            BigInteger r1 = (char)arr.val.ElementAt((int)index);
                            arr.val.RemoveAt((int)index);
                            arr.val.Insert((int)index, Operacion.Validar(r1 + 1, ctx, stuff, aa.indice.getLinea(), aa.indice.getColumna()));
                            return(r1);
                        }
                        stuff.error("Semántico", "'AUMENTO', el tipo del elemento indizado es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(arr.val.ElementAt((int)index)) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                        return(null);
                    }
                    stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del indice es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resIndice) + ", Esperado: 'ENTERO'.", aa.indice.getLinea(), aa.indice.getColumna(), ctx);
                    return(null);
                }
                stuff.error("Semántico", "'ACCESO ARREGLO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resEx) + ", Esperado: 'ARREGLO'.", aa.exp.getLinea(), aa.exp.getColumna(), ctx);
                return(null);
            }
            else if (op is AccesoPropiedad)
            {
                AccesoPropiedad ap = (AccesoPropiedad)op;

                object resExp1 = Operacion.Validar(ap.exp1.ejecutar(ctx, stuff), ctx, stuff, ap.exp1.getLinea(), ap.exp1.getColumna());
                if (resExp1 == null)
                {
                    return(null);
                }
                if (resExp1 is Objeto)
                {
                    if (ap.exp2 is LlamadaMetodo)
                    {
                        LlamadaMetodo ll = (LlamadaMetodo)ap.exp2;
                        Objeto        ob = (Objeto)resExp1;
                        Metodo        m  = ob.atributos.findLocalMethod(ll.id, ll.expresiones_params.Count);
                        if (m == null)
                        {
                            stuff.error("Semántico", "'LLAMADA METODO/FUNCION',  el método o función '" + ll.id + "' no está definido dentro de la clase '" + ob.nombre_clase + "', o no tiene '" + ll.expresiones_params.Count + "' parametros.", ll.getLinea(), ll.getColumna(), ctx);
                            return(null);
                        }
                        else
                        {
                            Contexto ctx_metodo = new Contexto();
                            ctx_metodo.otrosArchivos    = ob.atributos.otrosArchivos;
                            ctx_metodo.currentFile      = ob.atributos.currentFile;
                            ctx_metodo.globales         = ob.atributos.globales;
                            ctx_metodo.atributos        = ob.atributos.atributos;
                            ctx_metodo.clases           = ob.atributos.clases;
                            ctx_metodo.metodos          = ob.atributos.metodos;
                            ctx_metodo.metodos_globales = ob.atributos.metodos_globales;
                            ctx_metodo.terminable       = false;
                            ctx_metodo.continuable      = false;
                            ctx_metodo.retornable       = true;
                            ctx_metodo.esVoid           = m.esVoid;

                            if (m.decl_params != null)
                            {
                                m.decl_params.ejecutar(ctx_metodo, stuff);
                            }
                            for (int j = 0; j < m.cantidad_params; j++)
                            {
                                Simbolo     s      = ctx_metodo.locales_mismo_nivel.ElementAt(j);
                                Instruccion i      = ll.expresiones_params.ElementAt(j);
                                object      resIns = Operacion.Validar(i.ejecutar(ctx, stuff), ctx, stuff, i.getLinea(), i.getColumna());
                                if (resIns == null)
                                {
                                    resIns = Simbolo.NULL;
                                }
                                s.value = resIns;
                            }
                            foreach (Instruccion i in m.listaInstrucciones)
                            {
                                object res = i.ejecutar(ctx_metodo, stuff);
                                if (res is Return r)
                                {
                                    if (r.expresionEvaluada is BigInteger)
                                    {
                                        BigInteger r1 = (BigInteger)r.expresionEvaluada + 1;
                                        return(r1);
                                    }
                                    if (r.expresionEvaluada is double)
                                    {
                                        double r1 = (double)r.expresionEvaluada + 1.0;
                                        return(r1);
                                    }
                                    if (r.expresionEvaluada is char)
                                    {
                                        BigInteger r1 = ((char)r.expresionEvaluada + 1);
                                        return(r1);
                                    }
                                    stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(r.expresionEvaluada) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                                    return(null);
                                }
                            }
                            if (!m.esVoid)
                            {
                                stuff.error("Semántico", "'LLAMADA METODO/FUNCION',  la función '" + ob.nombre_clase + "." + ll.id + "' de " + m.cantidad_params + " parametros carece de una instrucción 'RETURN' con expresion.", ll.getLinea(), ll.getColumna(), ctx);
                                return(null);
                            }
                            return(new lang.engine.Void(ob.nombre_clase, ll.id, m.cantidad_params));
                        }
                    }
                    else if (ap.exp2 is Operacion)
                    {
                        Operacion op = (Operacion)ap.exp2;
                        Objeto    ob = (Objeto)resExp1;
                        Simbolo   s  = ob.atributos.findAttribute(op.value.ToString());
                        if (s == null)
                        {
                            stuff.error("Semántico", "'ACCESO PROPIEDAD', la variable '" + op.value.ToString() + "' no existe como propiedad de la clase '" + ob.nombre_clase + "'.", op.getLinea(), op.getColumna(), ctx);
                            return(null);
                        }
                        if (s.value is BigInteger)
                        {
                            BigInteger r1 = (BigInteger)s.value;
                            s.value = Operacion.Validar(r1 + 1, ctx, stuff, op.getLinea(), op.getColumna());
                            return(r1);
                        }
                        if (s.value is double)
                        {
                            double r1 = (double)s.value;
                            s.value = Operacion.Validar(r1 + 1.0, ctx, stuff, op.getLinea(), op.getColumna());
                            return(r1);
                        }
                        if (s.value is char)
                        {
                            BigInteger r1 = (char)s.value;
                            s.value = Operacion.Validar(r1 + 1, ctx, stuff, op.getLinea(), op.getColumna());
                            return(r1);
                        }
                        stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(s.value) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                        return(null);
                    }
                }
                else
                {
                    stuff.error("Semántico", "'ACCESO PROPIEDAD', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resExp1) + ", Esperado: 'OBJETO'.", ap.exp1.getLinea(), ap.exp1.getColumna(), ctx);
                }
                return(null);
            }
            else if (op is LlamadaMetodo)
            {
                object resOp = Operacion.Validar(op.ejecutar(ctx, stuff), ctx, stuff, fila, columna);
                if (resOp == null)
                {
                    return(null);
                }
                if (resOp is BigInteger)
                {
                    BigInteger r1 = (BigInteger)resOp + 1;
                    return(r1);
                }
                if (resOp is double)
                {
                    double r1 = (double)resOp + 1.0;
                    return(r1);
                }
                if (resOp is char)
                {
                    BigInteger r1 = ((char)resOp + 1);
                    return(r1);
                }
                stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(resOp) + ", Esperado: 'ENTERO', 'DOUBLE', 'CHAR'.", fila, columna, ctx);
                return(null);
            }
            else
            {
                stuff.error("Semántico", "'AUMENTO', el tipo del operando es incompatible con esta instruccion. Encontrado: " + Operacion.getTipo(op) + ", Esperado: 'EXPRESION', 'LLAMADA METODO', 'VARIABLE', 'PROPIEDAD' , 'INDIZADOR'.", fila, columna, ctx);
            }
            return(null);
        }
示例#14
0
        public Declaracion DeclarsCstruct(Declaracion decl)
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba un token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    decl.Sig.Var = nombre;
                    decl.Sig.Tip = decl.Tip;
                    DeclarsCstruct(decl.Sig);
                    return decl;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
                {
                    currentToken = lex.NextToken();
                    Expresiones E1 = Expression();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR)
                        throw new Exception("Se esperaba el token ] ");
                    currentToken = lex.NextToken();
                    Arreglo tipoArreglo = new Arreglo();
                    tipoArreglo.Rangos.Add(E1);
                    tipoArreglo.Contenido = decl.Tip;
                    decl.Tip = tipoArreglo;
                    DeclarsCstruct(decl.Sig);
                    return decl;
                }
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.arr   = new Arreglo();
     this.datos = this.arr.getLista();
     this.texto = "mi muñeca me habló";
 }
示例#16
0
        public Sentencia DeclaracionesClase()
        {
            Declaracion Decl = new Declaracion();

            VARTYPE();
            try
            {
                Class c = new Class();
                c.Nombre = currentToken.Lexema;
                c.Campos=new T_Campos();
                Decl.Tip =c;
                currentToken = lex.NextToken();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (currentToken.Tipo == TipoToken.TK_OPENCOR) //ARREGLO
            {
                int dim = arrayDimensions(1);
                Arreglo ArrTip = new Arreglo();
                ArrTip.Contenido = Decl.Tip;
                ArrTip.Dimensiones = dim;
                Decl.Tip = ArrTip;
                if (currentToken.Tipo == TipoToken.TK_ID)
                {
                    Decl.Var.id = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
                    {
                        currentToken = lex.NextToken();
                        return Decl;
                    }
                    try
                    {
                        Decl = DeclOption(Decl);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA)
                    {
                        currentToken = lex.NextToken();
                        return Decl;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba Fin Sentencia");
                    }
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un ID");
                }

            }
            else if (currentToken.Tipo == TipoToken.TK_ID)
            {
                Decl.Var.id = currentToken.Lexema;
                currentToken = lex.NextToken();
                if (currentToken.Tipo == TipoToken.TK_COMA || currentToken.Tipo == TipoToken.TK_ASSIGN)
                {
                    try
                    {
                        DeclaracionesVarias(Decl);
                        DeclOption(Decl);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_OPENPAR)
                {
                    currentToken = lex.NextToken();
                    S_Functions sFunctions = new S_Functions();
                    sFunctions.Retorno = Decl.Tip;
                    sFunctions.Var = Decl.Var.id;
                    try
                    {
                        sFunctions.Campo = ParameterList();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo == TipoToken.TK_CLOSEPAR)
                    {
                        currentToken = lex.NextToken();
                        try
                        {
                            sFunctions.S = CompoundStatement();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        return sFunctions;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba simbolo )");
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_OPENLLAVE)
                {
                    currentToken = lex.NextToken();
                    S_Class sClass = new S_Class();
                    sClass.Var.id = Decl.Var.id;

                    try
                    {
                        sClass.CamposClase = ListaDeclaracion(sClass.CamposClase);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo != TipoToken.TK_CLOSELLAVE)
                        throw new Exception("Error Sintactico - Se esperaba simbolo }");
                    currentToken = lex.NextToken();
                    return sClass;
                }
                else if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
                {
                    currentToken = lex.NextToken();
                    return Decl;
                }
                else
                    throw new Exception("Error Sintactico - Se esperaba simbolo ;");
            }
            return Decl;
        }
示例#17
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                if (s != null)
                {
                    if (s is Variable)
                    {
                        Variable vari           = (Variable)s;
                        String   tipoEsperado   = vari.Tipo;
                        Object   val            = this.valor.getValor(ambito);
                        String   tipoEncontrado = this.valor.getTipo(ambito);
                        if (tipoEncontrado.ToLower().Equals(tipoEsperado.ToLower()) || tipoEncontrado.ToLower().Equals("nulo"))
                        {
                            vari.valor = val;//ASIGNO EL NUEVO VALOR
                        }
                        ////////////////////////////////////////////////////////////////
                        else if (tipoEsperado.ToLower().Equals("entero") && val is double)
                        {
                            Double valor = (Double)val;
                            int    real  = Convert.ToInt32(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("decimal") && val is int)
                        {
                            int    valor = (int)val;
                            double real  = Convert.ToDouble(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("entero") && val is bool)
                        {
                            Boolean valor = (Boolean)val;
                            int     real  = Convert.ToInt32(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("booleano") && val is int)
                        {
                            int     valor = (int)val;
                            Boolean real  = false;
                            if (valor == 1)
                            {
                                real = true;
                            }
                            vari.valor = real;
                        }
                        ////////////////////////////////////////////////////////////////
                        else
                        {
                            TError error = new TError("Semantico", "Tipos no Coinciden al Asignar, Esperado: \"" + tipoEsperado + "\", Encontrado: " + tipoEncontrado + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else if (s is Arreglo)
                    {
                        Arreglo a = (Arreglo)s;
                        Object  v = this.valor.getValor(ambito);
                        String  tipoEncontrado = this.valor.getTipo(ambito);
                        if (v is Arreglo)
                        {
                            Arreglo asig = (Arreglo)v;

                            if (a.numDimensiones == asig.numDimensiones && a.Tipo.ToLower().Equals(asig.Tipo.ToLower()))
                            {
                                Ambito aux = buscarAmbitoDondeEsta(this.identificador.ToLower(), ambito);
                                aux.removerArreglo(this.identificador.ToLower());
                                aux.agregarVariableAlAmbito(this.identificador.ToLower(), new Arreglo(asig.linealizacion, asig.dimensiones, asig.numDimensiones, a.idSimbolo, true, a.Visibilidad, a.Tipo));
                            }
                            else
                            {
                                TError error = new TError("Semantico", " Arreglos no tienen la misma caracteristicas, Se esperaba arreglo: Dimensiones: " + a.numDimensiones + " y Tipo: " + a.Tipo + ", Se econtro: Dimensiones: " + asig.numDimensiones + " y Tipo: " + asig.Tipo + "| Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                Estatico.errores.Add(error);
                                Estatico.ColocaError(error);
                            }
                        }
                        else
                        {
                            TError error = new TError("Semantico", "Tipos no Coinciden al Asignar, Esperado: \"" + "Arreglo" + "\", Encontrado: " + tipoEncontrado + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "Referencia a Simbolo: \"" + this.identificador + "\" inexistente | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecuccion", "Error al ejecutar la asignacion a Var: \"" + this.identificador + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(null);
        }
示例#18
0
        public Declaracion ParameterList()
        {
            if (currentToken.Tipo == TipoToken.TK_CHAR || currentToken.Tipo == TipoToken.TK_BOOL || currentToken.Tipo == TipoToken.TK_STRING || currentToken.Tipo == TipoToken.TK_FLOAT || currentToken.Tipo == TipoToken.TK_INT)
            {
                Declaracion C = new Declaracion();
                try
                {
                    C.Tip = Type();
                }
                catch (Exception ex)
                {

                    throw ex;
                }
                if (currentToken.Tipo == TipoToken.TK_OPENCOR) //ARREGLO
                {
                    int dim = arrayDimensions(1);
                    Arreglo ArrTip = new Arreglo();
                    ArrTip.Contenido = C.Tip;
                    ArrTip.Dimensiones = dim;
                    C.Tip = ArrTip;
                    if (currentToken.Tipo == TipoToken.TK_ID)
                    {
                        C.Var.id = currentToken.Lexema;
                        currentToken = lex.NextToken();
                        //C = DeclOption(C); /////PORQUE NO DEVUELVO NADA ACA??????????????????????????????
                        try
                        {
                            C.Sig = ParameterListP();
                        }
                        catch (Exception ex)
                        {

                            throw ex;
                        }

                        return C;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba un ID");
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_ID)
                {
                    C.Var.id = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    try
                    {
                        C.Sig = ParameterListP();
                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }

                    return C;
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un identificador");
                }
            }
            else
            {
                return null;
            }
        }
示例#19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.arr   = new Arreglo();
     this.datos = this.arr.GetLista();
     this.texto = "la mona hablo";
 }
示例#20
0
        public Sentencia DeclaracionesCPrima(Declaracion decl)
        {
            try
            {
                /*Cuando se declaran varias variables seguidas int x,t,y  */
                #region
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba un token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    decl.Sig.Tip = decl.Tip;
                    decl.Sig.Var = nombre;
                    currentToken = lex.NextToken();
                    DeclCPrima(decl.Sig);
                    return decl;
                }
                #endregion
                /*Declaracion de arreglos */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
                {
                    currentToken = lex.NextToken();
                    Expresiones E1 = Expression();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR)
                        throw new Exception("Se esperaba el token ] ");
                    currentToken = lex.NextToken();
                    Arreglo tipoArreglo = new Arreglo();
                    tipoArreglo.Contenido = decl.Tip;
                    tipoArreglo.Rangos.Add(E1);
                    DeclArreglo(tipoArreglo);
                    tipoArreglo.Dimensiones = tipoArreglo.Rangos.Count;
                    decl.Tip = tipoArreglo;
                    return decl;
                }
                #endregion
                /*Declaracion de funciones */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR)
                {
                    currentToken = lex.NextToken();
                    Declaracion listaParams = FuncionesParams();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR)
                        throw new Exception("Se esperaba el token )");
                    currentToken = lex.NextToken();

                    S_Functions declFuncion = new S_Functions();
                    declFuncion.Retorno = decl.Tip;
                    declFuncion.Var = decl.Var.id;
                    declFuncion.S = CompoundStatement();
                    if (listaParams != null)
                        declFuncion.Campo = listaParams;
                    return declFuncion;
                }
                #endregion
                /*Declaracion de Structs */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENLLAVE)
                {
                    currentToken = lex.NextToken();
                    Declaracion strDec = StructDeclaration();
                    Declaracion tmp = StructDeclaration();
                    while (tmp != null)
                    {
                        strDec.Sig = tmp;
                        tmp = StructDeclaration();
                    }

                    Structs s = new Structs();
                    s.nombre = decl.Var.id;
                    s.campos = strDec;
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSELLAVE)
                        throw new Exception("Error sintactico se esperaba }");
                    currentToken = lex.NextToken();

                    if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                        throw new Exception("Error sintactico se esperaba ;");
                    currentToken = lex.NextToken();

                    return s;
                }
                #endregion
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#21
0
 Tipo ParseType()
 {
     switch (currentToken.Tipo)
     {
         case TipoToken.TK_INT:
             {
                 currentToken = lex.NextToken();
                 return new Entero();
             }
         case TipoToken.TK_BOOL:
             {
                 currentToken = lex.NextToken();
                 return new Booleano();
             }
         case TipoToken.TK_CHAR:
             {
                 currentToken = lex.NextToken();
                 return new Caracter();
             }
         case TipoToken.TK_ID:
             {
                 if (InfSemantica.getInstance().tblTipos.ContainsKey(currentToken.Lexema))
                 {
                     string nom = currentToken.Lexema;
                     currentToken = lex.NextToken();
                     return InfSemantica.getInstance().tblTipos[nom];
                 }
                 else throw new Exception("Tipo no reconocido.");
             }
         case TipoToken.TK_ARRAY:
             {
                 currentToken = lex.NextToken();
                 if (currentToken.Tipo != TipoToken.TK_OPENCOR)
                     throw new Exception("Se esperaba [");
                 else
                 {
                     currentToken = lex.NextToken();
                     Arreglo ret = new Arreglo();
                     try
                     {
                         ret.Rangos = ExprList();
                     }
                     catch (Exception ex) { throw ex; }
                     ret.Dimensiones = ret.Rangos.Count;
                     if (currentToken.Tipo != TipoToken.TK_CLOSECOR)
                         throw new Exception("Se esperaba ]");
                     else
                     {
                         currentToken = lex.NextToken();
                         if (currentToken.Tipo != TipoToken.TK_OF)
                             throw new Exception("Se esperaba of.");
                         else
                         {
                             currentToken = lex.NextToken();
                             try
                             {
                                 ret.Contenido = ParseType();
                             }
                             catch (Exception ex) { throw ex; }
                             return ret;
                         }
                     }
                 }
             }
         case TipoToken.TK_STRING:
             {
                 currentToken = lex.NextToken();
                 return new Cadena();
             }
         default: throw new Exception("Eso no es un tipo.");
     }
 }
示例#22
0
 /*Aqui se efectua la recursividad de [][][]*/
 public Arreglo DeclArreglo(Arreglo tipoArreglo)
 {
     try
     {
         if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
         {
             currentToken = lex.NextToken();
             Expresiones E1 = Expression();
             if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR)
                 throw new Exception("Se esperaba el token ] ");
             currentToken = lex.NextToken();
             tipoArreglo.Rangos.Add(E1);
             DeclArreglo(tipoArreglo);
             return tipoArreglo;
         }
         return tipoArreglo;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }