예제 #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     ingresoM      = new Multiplicacion();
     ingresoM.M1   = double.Parse(txtValorA.Text);
     ingresoM.M2   = double.Parse(txtValorB.Text);
     lblResul.Text = ingresoM.CalcularM().ToString();
 }
예제 #2
0
        private void BtnResultado_Click(object sender, EventArgs e)
        {
            segundo = double.Parse(TxtBPantalla.Text);

            double Suma;
            double Resta;
            double Multiplicacion;
            double Division;

            switch (operador)
            {
            case "+":
                Suma = obj.Sumar((primero), (segundo));
                TxtBPantalla.Text = Suma.ToString();
                break;

            case "-":
                Resta             = obj2.Restar((primero), (segundo));
                TxtBPantalla.Text = Resta.ToString();
                break;

            case "*":
                Multiplicacion    = obj3.Multiplicacion((primero), (segundo));
                TxtBPantalla.Text = Multiplicacion.ToString();
                break;

            case "/":
                Division          = obj4.Division((primero), (segundo));
                TxtBPantalla.Text = Division.ToString();
                break;
            }
        }
예제 #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            Multiplicacion ingreso3 = new Multiplicacion();

            ingreso3.V1   = double.Parse(textvalA.Text);
            ingreso3.V2   = double.Parse(textvalB.Text);
            lblResul.Text = ingreso3.CalcularProducto().ToString();
        }
예제 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            multi    = new Multiplicacion();
            multi.M1 = double.Parse(txtValA.Text);
            multi.M2 = double.Parse(txtValB.Text);

            lblResult.Text = Convert.ToString(multi.Calcular());
        }
예제 #5
0
        private void btnMultiplicacion_Click(object sender, EventArgs e)
        {
            multi    = new Multiplicacion();
            multi.M1 = int.Parse(txtValorA.Text);
            multi.M2 = int.Parse(txtValorB.Text);

            lblResultado.Text = "Resultado: " + multi.Multiplicar().ToString();;
        }
        static void Main(string[] args)
        {
            Multiplicacion mul = new Multiplicacion();

            mul.Cargar();
            mul.Multiplicar();
            mul.Imprimir();
            Console.ReadKey();
        }
예제 #7
0
        static void Main(string[] args)
        {
            string datos  = "";
            double x      = 0;
            double y      = 0;
            double r      = 0;
            string opcion = "";

            IOperacion miOperacion = new Suma();

            while (opcion != "5")
            {
                Console.BackgroundColor = ConsoleColor.Yellow;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine("1-suma, 2-resta, 3-multiplicacion, 4-division, 5-salir");
                opcion = Console.ReadLine();
                if (opcion == "5")
                {
                    break;
                }
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("valor de a");
                datos = Console.ReadLine();
                x     = Convert.ToDouble(datos);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Valor de b");
                datos = Console.ReadLine();
                y     = Convert.ToDouble(datos);

                //Ahora selecionamos el algorimo de acuerdo a la necesidad
                if (opcion.Equals("1"))
                {
                    miOperacion = new Suma();
                }
                if (opcion == "2")
                {
                    miOperacion = new Resta();
                }
                if (opcion.Equals("3"))
                {
                    miOperacion = new Multiplicacion();
                }
                if (opcion.Equals("4"))
                {
                    miOperacion = new Division();
                }
                r = miOperacion.operacion(x, y);
                Console.BackgroundColor = ConsoleColor.DarkMagenta;
                Console.WriteLine("El resultado es {0}", r);
            }
            Console.ReadKey();
        }
예제 #8
0
        public ActionResult Index(Multiplicacion model, string command)
        {
            if (command == "multiplicar")
            {
                model.Resultado = model.NumeroA * model.NumeroB;
            }
            else
            {
                model.Resultado = model.NumeroA + model.NumeroB;
            }

            return(View(model));
        }
예제 #9
0
        private void Buttonigual_Click(object sender, RoutedEventArgs e)
        {
            num2 = Double.Parse(resTextBox.Text);

            double Suma;
            double Resta;
            double Multiplicacion;
            double Division;

            switch (Operation)
            {
            case "+":
                Suma            = op1.Sum((num1), (num2));
                resTextBox.Text = Suma.ToString();

                break;

            case "-":
                Resta           = op2.Res((num1), (num2));
                resTextBox.Text = Resta.ToString();
                break;

            case "*":
                Multiplicacion  = op3.Multi((num1), (num2));
                resTextBox.Text = Multiplicacion.ToString();
                break;

            case "/":
                if (num2 == 0)
                {
                    MessageBox.Show("SYSTEM ERROR");
                    resTextBox.Clear();
                }
                else
                {
                    Division        = op4.Div((num1), (num2));
                    resTextBox.Text = Division.ToString();
                }
                break;

            case " ":

                MessageBox.Show("no se encontro en numero secundario");


                break;
            }
        }
예제 #10
0
        private void Btnigual_Click(object sender, EventArgs e)
        {
            Segundo = double.Parse(Txtmostrar.Text);

            double Suma;
            double Resta;
            double Division;
            double Multiplicacion;


            switch (Operando)
            {
            case "+":
            {
                Suma            = Operador.Sumar((Primero), (Segundo));
                Txtmostrar.Text = Suma.ToString();
            }
            break;

            case "-":
            {
                Resta           = Operador.Restar((Primero), (Segundo));
                Txtmostrar.Text = Resta.ToString();
            }
            break;

            case "/":
            {
                Division        = Operador.Dividir((Primero), (Segundo));
                Txtmostrar.Text = Division.ToString();
            }
            break;

            case "*":
            {
                Multiplicacion  = Operador.Multiplicar((Primero), (Segundo));
                Txtmostrar.Text = Multiplicacion.ToString();
            }
            break;
            }
        }
예제 #11
0
        public static void multiplicar()
        {
            string linea2 = "";

            Console.WriteLine("Escribe los números que quieres multiplicar");
            string         urlAddress = "https://calculadora20190401125057.azurewebsites.net/Calculadora/Multiplicar";
            Multiplicacion mult       = new Multiplicacion();


            // El usuario introduce datos hasta que escriba "salir", si mete valores no numéricos, no se guardan.
            do
            {
                linea2 = Console.ReadLine();
                if (!linea2.Equals("salir"))
                {
                    mult.valores.Add(linea2);
                }
            } while (!linea2.Equals("salir"));

            sendJson(urlAddress, mult);
        }
        public void MultiplicacionUTest(double input1, double input2, double expectedResult)
        {
            // ** Arrange
            // Create instance calculadora
            Multiplicacion multiplicacion = new Multiplicacion();



            //  Arrange **


            // ** Act
            // Ejecutar el metodo bajo prueba:
            double actualResult = multiplicacion.Operar(input1, input2);

            //  Act **

            // ** Assert
            // Verificar el resultado:
            Assert.AreEqual(expectedResult, actualResult);
            // Assert **
        }
 /// <summary>
 /// Establece un automata donde contenedremos todas las gramaticas clases que se establecieron
 /// </summary>
 public Lenguaje()
 {
     //Establecemos una lista de las gramaticas que contiene el automata
     gramaticas[0]  = new And();
     gramaticas[1]  = new Boolean_();
     gramaticas[2]  = new Cadena();
     gramaticas[3]  = new Chart();
     gramaticas[4]  = new Colon();
     gramaticas[5]  = new ComentarioUnaLinea();
     gramaticas[6]  = new ComentarioVariasLineas();
     gramaticas[7]  = new Comparacion();
     gramaticas[8]  = new Decimal_();
     gramaticas[9]  = new Desde();
     gramaticas[10] = new Diferente();
     gramaticas[11] = new Disminuir();
     gramaticas[12] = new Division();
     gramaticas[13] = new Entero();
     gramaticas[14] = new Hacer();
     gramaticas[15] = new Hasta();
     gramaticas[16] = new Igual();
     gramaticas[17] = new Incrementar();
     gramaticas[18] = new Incremento();
     gramaticas[19] = new Mayor();
     gramaticas[20] = new MayorIgual();
     gramaticas[21] = new Menor();
     gramaticas[22] = new MenorIgual();
     gramaticas[23] = new Mientras();
     gramaticas[24] = new Multiplicacion();
     gramaticas[25] = new Negacion();
     gramaticas[26] = new Or();
     gramaticas[27] = new ParentesisAbrir();
     gramaticas[28] = new ParentesisCerrar();
     gramaticas[29] = new Resta();
     gramaticas[30] = new Si();
     gramaticas[31] = new Sino();
     gramaticas[32] = new Sino_Si();
     gramaticas[33] = new Suma();
 }
예제 #14
0
            static void Main(string[] args)
            {
                //TOMA EL VALOR INGRESADO DE LA OPCION DEL MENU
                string linea;

                do
                {
                    Console.WriteLine("MENU PRINCIPAL");
                    Console.WriteLine();
                    Console.WriteLine("1-Suma");
                    Console.WriteLine("2-Resta");
                    Console.WriteLine("3-Multiplicación");
                    Console.WriteLine("4-División");
                    Console.WriteLine("5-Raíz Cuadrada");
                    Console.WriteLine("6-Potencia(al cuadrado).");
                    Console.WriteLine("7-Potencia(a la n)");
                    Console.WriteLine("8-Contar caracteres de un texto ingresado por el usuario");
                    Console.WriteLine("9-Contar repeticiones de un carácter recibido como parámetro, en un texto que también ingresa el usuario");
                    Console.WriteLine("0-Salir");
                    Console.WriteLine();
                    Console.Write("Ingrese el numero de opcion: ");
                    linea = Console.ReadLine();
                    //VALIDA SI LA OPCION INGRESADA ES CORRECTA
                    try
                    {
                        int.Parse(linea);
                    }
                    catch (Exception)
                    {
                        //SI NO CORRECTA, MUESTRA UN MENSAJE Y VUELVE AL MENU PRINCIPAL
                        Console.WriteLine("Ingrese una opcion correcta");
                        Console.WriteLine("Presione un tecla para continuar");
                        Console.ReadKey();
                        linea = "-1";
                        Console.Clear();
                        continue;
                    }


                    //DE ACUERDO A LA OPCION ELEGIDA CREA LA INSTANCIA CORRECTA
                    switch (int.Parse(linea))
                    {
                    case 1:
                        oper = new Suma();
                        break;

                    case 2:
                        oper = new Resta();
                        break;

                    case 3:
                        oper = new Multiplicacion();
                        break;

                    case 4:
                        oper = new Division();
                        break;

                    case 5:
                        oper = new RaízCuadrada();
                        break;

                    case 6:
                        oper = new PotenciaCuadrado();
                        break;

                    case 7:
                        oper = new PotenciaALaN();
                        break;

                    case 8:
                        cadena           = new Cadena();
                        Cadena.operacion = "contar";
                        break;

                    case 9:
                        cadena           = new Cadena();
                        Cadena.operacion = "ContarCaracteresRepetidos";
                        break;

                    default:
                        Console.Write("Se ingreso un valor fuera de rango");
                        break;
                    }
                    //SI SELECCIONA LA OPCION SALIR
                    if (int.Parse(linea) == 0)
                    {
                        return;
                    }
                    //SI SELECCIONO LA OPCION 8 O 9 INGRESA A ESTE IF
                    if (cadena != null)
                    {
                        try
                        {
                            //VERIFICA EL VALOR DEL ATRIBUTO OPERACION Y REALIZA O NO LA ACCION
                            if (Cadena.operacion == "contar")
                            {
                                cadena.contar();
                                Console.Clear();
                                cadena = null;
                            }
                            else
                            {
                                cadena.ContarCaracteresRepetidos();
                                Console.Clear();
                                cadena = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.Write("Error: " + ex.Message);
                            throw;
                        }
                        //EVITA INGRESAR EN EL SIGUIENTE TRY - CATCH PARA VOLVER AL MENU PRINCIPAL
                        continue;
                    }
                    // SI SE ELIGIO LAS OPCIONES DESDE LA 1 A LA 7 INGRESA EN ESTE TRY
                    try
                    {
                        //SI SELECCIONA RAIZ CUADRADA O LA POTENCIA AL CUADRADO (OPCION 5 O 6) REALIZA ESTA OPERACION
                        if (oper is RaízCuadrada || oper is PotenciaCuadrado)
                        {
                            Console.Write(oper.tituloValor1);
                            oper.valor1 = double.Parse(Console.ReadLine());
                            oper.Operar();
                            Console.WriteLine(oper.tituloResultado + oper.resultado);
                            Console.ReadKey();
                        }
                        else if (oper != null)
                        {
                            Console.WriteLine(oper.tituloOperacion);
                            Console.Write(oper.tituloValor1);
                            oper.valor1 = double.Parse(Console.ReadLine());
                            Console.Write(oper.tituloValor2);
                            oper.valor2 = double.Parse(Console.ReadLine());
                            oper.Operar();
                            Console.WriteLine(oper.tituloResultado + oper.resultado);
                            Console.ReadKey();
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Debe ingresar valores validos, volvera al menu principal ");
                        Console.WriteLine("Presione una tecla para continuar");
                        Console.ReadKey();
                        Console.Clear();
                        continue;
                    }
                    //LIMPIA LA CONSOLA
                    Console.Clear();
                    oper = null;
                } while (int.Parse(linea) != 0);
                Console.ReadKey();
            }
예제 #15
0
        public double Get(double input1, double input2)
        {
            Multiplicacion multiplicacion = new Multiplicacion();

            return(multiplicacion.Operar(input1, input2));
        }
예제 #16
0
        //En este método se realiza la operación correspondiente a la selección en el combobox de la operación,
        // y en el combobox del tamaño, llamando el método correspondiente desde la librería creada por nosotros
        public void Operacion()
        {
            switch (op)
            {
            case "A+B":
                if (opc == "2x2")
                {
                    matrizC = Suma.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Suma.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Suma.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Suma.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "B-A":
                if (opc == "2x2")
                {
                    matrizC = Resta.DosxDos(matrizB, matrizA);
                }
                else if (opc == "3x3")
                {
                    matrizC = Resta.TresxTres(matrizB, matrizA);
                }
                else if (opc == "4x4")
                {
                    matrizC = Resta.CuatroxCuatro(matrizB, matrizA);
                }
                else if (opc == "5x5")
                {
                    matrizC = Resta.CincoxCinco(matrizB, matrizA);
                }

                break;

            case "A-B":
                if (opc == "2x2")
                {
                    matrizC = Resta.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Resta.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Resta.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Resta.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "B*A":
                if (opc == "2x2")
                {
                    matrizC = Multiplicacion.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Multiplicacion.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Multiplicacion.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Multiplicacion.CincoxCinco(matrizA, matrizB);
                }

                break;

            case "Suma de la diagonal":
                if (opc == "2x2")
                {
                    matrizC = Diagonal.DosxDos(matrizA, matrizB);
                }
                else if (opc == "3x3")
                {
                    matrizC = Diagonal.TresxTres(matrizA, matrizB);
                }
                else if (opc == "4x4")
                {
                    matrizC = Diagonal.CuatroxCuatro(matrizA, matrizB);
                }
                else if (opc == "5x5")
                {
                    matrizC = Diagonal.CincoxCinco(matrizA, matrizB);
                }

                break;
            }
        }
    public void OnTriggerStay(Collider other)
    {
        Debug.Log(other.tag);
        if (other.CompareTag("tagEnemigo"))
        {
            Debug.Log("ALGO Tagherir");
            if (bloq == 0)
            {
                //Llamando a una funcion, se aumenta el MIEDO del personaje cuando lo toque un enemigo((PROGRAMACION FUNCIONAL)) 4
                estadisticas.miedo = (float)Suma.fsum(estadisticas.miedo, 30);

                /*Se disminuye la velocidad en la que se mueve el personaje llamando una funcion para que multiplique y reste velocidad. Dependiendo
                 * del MIEDO del personaje bajara aun mas ////////////////////////((PROGRAMACION FUNCIONAL))  5*/
                movimient.velocidadMovimiento = movimient.velocidadMovimiento - ((float)Multiplicacion.fmul(estadisticas.miedo, 0.1));

                bloq = 1;
            }
        }
        if (other.CompareTag("tagDaño"))
        {
            if (bloq == 0)
            {
                tiempo = 0;
                if (estadisticas.miedo <= 0)
                {
                    vida = (float)Resta.fres(vida, 20);//Llamando a una funcion, se le resta vida a el Personaje ((PROGRAMACION FUNCIONAL))  6
                }
                else
                {
                    //Llamando a una funcion, Se le resta vida al personaje dependiendo si tiene MIEDO se le restara aun MAS ((PROGRAMACION FUNCIONAL))  7
                    vida = (float)Resta.fres(vida, VulnerabilidadMiedo.bajandoVidaMiedo(estadisticas.miedo, 20));
                }
                bloq = 1;
            }
        }
        if (other.CompareTag("tagMaderaClavos"))
        {
            equipo.AgregandoObjeto("01");
            Destroy(other.transform.gameObject);
        }
    }
예제 #18
0
        /** Method with the actual generated action code. */
        public TUVienna.CS_CUP.Runtime.Symbol CUP_TinyParser_do_action(
            int CUP_TinyParser_act_num,
            TUVienna.CS_CUP.Runtime.lr_parser CUP_TinyParser_parser,
            System.Collections.Stack xstack1,
            int CUP_TinyParser_top)
        {
            /* Symbol object for return from actions */
            mStack CUP_TinyParser_stack = new mStack(xstack1);

            TUVienna.CS_CUP.Runtime.Symbol CUP_TinyParser_result;

            /* select the action based on the action number */
            switch (CUP_TinyParser_act_num)
            {
            /*. . . . . . . . . . . . . . . . . . . .*/
            case 30: // factor ::= error
            {
                Expresion RESULT = null;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(13 /*factor*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 29: // factor ::= IDENTIFICADOR
            {
                Expresion        RESULT = null;
                SimboloAbstracto id     = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Variable(id, id.Linea, id.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(13 /*factor*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 28: // factor ::= LIT_ENTERO
            {
                Expresion        RESULT = null;
                SimboloAbstracto val    = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new NumeroEntero(val, val.Linea, val.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(13 /*factor*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 27: // factor ::= PARENT_IZQ exp PARENT_DER
            {
                Expresion RESULT = null;
                Expresion e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;

                RESULT = e;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(13 /*factor*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 26: // term ::= factor
            {
                Expresion RESULT = null;
                Expresion e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = e;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(12 /*term*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 25: // term ::= term DIVISION factor
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto d      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Division(e1, e2, d.Linea, d.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(12 /*term*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 24: // term ::= term MULTIPLICACION factor
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto m      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Multiplicacion(e1, e2, m.Linea, m.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(12 /*term*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 23: // exp_simple ::= term
            {
                Expresion RESULT = null;
                Expresion e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = e;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(11 /*exp_simple*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 22: // exp_simple ::= exp_simple RESTA term
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto r      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Resta(e1, e2, r.Linea, r.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(11 /*exp_simple*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 21: // exp_simple ::= exp_simple SUMA term
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto s      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Suma(e1, e2, s.Linea, s.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(11 /*exp_simple*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 20: // exp ::= exp_simple
            {
                Expresion RESULT = null;
                Expresion e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = e;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(10 /*exp*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 19: // exp ::= exp_simple IGUAL exp_simple
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto i      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Igual(e1, e2, i.Linea, i.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(10 /*exp*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 18: // exp ::= exp_simple MENOR exp_simple
            {
                Expresion        RESULT = null;
                Expresion        e1     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto m      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e2     = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Menor(e1, e2, m.Linea, m.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(10 /*exp*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 17: // args ::= args COMA exp
            {
                ListaParametros RESULT = null;
                ListaParametros p      = (ListaParametros)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                Expresion       e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                p.agregarElemento(e);
                RESULT = p;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(9 /*args*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 16: // args ::= exp
            {
                ListaParametros RESULT = null;
                Expresion       e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new ListaParametros();
                RESULT.agregarElemento(e);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(9 /*args*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 15: // opt_args ::=
            {
                ListaParametros RESULT = null;

                RESULT = new ListaParametros();

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(8 /*opt_args*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 14: // opt_args ::= args
            {
                ListaParametros RESULT = null;
                ListaParametros p      = (ListaParametros)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = p;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(8 /*opt_args*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 13: // fuction_call ::= IDENTIFICADOR opt_args
            {
                Sentencia        RESULT = null;
                SimboloAbstracto id     = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                ListaParametros  p      = (ListaParametros)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new LLamadaFuncion(id, p, id.Linea, id.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(7 /*fuction_call*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 12: // sent_assign ::= IDENTIFICADOR ASIGNACION exp
            {
                Sentencia        RESULT = null;
                SimboloAbstracto id     = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                SimboloAbstracto a      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                Expresion        e      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Asignacion(new Variable(id, id.Linea, id.Columna), e, a.Linea, a.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(6 /*sent_assign*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 11: // sent_repeat ::= REPITA secuencia_sent HASTA exp
            {
                Sentencia        RESULT = null;
                SimboloAbstracto r      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 3)).value;
                ListaSentencia   s      = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                Expresion        c      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new RepitaHasta(c, s, r.Linea, r.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(5 /*sent_repeat*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 10: // sent_if ::= SI exp ENTONCES secuencia_sent SINO secuencia_sent FIN
            {
                Sentencia        RESULT = null;
                SimboloAbstracto s      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 6)).value;
                Expresion        c      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 5)).value;
                ListaSentencia   en     = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 3)).value;
                ListaSentencia   sn     = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;

                RESULT = new Condicional(c, en, sn, s.Linea, s.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(4 /*sent_if*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 9: // sent_if ::= SI exp ENTONCES secuencia_sent FIN
            {
                Sentencia        RESULT = null;
                SimboloAbstracto s      = (SimboloAbstracto)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 4)).value;
                Expresion        c      = (Expresion)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 3)).value;
                ListaSentencia   en     = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;

                RESULT = new Condicional(c, en, null, s.Linea, s.Columna);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(4 /*sent_if*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 8: // sent ::= error
            {
                Sentencia RESULT = null;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(3 /*sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 7: // sent ::= fuction_call
            {
                Sentencia RESULT = null;
                Sentencia s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;
                RESULT = s;
                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(3 /*sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 6: // sent ::= sent_assign
            {
                Sentencia RESULT = null;
                Sentencia s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;
                RESULT = s;
                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(3 /*sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 5: // sent ::= sent_repeat
            {
                Sentencia RESULT = null;
                Sentencia s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;
                RESULT = s;
                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(3 /*sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 4: // sent ::= sent_if
            {
                Sentencia RESULT = null;
                Sentencia s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;
                RESULT = s;
                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(3 /*sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 3: // secuencia_sent ::= sent
            {
                ListaSentencia RESULT = null;
                Sentencia      s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new ListaSentencia();
                RESULT.agregarElemento(s);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(2 /*secuencia_sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 2: // secuencia_sent ::= secuencia_sent PUNTO_Y_COMA sent
            {
                ListaSentencia RESULT = null;
                ListaSentencia sc     = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 2)).value;
                Sentencia      s      = (Sentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                sc.agregarElemento(s);
                RESULT = sc;

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(2 /*secuencia_sent*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 1: // programa ::= secuencia_sent
            {
                Programa       RESULT = null;
                ListaSentencia sc     = (ListaSentencia)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 0)).value;

                RESULT = new Programa(sc, 1, 0);

                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(1 /*programa*/, RESULT);
            }
                return(CUP_TinyParser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 0: // $START ::= programa EOF
            {
                object   RESULT    = null;
                Programa start_val = (Programa)((TUVienna.CS_CUP.Runtime.Symbol)CUP_TinyParser_stack.elementAt(CUP_TinyParser_top - 1)).value;
                RESULT = start_val;
                CUP_TinyParser_result = new TUVienna.CS_CUP.Runtime.Symbol(0 /*$START*/, RESULT);
            }
                /* ACCEPT */
                CUP_TinyParser_parser.done_parsing();
                return(CUP_TinyParser_result);

            /* . . . . . .*/
            default:
                throw new System.Exception(
                          "Invalid action number found in internal parse table");
            }
        }
예제 #19
0
        public String Multiplicar(double[] numeros)
        {
            // Creo objeto Nlog y escribo la operación en el registro la operación.
            var            logger  = NLog.LogManager.GetCurrentClassLogger();
            string         json    = "";
            Multiplicacion desMult = new Multiplicacion();

            Random random = new Random();

            id = random.Next(0, 100);

            // Recibe el objeto en formato JSON y lo almaceno en un objeto de tipo Multiplicacion.
            using (var streamReader = new StreamReader(HttpContext.Request.Body))
            {
                var result = streamReader.ReadToEnd();
                try
                {
                    logger.Info("Operación de multiplicación");
                    desMult = JsonConvert.DeserializeObject <Multiplicacion>(result);

                    double[] nums = new double[desMult.valores.ToArray().Length];

                    for (int i = 0; i < desMult.valores.ToArray().Length; i++)
                    {
                        nums[i] = Double.Parse(desMult.valores[i]);
                    }

                    desMult.resultado = WebApplication1.Models.Calculadora.multiplicacion(nums);


                    // Creo un objeto operacion y almaceno sus datos
                    op.Tipo = "Mul";


                    for (int i = 0; i < nums.Length; i++)
                    {
                        if (i == 0)
                        {
                            op.Calculo += " * " + nums[i];
                        }
                        else
                        {
                            op.Calculo += nums[i];
                        }
                    }

                    op.Calculo += " = " + desMult.resultado;



                    DateTime fecha = DateTime.Now;

                    op.Fecha = Convert.ToString(fecha);

                    // Convierto el objeto a JSON y lo añado la operación al listado general
                    JournalList.Listado.Add(id, JsonConvert.SerializeObject(op));


                    // Añado nuevas propiedades al objeto, lo serializo y lo envío
                    Response.Clear();
                    Response.ContentType = "application/json; charset=utf-8";
                    var json2 = JsonConvert.SerializeObject(desMult);
                    Response.WriteAsync(json2);
                }
                catch
                {
                    Error500();
                }
            }



            return("");
        }
예제 #20
0
        //procedimiento recursivo que genera el arbol
        private void generar(NodoArbol nodoActual)
        {
            //Valido nodos nulos para evitar incluir condicionales en generacion de nodos cuando es nulo
            if (nodoActual == null)
            {
                return;
            }

            if (nodoActual.GetType() == typeof(Programa))
            {
                Programa n = (Programa)nodoActual;
                generar(n.Sentencias);
            }
            else if (nodoActual.GetType() == typeof(ListaSentencia))
            {
                ListaSentencia ls = (ListaSentencia)nodoActual;
                foreach (Sentencia sent in ls.getLista())
                {
                    generar(sent);
                }
            }
            else if (nodoActual.GetType() == typeof(Condicional))
            {
                Emit.LocalBuilder tmpVarLogico;
                Condicional       n = (Condicional)nodoActual;

                generar(n.Condicion);

                this.il.Emit(Emit.OpCodes.Ldc_I4_0); //Ingreso constante 0
                this.il.Emit(Emit.OpCodes.Ceq);      //Comparo si es falso (es 0)
                //Almaceno este resultado en una variable temporal
                tmpVarLogico = this.il.DeclareLocal(typeof(bool));
                this.il.Emit(Emit.OpCodes.Stloc, tmpVarLogico);
                //cargo el resultado de la variable temporal
                this.il.Emit(Emit.OpCodes.Ldloc, tmpVarLogico);
                Emit.Label bloqueFalso = this.il.DefineLabel();
                //salto en caso que sea verdadero el resultado es decir es cero la evaluacion del (pila==0) hago el sino
                this.il.Emit(Emit.OpCodes.Brtrue, bloqueFalso);

                generar(n.Entonces);

                Emit.Label finSi = this.il.DefineLabel();
                this.il.Emit(Emit.OpCodes.Br, finSi);
                this.il.MarkLabel(bloqueFalso);

                generar(n.Sino);

                this.il.MarkLabel(finSi);
            }
            else if (nodoActual.GetType() == typeof(RepitaHasta))
            {
                RepitaHasta       n = (RepitaHasta)nodoActual;
                Emit.LocalBuilder tmpCondicion;
                tmpCondicion = this.il.DeclareLocal(typeof(bool));
                Emit.Label sentenciasRepita = this.il.DefineLabel();
                this.il.MarkLabel(sentenciasRepita);
                this.il.Emit(Emit.OpCodes.Nop);         //emito primera sentencia vacia

                generar(n.Sentencias);

                generar(n.Condicion);

                this.il.Emit(Emit.OpCodes.Stloc, tmpCondicion);  //almaceno resultado de condicion del mientras
                this.il.Emit(Emit.OpCodes.Ldloc, tmpCondicion);  //cargo resultado de condicion del mientras
                this.il.Emit(Emit.OpCodes.Brfalse, sentenciasRepita);
            }
            else if (nodoActual.GetType() == typeof(Asignacion))
            {
                Asignacion n = (Asignacion)nodoActual;

                generar(n.Expr);

                Almacenar(n.Id.Nombre.Texto, this.il);
            }
            else if (nodoActual.GetType() == typeof(LLamadaFuncion)) //Leer, Escribir
            {
                LLamadaFuncion    n    = (LLamadaFuncion)nodoActual;
                List <FuncionDef> funs = NucleoLenguaje.Instancia.getFuncBasicas();
                //En la lista de definiciones de funciones estandar busco la definicion de la llamada para funcion deseada
                foreach (FuncionDef fun in funs)
                {
                    if (n.Id.Texto.Equals(fun.Nombre.Texto))
                    {
                        fun.ejecutarMetodo(il, n.Params);
                    }
                }
            }
            else if (nodoActual.GetType() == typeof(NumeroEntero))
            {
                NumeroEntero n = (NumeroEntero)nodoActual;
                this.il.Emit(Emit.OpCodes.Ldc_I4, convertir_a_entero(n.Token.Texto));
            }
            else if (nodoActual.GetType() == typeof(Variable))
            {
                Variable n = (Variable)nodoActual;
                if (!TablaDireccionesSimbolos.ContainsKey(n.Nombre.Texto))
                {
                    throw new System.Exception("ERROR-0008 fallo en analisis semantico Variable no declarada encontrada durante generacion '" + n.Nombre.Texto + "'");
                }
                else
                {
                    this.il.Emit(Emit.OpCodes.Ldloc, TablaDireccionesSimbolos[n.Nombre.Texto]);
                }
            }
            else if (nodoActual.GetType() == typeof(Suma))
            {
                Suma n = (Suma)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Add);
            }
            else if (nodoActual.GetType() == typeof(Resta))
            {
                Resta n = (Resta)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Sub);
            }
            else if (nodoActual.GetType() == typeof(Multiplicacion))
            {
                Multiplicacion n = (Multiplicacion)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Mul);
            }
            else if (nodoActual.GetType() == typeof(Division))
            {
                Division n = (Division)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Div);
            }
            else if (nodoActual.GetType() == typeof(Menor))
            {
                Menor n = (Menor)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Clt);
            }
            else if (nodoActual.GetType() == typeof(Igual))
            {
                Igual n = (Igual)nodoActual;
                generar(n.ExprIzq);
                generar(n.ExprDer);
                this.il.Emit(Emit.OpCodes.Ceq);
            }
            else
            {
                Console.WriteLine("ERROR-0006 Error tipo de Nodo no identificado");
            }
        }