public bool Visit(Program node)
        {
            Context.DefineSymbol("void", Context.GetType("Object"));
            foreach (Class_Def cldr in node.list)
            {
                if (!this.Visit(cldr))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public IType Visit(BinaryExpr node)
        {
            IType type_left  = this.Visit(node.left);
            IType type_rigth = this.Visit(node.right);

            List <string> arith_op = new List <string> {
                "+", "-", "*", "/"
            };
            List <string> comp_op = new List <string> {
                "<", "<="
            };
            List <string> basic_types = new List <string> {
                "Int", "Bool", "String", "Object"
            };

            // Es una operacion aritmetica o de comparacion
            if (arith_op.Contains(node.op) || comp_op.Contains(node.op))
            {
                if (type_left != null && type_left.Name != "Int")
                {
                    Logger += "En la expresion " + node.ToString() + "-> error de tipos (La expresion izquierda no es Int) \n";
                }
                if (type_rigth != null && type_rigth.Name != "Int")
                {
                    Logger += "En la expresion " + node.ToString() + "-> error de tipos (La expresion derecha no es Int) \n";
                }
                if (type_left == null || type_rigth == null)
                {
                    return(null);
                }

                if (type_left.Name != "Int" && type_rigth.Name != "Int")
                {
                    Logger += "En la expresion " + node.ToString() + "-> error de tipos (Las expresiones no son Int) \n";
                }

                if (arith_op.Contains(node.op))
                {
                    return(Context.GetType("Int"));
                }
                return(Context.GetType("Bool"));
            }

            // Es una operacion (=)

            if (type_left == null || type_rigth == null)
            {
                return(Context.GetType("Bool"));
            }

            bool is_built_in = basic_types.Contains(type_left.Name) || basic_types.Contains(type_rigth.Name);

            if (is_built_in && type_left.Name != type_rigth.Name)
            {
                Logger += "En la expresion " + node.ToString() + "-> error de tipos (Las expresiones no tienen el mismo tipo built-in) \n";
            }

            bool conform1 = type_left.Conform(type_rigth);
            bool conform2 = type_rigth.Conform(type_left);

            if (!is_built_in && !conform1 && !conform2)
            {
                Logger += "En la expresion " + node.ToString() + "-> error de tipos (Las expresiones no tienen tipos conformables)\n";
            }

            return(Context.GetType("Bool"));
        }