Example #1
0
        public override TiposBases ValidateSemantic()
        {
            var Izquierdo = OperadorIzquierdo.ValidateSemantic();
            var Derecho   = OperadorDerecho.ValidateSemantic();

            if (OperadorIzquierdo == null)
            {
                return(Derecho);
            }
            if (!(OperadorIzquierdo is IdentificadorNode))
            {
                throw new SemanticoException("no se puede asignar literales  fila " + _TOKEN.Fila + " columna " + _TOKEN.Columna);
            }
            if (!(Derecho is IntTipo))
            {
                throw new SemanticoException(" El incremeto debe ser de tipo int fila " + OperadorDerecho._TOKEN.Fila + " columna +" + OperadorDerecho._TOKEN.Columna);
            }
            if (Izquierdo is IntTipo || Izquierdo is CharTipo)
            {
                return(new IntTipo());
            }
            throw new SemanticoException("El tipo de dato no puede hacerse corrimiento Derecha  fila " + _TOKEN.Fila + " columna " + _TOKEN.Columna);
        }
        public override Implementacion.Value Interpret()
        {
            dynamic left  = OperadorIzquierdo.Interpret();
            dynamic right = OperadorDerecho.Interpret();

            if (!(right is IntValue))
            {
                if (left is IntValue)
                {
                    return new IntValue {
                               Value = (right as IntValue).Value >> (left as IntValue).Value
                    }
                }
                ;
                if (left is CharValue)
                {
                    return new IntValue {
                               Value = (right as CharValue).Value >> (left as IntValue).Value
                    }
                }
                ;
            }
            return(null);
        }
        public override TiposBases ValidateSemantic()
        {
            var expresion1 = OperadorDerecho.ValidateSemantic();

            if (OperadorIzquierdo == null)
            {
                return(expresion1);
            }
            if (!(OperadorIzquierdo is IdentificadorNode))
            {
                throw new SemanticoException("no se puede asignar literales  fila " + _TOKEN.Fila + " columna " + _TOKEN.Columna);
            }
            var expresion2 = OperadorIzquierdo.ValidateSemantic();

            if (expresion1 is BooleanTipo && expresion2 is BooleanTipo)
            {
                return(expresion1);
            }
            if (expresion2 is IntTipo && expresion1 is IntTipo)
            {
                return(new IntTipo());
            }
            throw new SemanticoException("no se puede auto operacion o logico no se puede  " + expresion1 + " con " + expresion2 + "fila " + _TOKEN.Fila + " columna " + _TOKEN.Columna);
        }
Example #4
0
        public override TiposBases ValidateSemantic()
        {
            var expresion1 = OperadorIzquierdo.ValidateSemantic();
            var expresion2 = OperadorDerecho.ValidateSemantic();


            if ((expresion1 is IntTipo || expresion1 is FloatTipo) && (expresion2 is FloatTipo || expresion2 is IntTipo))
            {
                if (expresion1.GetType() == expresion2.GetType())
                {
                    return(expresion1);
                }
            }
            if (expresion1 is FloatTipo || expresion2 is FloatTipo)
            {
                return(new FloatTipo());
            }
            if (expresion1 is IntTipo && expresion2 is IntTipo)
            {
                return(new IntTipo());
            }

            throw new SemanticoException("no se puede restar" + expresion1 + " con " + expresion2 + "fila " + _TOKEN.Fila + " columna " + _TOKEN.Columna);
        }
        public override Implementacion.Value Interpret()

        {
            var rightV = OperadorDerecho.Interpret();

            if (OperadorIzquierdo is IdentificadorNode)
            {
                var nombre = (OperadorIzquierdo as IdentificadorNode).value;
                foreach (var stack in ContenidoStack.InstanceStack.Stack)
                {
                    if (stack.VariableExist(nombre))
                    {
                        var valorID = stack.GetVariableValue(nombre);
                        if (valorID.GetType() == rightV.GetType())
                        {
                            stack.SetVariableValue(nombre, rightV);
                        }
                    }
                }
            }


            return(rightV);
        }
        public override Implementacion.Value Interpret()
        {
            Value  valorID = null;
            string nombre  = " ";

            if (OperadorIzquierdo is IdentificadorNode)
            {
                nombre = (OperadorIzquierdo as IdentificadorNode).value;
                foreach (var stack in ContenidoStack.InstanceStack.Stack)
                {
                    if (stack.VariableExist(nombre))
                    {
                        valorID = stack.GetVariableValue(nombre);
                    }
                }
            }
            var rightV = OperadorDerecho.Interpret();

            foreach (var stack in ContenidoStack.InstanceStack.Stack)
            {
                if (stack.VariableExist(nombre))
                {
                    if (valorID is StringValue && rightV is StringValue)
                    {
                        stack.SetVariableValue(nombre, new StringValue {
                            Value = (valorID as StringValue).Value + (rightV as StringValue).Value
                        });
                    }
                    if (valorID is StringValue && rightV is IntValue)
                    {
                        stack.SetVariableValue(nombre, new StringValue {
                            Value = (valorID as StringValue).Value + (rightV  as IntValue).Value
                        });
                    }
                    if (valorID is StringValue && rightV is FloatValue)
                    {
                        stack.SetVariableValue(nombre, new StringValue {
                            Value = (valorID as StringValue).Value + (rightV as FloatValue).Value
                        });
                    }
                    if (valorID is IntValue && rightV is FloatValue)
                    {
                        stack.SetVariableValue(nombre, new FloatValue {
                            Value = (valorID as IntValue).Value + (rightV as FloatValue).Value
                        });
                    }
                    if (valorID is FloatValue && rightV is IntValue)
                    {
                        stack.SetVariableValue(nombre, new FloatValue {
                            Value = (valorID as FloatValue).Value + (rightV as IntValue).Value
                        });
                    }
                    if (valorID is FloatValue && rightV is FloatValue)
                    {
                        stack.SetVariableValue(nombre, new FloatValue {
                            Value = (valorID as FloatValue).Value + (rightV as FloatValue).Value
                        });
                    }
                    if (valorID is IntValue && rightV is IntValue)
                    {
                        stack.SetVariableValue(nombre, new IntValue {
                            Value = (valorID as IntValue).Value + (rightV as IntValue).Value
                        });
                    }
                    if (valorID is StringValue && rightV is CharValue)
                    {
                        stack.SetVariableValue(nombre, new StringValue {
                            Value = (valorID as StringValue).Value + (rightV as CharValue).Value
                        });
                    }
                    if (valorID is CharValue && rightV is StringValue)
                    {
                        stack.SetVariableValue(nombre, new StringValue {
                            Value = (valorID as CharValue).Value + (rightV as StringValue).Value
                        });
                    }
                    if (valorID is IntValue && rightV is CharValue)
                    {
                        stack.SetVariableValue(nombre, new IntValue {
                            Value = (valorID as IntValue).Value + (rightV as CharValue).Value
                        });
                    }
                }
            }
            foreach (var stack in ContenidoStack.InstanceStack.Stack)
            {
                if (stack.VariableExist(nombre))
                {
                    valorID = stack.GetVariableValue(nombre);
                }
            }
            return(valorID);
        }
Example #7
0
        public override Implementacion.Value Interpret()
        {
            var leftV  = OperadorIzquierdo.Interpret();
            var rightV = OperadorDerecho.Interpret();

            if (leftV is CharValue && rightV is CharValue)
            {
                return new IntValue {
                           Value = (leftV as CharValue).Value + (rightV as CharValue).Value
                }
            }
            ;
            if (leftV is StringValue && rightV is StringValue)
            {
                return new StringValue {
                           Value = (leftV as StringValue).Value + (rightV as StringValue).Value
                }
            }
            ;
            if (leftV is FloatValue && rightV is IntValue)
            {
                return new FloatValue {
                           Value = (leftV as FloatValue).Value + (rightV as IntValue).Value
                }
            }
            ;
            if (leftV is IntValue && rightV is FloatValue)
            {
                return new FloatValue {
                           Value = (leftV as IntValue).Value + (rightV as FloatValue).Value
                }
            }
            ;
            if (leftV is FloatValue && rightV is FloatValue)
            {
                return new FloatValue {
                           Value = (leftV as FloatValue).Value + (rightV as FloatValue).Value
                }
            }
            ;
            if (leftV is StringValue && rightV is FloatValue)
            {
                return new StringValue {
                           Value = (leftV as StringValue).Value + (rightV as FloatValue).Value
                }
            }
            ;
            if (rightV is StringValue && leftV is FloatValue)
            {
                return new StringValue {
                           Value = (rightV as StringValue).Value + (leftV as FloatValue).Value
                }
            }
            ;
            if (rightV is StringValue && leftV is IntValue)
            {
                return new StringValue {
                           Value = (rightV as StringValue).Value + (leftV as IntValue).Value
                }
            }
            ;
            if (rightV is IntValue && leftV is StringValue)
            {
                return new StringValue {
                           Value = (rightV as IntValue).Value + (leftV as StringValue).Value
                }
            }
            ;
            if (leftV is IntValue && rightV is IntValue)
            {
                return new IntValue {
                           Value = (leftV as IntValue).Value + (rightV as IntValue).Value
                }
            }
            ;
            return(null);
        }