Exemplo n.º 1
0
 public NodoDeclararFuncion(Instruccion tipo, string id, List <NodoDeclararParametro> parametros, List <Instruccion> lInsturcciones)
 {
     this.tipo           = tipo;
     this.id             = id;
     this.parametros     = parametros;
     this.lInsturcciones = lInsturcciones;
 }
Exemplo n.º 2
0
        //for init -> exp = exp
        // tipo id = exp;

        //exp--> retornar booleando

        //actualizacion ---> exp = exp
        // exp ++
        // exp --
        // exp += exp


        public NodoFor(Instruccion inicicializacion, Instruccion condicion, Instruccion actualizacion, List <Instruccion> instrucciones)
        {
            this.inicicializacion = inicicializacion;
            this.condicion        = condicion;
            this.actualizacion    = actualizacion;
            this.instrucciones    = instrucciones;
        }
Exemplo n.º 3
0
 public Graph(Instruccion op1, Instruccion op2, int fila, int columna)
 {
     this.op1     = op1;
     this.op2     = op2;
     this.fila    = fila;
     this.columna = columna;
 }
Exemplo n.º 4
0
 public For(Instruccion init, Instruccion cond, Instruccion aumento)
 {
     this.init    = init;
     this.cond    = cond;
     this.aumento = aumento;
     this.ins     = new List <Instruccion>();
 }
Exemplo n.º 5
0
        public void instruccionesMultiples(ref LinkedList <Instruccion> listaInstrucciones, ParseTreeNode actual)
        {
            //LLEGA A INSTRUCCIONES QUE PUEDEN TENER MAS INSTRUCCIONES
            foreach (ParseTreeNode nodo in actual.ChildNodes)
            {
                //Aca se van a hacer los 2 ciclos
                Debug.WriteLine("Nodo -> " + nodo.Term.ToString());
                if (nodo.ChildNodes.Count == 2 && nodo.ChildNodes[1].Term.ToString() != "Pt_Comas")
                {
                    instruccionesMultiples(ref listaInstrucciones, nodo);
                    continue;
                }

                if (nodo.ChildNodes.Count != 0)
                {
                    Instruccion instr = instruccion(nodo);
                    if (instr != null)
                    {
                        listaInstrucciones.AddLast(instr);
                    }
                    else
                    {
                        instruccionesMultiples(ref listaInstrucciones, nodo);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void EscribirInstruccionMemoria(Instruccion instruccion, ref ushort posicion)
        {
            memoria[posicion].Contenido = instruccion.Codigo;
            if (instruccion.NumArgumentos == 1 && instruccion.ObtenerArgumento(0).TipoArgumento() != Tipo.Registro)
            {
                if (instruccion.ObtenerArgumento(0).TipoArgumento() == Tipo.Memoria)
                {
                    memoria[++posicion].Contenido = BitConverter.GetBytes((instruccion.ObtenerArgumento(0) as ArgMemoria).DireccionMemoria)[1];
                    memoria[++posicion].Contenido = BitConverter.GetBytes((instruccion.ObtenerArgumento(0) as ArgMemoria).DireccionMemoria)[0];
                }
                else
                {
                    memoria[++posicion].Contenido = (instruccion.ObtenerArgumento(0) as ArgLiteral).Valor;
                }
            }
            else if (instruccion.NumArgumentos == 2)
            {
                if (instruccion.ObtenerArgumento(0).TipoArgumento() == Tipo.Memoria || instruccion.ObtenerArgumento(1).TipoArgumento() == Tipo.Memoria)
                {
                    int n = instruccion.ObtenerArgumento(0).TipoArgumento() == Tipo.Memoria ? 0 : 1;
                    memoria[++posicion].Contenido = BitConverter.GetBytes((instruccion.ObtenerArgumento(n) as ArgMemoria).DireccionMemoria)[1];
                    memoria[++posicion].Contenido = BitConverter.GetBytes((instruccion.ObtenerArgumento(n) as ArgMemoria).DireccionMemoria)[0];
                }
                else
                {
                    int n = instruccion.ObtenerArgumento(0).TipoArgumento() == Tipo.Literal ? 0 : 1;
                    memoria[++posicion].Contenido = (instruccion.ObtenerArgumento(n) as ArgLiteral).Valor;
                }
            }

            posicion++;
        }
 public object Ejecutar(Ambito ambito)
 {
     try
     {
         foreach (Object ob in this.instrucciones)
         {
             if (ob is Instruccion)
             {
                 Instruccion aux = (Instruccion)ob;
                 Object      res = aux.Ejecutar(ambito);
                 if (res is NodoReturn)
                 {
                     return(res);
                 }
             }
             else if (ob is Expresion)
             {
                 Expresion exp = (Expresion)ob;
                 Object    res = exp.getValor(ambito);
                 if (res is NodoReturn)
                 {
                     return(res);
                 }
             }
         }
     }
     catch (Exception e)
     {
         TError error = new TError("Ejecucion", "Error al Ejecutar la funcion: " + idFuncion + " | Error: " + e.Message, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
     return(new NodoReturn(new Vacio(), "vacio"));
 }
Exemplo n.º 8
0
 public For(Instruccion init, Instruccion cond, Instruccion aumento, List <Instruccion> ins)
 {
     this.init    = init;
     this.cond    = cond;
     this.aumento = aumento;
     this.ins     = ins;
 }
Exemplo n.º 9
0
        private void btnFinalizarTurno_Click(object sender, EventArgs e)
        {
            int nextPlayer = jugadorLocal.getID() + 1;

            if (jugadorLocal.getID() == board.getPlayers().Length - 1)
            {
                nextPlayer = 0;
            }

            byte   nextJugadorLocalId        = Convert.ToByte(nextPlayer);
            string nextJugadorLocalIdStrByte = Instruccion.ByteToString(nextJugadorLocalId);
            string nextJugadorLocalIdStr     = nextJugadorLocalIdStrByte.Substring(6, 2);

            Trace.WriteLine("Siguiente jugador: " + nextJugadorLocalIdStr);

            this.btnRollDices.Enabled      = false;
            this.btnFinalizarTurno.Enabled = false;
            lbxHistoria.Items.Add("Siguiente jugador: " + nextJugadorLocalIdStr);
            lbxHistoria.Items.Add("     Trama: " + Instruccion.ByteToString(Instruccion.FormarPrimerByte(jugadorLocal.GetIdAsString(), nextJugadorLocalIdStr, Instruccion.PrimerByte.TIRAR_DADOS)));
            // Mandamos 01 y 01 en los dados pero realmente este valor no afecta, solo importa que sea != 0
            this.comPort.Write(Instruccion.FormarTrama(
                                   Instruccion.FormarPrimerByte(jugadorLocal.GetIdAsString(), nextJugadorLocalIdStr, Instruccion.PrimerByte.TIRAR_DADOS),
                                   Instruccion.FormarSegundoByteDados("01", "01")
                                   ), 0, 4);
        }
Exemplo n.º 10
0
 public For(Instruccion init, Expresion expr, NodoASTCQL update, Bloque bloque, int linea, int columna) : base(linea, columna)
 {
     Init   = init;
     Expr   = expr;
     Update = update;
     Bloque = bloque;
 }
Exemplo n.º 11
0
        public static List <OmegaUp> obtenerInstrucciones(Instruccion i = Instruccion.NULL)
        {
            Acceso         db    = new Acceso();
            StringBuilder  query = new StringBuilder();
            List <OmegaUp> lista = new List <OmegaUp>();

            query.Append(" select * from omegaup ");
            if (i != Instruccion.NULL)
            {
                query.Append(" where tipo = ");
                query.Append(Cadenas.comillas(i.ToString().ToLower()));
            }
            query.Append(" order by tipo asc ");

            db.EjecutarQuery(query.ToString());

            DataTable table = db.getTable();

            foreach (DataRow r in table.Rows)
            {
                OmegaUp o = new OmegaUp();
                o.llenarDatos(r);

                lista.Add(o);
            }

            return(lista);
        }
Exemplo n.º 12
0
        private void leerTramaPropiedades(String origen, String destino, String segundoByte)
        {
            string propiedadComprada = segundoByte.Substring(3, 5);
            int    posicionPropiedad = board.GetHousePositionFromBits(propiedadComprada);

            if (jugadorLocal.GetIdAsString() != destino)
            {
                byte origenByte   = Convert.ToByte(origen);
                int  origenNumber = Convert.ToInt32(origenByte);

                HouseSquare propiedad = (HouseSquare)board.GetSquares()[posicionPropiedad];
                Trace.WriteLine("Owner: " + origenNumber);
                Trace.WriteLine("Player: " + board.getPlayer(origenNumber).getID());
                propiedad.setOwner(origenNumber);

                this.BeginInvoke((MethodInvoker) delegate()
                {
                    lbxHistoria.Items.Add("Jugador " + origen + " compró la propiedad " + board.GetSquares()[posicionPropiedad].getName());
                });

                this.comPort.Write(Instruccion.FormarTrama(
                                       Instruccion.FormarPrimerByte(origen, destino, Instruccion.PrimerByte.PROPIEDADES),
                                       Convert.ToByte("000" + propiedadComprada, 2)
                                       ), 0, 4);
            }
            else
            {
                this.BeginInvoke((MethodInvoker) delegate()
                {
                    lbxPropiedades.Items.Add(posicionPropiedad + " " + board.GetSquares()[posicionPropiedad].getName());
                    lbxHistoria.Items.Add("Compré la propiedad " + board.GetSquares()[posicionPropiedad].getName());
                });
            }
        }
 public CicloPara(Instruccion varcontrol, Expresion condicional, Instruccion operacion, List <Object> instrucciones, String clase, int linea, int col) : base(linea, col, clase)
 {
     this.varControl    = varcontrol;
     this.condicional   = condicional;
     this.operacion     = operacion;
     this.instrucciones = instrucciones;
 }
Exemplo n.º 14
0
 public Declaracion(Tipo tipo, List <string> ids, Instruccion op, int fila, int columna)
 {
     this.tipo    = tipo;
     this.ids     = ids;
     this.op      = op;
     this.fila    = fila;
     this.columna = columna;
 }
Exemplo n.º 15
0
 public For(Instruccion InsInicial, String nombreVarAsignacion, Expresion valorFinal, Bloque instrucciones, bool up_to)
 {
     this.InsInicial          = InsInicial;
     this.nombreVarAsignacion = nombreVarAsignacion;
     this.valorFinal          = valorFinal;
     this.instrucciones       = instrucciones;
     this.up_to = up_to;
 }
Exemplo n.º 16
0
 public Metodo(bool esVoid, string id, Instruccion decl_params, int cantidad_params, List <Instruccion> listaInstrucciones)
 {
     this.esVoid             = esVoid;
     this.id                 = id;
     this.decl_params        = decl_params;
     this.cantidad_params    = cantidad_params;
     this.listaInstrucciones = listaInstrucciones;
 }
Exemplo n.º 17
0
 public For(Instruccion inicio, Expresion condicion, Instruccion aumento, LinkedList <Instruccion> instruccions, int linea, int columna)
 {
     this.linea          = linea;
     this.columna        = columna;
     this.inicializacion = inicio;
     this.condicion      = condicion;
     this.actualizacion  = aumento;
     this.instrucciones  = instruccions;
 }
Exemplo n.º 18
0
 public For(Instruccion inicializacion, Expresion condicion, NodoAST actualizacion, LinkedList <NodoAST> sentencias, int fila, int columna)
 {
     this.inicializacion = inicializacion;
     this.condicion      = condicion;
     this.actualizacion  = actualizacion;
     this.sentencias     = sentencias;
     this.fila           = fila;
     this.columna        = columna;
 }
Exemplo n.º 19
0
 public static void nuevaInstruccion(Instruccion instruccion, bool unica)
 {
     if (!unica || OmegaUp.obtenerInstrucciones(instruccion).Count == 0)
     {
         OmegaUp o = new OmegaUp();
         o.instruccion = instruccion;
         o.guardarNuevo();
     }
 }
Exemplo n.º 20
0
 public object ejecutar(Entorno ent, AST arbol)
 {
     if ((bool)(Condicion.getValorImplicito(ent, arbol)))
     {
         // Si la condicion del if se cumple, entonces ejecuto las instrucciones.
         Entorno local = new Entorno(ent);
         foreach (NodoAST nodo in Instrucciones)
         {
             /*
              * Por la estructura utilizada, se debe verificar si el nodo es
              * una expresion o una instruccion, ya que se manejan de diferente forma.
              */
             if (nodo is Instruccion)
             {
                 Instruccion ins    = (Instruccion)nodo;
                 object      result = ins.ejecutar(local, arbol);
                 if (result != null)
                 {
                     return(result);
                 }
             }
             else if (nodo is Expresion)
             {
                 Expresion expr = (Expresion)nodo;
                 return(expr.getValorImplicito(local, arbol));
             }
         }
     }
     else
     {
         // Si la condicion del if NO se cumple, entonces ejecuto las instrucciones asociadas al Else.
         Entorno local = new Entorno(ent);
         foreach (NodoAST nodo in InstruccionesElse)
         {
             /*
              * Por la estructura utilizada, se debe verificar si el nodo es
              * una expresion o una instruccion, ya que se manejan de diferente forma.
              */
             if (nodo is Instruccion)
             {
                 Instruccion ins    = (Instruccion)nodo;
                 object      result = ins.ejecutar(local, arbol);
                 if (result != null)
                 {
                     return(result);
                 }
             }
             else if (nodo is Expresion)
             {
                 Expresion expr = (Expresion)nodo;
                 return(expr.getValorImplicito(local, arbol));
             }
         }
     }
     return(null);
 }
Exemplo n.º 21
0
        public object ejecutar(Entorno.Entorno ent)
        {
            Entorno.Entorno local  = new Entorno.Entorno(ent);
            object          inicio = this.inicializacion.ejecutar(local);

            while ((Boolean)this.condicion.getValor(local))
            {
                Entorno.Entorno local2 = new Entorno.Entorno(local);
                foreach (NodoAST nodo in this.sentencias)
                {
                    if (nodo is Instruccion)
                    {
                        Instruccion ins    = (Instruccion)nodo;
                        Object      result = ins.ejecutar(local);

                        if (result != null)
                        {
                            if (result is Break)
                            {
                                return(null);
                            }
                            else if (result is Continue)
                            {
                                goto siguiente;
                            }
                            else
                            {
                                return(result);
                            }
                        }
                    }
                    else if (nodo is Expresion)
                    {
                        Expresion expr = (Expresion)nodo;
                        Object    ret  = expr.getValor(local);
                        if (ret is Return)
                        {
                            return(ret);
                        }
                    }
                }
siguiente:
                if (actualizacion is Instruccion)
                {
                    Instruccion act    = (Instruccion)this.actualizacion;
                    Object      valact = act.ejecutar(local);
                }
                else if (actualizacion is Expresion)
                {
                    Expresion act    = (Expresion)this.actualizacion;
                    Object    valact = act.getValor(local);
                }
            }
            return(null);
        }
Exemplo n.º 22
0
 public DeclaracionMetodo(bool global, bool esVoid, string id, Instruccion decl_parametros, int fila, int columna)
 {
     this.global          = global;
     this.esVoid          = esVoid;
     this.id              = id;
     this.decl_parametros = decl_parametros;
     this.cantidad_params = ((Declaracion)decl_parametros).ids.Count;
     this.ins             = new List <Instruccion>();
     this.fila            = fila;
     this.columna         = columna;
 }
Exemplo n.º 23
0
        public static ZBool evaluarCondicion(Instruccion exp, ZContenedor e)
        {
            var algo      = exp.ejecutar(e);
            var condicion = desenvolver(algo);

            if (condicion is ZBool c)
            {
                return(c);
            }
            throw  new SemanticError("la expresion evaluada no es una condicion");
        }
 private void AnunciarJugadores(string origen, string destino, string numeroFaltante)
 {
     byte[] toSend = Instruccion.FormarTrama(
         Instruccion.FormarPrimerByte(origen, destino, Instruccion.PrimerByte.INICIAR_PARTIDA),
         Instruccion.FormarSegundoByte(
             Instruccion.SegundoByte.CONFIGURAR_PARTIDA + Instruccion.SegundoByte.ANUNCIAR,
             numeroFaltante));
     foreach (byte b in toSend)
     {
         Trace.WriteLine(Instruccion.ByteToString(b));
     }
     comPort.Write(toSend, 0, 4);
 }
Exemplo n.º 25
0
        private void btnRollDices_Click(object sender, EventArgs e)
        {
            this.btnRollDices.Enabled = false;
            Random randDado = new Random();

            numeroDado1 = randDado.Next(1, 7);
            numeroDado2 = randDado.Next(1, 7);
            dice1.Image = (Image)Properties.Resources.ResourceManager.GetObject("dado" + numeroDado1);
            dice2.Image = (Image)Properties.Resources.ResourceManager.GetObject("dado" + numeroDado2);

            string numeroDado1Byte = Instruccion.ByteToString(Convert.ToByte(numeroDado1));
            string numeroDado1Str  = numeroDado1Byte.Substring(5);
            string numeroDado2Byte = Instruccion.ByteToString(Convert.ToByte(numeroDado2));
            string numeroDado2Str  = numeroDado2Byte.Substring(5);

            this.btnFinalizarTurno.Enabled = true;
            lbxHistoria.Items.Add("Lanzar dados: " + Instruccion.ByteToString(Instruccion.FormarPrimerByte(jugadorLocal.GetIdAsString(), jugadorLocal.GetIdAsString(), Instruccion.PrimerByte.TIRAR_DADOS)));
            this.comPort.Write(Instruccion.FormarTrama(
                                   Instruccion.FormarPrimerByte(jugadorLocal.GetIdAsString(), jugadorLocal.GetIdAsString(), Instruccion.PrimerByte.TIRAR_DADOS),
                                   Instruccion.FormarSegundoByteDados(numeroDado1Str, numeroDado2Str)
                                   ), 0, 4);

            Square currentSquare = board.movePlayer(jugadorLocal, numeroDado1, numeroDado2);

            Trace.WriteLine("Current Position: " + jugadorLocal.getCurrentPosition());

            jugadorLocal.SetPoisitionX(currentSquare.GetPositionX());
            jugadorLocal.SetPoisitionY(currentSquare.GetPositionY());
            tablero.Invalidate();

            int resultado = currentSquare.doAction(jugadorLocal, board);

            Trace.WriteLine("New player money: " + jugadorLocal.getMoney().getMoney());
            // Esto estaba así en el board, no se si haga falta porque tal vez podamos validarlo dentro del doAction
            if (jugadorLocal.getMoney().isBrokeOut())
            {
                Trace.WriteLine(jugadorLocal, jugadorLocal.getName() + " has been broke out!");
                jugadorLocal.setBrokeOut(true);
            }
            actualizarDatosJugadorLocal();

            // Aquí empieza lo bueno
            if (resultado == 1)
            {
                Trace.WriteLine("Debería enviar el mensaje");
                this.comPort.Write(Instruccion.FormarTrama(
                                       Instruccion.FormarPrimerByte(jugadorLocal.GetIdAsString(), jugadorLocal.GetIdAsString(), Instruccion.PrimerByte.PROPIEDADES),
                                       Convert.ToByte("000" + board.GetHouseBits(jugadorLocal.getCurrentPosition()), 2)
                                       ), 0, 4);
            }
        }
Exemplo n.º 26
0
        public object ejecutar(Entorno.Entorno ent)
        {
            Object condicion_while = this.condicion.getValor(ent);

            if (condicion_while is Boolean)
            {
                do
                {
                    Entorno.Entorno local = new Entorno.Entorno(ent);
                    foreach (NodoAST nodo in this.sentencias)
                    {
                        if (nodo is Instruccion)
                        {
                            Instruccion ins = (Instruccion)nodo;

                            Object result = ins.ejecutar(local);
                            if (result != null)
                            {
                                if (result is Break)
                                {
                                    return(null);
                                }
                                else if (result is Continue)
                                {
                                    break;
                                }
                                else
                                {
                                    return(result);
                                }
                            }
                        }
                        else if (nodo is Expresion)
                        {
                            Expresion expr = (Expresion)nodo;
                            Object    ret  = expr.getValor(local);
                            if (ret is Return)
                            {
                                return(ret);
                            }
                        }
                    }
                } while ((Boolean)this.condicion.getValor(ent));
            }
            else
            {
                Estatico.errores.Add(new ErrorCQL("Semantico", "La expresion del Do_While no es booleana ", fila, columna));
            }
            return(null);
        }
Exemplo n.º 27
0
        public void EscribirLinea(ref ushort posicion)
        {
            if (lineas.Count > 0)
            {
                foreach (string[] linea in lineas)
                {
                    //forma fácil: escribir en memoria y en registro de instrucciones al mismo tiempo
                    //Main.AñadirInstruccionRegistroInstrucciones(FInstruccion.ConvertirEnInstruccion(UtilidadesInstruccion.ExtraerInstruccionArgumentos(linea[1])), posicion);

                    ushort pos = posicion;
                    Main.ObtenerMemoria.EscribirInstruccionMemoria(Instruccion.ConvertirEnInstruccion(UtilidadesInstruccion.ExtraerInstruccionArgumentos(linea[1])), ref posicion);
                    Main.AñadirInstruccionListaInstrucciones(UtilidadesInstruccion.DescodificarInstruccion(Main.ObtenerMemoria.ObtenerDireccion(pos).Contenido, pos), pos);
                }
            }
        }
Exemplo n.º 28
0
        public Instruccion DecodificaInstruccion(UInt32 instruccion)
        {
            Instruccion inst = new Instruccion();

            inst.opcode    = (byte)(instruccion >> 16);
            inst.direccion = (UInt16)(instruccion & 0xFFFF);
            inst.modo      = 0;

            if ((inst.direccion & 0x8000) != 0)
            {
                inst.direccion = (UInt16)(inst.direccion & 0x7FFF);
                inst.modo      = 1;
            }

            return(inst);
        }
Exemplo n.º 29
0
 public object ejecutar(Ambito amb, AST arbol)
 {
     if ((bool)(Condicion.getValorImplicito(amb, arbol)))
     {
         //Si se cumple
         Ambito local = new Ambito(amb);
         foreach (NodoAST nodo in condInstrucciones)
         {
             if (nodo is Instruccion)
             {
                 Instruccion ins    = (Instruccion)nodo;
                 object      result = ins.ejecutar(local, arbol);
                 if (result != null)
                 {
                     return(result);
                 }
             }
             else if (nodo is Exp)
             {
                 Exp expr = (Exp)nodo;
                 return(expr.getValorImplicito(local, arbol));
             }
         }
     }//Si no se cumple
     else
     {
         Ambito local = new Ambito(amb);
         foreach (NodoAST nodo in InstruccionesElse)
         {
             if (nodo is Instruccion)
             {
                 Instruccion ins    = (Instruccion)nodo;
                 object      result = ins.ejecutar(local, arbol);
                 if (result != null)
                 {
                     return(result);
                 }
             }
             else if (nodo is Exp)
             {
                 Exp expr = (Exp)nodo;
                 return(expr.getValorImplicito(local, arbol));
             }
         }
     }
     return(null);
 }
Exemplo n.º 30
0
        public static ZContenedor accederElementoLista(ZContenedor ambito, Instruccion exp1, Instruccion exp2)
        {
            var z1 = desenvolver(exp1.ejecutar(ambito));
            var z2 = desenvolver(exp2.ejecutar(ambito));

            if (!(z1 is ZLista zLista))
            {
                throw new SemanticError($"Operador de accesso [] no valido para acceder tipo '{z1.Origen.Nombre}' ");
            }

            if (!(z2 is ZNumero zNumero))
            {
                throw new SemanticError($"Operador de accesso [] tiene que tener valores enteros, no de tipo '{z2.Origen.Nombre}'");
            }

            return(zLista.obtenerElemento(zNumero.obtenerValor()));
        }
Exemplo n.º 31
0
 public static void inicializaCil()
 {
     cil = new Instruccion[maxnroDeInstrCorriente];
     for (int i = 0; i < maxnroDeInstrCorriente; i++)
     cil[i] = new Instruccion(AccionInstr.nop, 0, 0,"",
                              Code.BrtrueENUM.BEQenum, Code.BrfalseENUM.BEQenum, "");
 }