Ejemplo n.º 1
0
        public Retorno compilar(Entorno ent)
        {
            Generator generator = Generator.getInstance();

            this.trueLabel  = this.trueLabel == "" ? generator.newLabel() : this.trueLabel;
            this.falseLabel = this.falseLabel == "" ? generator.newLabel() : this.falseLabel;

            this.left.trueLabel   = this.right.trueLabel = this.trueLabel;
            this.left.falseLabel  = generator.newLabel();
            this.right.falseLabel = this.falseLabel;

            generator.addComment("Inicia Or");
            Retorno left = this.left.compilar(ent);

            generator.addLabel(this.left.falseLabel);
            Retorno right = this.right.compilar(ent);

            generator.addComment("Finaliza Or");

            Tipos tipoResultado = TablaTipos.obtenerTipo("or", left.type, right.type);

            if (tipoResultado == Tipos.ERROR)
            {
                throw new Error("Semántico", "No se puede evaluar un OR entre un " + left.type.tipoToString() + " y un " + right.type.tipoToString(), ent.obtenerAmbito(), linea, columna);
            }
            Tipo    tipo    = new Tipo(tipoResultado); //INTEGER o BOOLEAN
            Retorno retorno = new Retorno("", false, tipo);

            retorno.trueLabel  = this.trueLabel;
            retorno.falseLabel = this.right.falseLabel;
            return(retorno);
        }
Ejemplo n.º 2
0
        public Retorno compilar(Entorno ent)
        {
            Retorno left          = this.left.compilar(ent);
            Retorno right         = this.right.compilar(ent);
            Tipos   tipoResultado = TablaTipos.obtenerTipo("-", left.type, right.type);

            if (tipoResultado == Tipos.ERROR)
            {
                throw new Error("Semántico", "No se puede evaluar una resta entre un " + left.type.tipoToString() + " y un " + right.type.tipoToString(), ent.obtenerAmbito(), linea, columna);
            }
            Tipo      tipo      = new Tipo(tipoResultado);
            Generator generator = Generator.getInstance();
            string    temp      = generator.newTemporal();

            //INTEGER, REAL
            generator.addExpression(temp, left.getValue(), right.getValue(), "-");
            return(new Retorno(temp, true, tipo));
        }
Ejemplo n.º 3
0
        public Retorno compilar(Entorno ent)
        {
            Retorno left          = this.left.compilar(ent);
            Retorno right         = this.right.compilar(ent);
            Tipos   tipoResultado = TablaTipos.obtenerTipo("mod", left.type, right.type);

            if (tipoResultado == Tipos.ERROR)
            {
                throw new Error("Semántico", "No se puede evaluar un modulo entre un " + left.type.tipoToString() + " y un " + right.type.tipoToString(), ent.obtenerAmbito(), linea, columna);
            }
            Tipo      tipo      = new Tipo(tipoResultado);
            Generator generator = Generator.getInstance();
            string    temp      = generator.newTemporal();

            //INTEGER
            if (right.valorToString().Equals("0"))
            {
                throw new Error("Semántico", "Resultado indefinido, no se puede realizar un modulo entre 0", ent.obtenerAmbito(), linea, columna);
            }
            generator.addExpression(temp, left.getValue(), right.getValue(), "%");
            return(new Retorno(temp, true, tipo));
        }